forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveJetConeGL.cxx
362 lines (284 loc) · 8.69 KB
/
TEveJetConeGL.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// @(#)root/eve:$Id$
// Author: Matevz Tadel, Jochen Thaeder 2009
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveJetConeGL.h"
#include "TEveJetCone.h"
#include "TEveProjectionManager.h"
#include "TMath.h"
#include "TGLRnrCtx.h"
#include "TGLIncludes.h"
/** \class TEveJetConeGL
\ingroup TEve
OpenGL renderer class for TEveJetCone.
*/
ClassImp(TEveJetConeGL);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveJetConeGL::TEveJetConeGL() :
TGLObject(), fC(0)
{
// fDLCache = kFALSE; // Disable display list.
}
////////////////////////////////////////////////////////////////////////////////
/// Set model object.
Bool_t TEveJetConeGL::SetModel(TObject* obj, const Option_t* /*opt*/)
{
fC = SetModelDynCast<TEveJetCone>(obj);
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Set bounding box.
void TEveJetConeGL::SetBBox()
{
SetAxisAlignedBBox(((TEveJetCone*)fExternalObj)->AssertBBox());
}
////////////////////////////////////////////////////////////////////////////////
/// Clear DL cache and reset internal point array.
void TEveJetConeGL::DLCacheClear()
{
fP.clear();
TGLObject::DLCacheClear();
}
////////////////////////////////////////////////////////////////////////////////
/// Calculate points for drawing.
void TEveJetConeGL::CalculatePoints() const
{
assert(fC->fNDiv > 2);
const Int_t NP = fC->fNDiv;
fP.resize(NP);
{
Float_t angle_step = TMath::TwoPi() / NP;
Float_t angle = 0;
for (Int_t i = 0; i < NP; ++i, angle += angle_step)
{
fP[i] = fC->CalcBaseVec(angle);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Draw the cone.
void TEveJetConeGL::Draw(TGLRnrCtx& rnrCtx) const
{
if (fP.empty()) CalculatePoints();
if (fC->fHighlightFrame && rnrCtx.Highlight())
{
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_LIGHTING);
if (fC->fDrawFrame)
{
TGLUtil::LineWidth(fC->fLineWidth);
TGLUtil::Color(fC->fLineColor);
}
const Int_t NP = fP.size();
glBegin(GL_LINE_LOOP);
for (Int_t i = 0; i < NP; ++i)
glVertex3fv(fP[i]);
glEnd();
glBegin(GL_LINES);
Double_t angle = 0;
for (Int_t i = 0; i < 4; ++i, angle += TMath::PiOver2())
{
glVertex3fv(fC->fApex);
glVertex3fv(fC->CalcBaseVec(angle));
}
glEnd();
glPopAttrib();
}
else
{
TGLObject::Draw(rnrCtx);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Render with OpenGL.
void TEveJetConeGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
{
// printf("TEveJetConeGL::DirectDraw LOD %d\n", rnrCtx.CombiLOD());
glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LIGHTING_BIT);
glDisable(GL_CULL_FACE);
glEnable(GL_NORMALIZE);
Int_t lmts = 1;
glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE, &lmts);
const Int_t NP = fC->fNDiv;
Int_t prev = NP - 1;
Int_t i = 0;
Int_t next = 1;
TEveVector curr_normal;
TEveVector prev_normal;
TMath::Cross((fP[next] - fP[prev]).Arr(), (fP[i] - fC->fApex).Arr(), prev_normal.Arr());
prev = i; i = next; ++next;
glBegin(GL_TRIANGLES);
do
{
TMath::Cross((fP[next] - fP[prev]).Arr(), (fP[i] - fC->fApex).Arr(), curr_normal.Arr());
glNormal3fv(prev_normal);
glVertex3fv(fP[prev]);
glNormal3fv(prev_normal + curr_normal);
glVertex3fv(fC->fApex);
glNormal3fv(curr_normal);
glVertex3fv(fP[i]);
prev_normal = curr_normal;
prev = i;
i = next;
++next; if (next >= NP) next = 0;
} while (prev != 0);
glEnd();
glPopAttrib();
}
/** \class TEveJetConeProjectedGL
\ingroup TEve
OpenGL renderer class for TEveJetConeProjected.
*/
ClassImp(TEveJetConeProjectedGL);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveJetConeProjectedGL::TEveJetConeProjectedGL() :
TEveJetConeGL(), fM(0)
{
// fDLCache = kFALSE; // Disable display list.
}
////////////////////////////////////////////////////////////////////////////////
/// Set model object.
Bool_t TEveJetConeProjectedGL::SetModel(TObject* obj, const Option_t* /*opt*/)
{
fM = SetModelDynCast<TEveJetConeProjected>(obj);
fC = dynamic_cast<TEveJetCone*>(fM->GetProjectable());
return fC != 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Set bounding box.
void TEveJetConeProjectedGL::SetBBox()
{
SetAxisAlignedBBox(((TEveJetConeProjected*)fExternalObj)->AssertBBox());
}
namespace
{
struct less_eve_vec_phi_t
{
bool operator()(const TEveVector& a, const TEveVector& b)
{ return a.Phi() < b.Phi(); }
};
}
////////////////////////////////////////////////////////////////////////////////
/// Calculate points for drawing.
void TEveJetConeProjectedGL::CalculatePoints() const
{
static const TEveException kEH("TEveJetConeProjectedGL::CalculatePoints ");
fP.resize(3);
TEveProjection *proj = fM->GetManager()->GetProjection();
switch (proj->GetType())
{
case TEveProjection::kPT_RPhi:
{
fP[0] = fC->fApex;
fP[1] = fC->CalcBaseVec(TMath::Pi() + TMath::PiOver2());
fP[2] = fC->CalcBaseVec(TMath::PiOver2());
for (Int_t i = 0; i < 3; ++i)
proj->ProjectVector(fP[i], fM->fDepth);
break;
}
case TEveProjection::kPT_RhoZ:
{
fP[0] = fC->fApex;
fP[1] = fC->CalcBaseVec(0);
fP[2] = fC->CalcBaseVec(TMath::Pi());
Float_t tm = fP[1].Theta();
Float_t tM = fP[2].Theta();
if (tM > fC->fThetaC && tm < fC->fThetaC)
{
fP.reserve(fP.size() + 1);
TEveVector v(0, fC->fLimits.fY, fC->fLimits.fZ);
fP.push_back(fC->CalcBaseVec(v.Eta(), fC->fPhi));
}
if (tM > TMath::Pi() - fC->fThetaC && tm < TMath::Pi() - fC->fThetaC)
{
fP.reserve(fP.size() + 1);
TEveVector v(0, fC->fLimits.fY, -fC->fLimits.fZ);
fP.push_back(fC->CalcBaseVec(v.Eta(), fC->fPhi));
}
const Int_t NP = fP.size();
for (Int_t i = 0; i < NP; ++i)
proj->ProjectVector(fP[i], fM->fDepth);
std::sort(fP.begin() + 1, fP.end(), less_eve_vec_phi_t());
break;
}
default:
throw kEH + "Unsupported projection type.";
}
}
////////////////////////////////////////////////////////////////////////////////
/// Draw jet outline.
void TEveJetConeProjectedGL::RenderOutline() const
{
const Int_t NP = fP.size();
glBegin(GL_LINE_LOOP);
for (Int_t i = 0; i < NP; ++i)
{
glVertex3fv(fP[i].Arr());
}
glEnd();
}
////////////////////////////////////////////////////////////////////////////////
/// Draw jet surface.
void TEveJetConeProjectedGL::RenderPolygon() const
{
const Int_t NP = fP.size();
glBegin(GL_POLYGON);
for (Int_t i = 0; i < NP; ++i)
{
glVertex3fv(fP[i].Arr());
}
glEnd();
}
////////////////////////////////////////////////////////////////////////////////
/// Draw the cone.
void TEveJetConeProjectedGL::Draw(TGLRnrCtx& rnrCtx) const
{
if (fP.empty()) CalculatePoints();
if (rnrCtx.IsDrawPassOutlineLine())
{
RenderOutline();
}
else if (fM->fHighlightFrame && rnrCtx.Highlight())
{
if (fM->fDrawFrame)
{
TGLUtil::LineWidth(fM->fLineWidth);
TGLUtil::Color(fM->fLineColor);
}
RenderOutline();
}
else
{
TGLObject::Draw(rnrCtx);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Render with OpenGL.
void TEveJetConeProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const
{
// printf("TEveJetConeProjectedGL::DirectDraw LOD %d\n", rnrCtx.CombiLOD());
fMultiColor = (fM->fDrawFrame && fM->fFillColor != fM->fLineColor);
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_LIGHTING);
if (fM->fDrawFrame)
{
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
}
RenderPolygon();
if (fM->fDrawFrame)
{
glEnable(GL_LINE_SMOOTH);
TGLUtil::Color(fM->fLineColor);
TGLUtil::LineWidth(fM->fLineWidth);
RenderOutline();
}
glPopAttrib();
}