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
24
25////////////////////////////////////////////////////////////////////////////////
26/// Constructor.
27
29{
30 // fDLCache = false; // Disable DL.
32}
33
34////////////////////////////////////////////////////////////////////////////////
35/// Set model object.
36
38{
40 return kTRUE;
41}
42
43namespace
44{
45 inline void AntiFlick(Float_t x, Float_t y, Float_t z)
46 {
47 // Render anti-flickering point.
48 glBegin(GL_POINTS);
49 glVertex3f(x, y, z);
50 glEnd();
51 }
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Draw quad-set with GL.
56
58{
59 static const TEveException eH("TEveQuadSetGL::DirectDraw ");
60
61 // printf("QuadSetGLRenderer::DirectDraw Style %d, LOD %d\n", rnrCtx.Style(), rnrCtx.LOD());
62
63 TEveQuadSet& mQ = * fM;
64
65 if (mQ.fPlex.Size() > 0)
66 {
67 if (! mQ.fSingleColor && ! mQ.fValueIsColor && mQ.fPalette == nullptr)
68 {
69 mQ.AssertPalette();
70 }
71
76
77 if ( ! rnrCtx.IsDrawPassOutlineLine())
78 {
79 if (mQ.fRenderMode == TEveDigitSet::kRM_Fill)
81 else if (mQ.fRenderMode == TEveDigitSet::kRM_Line)
83 }
84
85 if (mQ.fDisableLighting) glDisable(GL_LIGHTING);
86
88 else if (mQ.fQuadType < TEveQuadSet::kQT_Line_End) RenderLines(rnrCtx);
90
92 }
93
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// GL rendering for free-quads and rectangles.
99
101{
102 static const TEveException eH("TEveQuadSetGL::RenderQuads ");
103
104 TEveQuadSet& mQ = * fM;
105
107 if (mQ.fRenderMode != TEveDigitSet::kRM_Line)
108 {
110 if (mQ.fQuadType == TEveQuadSet::kQT_FreeQuad)
112 else
113 glNormal3f(0, 0, 1);
114 } else {
115 primitiveType = GL_LINE_LOOP;
116 }
117
119 if (rnrCtx.Highlight() && fHighlightSet)
120 qi.fSelection = fHighlightSet;
121
122 if (rnrCtx.SecSelection()) glPushName(0);
123
124 switch (mQ.fQuadType)
125 {
127 {
128 Float_t e1[3], e2[3], normal[3];
129 while (qi.next()) {
131 if (SetupColor(q))
132 {
133 Float_t* p = q.fVertices;
134 e1[0] = p[3] - p[0]; e1[1] = p[4] - p[1]; e1[2] = p[5] - p[2];
135 e2[0] = p[6] - p[0]; e2[1] = p[7] - p[1]; e2[2] = p[8] - p[2];
137 if (rnrCtx.SecSelection()) glLoadName(qi.index());
140 glVertex3fv(p);
141 glVertex3fv(p + 3);
142 glVertex3fv(p + 6);
143 glVertex3fv(p + 9);
144 glEnd();
145 if (mQ.fAntiFlick)
146 AntiFlick(0.5f*(p[0]+p[6]), 0.5f*(p[1]+p[7]), 0.5f*(p[2]+p[8]));
147 }
148 }
149 break;
150 }
151
153 {
154 while (qi.next()) {
156 if (SetupColor(q))
157 {
158 if (rnrCtx.SecSelection()) glLoadName(qi.index());
160 glVertex3f(q.fA, q.fB, q.fC);
161 glVertex3f(q.fA + q.fW, q.fB, q.fC);
162 glVertex3f(q.fA + q.fW, q.fB + q.fH, q.fC);
163 glVertex3f(q.fA, q.fB + q.fH, q.fC);
164 glEnd();
165 if (mQ.fAntiFlick)
166 AntiFlick(q.fA + 0.5f*q.fW, q.fB + 0.5f*q.fH, q.fC);
167 }
168 }
169 break;
170 }
171
173 {
174 while (qi.next()) {
176 if (SetupColor(q))
177 {
178 if (rnrCtx.SecSelection()) glLoadName(qi.index());
180 glVertex3f(q.fA, q.fC, q.fB);
181 glVertex3f(q.fA + q.fW, q.fC, q.fB);
182 glVertex3f(q.fA + q.fW, q.fC, q.fB + q.fH);
183 glVertex3f(q.fA, q.fC, q.fB + q.fH);
184 glEnd();
185 if (mQ.fAntiFlick)
186 AntiFlick(q.fA + 0.5f*q.fW, q.fC, q.fB + 0.5f*q.fH);
187 }
188 }
189 break;
190 }
191
193 {
194 while (qi.next()) {
196 if (SetupColor(q))
197 {
198 if (rnrCtx.SecSelection()) glLoadName(qi.index());
200 glVertex3f(q.fC, q.fA, q.fB);
201 glVertex3f(q.fC, q.fA + q.fW, q.fB);
202 glVertex3f(q.fC, q.fA + q.fW, q.fB + q.fH);
203 glVertex3f(q.fC, q.fA, q.fB + q.fH);
204 glEnd();
205 if (mQ.fAntiFlick)
206 AntiFlick(q.fC, q.fA + 0.5f*q.fW, q.fB + 0.5f*q.fH);
207 }
208 }
209 break;
210 }
211
213 {
214 const Float_t& w = mQ.fDefWidth;
215 const Float_t& h = mQ.fDefHeight;
216 while (qi.next()) {
218 if (SetupColor(q))
219 {
220 if (rnrCtx.SecSelection()) glLoadName(qi.index());
222 glVertex3f(q.fA, q.fB, q.fC);
223 glVertex3f(q.fA + w, q.fB, q.fC);
224 glVertex3f(q.fA + w, q.fB + h, q.fC);
225 glVertex3f(q.fA, q.fB + h, q.fC);
226 glEnd();
227 glEnd();
228 if (mQ.fAntiFlick)
229 AntiFlick(q.fA + 0.5f*w, q.fB + 0.5f*h, q.fC);
230 }
231 }
232 break;
233 }
234
236 {
237 const Float_t& z = mQ.fDefCoord;
238 while (qi.next()) {
240 if (SetupColor(q))
241 {
242 if (rnrCtx.SecSelection()) glLoadName(qi.index());
244 glVertex3f(q.fA, q.fB, z);
245 glVertex3f(q.fA + q.fW, q.fB, z);
246 glVertex3f(q.fA + q.fW, q.fB + q.fH, z);
247 glVertex3f(q.fA, q.fB + q.fH, z);
248 glEnd();
249 if (mQ.fAntiFlick)
250 AntiFlick(q.fA + 0.5f*q.fW, q.fB + 0.5f*q.fH, z);
251 }
252 }
253 break;
254 }
255
257 {
258 const Float_t& y = mQ.fDefCoord;
259 while (qi.next()) {
261 if (SetupColor(q))
262 {
263 if (rnrCtx.SecSelection()) glLoadName(qi.index());
265 glVertex3f(q.fA, y, q.fB);
266 glVertex3f(q.fA + q.fW, y, q.fB);
267 glVertex3f(q.fA + q.fW, y, q.fB + q.fH);
268 glVertex3f(q.fA, y, q.fB + q.fH);
269 glEnd();
270 if (mQ.fAntiFlick)
271 AntiFlick(q.fA + 0.5f*q.fW, y, q.fB + 0.5f*q.fH);
272 }
273 }
274 break;
275 }
276
278 {
279 const Float_t& x = mQ.fDefCoord;
280 while (qi.next()) {
282 if (SetupColor(q))
283 {
284 if (rnrCtx.SecSelection()) glLoadName(qi.index());
286 glVertex3f(x, q.fA, q.fB);
287 glVertex3f(x, q.fA + q.fW, q.fB);
288 glVertex3f(x, q.fA + q.fW, q.fB + q.fH);
289 glVertex3f(x, q.fA, q.fB + q.fH);
290 glEnd();
291 if (mQ.fAntiFlick)
292 AntiFlick(x, q.fA + 0.5f*q.fW, q.fB + 0.5f*q.fH);
293 }
294 }
295 break;
296 }
297
299 {
300 const Float_t& z = mQ.fDefCoord;
301 const Float_t& w = mQ.fDefWidth;
302 const Float_t& h = mQ.fDefHeight;
303 while (qi.next()) {
305 if (SetupColor(q))
306 {
307 if (rnrCtx.SecSelection()) glLoadName(qi.index());
309 glVertex3f(q.fA, q.fB, z);
310 glVertex3f(q.fA + w, q.fB, z);
311 glVertex3f(q.fA + w, q.fB + h, z);
312 glVertex3f(q.fA, q.fB + h, z);
313 glEnd();
314 if (mQ.fAntiFlick)
315 AntiFlick(q.fA + 0.5f*w, q.fB + 0.5f*h, z);
316 }
317 }
318 break;
319 }
320
322 {
323 const Float_t& y = mQ.fDefCoord;
324 const Float_t& w = mQ.fDefWidth;
325 const Float_t& h = mQ.fDefHeight;
326 while (qi.next()) {
328 if (SetupColor(q))
329 {
330 if (rnrCtx.SecSelection()) glLoadName(qi.index());
332 glVertex3f(q.fA, y, q.fB);
333 glVertex3f(q.fA + w, y, q.fB);
334 glVertex3f(q.fA + w, y, q.fB + h);
335 glVertex3f(q.fA, y, q.fB + h);
336 glEnd();
337 if (mQ.fAntiFlick)
338 AntiFlick(q.fA + 0.5f*w, y, q.fB + 0.5f*h);
339 }
340 }
341 break;
342 }
343
345 {
346 const Float_t& x = mQ.fDefCoord;
347 const Float_t& w = mQ.fDefWidth;
348 const Float_t& h = mQ.fDefHeight;
349 while (qi.next()) {
351 if (SetupColor(q))
352 {
353 if (rnrCtx.SecSelection()) glLoadName(qi.index());
355 glVertex3f(x, q.fA, q.fB);
356 glVertex3f(x, q.fA + w, q.fB);
357 glVertex3f(x, q.fA + w, q.fB + h);
358 glVertex3f(x, q.fA, q.fB + h);
359 glEnd();
360 if (mQ.fAntiFlick)
361 AntiFlick(x, q.fA + 0.5f*w, q.fB + 0.5f*h);
362 }
363 }
364 break;
365 }
366
367 default:
368 throw(eH + "unsupported quad-type.");
369
370 } // end switch quad-type
371
372 if (rnrCtx.SecSelection()) glPopName();
373}
374
375////////////////////////////////////////////////////////////////////////////////
376/// GL rendering for line-types.
377
379{
380 static const TEveException eH("TEveQuadSetGL::RenderLines ");
381
382 TEveQuadSet& mQ = * fM;
383
385 if (rnrCtx.Highlight() && fHighlightSet)
386 qi.fSelection = fHighlightSet;
387
388 if (rnrCtx.SecSelection()) glPushName(0);
389
390 switch (mQ.fQuadType)
391 {
392
394 {
395 const Float_t& z = mQ.fDefCoord;
396 while (qi.next()) {
398 if (SetupColor(q))
399 {
400 if (rnrCtx.SecSelection()) glLoadName(qi.index());
401 glBegin(GL_LINES);
402 glVertex3f(q.fA, q.fB, z);
403 glVertex3f(q.fA + q.fDx, q.fB + q.fDy, z);
404 glEnd();
405 }
406 }
407 break;
408 }
409
411 {
412 const Float_t& z = mQ.fDefCoord;
413 while (qi.next()) {
415 if (SetupColor(q))
416 {
417 if (rnrCtx.SecSelection()) glLoadName(qi.index());
418 glBegin(GL_LINES);
419 glVertex3f(q.fA, z, q.fB);
420 glVertex3f(q.fA + q.fDx, z, q.fB + q.fDy);
421 glEnd();
422 }
423 }
424 break;
425 }
426
427 default:
428 throw(eH + "unsupported quad-type.");
429
430 }
431
432 if (rnrCtx.SecSelection()) glPopName();
433}
434
435////////////////////////////////////////////////////////////////////////////////
436/// GL rendering for hexagons.
437
439{
440 static const TEveException eH("TEveQuadSetGL::RenderHexagons ");
441
442 const Float_t sqr3hf = 0.5*TMath::Sqrt(3);
443
444 TEveQuadSet& mQ = * fM;
445
446 GLenum primitveType = (mQ.fRenderMode != TEveDigitSet::kRM_Line) ?
447 GL_POLYGON : GL_LINE_LOOP;
448
449 glNormal3f(0, 0, 1);
450
452 if (rnrCtx.Highlight() && fHighlightSet)
453 qi.fSelection = fHighlightSet;
454
455 if (rnrCtx.SecSelection()) glPushName(0);
456
457 switch (mQ.fQuadType)
458 {
460 {
461 while (qi.next()) {
463 if (SetupColor(q))
464 {
465 const Float_t rh = q.fR * 0.5;
466 const Float_t rs = q.fR * sqr3hf;
467 if (rnrCtx.SecSelection()) glLoadName(qi.index());
469 glVertex3f( q.fR + q.fA, q.fB, q.fC);
470 glVertex3f( rh + q.fA, rs + q.fB, q.fC);
471 glVertex3f( -rh + q.fA, rs + q.fB, q.fC);
472 glVertex3f(-q.fR + q.fA, q.fB, q.fC);
473 glVertex3f( -rh + q.fA, -rs + q.fB, q.fC);
474 glVertex3f( rh + q.fA, -rs + q.fB, q.fC);
475 glEnd();
476 if (mQ.fAntiFlick)
477 AntiFlick(q.fA, q.fB, q.fC);
478 }
479 }
480 break;
481 }
482
484 {
485 while (qi.next()) {
487 if (SetupColor(q))
488 {
489 const Float_t rh = q.fR * 0.5;
490 const Float_t rs = q.fR * sqr3hf;
491 if (rnrCtx.SecSelection()) glLoadName(qi.index());
493 glVertex3f( rs + q.fA, rh + q.fB, q.fC);
494 glVertex3f( q.fA, q.fR + q.fB, q.fC);
495 glVertex3f(-rs + q.fA, rh + q.fB, q.fC);
496 glVertex3f(-rs + q.fA, -rh + q.fB, q.fC);
497 glVertex3f( q.fA, -q.fR + q.fB, q.fC);
498 glVertex3f( rs + q.fA, -rh + q.fB, q.fC);
499 glEnd();
500 if (mQ.fAntiFlick)
501 AntiFlick(q.fA, q.fB, q.fC);
502 }
503 }
504 break;
505 }
506
507 default:
508 throw(eH + "unsupported quad-type.");
509
510 } // end switch quad-type
511
512 if (rnrCtx.SecSelection()) glPopName();
513}
#define h(i)
Definition RSha256.hxx:106
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
float * q
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.
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
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
@ 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
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
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:673
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:1284