Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveQuadSetGL.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
12#include "TMath.h"
13
14#include "TEveQuadSetGL.h"
15
16#include "TGLRnrCtx.h"
17#include "TGLIncludes.h"
18
19/** \class TEveQuadSetGL
20\ingroup TEve
21GL-renderer for TEveQuadSet class.
22*/
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Constructor.
28
30{
31 // fDLCache = false; // Disable DL.
33}
34
35////////////////////////////////////////////////////////////////////////////////
36/// Set model object.
37
39{
40 fM = SetModelDynCast<TEveQuadSet>(obj);
41 return kTRUE;
42}
43
44namespace
45{
46 inline void AntiFlick(Float_t x, Float_t y, Float_t z)
47 {
48 // Render anti-flickering point.
49 glBegin(GL_POINTS);
50 glVertex3f(x, y, z);
51 glEnd();
52 }
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Draw quad-set with GL.
57
59{
60 static const TEveException eH("TEveQuadSetGL::DirectDraw ");
61
62 // printf("QuadSetGLRenderer::DirectDraw Style %d, LOD %d\n", rnrCtx.Style(), rnrCtx.LOD());
63
64 TEveQuadSet& mQ = * fM;
65
66 if (mQ.fPlex.Size() > 0)
67 {
68 if (! mQ.fSingleColor && ! mQ.fValueIsColor && mQ.fPalette == nullptr)
69 {
70 mQ.AssertPalette();
71 }
72
73 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
74 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
75 glEnable(GL_COLOR_MATERIAL);
76 glDisable(GL_CULL_FACE);
77
78 if ( ! rnrCtx.IsDrawPassOutlineLine())
79 {
81 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
83 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
84 }
85
86 if (mQ.fDisableLighting) glDisable(GL_LIGHTING);
87
89 else if (mQ.fQuadType < TEveQuadSet::kQT_Line_End) RenderLines(rnrCtx);
91
92 glPopAttrib();
93 }
94
95 DrawFrameIfNeeded(rnrCtx);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// GL rendering for free-quads and rectangles.
100
102{
103 static const TEveException eH("TEveQuadSetGL::RenderQuads ");
104
105 TEveQuadSet& mQ = * fM;
106
107 GLenum primitiveType;
109 {
110 primitiveType = GL_QUADS;
112 glEnable(GL_NORMALIZE);
113 else
114 glNormal3f(0, 0, 1);
115 } else {
116 primitiveType = GL_LINE_LOOP;
117 }
118
120 if (rnrCtx.Highlight() && fHighlightSet)
122
123 if (rnrCtx.SecSelection()) glPushName(0);
124
125 switch (mQ.fQuadType)
126 {
128 {
129 Float_t e1[3], e2[3], normal[3];
130 while (qi.next()) {
132 if (SetupColor(q))
133 {
134 Float_t* p = q.fVertices;
135 e1[0] = p[3] - p[0]; e1[1] = p[4] - p[1]; e1[2] = p[5] - p[2];
136 e2[0] = p[6] - p[0]; e2[1] = p[7] - p[1]; e2[2] = p[8] - p[2];
137 TMath::Cross(e1, e2, normal);
138 if (rnrCtx.SecSelection()) glLoadName(qi.index());
139 glBegin(primitiveType);
140 glNormal3fv(normal);
141 glVertex3fv(p);
142 glVertex3fv(p + 3);
143 glVertex3fv(p + 6);
144 glVertex3fv(p + 9);
145 glEnd();
146 if (mQ.fAntiFlick)
147 AntiFlick(0.5f*(p[0]+p[6]), 0.5f*(p[1]+p[7]), 0.5f*(p[2]+p[8]));
148 }
149 }
150 break;
151 }
152
154 {
155 while (qi.next()) {
157 if (SetupColor(q))
158 {
159 if (rnrCtx.SecSelection()) glLoadName(qi.index());
160 glBegin(primitiveType);
161 glVertex3f(q.fA, q.fB, q.fC);
162 glVertex3f(q.fA + q.fW, q.fB, q.fC);
163 glVertex3f(q.fA + q.fW, q.fB + q.fH, q.fC);
164 glVertex3f(q.fA, q.fB + q.fH, q.fC);
165 glEnd();
166 if (mQ.fAntiFlick)
167 AntiFlick(q.fA + 0.5f*q.fW, q.fB + 0.5f*q.fH, q.fC);
168 }
169 }
170 break;
171 }
172
174 {
175 while (qi.next()) {
177 if (SetupColor(q))
178 {
179 if (rnrCtx.SecSelection()) glLoadName(qi.index());
180 glBegin(primitiveType);
181 glVertex3f(q.fA, q.fC, q.fB);
182 glVertex3f(q.fA + q.fW, q.fC, q.fB);
183 glVertex3f(q.fA + q.fW, q.fC, q.fB + q.fH);
184 glVertex3f(q.fA, q.fC, q.fB + q.fH);
185 glEnd();
186 if (mQ.fAntiFlick)
187 AntiFlick(q.fA + 0.5f*q.fW, q.fC, q.fB + 0.5f*q.fH);
188 }
189 }
190 break;
191 }
192
194 {
195 while (qi.next()) {
197 if (SetupColor(q))
198 {
199 if (rnrCtx.SecSelection()) glLoadName(qi.index());
200 glBegin(primitiveType);
201 glVertex3f(q.fC, q.fA, q.fB);
202 glVertex3f(q.fC, q.fA + q.fW, q.fB);
203 glVertex3f(q.fC, q.fA + q.fW, q.fB + q.fH);
204 glVertex3f(q.fC, q.fA, q.fB + q.fH);
205 glEnd();
206 if (mQ.fAntiFlick)
207 AntiFlick(q.fC, q.fA + 0.5f*q.fW, q.fB + 0.5f*q.fH);
208 }
209 }
210 break;
211 }
212
214 {
215 const Float_t& w = mQ.fDefWidth;
216 const Float_t& h = mQ.fDefHeight;
217 while (qi.next()) {
219 if (SetupColor(q))
220 {
221 if (rnrCtx.SecSelection()) glLoadName(qi.index());
222 glBegin(primitiveType);
223 glVertex3f(q.fA, q.fB, q.fC);
224 glVertex3f(q.fA + w, q.fB, q.fC);
225 glVertex3f(q.fA + w, q.fB + h, q.fC);
226 glVertex3f(q.fA, q.fB + h, q.fC);
227 glEnd();
228 glEnd();
229 if (mQ.fAntiFlick)
230 AntiFlick(q.fA + 0.5f*w, q.fB + 0.5f*h, q.fC);
231 }
232 }
233 break;
234 }
235
237 {
238 const Float_t& z = mQ.fDefCoord;
239 while (qi.next()) {
241 if (SetupColor(q))
242 {
243 if (rnrCtx.SecSelection()) glLoadName(qi.index());
244 glBegin(primitiveType);
245 glVertex3f(q.fA, q.fB, z);
246 glVertex3f(q.fA + q.fW, q.fB, z);
247 glVertex3f(q.fA + q.fW, q.fB + q.fH, z);
248 glVertex3f(q.fA, q.fB + q.fH, z);
249 glEnd();
250 if (mQ.fAntiFlick)
251 AntiFlick(q.fA + 0.5f*q.fW, q.fB + 0.5f*q.fH, z);
252 }
253 }
254 break;
255 }
256
258 {
259 const Float_t& y = mQ.fDefCoord;
260 while (qi.next()) {
262 if (SetupColor(q))
263 {
264 if (rnrCtx.SecSelection()) glLoadName(qi.index());
265 glBegin(primitiveType);
266 glVertex3f(q.fA, y, q.fB);
267 glVertex3f(q.fA + q.fW, y, q.fB);
268 glVertex3f(q.fA + q.fW, y, q.fB + q.fH);
269 glVertex3f(q.fA, y, q.fB + q.fH);
270 glEnd();
271 if (mQ.fAntiFlick)
272 AntiFlick(q.fA + 0.5f*q.fW, y, q.fB + 0.5f*q.fH);
273 }
274 }
275 break;
276 }
277
279 {
280 const Float_t& x = mQ.fDefCoord;
281 while (qi.next()) {
283 if (SetupColor(q))
284 {
285 if (rnrCtx.SecSelection()) glLoadName(qi.index());
286 glBegin(primitiveType);
287 glVertex3f(x, q.fA, q.fB);
288 glVertex3f(x, q.fA + q.fW, q.fB);
289 glVertex3f(x, q.fA + q.fW, q.fB + q.fH);
290 glVertex3f(x, q.fA, q.fB + q.fH);
291 glEnd();
292 if (mQ.fAntiFlick)
293 AntiFlick(x, q.fA + 0.5f*q.fW, q.fB + 0.5f*q.fH);
294 }
295 }
296 break;
297 }
298
300 {
301 const Float_t& z = mQ.fDefCoord;
302 const Float_t& w = mQ.fDefWidth;
303 const Float_t& h = mQ.fDefHeight;
304 while (qi.next()) {
306 if (SetupColor(q))
307 {
308 if (rnrCtx.SecSelection()) glLoadName(qi.index());
309 glBegin(primitiveType);
310 glVertex3f(q.fA, q.fB, z);
311 glVertex3f(q.fA + w, q.fB, z);
312 glVertex3f(q.fA + w, q.fB + h, z);
313 glVertex3f(q.fA, q.fB + h, z);
314 glEnd();
315 if (mQ.fAntiFlick)
316 AntiFlick(q.fA + 0.5f*w, q.fB + 0.5f*h, z);
317 }
318 }
319 break;
320 }
321
323 {
324 const Float_t& y = mQ.fDefCoord;
325 const Float_t& w = mQ.fDefWidth;
326 const Float_t& h = mQ.fDefHeight;
327 while (qi.next()) {
329 if (SetupColor(q))
330 {
331 if (rnrCtx.SecSelection()) glLoadName(qi.index());
332 glBegin(primitiveType);
333 glVertex3f(q.fA, y, q.fB);
334 glVertex3f(q.fA + w, y, q.fB);
335 glVertex3f(q.fA + w, y, q.fB + h);
336 glVertex3f(q.fA, y, q.fB + h);
337 glEnd();
338 if (mQ.fAntiFlick)
339 AntiFlick(q.fA + 0.5f*w, y, q.fB + 0.5f*h);
340 }
341 }
342 break;
343 }
344
346 {
347 const Float_t& x = mQ.fDefCoord;
348 const Float_t& w = mQ.fDefWidth;
349 const Float_t& h = mQ.fDefHeight;
350 while (qi.next()) {
352 if (SetupColor(q))
353 {
354 if (rnrCtx.SecSelection()) glLoadName(qi.index());
355 glBegin(primitiveType);
356 glVertex3f(x, q.fA, q.fB);
357 glVertex3f(x, q.fA + w, q.fB);
358 glVertex3f(x, q.fA + w, q.fB + h);
359 glVertex3f(x, q.fA, q.fB + h);
360 glEnd();
361 if (mQ.fAntiFlick)
362 AntiFlick(x, q.fA + 0.5f*w, q.fB + 0.5f*h);
363 }
364 }
365 break;
366 }
367
368 default:
369 throw(eH + "unsupported quad-type.");
370
371 } // end switch quad-type
372
373 if (rnrCtx.SecSelection()) glPopName();
374}
375
376////////////////////////////////////////////////////////////////////////////////
377/// GL rendering for line-types.
378
380{
381 static const TEveException eH("TEveQuadSetGL::RenderLines ");
382
383 TEveQuadSet& mQ = * fM;
384
386 if (rnrCtx.Highlight() && fHighlightSet)
388
389 if (rnrCtx.SecSelection()) glPushName(0);
390
391 switch (mQ.fQuadType)
392 {
393
395 {
396 const Float_t& z = mQ.fDefCoord;
397 while (qi.next()) {
399 if (SetupColor(q))
400 {
401 if (rnrCtx.SecSelection()) glLoadName(qi.index());
402 glBegin(GL_LINES);
403 glVertex3f(q.fA, q.fB, z);
404 glVertex3f(q.fA + q.fDx, q.fB + q.fDy, z);
405 glEnd();
406 }
407 }
408 break;
409 }
410
412 {
413 const Float_t& z = mQ.fDefCoord;
414 while (qi.next()) {
416 if (SetupColor(q))
417 {
418 if (rnrCtx.SecSelection()) glLoadName(qi.index());
419 glBegin(GL_LINES);
420 glVertex3f(q.fA, z, q.fB);
421 glVertex3f(q.fA + q.fDx, z, q.fB + q.fDy);
422 glEnd();
423 }
424 }
425 break;
426 }
427
428 default:
429 throw(eH + "unsupported quad-type.");
430
431 }
432
433 if (rnrCtx.SecSelection()) glPopName();
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// GL rendering for hexagons.
438
440{
441 static const TEveException eH("TEveQuadSetGL::RenderHexagons ");
442
443 const Float_t sqr3hf = 0.5*TMath::Sqrt(3);
444
445 TEveQuadSet& mQ = * fM;
446
447 GLenum primitveType = (mQ.fRenderMode != TEveDigitSet::kRM_Line) ?
449
450 glNormal3f(0, 0, 1);
451
453 if (rnrCtx.Highlight() && fHighlightSet)
455
456 if (rnrCtx.SecSelection()) glPushName(0);
457
458 switch (mQ.fQuadType)
459 {
461 {
462 while (qi.next()) {
464 if (SetupColor(q))
465 {
466 const Float_t rh = q.fR * 0.5;
467 const Float_t rs = q.fR * sqr3hf;
468 if (rnrCtx.SecSelection()) glLoadName(qi.index());
469 glBegin(primitveType);
470 glVertex3f( q.fR + q.fA, q.fB, q.fC);
471 glVertex3f( rh + q.fA, rs + q.fB, q.fC);
472 glVertex3f( -rh + q.fA, rs + q.fB, q.fC);
473 glVertex3f(-q.fR + q.fA, q.fB, q.fC);
474 glVertex3f( -rh + q.fA, -rs + q.fB, q.fC);
475 glVertex3f( rh + q.fA, -rs + q.fB, q.fC);
476 glEnd();
477 if (mQ.fAntiFlick)
478 AntiFlick(q.fA, q.fB, q.fC);
479 }
480 }
481 break;
482 }
483
485 {
486 while (qi.next()) {
488 if (SetupColor(q))
489 {
490 const Float_t rh = q.fR * 0.5;
491 const Float_t rs = q.fR * sqr3hf;
492 if (rnrCtx.SecSelection()) glLoadName(qi.index());
493 glBegin(primitveType);
494 glVertex3f( rs + q.fA, rh + q.fB, q.fC);
495 glVertex3f( q.fA, q.fR + q.fB, q.fC);
496 glVertex3f(-rs + q.fA, rh + q.fB, q.fC);
497 glVertex3f(-rs + q.fA, -rh + q.fB, q.fC);
498 glVertex3f( q.fA, -q.fR + q.fB, q.fC);
499 glVertex3f( rs + q.fA, -rh + q.fB, q.fC);
500 glEnd();
501 if (mQ.fAntiFlick)
502 AntiFlick(q.fA, q.fB, q.fC);
503 }
504 }
505 break;
506 }
507
508 default:
509 throw(eH + "unsupported quad-type.");
510
511 } // end switch quad-type
512
513 if (rnrCtx.SecSelection()) glPopName();
514}
#define GL_QUADS
Definition GL_glu.h:290
#define GL_LINES
Definition GL_glu.h:284
#define GL_POINTS
Definition GL_glu.h:283
#define GL_POLYGON
Definition GL_glu.h:292
#define GL_LINE_LOOP
Definition GL_glu.h:285
#define h(i)
Definition RSha256.hxx:106
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
winID h TVirtualViewer3D TVirtualGLPainter p
float * q
Int_t Size() const
OpenGL renderer class for TEveDigitSet.
const std::set< Int_t > * fHighlightSet
void DrawFrameIfNeeded(TGLRnrCtx &rnrCtx) const
Make a decision if the frame should be drawn.
Bool_t SetupColor(const TEveDigitSet::DigitBase_t &q) const
Set color for rendering of the specified digit.
Bool_t fDisableLighting
TEveRGBAPalette * fPalette
TEveRGBAPalette * AssertPalette()
Make sure the TEveRGBAPalette pointer is not null.
Bool_t fSingleColor
ERenderMode_e fRenderMode
TEveChunkManager fPlex
Bool_t fValueIsColor
Bool_t fAntiFlick
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
GL-renderer for TEveQuadSet class.
TEveQuadSetGL()
Constructor.
void RenderQuads(TGLRnrCtx &rnrCtx) const
GL rendering for free-quads and rectangles.
void RenderHexagons(TGLRnrCtx &rnrCtx) const
GL rendering for hexagons.
void RenderLines(TGLRnrCtx &rnrCtx) const
GL rendering for line-types.
void DirectDraw(TGLRnrCtx &rnrCtx) const override
Draw quad-set with GL.
Bool_t SetModel(TObject *obj, const Option_t *opt=nullptr) override
Set model object.
TEveQuadSet * fM
Supports various internal formats that result in rendering of a set of planar (lines,...
Definition TEveQuadSet.h:20
Float_t fDefHeight
Definition TEveQuadSet.h:75
@ kQT_RectangleYZFixedX
Definition TEveQuadSet.h:36
@ kQT_RectangleXZFixedDimY
Definition TEveQuadSet.h:38
@ kQT_RectangleXYFixedDim
Definition TEveQuadSet.h:33
@ kQT_RectangleXYFixedZ
Definition TEveQuadSet.h:34
@ kQT_RectangleXYFixedDimZ
Definition TEveQuadSet.h:37
@ kQT_RectangleYZFixedDimX
Definition TEveQuadSet.h:39
@ kQT_RectangleXZFixedY
Definition TEveQuadSet.h:35
Float_t fDefWidth
Definition TEveQuadSet.h:74
Float_t fDefCoord
Definition TEveQuadSet.h:76
EQuadType_e fQuadType
Definition TEveQuadSet.h:72
Bool_t fMultiColor
Definition TGLObject.h:28
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
Bool_t SecSelection() const
Definition TGLRnrCtx.h:224
Bool_t IsDrawPassOutlineLine() const
Definition TGLRnrCtx.h:207
Bool_t Highlight() const
Definition TGLRnrCtx.h:218
Mother of all ROOT objects.
Definition TObject.h:41
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
T * Cross(const T v1[3], const T v2[3], T out[3])
Calculates the Cross Product of two vectors: out = [v1 x v2].
Definition TMath.h:1197
Bool_t next()
Go to next atom.
const std::set< Int_t > * fSelection