ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TEveJetConeGL.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel, Jochen Thaeder 2009
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 
12 #include "TEveJetConeGL.h"
13 #include "TEveJetCone.h"
14 #include "TEveProjectionManager.h"
15 
16 #include "TMath.h"
17 
18 #include "TGLRnrCtx.h"
19 #include "TGLIncludes.h"
20 
21 /** \class TEveJetConeGL
22 \ingroup TEve
23 OpenGL renderer class for TEveJetCone.
24 */
25 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Constructor.
30 
32  TGLObject(), fC(0)
33 {
34  // fDLCache = kFALSE; // Disable display list.
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Set model object.
39 
41 {
42  fC = SetModelDynCast<TEveJetCone>(obj);
43  return kTRUE;
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Set bounding box.
48 
50 {
51  SetAxisAlignedBBox(((TEveJetCone*)fExternalObj)->AssertBBox());
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Clear DL cache and reset internal point array.
56 
58 {
59  fP.clear();
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Calculate points for drawing.
65 
67 {
68  assert(fC->fNDiv > 2);
69 
70  const Int_t NP = fC->fNDiv;
71  fP.resize(NP);
72  {
73  Float_t angle_step = TMath::TwoPi() / NP;
74  Float_t angle = 0;
75  for (Int_t i = 0; i < NP; ++i, angle += angle_step)
76  {
77  fP[i] = fC->CalcBaseVec(angle);
78  }
79  }
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Draw the cone.
84 
85 void TEveJetConeGL::Draw(TGLRnrCtx& rnrCtx) const
86 {
87  if (fP.empty()) CalculatePoints();
88 
89  if (fC->fHighlightFrame && rnrCtx.Highlight())
90  {
91  glPushAttrib(GL_ENABLE_BIT);
92  glDisable(GL_LIGHTING);
93 
94  if (fC->fDrawFrame)
95  {
98  }
99 
100  const Int_t NP = fP.size();
101  glBegin(GL_LINE_LOOP);
102  for (Int_t i = 0; i < NP; ++i)
103  glVertex3fv(fP[i]);
104  glEnd();
105  glBegin(GL_LINES);
106  Double_t angle = 0;
107  for (Int_t i = 0; i < 4; ++i, angle += TMath::PiOver2())
108  {
109  glVertex3fv(fC->fApex);
110  glVertex3fv(fC->CalcBaseVec(angle));
111  }
112  glEnd();
113 
114  glPopAttrib();
115  }
116  else
117  {
118  TGLObject::Draw(rnrCtx);
119  }
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Render with OpenGL.
124 
125 void TEveJetConeGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
126 {
127  // printf("TEveJetConeGL::DirectDraw LOD %d\n", rnrCtx.CombiLOD());
128 
129  glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LIGHTING_BIT);
130 
131  glDisable(GL_CULL_FACE);
132  glEnable(GL_NORMALIZE);
133  Int_t lmts = 1;
134  glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE, &lmts);
135 
136  const Int_t NP = fC->fNDiv;
137  Int_t prev = NP - 1;
138  Int_t i = 0;
139  Int_t next = 1;
140 
141  TEveVector curr_normal;
142  TEveVector prev_normal;
143  TMath::Cross((fP[next] - fP[prev]).Arr(), (fP[i] - fC->fApex).Arr(), prev_normal.Arr());
144 
145  prev = i; i = next; ++next;
146 
147  glBegin(GL_TRIANGLES);
148  do
149  {
150  TMath::Cross((fP[next] - fP[prev]).Arr(), (fP[i] - fC->fApex).Arr(), curr_normal.Arr());
151 
152  glNormal3fv(prev_normal);
153  glVertex3fv(fP[prev]);
154 
155  glNormal3fv(prev_normal + curr_normal);
156  glVertex3fv(fC->fApex);
157 
158  glNormal3fv(curr_normal);
159  glVertex3fv(fP[i]);
160 
161  prev_normal = curr_normal;
162 
163  prev = i;
164  i = next;
165  ++next; if (next >= NP) next = 0;
166  } while (prev != 0);
167  glEnd();
168 
169  glPopAttrib();
170 }
171 
172 /** \class TEveJetConeProjectedGL
173 \ingroup TEve
174 OpenGL renderer class for TEveJetConeProjected.
175 */
176 
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Constructor.
181 
183  TEveJetConeGL(), fM(0)
184 {
185  // fDLCache = kFALSE; // Disable display list.
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Set model object.
190 
192 {
193  fM = SetModelDynCast<TEveJetConeProjected>(obj);
194  fC = dynamic_cast<TEveJetCone*>(fM->GetProjectable());
195  return fC != 0;
196 }
197 
198 ////////////////////////////////////////////////////////////////////////////////
199 /// Set bounding box.
200 
202 {
204 }
205 
206 namespace
207 {
208  struct less_eve_vec_phi_t
209  {
210  bool operator()(const TEveVector& a, const TEveVector& b)
211  { return a.Phi() < b.Phi(); }
212  };
213 }
214 
215 ////////////////////////////////////////////////////////////////////////////////
216 /// Calculate points for drawing.
217 
219 {
220  static const TEveException kEH("TEveJetConeProjectedGL::CalculatePoints ");
221 
222  fP.resize(3);
223 
225 
226  switch (proj->GetType())
227  {
229  {
230  fP[0] = fC->fApex;
232  fP[2] = fC->CalcBaseVec(TMath::PiOver2());
233 
234  for (Int_t i = 0; i < 3; ++i)
235  proj->ProjectVector(fP[i], fM->fDepth);
236 
237  break;
238  }
239 
241  {
242  fP[0] = fC->fApex;
243  fP[1] = fC->CalcBaseVec(0);
244  fP[2] = fC->CalcBaseVec(TMath::Pi());
245 
246  Float_t tm = fP[1].Theta();
247  Float_t tM = fP[2].Theta();
248 
249  if (tM > fC->fThetaC && tm < fC->fThetaC)
250  {
251  fP.reserve(fP.size() + 1);
252  TEveVector v(0, fC->fLimits.fY, fC->fLimits.fZ);
253  fP.push_back(fC->CalcBaseVec(v.Eta(), fC->fPhi));
254  }
255 
256  if (tM > TMath::Pi() - fC->fThetaC && tm < TMath::Pi() - fC->fThetaC)
257  {
258  fP.reserve(fP.size() + 1);
259  TEveVector v(0, fC->fLimits.fY, -fC->fLimits.fZ);
260  fP.push_back(fC->CalcBaseVec(v.Eta(), fC->fPhi));
261  }
262 
263  const Int_t NP = fP.size();
264  for (Int_t i = 0; i < NP; ++i)
265  proj->ProjectVector(fP[i], fM->fDepth);
266 
267  std::sort(fP.begin() + 1, fP.end(), less_eve_vec_phi_t());
268 
269  break;
270  }
271 
272  default:
273  throw kEH + "Unsupported projection type.";
274  }
275 
276 }
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Draw jet outline.
280 
282 {
283  const Int_t NP = fP.size();
284  glBegin(GL_LINE_LOOP);
285  for (Int_t i = 0; i < NP; ++i)
286  {
287  glVertex3fv(fP[i].Arr());
288  }
289  glEnd();
290 }
291 
292 ////////////////////////////////////////////////////////////////////////////////
293 /// Draw jet surface.
294 
296 {
297  const Int_t NP = fP.size();
298  glBegin(GL_POLYGON);
299  for (Int_t i = 0; i < NP; ++i)
300  {
301  glVertex3fv(fP[i].Arr());
302  }
303  glEnd();
304 }
305 
306 ////////////////////////////////////////////////////////////////////////////////
307 /// Draw the cone.
308 
310 {
311  if (fP.empty()) CalculatePoints();
312 
313  if (rnrCtx.IsDrawPassOutlineLine())
314  {
315  RenderOutline();
316  }
317  else if (fM->fHighlightFrame && rnrCtx.Highlight())
318  {
319  if (fM->fDrawFrame)
320  {
323  }
324  RenderOutline();
325  }
326  else
327  {
328  TGLObject::Draw(rnrCtx);
329  }
330 }
331 
332 ////////////////////////////////////////////////////////////////////////////////
333 /// Render with OpenGL.
334 
336 {
337  // printf("TEveJetConeProjectedGL::DirectDraw LOD %d\n", rnrCtx.CombiLOD());
338 
340 
341  glPushAttrib(GL_ENABLE_BIT);
342  glDisable(GL_LIGHTING);
343 
344  if (fM->fDrawFrame)
345  {
346  glEnable(GL_POLYGON_OFFSET_FILL);
347  glPolygonOffset(1.0f, 1.0f);
348  }
349 
350  RenderPolygon();
351 
352  if (fM->fDrawFrame)
353  {
354  glEnable(GL_LINE_SMOOTH);
355 
358  RenderOutline();
359  }
360 
361  glPopAttrib();
362 }
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
TEveJetConeProjectedGL()
Constructor.
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition: TGLUtil.cxx:1658
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
TEveVector fApex
Definition: TEveJetCone.h:34
#define assert(cond)
Definition: unittest.h:542
Color_t fFillColor
Definition: TEveShape.h:37
Draws a jet cone with leading particle is specified in (eta,phi) and cone radius is given...
Definition: TEveJetCone.h:23
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
TArc * a
Definition: textangle.C:12
TEveProjectable * GetProjectable() const
Bool_t fHighlightFrame
Definition: TEveShape.h:42
virtual void DirectDraw(TGLRnrCtx &rnrCtx) const
Render with OpenGL.
EPType_e GetType() const
TFile * f
Float_t fLineWidth
Definition: TEveShape.h:39
OpenGL renderer class for TEveJetConeProjected.
Definition: TEveJetConeGL.h:59
virtual void DLCacheClear()
Clear DL cache and reset internal point array.
Bool_t Highlight() const
Definition: TGLRnrCtx.h:218
virtual Bool_t SetModel(TObject *obj, const Option_t *opt=0)
Set model object.
Projection of TEveJetCone.
Definition: TEveJetCone.h:72
void RenderOutline() const
Draw jet outline.
Base-class for direct OpenGL renderers.
Definition: TGLObject.h:21
void ProjectVector(TEveVector &v, Float_t d)
Project TEveVector.
Base-class for non-linear projections.
Float_t fPhi
Definition: TEveJetCone.h:38
Double_t TwoPi()
Definition: TMath.h:45
virtual void CalculatePoints() const
Calculate points for drawing.
TObject * fExternalObj
first replica
TT Eta() const
Calculate eta of the point, pretending it's a momentum vector.
Definition: TEveVector.cxx:44
virtual void SetBBox()
Set bounding box.
void RenderPolygon() const
Draw jet surface.
virtual void SetBBox()
Set bounding box.
SVector< double, 2 > v
Definition: Dict.h:5
std::vector< TEveVector > fP
Definition: TEveJetConeGL.h:36
Float_t fThetaC
Definition: TEveJetCone.h:37
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw the GL drawable, using draw flags.
Bool_t IsDrawPassOutlineLine() const
Definition: TGLRnrCtx.h:207
const TT * Arr() const
Definition: TEveVector.h:45
TT Phi() const
Definition: TEveVector.h:99
T * Cross(const T v1[3], const T v2[3], T out[3])
Definition: TMath.h:1020
TEveJetConeProjected * fM
Definition: TEveJetConeGL.h:66
TEveJetConeGL()
Constructor.
virtual Bool_t SetModel(TObject *obj, const Option_t *opt=0)
Set model object.
Double_t Pi()
Definition: TMath.h:44
TEveProjection * GetProjection()
TRObject operator()(const T1 &t1) const
Bool_t fDrawFrame
Definition: TEveShape.h:41
TEveJetCone * fC
Definition: TEveJetConeGL.h:35
double Double_t
Definition: RtypesCore.h:55
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw the cone.
Bool_t fMultiColor
Definition: TGLObject.h:28
ClassImp(TEveJetConeGL)
Mother of all ROOT objects.
Definition: TObject.h:58
TEveVector fLimits
Definition: TEveJetCone.h:36
OpenGL renderer class for TEveJetCone.
Definition: TEveJetConeGL.h:28
Double_t PiOver2()
Definition: TMath.h:46
virtual void DirectDraw(TGLRnrCtx &rnrCtx) const
Render with OpenGL.
virtual void CalculatePoints() const
Calculate points for drawing.
Exception class thrown by TEve classes and macros.
Definition: TEveUtil.h:102
TEveProjectionManager * GetManager() const
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
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
Int_t fNDiv
Definition: TEveJetCone.h:40
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw the cone.
TEveVector CalcBaseVec(Float_t eta, Float_t phi) const
Returns point on the base of the cone with given eta and phi.
virtual void DLCacheClear()
Clear all entries for all LODs for this drawable from the display list cache but keeping the reserved...