ROOT logo
// @(#)root/gl:$Id$
// Author:  Timur Pocheptsov  03/08/2004
// NOTE: This code moved from obsoleted TGLSceneObject.h / .cxx - see these
// attic files for previous CVS history

/*************************************************************************
 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TGLPolyMarker.h"
#include "TGLRnrCtx.h"
#include "TGLIncludes.h"
#include "TGLUtil.h"

#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TMath.h"

#include "TAttMarker.h"

// For debug tracing
#include "TClass.h"
#include "TError.h"

//______________________________________________________________________________
/* Begin_Html
<center><h2>GL Polymarker</h2></center>
To draw a 3D polymarker in a GL window.
End_Html */

ClassImp(TGLPolyMarker)

//______________________________________________________________________________
TGLPolyMarker::TGLPolyMarker(const TBuffer3D & buffer) :
   TGLLogicalShape(buffer),
   fVertices(buffer.fPnts, buffer.fPnts + 3 * buffer.NbPnts()),
   fStyle(7),
   fSize(1.)
{
   //TAttMarker is not TObject descendant, so I need dynamic_cast
   if (TAttMarker *realObj = dynamic_cast<TAttMarker *>(buffer.fID)) {
      fStyle = realObj->GetMarkerStyle();
      fSize  = realObj->GetMarkerSize() / 2.;
   }
}


//______________________________________________________________________________
void TGLPolyMarker::DirectDraw(TGLRnrCtx & rnrCtx) const
{
   // Debug tracing
   if (gDebug > 4) {
      Info("TGLPolyMarker::DirectDraw", "this %ld (class %s) LOD %d", (Long_t)this, IsA()->GetName(), rnrCtx.ShapeLOD());
   }

   if (rnrCtx.DrawPass() == TGLRnrCtx::kPassOutlineLine)
      return;

   const Double_t *vertices = &fVertices[0];
   UInt_t size = fVertices.size();
   Int_t stacks = 6, slices = 6;
   Float_t pixelSize  = 1;
   Double_t topRadius = fSize;

   switch (fStyle) {
   case 27:
      stacks = 2, slices = 4;
      // intentionaly no break
   case 4:case 8:case 20:case 24:
      for (UInt_t i = 0; i < size; i += 3) {
         glPushMatrix();
         glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
         gluSphere(rnrCtx.GetGluQuadric(), fSize, slices, stacks);
         glPopMatrix();
      }
      break;
   case 22:case 26:
      topRadius = 0.;
      // intentionaly no break
   case 21:case 25:
      for (UInt_t i = 0; i < size; i += 3) {
         glPushMatrix();
         glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
         gluCylinder(rnrCtx.GetGluQuadric(), fSize, topRadius, fSize, 4, 1);
         glPopMatrix();
      }
      break;
   case 23:
      for (UInt_t i = 0; i < size; i += 3) {
         glPushMatrix();
         glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
         glRotated(180, 1., 0., 0.);
         gluCylinder(rnrCtx.GetGluQuadric(), fSize, 0., fSize, 4, 1);
         glPopMatrix();
      }
      break;
   case 3: case 2: case 5:
      DrawStars();
      break;
   case 7:
      pixelSize += 1;
      // intentionaly no break
   case 6:
      pixelSize += 1;
      // intentionaly no break
   case 1: case 9: case 10: case 11: default:
      TGLUtil::PointSize(pixelSize);
      glBegin(GL_POINTS);
      for (UInt_t i = 0; i < size; i += 3)
         glVertex3dv(vertices + i);
      glEnd();
      break;
   }
}


//______________________________________________________________________________
void TGLPolyMarker::DrawStars()const
{
   // Draw stars
   glDisable(GL_LIGHTING);
   const Double_t diag = TMath::Sqrt(2 * fSize * fSize) / 2;

   for (UInt_t i = 0; i < fVertices.size(); i += 3) {
      Double_t x = fVertices[i];
      Double_t y = fVertices[i + 1];
      Double_t z = fVertices[i + 2];
      glBegin(GL_LINES);
      if (fStyle == 2 || fStyle == 3) {
         glVertex3d(x - fSize, y, z);
         glVertex3d(x + fSize, y, z);
         glVertex3d(x, y, z - fSize);
         glVertex3d(x, y, z + fSize);
         glVertex3d(x, y - fSize, z);
         glVertex3d(x, y + fSize, z);
      }
      if(fStyle != 2) {
         glVertex3d(x - diag, y - diag, z - diag);
         glVertex3d(x + diag, y + diag, z + diag);
         glVertex3d(x - diag, y - diag, z + diag);
         glVertex3d(x + diag, y + diag, z - diag);
         glVertex3d(x - diag, y + diag, z - diag);
         glVertex3d(x + diag, y - diag, z + diag);
         glVertex3d(x - diag, y + diag, z + diag);
         glVertex3d(x + diag, y - diag, z - diag);
      }
      glEnd();
   }
   glEnable(GL_LIGHTING);
}
 TGLPolyMarker.cxx:1
 TGLPolyMarker.cxx:2
 TGLPolyMarker.cxx:3
 TGLPolyMarker.cxx:4
 TGLPolyMarker.cxx:5
 TGLPolyMarker.cxx:6
 TGLPolyMarker.cxx:7
 TGLPolyMarker.cxx:8
 TGLPolyMarker.cxx:9
 TGLPolyMarker.cxx:10
 TGLPolyMarker.cxx:11
 TGLPolyMarker.cxx:12
 TGLPolyMarker.cxx:13
 TGLPolyMarker.cxx:14
 TGLPolyMarker.cxx:15
 TGLPolyMarker.cxx:16
 TGLPolyMarker.cxx:17
 TGLPolyMarker.cxx:18
 TGLPolyMarker.cxx:19
 TGLPolyMarker.cxx:20
 TGLPolyMarker.cxx:21
 TGLPolyMarker.cxx:22
 TGLPolyMarker.cxx:23
 TGLPolyMarker.cxx:24
 TGLPolyMarker.cxx:25
 TGLPolyMarker.cxx:26
 TGLPolyMarker.cxx:27
 TGLPolyMarker.cxx:28
 TGLPolyMarker.cxx:29
 TGLPolyMarker.cxx:30
 TGLPolyMarker.cxx:31
 TGLPolyMarker.cxx:32
 TGLPolyMarker.cxx:33
 TGLPolyMarker.cxx:34
 TGLPolyMarker.cxx:35
 TGLPolyMarker.cxx:36
 TGLPolyMarker.cxx:37
 TGLPolyMarker.cxx:38
 TGLPolyMarker.cxx:39
 TGLPolyMarker.cxx:40
 TGLPolyMarker.cxx:41
 TGLPolyMarker.cxx:42
 TGLPolyMarker.cxx:43
 TGLPolyMarker.cxx:44
 TGLPolyMarker.cxx:45
 TGLPolyMarker.cxx:46
 TGLPolyMarker.cxx:47
 TGLPolyMarker.cxx:48
 TGLPolyMarker.cxx:49
 TGLPolyMarker.cxx:50
 TGLPolyMarker.cxx:51
 TGLPolyMarker.cxx:52
 TGLPolyMarker.cxx:53
 TGLPolyMarker.cxx:54
 TGLPolyMarker.cxx:55
 TGLPolyMarker.cxx:56
 TGLPolyMarker.cxx:57
 TGLPolyMarker.cxx:58
 TGLPolyMarker.cxx:59
 TGLPolyMarker.cxx:60
 TGLPolyMarker.cxx:61
 TGLPolyMarker.cxx:62
 TGLPolyMarker.cxx:63
 TGLPolyMarker.cxx:64
 TGLPolyMarker.cxx:65
 TGLPolyMarker.cxx:66
 TGLPolyMarker.cxx:67
 TGLPolyMarker.cxx:68
 TGLPolyMarker.cxx:69
 TGLPolyMarker.cxx:70
 TGLPolyMarker.cxx:71
 TGLPolyMarker.cxx:72
 TGLPolyMarker.cxx:73
 TGLPolyMarker.cxx:74
 TGLPolyMarker.cxx:75
 TGLPolyMarker.cxx:76
 TGLPolyMarker.cxx:77
 TGLPolyMarker.cxx:78
 TGLPolyMarker.cxx:79
 TGLPolyMarker.cxx:80
 TGLPolyMarker.cxx:81
 TGLPolyMarker.cxx:82
 TGLPolyMarker.cxx:83
 TGLPolyMarker.cxx:84
 TGLPolyMarker.cxx:85
 TGLPolyMarker.cxx:86
 TGLPolyMarker.cxx:87
 TGLPolyMarker.cxx:88
 TGLPolyMarker.cxx:89
 TGLPolyMarker.cxx:90
 TGLPolyMarker.cxx:91
 TGLPolyMarker.cxx:92
 TGLPolyMarker.cxx:93
 TGLPolyMarker.cxx:94
 TGLPolyMarker.cxx:95
 TGLPolyMarker.cxx:96
 TGLPolyMarker.cxx:97
 TGLPolyMarker.cxx:98
 TGLPolyMarker.cxx:99
 TGLPolyMarker.cxx:100
 TGLPolyMarker.cxx:101
 TGLPolyMarker.cxx:102
 TGLPolyMarker.cxx:103
 TGLPolyMarker.cxx:104
 TGLPolyMarker.cxx:105
 TGLPolyMarker.cxx:106
 TGLPolyMarker.cxx:107
 TGLPolyMarker.cxx:108
 TGLPolyMarker.cxx:109
 TGLPolyMarker.cxx:110
 TGLPolyMarker.cxx:111
 TGLPolyMarker.cxx:112
 TGLPolyMarker.cxx:113
 TGLPolyMarker.cxx:114
 TGLPolyMarker.cxx:115
 TGLPolyMarker.cxx:116
 TGLPolyMarker.cxx:117
 TGLPolyMarker.cxx:118
 TGLPolyMarker.cxx:119
 TGLPolyMarker.cxx:120
 TGLPolyMarker.cxx:121
 TGLPolyMarker.cxx:122
 TGLPolyMarker.cxx:123
 TGLPolyMarker.cxx:124
 TGLPolyMarker.cxx:125
 TGLPolyMarker.cxx:126
 TGLPolyMarker.cxx:127
 TGLPolyMarker.cxx:128
 TGLPolyMarker.cxx:129
 TGLPolyMarker.cxx:130
 TGLPolyMarker.cxx:131
 TGLPolyMarker.cxx:132
 TGLPolyMarker.cxx:133
 TGLPolyMarker.cxx:134
 TGLPolyMarker.cxx:135
 TGLPolyMarker.cxx:136
 TGLPolyMarker.cxx:137
 TGLPolyMarker.cxx:138
 TGLPolyMarker.cxx:139
 TGLPolyMarker.cxx:140
 TGLPolyMarker.cxx:141
 TGLPolyMarker.cxx:142
 TGLPolyMarker.cxx:143
 TGLPolyMarker.cxx:144
 TGLPolyMarker.cxx:145
 TGLPolyMarker.cxx:146
 TGLPolyMarker.cxx:147
 TGLPolyMarker.cxx:148
 TGLPolyMarker.cxx:149
 TGLPolyMarker.cxx:150
 TGLPolyMarker.cxx:151
 TGLPolyMarker.cxx:152
 TGLPolyMarker.cxx:153
 TGLPolyMarker.cxx:154