Logo ROOT   6.08/07
Reference Guide
TEvePolygonSetProjectedGL.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
14 #include "TEveVector.h"
15 
16 #include "TGLRnrCtx.h"
17 #include "TGLCamera.h"
18 #include "TGLPhysicalShape.h"
19 #include "TGLIncludes.h"
20 
21 /** \class TEvePolygonSetProjectedGL
22 \ingroup TEve
23 GL-renderer for TEvePolygonSetProjected class.
24 */
25 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Constructor
30 
32 {
33  // fDLCache = kFALSE; // Disable DL.
34  fMultiColor = kTRUE; // Potentially false, reset in DirectDraw().
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Set model object.
39 
41 {
42  fM = SetModelDynCast<TEvePolygonSetProjected>(obj);
43  return kTRUE;
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Setup bounding-box information.
48 
50 {
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Draw function for TEvePolygonSetProjectedGL.
56 /// Skips line-pass of outline mode.
57 
59 {
60  if (rnrCtx.IsDrawPassOutlineLine())
61  return;
62 
63  TGLObject::Draw(rnrCtx);
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Draw polygons outline.
68 
70 {
71  if (fM->fPols.size() == 0) return;
72 
73  Bool_t done_p = kFALSE;
74 
75  if (fM->GetMiniFrame())
76  {
77  std::map<Edge_t, Int_t> edges;
78 
80  i != fM->fPols.end(); ++i)
81  {
82  for(Int_t k = 0; k < i->fNPnts - 1; ++k)
83  {
84  ++edges[Edge_t(i->fPnts[k], i->fPnts[k+1])];
85  }
86  ++edges[Edge_t(i->fPnts[0], i->fPnts[i->fNPnts - 1])];
87  }
88 
89  glBegin(GL_LINES);
90  for (std::map<Edge_t, Int_t>::iterator i = edges.begin(); i != edges.end(); ++i)
91  {
92  if (i->second == 1)
93  {
94  glVertex3fv(fM->fPnts[i->first.fI].Arr());
95  glVertex3fv(fM->fPnts[i->first.fJ].Arr());
96  done_p = kTRUE;
97  }
98  }
99  glEnd();
100  }
101 
102  if ( ! done_p)
103  {
105  i != fM->fPols.end(); ++i)
106  {
107  glBegin(GL_LINE_LOOP);
108  for(Int_t k = 0; k < i->fNPnts; ++k)
109  {
110  glVertex3fv(fM->fPnts[i->fPnts[k]].Arr());
111  }
112  glEnd();
113  }
114  }
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Do GL rendering.
119 
121 {
122  if (fM->fPols.size() == 0) return;
123 
124  glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
125 
126  glDisable(GL_LIGHTING);
127  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
128  glEnable(GL_COLOR_MATERIAL);
129  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
130  glDisable(GL_CULL_FACE);
131 
132  // This tells TGLObject we don't want display-lists in some cases.
134 
135  // polygons
136  glEnable(GL_POLYGON_OFFSET_FILL);
137  glPolygonOffset(1, 1);
138  GLUtesselator *tessObj = TGLUtil::GetDrawTesselator3fv();
139 
140  TEveVector* pnts = fM->fPnts;
142  i != fM->fPols.end(); ++i)
143  {
144  Int_t vi; //current vertex index of curent polygon
145  Int_t pntsN = (*i).fNPnts; // number of points in current polygon
146  if (pntsN < 4)
147  {
148  glBegin(GL_POLYGON);
149  for (Int_t k = 0; k < pntsN; ++k)
150  {
151  vi = (*i).fPnts[k];
152  glVertex3fv(pnts[vi].Arr());
153  }
154  glEnd();
155  }
156  else
157  {
158  gluBeginPolygon(tessObj);
159  gluNextContour(tessObj, (GLenum)GLU_UNKNOWN);
160  glNormal3f(0, 0, 1);
161  Double_t coords[3];
162  coords[2] = 0;
163  for (Int_t k = 0; k < pntsN; ++k)
164  {
165  vi = (*i).fPnts[k];
166  coords[0] = pnts[vi].fX;
167  coords[1] = pnts[vi].fY;
168  gluTessVertex(tessObj, coords, pnts[vi].Arr());
169  }
170  gluEndPolygon(tessObj);
171  }
172  }
173  glDisable(GL_POLYGON_OFFSET_FILL);
174 
175  // Outline
176  if (fM->fDrawFrame)
177  {
179  glEnable(GL_LINE_SMOOTH);
181  DrawOutline();
182  }
183 
184  glPopAttrib();
185 }
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// Draw polygons in highlight mode.
189 
191 {
192  if (lvl < 0) lvl = pshp->GetSelected();
193 
194  glColor4ubv(rnrCtx.ColorSet().Selection(lvl).CArr());
196 
197  if (fM->GetHighlightFrame())
198  {
199  DrawOutline();
200  }
201  else
202  {
203  Draw(rnrCtx);
204  }
205 
207 }
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
static GLUtesselator * GetDrawTesselator3fv()
Returns a tesselator for direct drawing when using 3-vertices with single precision.
Definition: TGLUtil.cxx:1499
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition: TGLUtil.cxx:1658
const char Option_t
Definition: RtypesCore.h:62
TEvePolygonSetProjected * fM
virtual Bool_t SetModel(TObject *obj, const Option_t *opt=0)
Set model object.
void SetAxisAlignedBBox(Float_t xmin, Float_t xmax, Float_t ymin, Float_t ymax, Float_t zmin, Float_t zmax)
Set axis-aligned bounding-box.
Definition: TGLObject.cxx:86
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
GL-renderer for TEvePolygonSetProjected class.
Bool_t IsDrawPassOutlineLine() const
Definition: TGLRnrCtx.h:207
UChar_t GetSelected() const
Float_t fLineWidth
Definition: TEveShape.h:39
Concrete physical shape - a GL drawable.
const UChar_t * CArr() const
Definition: TGLUtil.h:803
virtual void DrawHighlight(TGLRnrCtx &rnrCtx, const TGLPhysicalShape *pshp, Int_t lvl=-1) const
Draw polygons in highlight mode.
Base-class for direct OpenGL renderers.
Definition: TGLObject.h:21
static UInt_t LockColor()
Prevent further color changes.
Definition: TGLUtil.cxx:1630
static UInt_t UnlockColor()
Allow color changes.
Definition: TGLUtil.cxx:1638
virtual void DirectDraw(TGLRnrCtx &rnrCtx) const
Do GL rendering.
const TT * Arr() const
Definition: TEveVector.h:45
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw function for TEvePolygonSetProjectedGL.
virtual void SetBBox()
Setup bounding-box information.
Bool_t fDrawFrame
Definition: TEveShape.h:41
#define ClassImp(name)
Definition: Rtypes.h:279
vpPolygon_t::const_iterator vpPolygon_ci
virtual Bool_t GetMiniFrame() const
Definition: TEveShape.h:57
double Double_t
Definition: RtypesCore.h:55
void DrawOutline() const
Draw polygons outline.
Bool_t fMultiColor
Definition: TGLObject.h:28
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw the GL drawable, using draw flags.
TGLColor & Selection(Int_t i)
Definition: TGLUtil.h:857
Float_t * AssertBBox()
Definition: TAttBBox.h:47
virtual Bool_t GetHighlightFrame() const
Definition: TEveShape.h:56
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition: TGLUtil.cxx:1904
Color_t fLineColor
Definition: TEveShape.h:38
TGLColorSet & ColorSet()
Return reference to current color-set (top of the stack).
Definition: TGLRnrCtx.cxx:278
const Bool_t kTRUE
Definition: Rtypes.h:91