]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/QuadSetGL.cxx
Dummy methods DefineParticle required by the interface added.
[u/mrichter/AliRoot.git] / EVE / Reve / QuadSetGL.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 #include <TMath.h>
19
20 #include "QuadSetGL.h"
21 #include <Reve/FrameBoxGL.h>
22
23 #include <TGLRnrCtx.h>
24 #include <TGLSelectRecord.h>
25 #include <TGLIncludes.h>
26
27 using namespace Reve;
28
29 //______________________________________________________________________
30 // OldQuadSetGL
31 //
32
33 ClassImp(OldQuadSetGL)
34
35 /**************************************************************************/
36
37 OldQuadSetGL::OldQuadSetGL() : TGLObject()
38 {
39   // fDLCache = false; // Disable DL.
40 }
41
42 OldQuadSetGL::~OldQuadSetGL()
43 {}
44
45 /**************************************************************************/
46
47 Bool_t OldQuadSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
48 {
49   return SetModelCheckClass(obj, Reve::OldQuadSet::Class());
50 }
51
52 void OldQuadSetGL::SetBBox()
53 {
54   SetAxisAlignedBBox(((OldQuadSet*)fExternalObj)->AssertBBox());
55 }
56
57 /**************************************************************************/
58
59 void OldQuadSetGL::DirectDraw(TGLRnrCtx & /*rnrCtx*/) const
60 {
61   // printf("OldQuadSetGLRenderer::DirectDraw Style %d, LOD %d\n", rnrCtx.Style(), rnrCtx.LOD());
62
63   OldQuadSet& Q = * (OldQuadSet*) fExternalObj;
64
65   glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
66
67   glDisable(GL_LIGHTING);
68   glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
69   glEnable(GL_COLOR_MATERIAL);
70   glPolygonMode(GL_FRONT, GL_LINE);
71   glPolygonMode(GL_BACK,  GL_LINE);
72   glDisable(GL_CULL_FACE);
73
74   Float_t c[4]; glGetFloatv(GL_CURRENT_COLOR, c);
75   //  UChar_t alpha = (UChar_t)(255*c[3]);
76
77   glBegin(GL_QUADS);
78   for(std::vector<Quad>::iterator q=Q.fQuads.begin(); q!=Q.fQuads.end(); ++q) {
79     UChar_t* c = (UChar_t*) &q->color;
80     //glColor4ub(c[0], c[1], c[2], (c[3]*alpha) >> 8);
81     glColor3ub(c[0], c[1], c[2]);
82     glVertex3fv(q->vertices);
83     glVertex3fv(q->vertices + 3);
84     glVertex3fv(q->vertices + 6);
85     glVertex3fv(q->vertices + 9);
86   }
87   glEnd();
88
89   glPopAttrib();
90 }
91
92
93 /**************************************************************************/
94 /**************************************************************************/
95 /**************************************************************************/
96 /**************************************************************************/
97
98 //______________________________________________________________________
99 // QuadSetGL
100 //
101
102 ClassImp(QuadSetGL)
103
104 /**************************************************************************/
105
106 QuadSetGL::QuadSetGL() : TGLObject(), fM(0)
107 {
108   // fDLCache = false; // Disable DL.
109 }
110
111 QuadSetGL::~QuadSetGL()
112 {}
113
114 /**************************************************************************/
115
116 Bool_t QuadSetGL::ShouldDLCache(const TGLRnrCtx & rnrCtx) const
117 {
118   if (rnrCtx.DrawPass() == TGLRnrCtx::kPassOutlineLine)
119     return kFALSE;
120   return TGLObject::ShouldDLCache(rnrCtx);
121 }
122
123 /**************************************************************************/
124
125 Bool_t QuadSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
126 {
127   Bool_t ok = SetModelCheckClass(obj, Reve::QuadSet::Class());
128   fM = ok ? dynamic_cast<Reve::QuadSet*>(obj) : 0;
129   return ok;
130 }
131
132 void QuadSetGL::SetBBox()
133 {
134   SetAxisAlignedBBox(fM->AssertBBox());
135 }
136
137 /**************************************************************************/
138
139 inline Bool_t QuadSetGL::SetupColor(const DigitSet::DigitBase& q) const
140 {
141   if (fM->fValueIsColor)
142   {
143     glColor4ubv((UChar_t*) & q.fValue);
144     return kTRUE;
145   }
146   else
147   {
148     UChar_t c[4];
149     Bool_t visible = fM->fPalette->ColorFromValue(q.fValue, fM->fDefaultValue, c);
150     if (visible)
151       glColor4ubv(c);
152     return visible;
153   }
154 }
155
156 /**************************************************************************/
157
158 void QuadSetGL::DirectDraw(TGLRnrCtx & rnrCtx) const
159 {
160   static const Exc_t eH("QuadSetGL::DirectDraw ");
161
162   // printf("QuadSetGLRenderer::DirectDraw Style %d, LOD %d\n", rnrCtx.Style(), rnrCtx.LOD());
163
164   if (rnrCtx.DrawPass() == TGLRnrCtx::kPassOutlineLine)
165     return;
166
167   QuadSet& mQ = * fM;
168
169   if (mQ.fFrame != 0 && ! rnrCtx.SecSelection())
170     FrameBoxGL::Render(mQ.fFrame);
171
172   if (mQ.fPlex.Size() == 0)
173     return;
174   if ( ! mQ.fValueIsColor && mQ.fPalette == 0)
175   {
176     mQ.AssertPalette();
177   }
178
179   glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
180   glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
181   glEnable(GL_COLOR_MATERIAL);
182   glDisable(GL_CULL_FACE);
183
184   if (mQ.fRenderMode == DigitSet::RM_Fill)
185     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
186   else if (mQ.fRenderMode == DigitSet::RM_Line)
187     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
188
189   if (mQ.fDisableLigting)  glDisable(GL_LIGHTING);
190
191   if (mQ.fQuadType < QuadSet::QT_Rectangle_End)      RenderQuads(rnrCtx);
192   else if (mQ.fQuadType < QuadSet::QT_Line_End)      RenderLines(rnrCtx);
193   else if (mQ.fQuadType < QuadSet::QT_Hexagon_End)   RenderHexagons(rnrCtx);
194
195   glPopAttrib();
196
197 }
198
199
200 void QuadSetGL::RenderQuads(TGLRnrCtx & rnrCtx) const
201 {
202   static const Exc_t eH("QuadSetGL::RenderQuads ");
203
204   QuadSet& mQ = * fM;
205
206   GLenum primitiveType;
207   if (mQ.fRenderMode != DigitSet::RM_Line)
208   {
209     primitiveType = GL_QUADS;
210     if (mQ.fQuadType == QuadSet::QT_FreeQuad)
211       glEnable(GL_NORMALIZE);
212     else
213       glNormal3f(0, 0, 1);
214   } else {
215     primitiveType = GL_LINE_LOOP;
216   }
217
218   VoidCPlex::iterator qi(mQ.fPlex);
219
220   if (rnrCtx.SecSelection()) glPushName(0);
221
222   switch (mQ.fQuadType)
223   {
224
225     case QuadSet::QT_FreeQuad:
226     {
227       Float_t e1[3], e2[3], normal[3];
228       while (qi.next()) {
229         QuadSet::QFreeQuad& q = * (QuadSet::QFreeQuad*) qi();
230         if (SetupColor(q))
231         {
232           Float_t* p = q.fVertices;
233           e1[0] = p[3] - p[0]; e1[1] = p[4] - p[1]; e1[2] = p[5] - p[2];
234           e2[0] = p[6] - p[0]; e2[1] = p[7] - p[1]; e2[2] = p[8] - p[2];
235           TMath::Cross(e1, e2, normal);
236           if (rnrCtx.SecSelection()) glLoadName(qi.index());
237           glBegin(primitiveType);
238           glNormal3fv(normal);
239           glVertex3fv(p);
240           glVertex3fv(p + 3);
241           glVertex3fv(p + 6);
242           glVertex3fv(p + 9);
243           glEnd();
244         }
245       }
246       break;
247     }
248
249     case QuadSet::QT_RectangleXY:
250     {
251       while (qi.next()) {
252         QuadSet::QRect& q = * (QuadSet::QRect*) qi();
253         if (SetupColor(q))
254         {
255           if (rnrCtx.SecSelection()) glLoadName(qi.index());
256           glBegin(primitiveType);
257           glVertex3f(q.fA,        q.fB,        q.fC);
258           glVertex3f(q.fA + q.fW, q.fB,        q.fC);
259           glVertex3f(q.fA + q.fW, q.fB + q.fH, q.fC);
260           glVertex3f(q.fA,        q.fB + q.fH, q.fC);
261           glEnd();
262         }
263       }
264       break;
265     }
266
267     case QuadSet::QT_RectangleXZ:
268     {
269       while (qi.next()) {
270         QuadSet::QRect& q = * (QuadSet::QRect*) qi();
271         if (SetupColor(q))
272         {
273           if (rnrCtx.SecSelection()) glLoadName(qi.index());
274           glBegin(primitiveType);
275           glVertex3f(q.fA,        q.fC, q.fB);
276           glVertex3f(q.fA + q.fW, q.fC, q.fB);
277           glVertex3f(q.fA + q.fW, q.fC, q.fB + q.fH);
278           glVertex3f(q.fA,        q.fC, q.fB + q.fH);
279           glEnd();
280         }
281       }
282       break;
283     }
284
285     case QuadSet::QT_RectangleYZ:
286     {
287       while (qi.next()) {
288         QuadSet::QRect& q = * (QuadSet::QRect*) qi();
289         if (SetupColor(q))
290         {
291           if (rnrCtx.SecSelection()) glLoadName(qi.index());
292           glBegin(primitiveType);
293           glVertex3f(q.fC, q.fA,        q.fB);
294           glVertex3f(q.fC, q.fA + q.fW, q.fB);
295           glVertex3f(q.fC, q.fA + q.fW, q.fB + q.fH);
296           glVertex3f(q.fC, q.fA,        q.fB + q.fH);
297           glEnd();
298         }
299       }
300       break;
301     }
302
303     case QuadSet::QT_RectangleXYFixedDim:
304     {
305       const Float_t& w = mQ.fDefWidth;
306       const Float_t& h = mQ.fDefHeight;
307       while (qi.next()) {
308         QuadSet::QRectFixDim& q = * (QuadSet::QRectFixDim*) qi();
309         if (SetupColor(q))
310         {
311           if (rnrCtx.SecSelection()) glLoadName(qi.index());
312           glBegin(primitiveType);
313           glVertex3f(q.fA,     q.fB,     q.fC);
314           glVertex3f(q.fA + w, q.fB,     q.fC);
315           glVertex3f(q.fA + w, q.fB + h, q.fC);
316           glVertex3f(q.fA,     q.fB + h, q.fC);
317           glEnd();
318         }
319       }
320       break;
321     }
322
323     case QuadSet::QT_RectangleXYFixedZ:
324     {
325       const Float_t& z = mQ.fDefCoord;
326       while (qi.next()) {
327         QuadSet::QRectFixC& q = * (QuadSet::QRectFixC*) qi();
328         if (SetupColor(q))
329         {
330           if (rnrCtx.SecSelection()) glLoadName(qi.index());
331           glBegin(primitiveType);
332           glVertex3f(q.fA,        q.fB,        z);
333           glVertex3f(q.fA + q.fW, q.fB,        z);
334           glVertex3f(q.fA + q.fW, q.fB + q.fH, z);
335           glVertex3f(q.fA,        q.fB + q.fH, z);
336           glEnd();
337         }
338       }
339       break;
340     }
341
342     case QuadSet::QT_RectangleXZFixedY:
343     {
344       const Float_t& y = mQ.fDefCoord;
345       while (qi.next()) {
346         QuadSet::QRectFixC& q = * (QuadSet::QRectFixC*) qi();
347         if (SetupColor(q))
348         {
349           if (rnrCtx.SecSelection()) glLoadName(qi.index());
350           glBegin(primitiveType);
351           glVertex3f(q.fA,        y, q.fB);
352           glVertex3f(q.fA + q.fW, y, q.fB);
353           glVertex3f(q.fA + q.fW, y, q.fB + q.fH);
354           glVertex3f(q.fA,        y, q.fB + q.fH);
355           glEnd();
356         }
357       }
358       break;
359     }
360
361     case QuadSet::QT_RectangleYZFixedX:
362     {
363       const Float_t& x = mQ.fDefCoord;
364       while (qi.next()) {
365         QuadSet::QRectFixC& q = * (QuadSet::QRectFixC*) qi();
366         if (SetupColor(q))
367         {
368           if (rnrCtx.SecSelection()) glLoadName(qi.index());
369           glBegin(primitiveType);
370           glVertex3f(x, q.fA,        q.fB);
371           glVertex3f(x, q.fA + q.fW, q.fB);
372           glVertex3f(x, q.fA + q.fW, q.fB + q.fH);
373           glVertex3f(x, q.fA,        q.fB + q.fH);
374           glEnd();
375         }
376       }
377       break;
378     }
379
380     case QuadSet::QT_RectangleXYFixedDimZ:
381     {
382       const Float_t& z = mQ.fDefCoord;
383       const Float_t& w = mQ.fDefWidth;
384       const Float_t& h = mQ.fDefHeight;
385       while (qi.next()) {
386         QuadSet::QRectFixDimC& q = * (QuadSet::QRectFixDimC*) qi();
387         if (SetupColor(q))
388         {
389           if (rnrCtx.SecSelection()) glLoadName(qi.index());
390           glBegin(primitiveType);
391           glVertex3f(q.fA,     q.fB,     z);
392           glVertex3f(q.fA + w, q.fB,     z);
393           glVertex3f(q.fA + w, q.fB + h, z);
394           glVertex3f(q.fA,     q.fB + h, z);
395           glEnd();
396         }
397       }
398       break;
399     }
400
401     case QuadSet::QT_RectangleXZFixedDimY:
402     {
403       const Float_t& y = mQ.fDefCoord;
404       const Float_t& w = mQ.fDefWidth;
405       const Float_t& h = mQ.fDefHeight;
406       while (qi.next()) {
407         QuadSet::QRectFixDimC& q = * (QuadSet::QRectFixDimC*) qi();
408         if (SetupColor(q))
409         {
410           if (rnrCtx.SecSelection()) glLoadName(qi.index());
411           glBegin(primitiveType);
412           glVertex3f(q.fA,     y, q.fB);
413           glVertex3f(q.fA + w, y, q.fB);
414           glVertex3f(q.fA + w, y, q.fB + h);
415           glVertex3f(q.fA,     y, q.fB + h);
416           glEnd();
417         }
418       }
419       break;
420     }
421
422     case QuadSet::QT_RectangleYZFixedDimX:
423     {
424       const Float_t& x = mQ.fDefCoord;
425       const Float_t& w = mQ.fDefWidth;
426       const Float_t& h = mQ.fDefHeight;
427       while (qi.next()) {
428         QuadSet::QRectFixDimC& q = * (QuadSet::QRectFixDimC*) qi();
429         if (SetupColor(q))
430         {
431           if (rnrCtx.SecSelection()) glLoadName(qi.index());
432           glBegin(primitiveType);
433           glVertex3f(x, q.fA,     q.fB);
434           glVertex3f(x, q.fA + w, q.fB);
435           glVertex3f(x, q.fA + w, q.fB + h);
436           glVertex3f(x, q.fA,     q.fB + h);
437           glEnd();
438         }
439       }
440       break;
441     }
442
443     default:
444       throw(eH + "unsupported quad-type.");
445
446   } // end switch quad-type
447
448   if (rnrCtx.SecSelection()) glPopName();
449 }
450
451
452 void QuadSetGL::RenderLines(TGLRnrCtx & rnrCtx) const
453 {
454   static const Exc_t eH("QuadSetGL::RenderLines ");
455
456   QuadSet& mQ = * fM;
457
458   VoidCPlex::iterator qi(mQ.fPlex);
459
460   if (rnrCtx.SecSelection()) glPushName(0);
461
462   switch (mQ.fQuadType)
463   {
464
465     case QuadSet::QT_LineXYFixedZ:
466     {
467       const Float_t& z = mQ.fDefCoord;
468       while (qi.next()) {
469         QuadSet::QLineFixC& q = * (QuadSet::QLineFixC*) qi();
470         if (SetupColor(q))
471         {
472           if (rnrCtx.SecSelection()) glLoadName(qi.index());
473           glBegin(GL_LINES);
474           glVertex3f(q.fA,         q.fB,         z);
475           glVertex3f(q.fA + q.fDx, q.fB + q.fDy, z);
476           glEnd();
477         }
478       }
479       break;
480     }
481
482     case QuadSet::QT_LineXZFixedY:
483     {
484       const Float_t& z = mQ.fDefCoord;
485       while (qi.next()) {
486         QuadSet::QLineFixC& q = * (QuadSet::QLineFixC*) qi();
487         if (SetupColor(q))
488         {
489           if (rnrCtx.SecSelection()) glLoadName(qi.index());
490           glBegin(GL_LINES);
491           glVertex3f(q.fA,         z, q.fB);
492           glVertex3f(q.fA + q.fDx, z, q.fB + q.fDy);
493           glEnd();
494         }
495       }
496       break;
497     }
498
499     default:
500       throw(eH + "unsupported quad-type.");
501
502   }
503
504   if (rnrCtx.SecSelection()) glPopName();
505 }
506
507 void QuadSetGL::RenderHexagons(TGLRnrCtx & rnrCtx) const
508 {
509   static const Exc_t eH("QuadSetGL::RenderHexagons ");
510
511   const Float_t sqr3hf = 0.5*TMath::Sqrt(3);
512
513   QuadSet& mQ = * fM;
514
515   GLenum primitveType = (mQ.fRenderMode != DigitSet::RM_Line) ?
516     GL_POLYGON : GL_LINE_LOOP;
517
518   glNormal3f(0, 0, 1);
519
520   VoidCPlex::iterator qi(mQ.fPlex);
521
522   if (rnrCtx.SecSelection()) glPushName(0);
523
524   switch (mQ.fQuadType)
525   {
526
527     case QuadSet::QT_HexagonXY:
528     {
529       while (qi.next()) {
530         QuadSet::QHex& q = * (QuadSet::QHex*) qi();
531         if (SetupColor(q))
532         {
533           const Float_t rh = q.fR * 0.5;
534           const Float_t rs = q.fR * sqr3hf;
535           if (rnrCtx.SecSelection()) glLoadName(qi.index());
536           glBegin(primitveType);
537           glVertex3f( q.fR + q.fA,       q.fB, q.fC);
538           glVertex3f(   rh + q.fA,  rs + q.fB, q.fC);
539           glVertex3f(  -rh + q.fA,  rs + q.fB, q.fC);
540           glVertex3f(-q.fR + q.fA,       q.fB, q.fC);
541           glVertex3f(  -rh + q.fA, -rs + q.fB, q.fC);
542           glVertex3f(   rh + q.fA, -rs + q.fB, q.fC);
543           glEnd();
544         }
545       }
546       break;
547     }
548
549     case QuadSet::QT_HexagonYX:
550     {
551       while (qi.next()) {
552         QuadSet::QHex& q = * (QuadSet::QHex*) qi();
553         if (SetupColor(q))
554         {
555           const Float_t rh = q.fR * 0.5;
556           const Float_t rs = q.fR * sqr3hf;
557           if (rnrCtx.SecSelection()) glLoadName(qi.index());
558           glBegin(primitveType);
559           glVertex3f( rs + q.fA,    rh + q.fB, q.fC);
560           glVertex3f(      q.fA,  q.fR + q.fB, q.fC);
561           glVertex3f(-rs + q.fA,    rh + q.fB, q.fC);
562           glVertex3f(-rs + q.fA,   -rh + q.fB, q.fC);
563           glVertex3f(      q.fA, -q.fR + q.fB, q.fC);
564           glVertex3f( rs + q.fA,   -rh + q.fB, q.fC);
565           glEnd();
566         }
567       }
568       break;
569     }
570
571     default:
572       throw(eH + "unsupported quad-type.");
573
574   } // end switch quad-type
575
576   if (rnrCtx.SecSelection()) glPopName();
577 }
578
579 /**************************************************************************/
580 /**************************************************************************/
581
582 //______________________________________________________________________________
583 void QuadSetGL::ProcessSelection(TGLRnrCtx & /*rnrCtx*/, TGLSelectRecord & rec)
584 {
585   // Processes secondary selection from TGLViewer.
586   // Calls TPointSet3D::PointSelected(Int_t) with index of selected
587   // point as an argument.
588
589   if (rec.GetN() < 2) return;
590   fM->DigitSelected(rec.GetItem(1));
591 }