Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 
26 ClassImp(TEveJetConeGL);
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Constructor.
30 
31 TEveJetConeGL::TEveJetConeGL() :
32  TGLObject(), fC(0)
33 {
34  // fDLCache = kFALSE; // Disable display list.
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Set model object.
39 
40 Bool_t TEveJetConeGL::SetModel(TObject* obj, const Option_t* /*opt*/)
41 {
42  fC = SetModelDynCast<TEveJetCone>(obj);
43  return kTRUE;
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Set bounding box.
48 
49 void TEveJetConeGL::SetBBox()
50 {
51  SetAxisAlignedBBox(((TEveJetCone*)fExternalObj)->AssertBBox());
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Clear DL cache and reset internal point array.
56 
57 void TEveJetConeGL::DLCacheClear()
58 {
59  fP.clear();
60  TGLObject::DLCacheClear();
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Calculate points for drawing.
65 
66 void TEveJetConeGL::CalculatePoints() const
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  {
96  TGLUtil::LineWidth(fC->fLineWidth);
97  TGLUtil::Color(fC->fLineColor);
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 
177 ClassImp(TEveJetConeProjectedGL);
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Constructor.
181 
182 TEveJetConeProjectedGL::TEveJetConeProjectedGL() :
183  TEveJetConeGL(), fM(0)
184 {
185  // fDLCache = kFALSE; // Disable display list.
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Set model object.
190 
191 Bool_t TEveJetConeProjectedGL::SetModel(TObject* obj, const Option_t* /*opt*/)
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 
201 void TEveJetConeProjectedGL::SetBBox()
202 {
203  SetAxisAlignedBBox(((TEveJetConeProjected*)fExternalObj)->AssertBBox());
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 
218 void TEveJetConeProjectedGL::CalculatePoints() const
219 {
220  static const TEveException kEH("TEveJetConeProjectedGL::CalculatePoints ");
221 
222  fP.resize(3);
223 
224  TEveProjection *proj = fM->GetManager()->GetProjection();
225 
226  switch (proj->GetType())
227  {
228  case TEveProjection::kPT_RPhi:
229  {
230  fP[0] = fC->fApex;
231  fP[1] = fC->CalcBaseVec(TMath::Pi() + TMath::PiOver2());
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 
240  case TEveProjection::kPT_RhoZ:
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 
281 void TEveJetConeProjectedGL::RenderOutline() const
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 
295 void TEveJetConeProjectedGL::RenderPolygon() const
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 
309 void TEveJetConeProjectedGL::Draw(TGLRnrCtx& rnrCtx) const
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  {
321  TGLUtil::LineWidth(fM->fLineWidth);
322  TGLUtil::Color(fM->fLineColor);
323  }
324  RenderOutline();
325  }
326  else
327  {
328  TGLObject::Draw(rnrCtx);
329  }
330 }
331 
332 ////////////////////////////////////////////////////////////////////////////////
333 /// Render with OpenGL.
334 
335 void TEveJetConeProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
336 {
337  // printf("TEveJetConeProjectedGL::DirectDraw LOD %d\n", rnrCtx.CombiLOD());
338 
339  fMultiColor = (fM->fDrawFrame && fM->fFillColor != fM->fLineColor);
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 
356  TGLUtil::Color(fM->fLineColor);
357  TGLUtil::LineWidth(fM->fLineWidth);
358  RenderOutline();
359  }
360 
361  glPopAttrib();
362 }