Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
26 ClassImp(TEvePolygonSetProjectedGL);
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Constructor
30 
31 TEvePolygonSetProjectedGL::TEvePolygonSetProjectedGL() : TGLObject()
32 {
33  // fDLCache = kFALSE; // Disable DL.
34  fMultiColor = kTRUE; // Potentially false, reset in DirectDraw().
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Set model object.
39 
40 Bool_t TEvePolygonSetProjectedGL::SetModel(TObject* obj, const Option_t* /*opt*/)
41 {
42  fM = SetModelDynCast<TEvePolygonSetProjected>(obj);
43  return kTRUE;
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Setup bounding-box information.
48 
49 void TEvePolygonSetProjectedGL::SetBBox()
50 {
51  SetAxisAlignedBBox(fM->AssertBBox());
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Draw function for TEvePolygonSetProjectedGL.
56 /// Skips line-pass of outline mode.
57 
58 void TEvePolygonSetProjectedGL::Draw(TGLRnrCtx& rnrCtx) const
59 {
60  if (rnrCtx.IsDrawPassOutlineLine())
61  return;
62 
63  TGLObject::Draw(rnrCtx);
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Draw polygons outline.
68 
69 void TEvePolygonSetProjectedGL::DrawOutline() const
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 
79  for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
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  {
104  for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
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 
120 void TEvePolygonSetProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
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.
133  fMultiColor = fM->fDrawFrame;
134 
135  // polygons
136  glEnable(GL_POLYGON_OFFSET_FILL);
137  glPolygonOffset(1, 1);
138  GLUtesselator *tessObj = TGLUtil::GetDrawTesselator3fv();
139 
140  TEveVector* pnts = fM->fPnts;
141  for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin();
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  {
178  TGLUtil::Color(fM->fLineColor);
179  glEnable(GL_LINE_SMOOTH);
180  TGLUtil::LineWidth(fM->fLineWidth);
181  DrawOutline();
182  }
183 
184  glPopAttrib();
185 }
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// Draw polygons in highlight mode.
189 
190 void TEvePolygonSetProjectedGL::DrawHighlight(TGLRnrCtx& rnrCtx, const TGLPhysicalShape* pshp, Int_t lvl) const
191 {
192  if (lvl < 0) lvl = pshp->GetSelected();
193 
194  glColor4ubv(rnrCtx.ColorSet().Selection(lvl).CArr());
195  TGLUtil::LockColor();
196 
197  if (fM->GetHighlightFrame())
198  {
199  DrawOutline();
200  }
201  else
202  {
203  Draw(rnrCtx);
204  }
205 
206  TGLUtil::UnlockColor();
207 }