Logo ROOT  
Reference Guide
TGLPolyMarker.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Timur Pocheptsov 03/08/2004
3// NOTE: This code moved from obsoleted TGLSceneObject.h / .cxx - see these
4// attic files for previous CVS history
5
6/*************************************************************************
7 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#include "TGLPolyMarker.h"
15#include "TGLRnrCtx.h"
16#include "TGLIncludes.h"
17#include "TGLUtil.h"
18
19#include "TBuffer3D.h"
20#include "TBuffer3DTypes.h"
21#include "TMath.h"
22
23#include "TAttMarker.h"
24
25// For debug tracing
26#include "TClass.h"
27#include "TError.h"
28
29/** \class TGLPolyMarker
30\ingroup opengl
31To draw a 3D polymarker in a GL window.
32*/
33
35
36////////////////////////////////////////////////////////////////////////////////
37///TAttMarker is not TObject descendant, so I need dynamic_cast
38
40 TGLLogicalShape(buffer),
41 fVertices(buffer.fPnts, buffer.fPnts + 3 * buffer.NbPnts()),
42 fStyle(7),
43 fSize(1.)
44{
45 if (TAttMarker *realObj = dynamic_cast<TAttMarker *>(buffer.fID)) {
46 fStyle = realObj->GetMarkerStyle();
47 fSize = realObj->GetMarkerSize() / 2.;
48 }
49}
50
51
52////////////////////////////////////////////////////////////////////////////////
53/// Debug tracing
54
56{
57 if (gDebug > 4) {
58 Info("TGLPolyMarker::DirectDraw", "this %zd (class %s) LOD %d", (size_t)this, IsA()->GetName(), rnrCtx.ShapeLOD());
59 }
60
62 return;
63
64 const Double_t *vertices = &fVertices[0];
65 UInt_t size = fVertices.size();
66 Int_t stacks = 6, slices = 6;
67 Float_t pixelSize = 1;
68 Double_t topRadius = fSize;
69
70 switch (fStyle) {
71 case 27:
72 stacks = 2, slices = 4;
73 // intentionally no break
74 case 4:case 8:case 20:case 24:
75 for (UInt_t i = 0; i < size; i += 3) {
76 glPushMatrix();
77 glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
78 gluSphere(rnrCtx.GetGluQuadric(), fSize, slices, stacks);
79 glPopMatrix();
80 }
81 break;
82 case 22:case 26:
83 topRadius = 0.;
84 // intentionally no break
85 case 21:case 25:
86 for (UInt_t i = 0; i < size; i += 3) {
87 glPushMatrix();
88 glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
89 gluCylinder(rnrCtx.GetGluQuadric(), fSize, topRadius, fSize, 4, 1);
90 glPopMatrix();
91 }
92 break;
93 case 23:
94 for (UInt_t i = 0; i < size; i += 3) {
95 glPushMatrix();
96 glTranslated(vertices[i], vertices[i + 1], vertices[i + 2]);
97 glRotated(180, 1., 0., 0.);
98 gluCylinder(rnrCtx.GetGluQuadric(), fSize, 0., fSize, 4, 1);
99 glPopMatrix();
100 }
101 break;
102 case 3: case 2: case 5:
103 DrawStars();
104 break;
105 case 7:
106 pixelSize += 1;
107 // intentionally no break
108 case 6:
109 pixelSize += 1;
110 // intentionally no break
111 case 1: case 9: case 10: case 11: default:
112 TGLUtil::PointSize(pixelSize);
113 glBegin(GL_POINTS);
114 for (UInt_t i = 0; i < size; i += 3)
115 glVertex3dv(vertices + i);
116 glEnd();
117 break;
118 }
119}
120
121
122////////////////////////////////////////////////////////////////////////////////
123/// Draw stars
124
126{
127 glDisable(GL_LIGHTING);
128 const Double_t diag = TMath::Sqrt(2 * fSize * fSize) / 2;
129
130 for (UInt_t i = 0; i < fVertices.size(); i += 3) {
131 Double_t x = fVertices[i];
132 Double_t y = fVertices[i + 1];
133 Double_t z = fVertices[i + 2];
134 glBegin(GL_LINES);
135 if (fStyle == 2 || fStyle == 3) {
136 glVertex3d(x - fSize, y, z);
137 glVertex3d(x + fSize, y, z);
138 glVertex3d(x, y, z - fSize);
139 glVertex3d(x, y, z + fSize);
140 glVertex3d(x, y - fSize, z);
141 glVertex3d(x, y + fSize, z);
142 }
143 if(fStyle != 2) {
144 glVertex3d(x - diag, y - diag, z - diag);
145 glVertex3d(x + diag, y + diag, z + diag);
146 glVertex3d(x - diag, y - diag, z + diag);
147 glVertex3d(x + diag, y + diag, z - diag);
148 glVertex3d(x - diag, y + diag, z - diag);
149 glVertex3d(x + diag, y - diag, z + diag);
150 glVertex3d(x - diag, y + diag, z + diag);
151 glVertex3d(x + diag, y - diag, z - diag);
152 }
153 glEnd();
154 }
155 glEnable(GL_LIGHTING);
156}
int Int_t
Definition: CPyCppyy.h:43
unsigned int UInt_t
Definition: CPyCppyy.h:44
size_t fSize
#define GL_LINES
Definition: GL_glu.h:284
#define GL_POINTS
Definition: GL_glu.h:283
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
double Double_t
Definition: RtypesCore.h:59
float Float_t
Definition: RtypesCore.h:57
#define ClassImp(name)
Definition: Rtypes.h:364
Int_t gDebug
Definition: TROOT.cxx:589
Marker Attributes class.
Definition: TAttMarker.h:19
Generic 3D primitive description class.
Definition: TBuffer3D.h:18
TObject * fID
Definition: TBuffer3D.h:87
Abstract logical shape - a GL 'drawable' - base for all shapes - faceset sphere etc.
To draw a 3D polymarker in a GL window.
Definition: TGLPolyMarker.h:25
virtual void DirectDraw(TGLRnrCtx &rnrCtx) const
Debug tracing.
std::vector< Double_t > fVertices
Definition: TGLPolyMarker.h:27
TGLPolyMarker(const TBuffer3D &buffer)
TAttMarker is not TObject descendant, so I need dynamic_cast.
Double_t fSize
Definition: TGLPolyMarker.h:29
void DrawStars() const
Draw stars.
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:41
GLUquadric * GetGluQuadric()
Initialize fQuadric.
Definition: TGLRnrCtx.cxx:403
Short_t DrawPass() const
Definition: TGLRnrCtx.h:204
@ kPassOutlineLine
Definition: TGLRnrCtx.h:57
Short_t ShapeLOD() const
Definition: TGLRnrCtx.h:177
static Float_t PointSize()
Get the point-size, taking the global scaling into account.
Definition: TGLUtil.cxx:1929
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
void Info(const char *location, const char *va_(fmt),...)
Definition: TClingUtils.h:809
Double_t Sqrt(Double_t x)
Definition: TMath.h:691