1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
20 #include "QuadSetGL.h"
21 #include <Reve/FrameBoxGL.h>
23 #include <TGLDrawFlags.h>
30 //______________________________________________________________________
34 ClassImp(OldQuadSetGL)
36 /**************************************************************************/
38 OldQuadSetGL::OldQuadSetGL() : TGLObject()
40 // fCached = false; // Disable DL.
43 OldQuadSetGL::~OldQuadSetGL()
46 /**************************************************************************/
48 Bool_t OldQuadSetGL::SetModel(TObject* obj)
50 return SetModelCheckClass(obj, Reve::OldQuadSet::Class());
53 void OldQuadSetGL::SetBBox()
55 SetAxisAlignedBBox(((OldQuadSet*)fExternalObj)->AssertBBox());
58 /**************************************************************************/
60 void OldQuadSetGL::DirectDraw(const TGLDrawFlags & ) const
62 // printf("OldQuadSetGLRenderer::DirectDraw Style %d, LOD %d\n", flags.Style(), flags.LOD());
64 OldQuadSet& Q = * (OldQuadSet*) fExternalObj;
66 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
68 glDisable(GL_LIGHTING);
69 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
70 glEnable(GL_COLOR_MATERIAL);
71 glPolygonMode(GL_FRONT, GL_LINE);
72 glPolygonMode(GL_BACK, GL_LINE);
73 glDisable(GL_CULL_FACE);
75 Float_t c[4]; glGetFloatv(GL_CURRENT_COLOR, c);
76 // UChar_t alpha = (UChar_t)(255*c[3]);
79 for(std::vector<Quad>::iterator q=Q.fQuads.begin(); q!=Q.fQuads.end(); ++q) {
80 UChar_t* c = (UChar_t*) &q->color;
81 //glColor4ub(c[0], c[1], c[2], (c[3]*alpha) >> 8);
82 glColor3ub(c[0], c[1], c[2]);
83 glVertex3fv(q->vertices);
84 glVertex3fv(q->vertices + 3);
85 glVertex3fv(q->vertices + 6);
86 glVertex3fv(q->vertices + 9);
94 /**************************************************************************/
95 /**************************************************************************/
96 /**************************************************************************/
97 /**************************************************************************/
99 //______________________________________________________________________
105 /**************************************************************************/
107 QuadSetGL::QuadSetGL() : TGLObject(), fM(0)
109 // fCached = false; // Disable DL.
112 QuadSetGL::~QuadSetGL()
115 /**************************************************************************/
117 Bool_t QuadSetGL::SetModel(TObject* obj)
119 Bool_t ok = SetModelCheckClass(obj, Reve::QuadSet::Class());
120 fM = ok ? dynamic_cast<Reve::QuadSet*>(obj) : 0;
124 void QuadSetGL::SetBBox()
126 SetAxisAlignedBBox(fM->AssertBBox());
129 /**************************************************************************/
131 inline Bool_t QuadSetGL::SetupColor(const QuadSet::QuadBase& q) const
133 if (fM->fValueIsColor)
135 glColor4ubv((UChar_t*) & q.fValue);
141 Bool_t visible = fM->fPalette->ColorFromValue(q.fValue, fM->fDefaultValue, c);
148 /**************************************************************************/
150 void QuadSetGL::DirectDraw(const TGLDrawFlags & flags) const
152 static const Exc_t eH("QuadSetGL::DirectDraw ");
154 // printf("QuadSetGLRenderer::DirectDraw Style %d, LOD %d\n", flags.Style(), flags.LOD());
159 FrameBoxGL::Render(mQ.fFrame);
161 if (mQ.fPlex.Size() == 0)
163 if ( ! mQ.fValueIsColor && mQ.fPalette == 0)
168 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
169 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
170 glEnable(GL_COLOR_MATERIAL);
171 glDisable(GL_CULL_FACE);
173 if (mQ.fRenderMode == QuadSet::RM_Fill)
174 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
175 else if (mQ.fRenderMode == QuadSet::RM_Line)
176 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
178 if (mQ.fDisableLigting) glDisable(GL_LIGHTING);
180 if (mQ.fQuadType < QuadSet::QT_Rectangle_End) RenderQuads(flags);
181 else if (mQ.fQuadType < QuadSet::QT_Line_End) RenderLines(flags);
182 else if (mQ.fQuadType < QuadSet::QT_Hexagon_End) RenderHexagons(flags);
189 void QuadSetGL::RenderQuads(const TGLDrawFlags &flags) const
191 static const Exc_t eH("QuadSetGL::RenderQuads ");
195 GLenum primitiveType;
196 if (mQ.fRenderMode != QuadSet::RM_Line)
198 primitiveType = GL_QUADS;
199 if (mQ.fQuadType == QuadSet::QT_FreeQuad)
200 glEnable(GL_NORMALIZE);
204 primitiveType = GL_LINE_LOOP;
207 VoidCPlex::iterator qi(mQ.fPlex);
209 if (flags.SecSelection()) glPushName(0);
211 switch (mQ.fQuadType)
214 case QuadSet::QT_FreeQuad:
216 Float_t e1[3], e2[3], normal[3];
218 QuadSet::QFreeQuad& q = * (QuadSet::QFreeQuad*) qi();
221 Float_t* p = q.fVertices;
222 e1[0] = p[3] - p[0]; e1[1] = p[4] - p[1]; e1[2] = p[5] - p[2];
223 e2[0] = p[6] - p[0]; e2[1] = p[7] - p[1]; e2[2] = p[8] - p[2];
224 TMath::Cross(e1, e2, normal);
225 if (flags.SecSelection()) glLoadName(qi.index());
226 glBegin(primitiveType);
238 case QuadSet::QT_RectangleXY:
241 QuadSet::QRect& q = * (QuadSet::QRect*) qi();
244 if (flags.SecSelection()) glLoadName(qi.index());
245 glBegin(primitiveType);
246 glVertex3f(q.fX, q.fY, q.fZ);
247 glVertex3f(q.fX + q.fW, q.fY, q.fZ);
248 glVertex3f(q.fX + q.fW, q.fY + q.fH, q.fZ);
249 glVertex3f(q.fX, q.fY + q.fH, q.fZ);
256 case QuadSet::QT_RectangleXYFixedDim:
258 const Float_t& w = mQ.fDefWidth;
259 const Float_t& h = mQ.fDefHeight;
261 QuadSet::QRectFixDim& q = * (QuadSet::QRectFixDim*) qi();
264 if (flags.SecSelection()) glLoadName(qi.index());
265 glBegin(primitiveType);
266 glVertex3f(q.fX, q.fY, q.fZ);
267 glVertex3f(q.fX + w, q.fY, q.fZ);
268 glVertex3f(q.fX + w, q.fY + h, q.fZ);
269 glVertex3f(q.fX, q.fY + h, q.fZ);
276 case QuadSet::QT_RectangleXYFixedZ:
278 const Float_t& z = mQ.fDefCoord;
280 QuadSet::QRectFixC& q = * (QuadSet::QRectFixC*) qi();
283 if (flags.SecSelection()) glLoadName(qi.index());
284 glBegin(primitiveType);
285 glVertex3f(q.fX, q.fY, z);
286 glVertex3f(q.fX + q.fW, q.fY, z);
287 glVertex3f(q.fX + q.fW, q.fY + q.fH, z);
288 glVertex3f(q.fX, q.fY + q.fH, z);
295 case QuadSet::QT_RectangleXZFixedY:
297 const Float_t& z = mQ.fDefCoord;
299 QuadSet::QRectFixC& q = * (QuadSet::QRectFixC*) qi();
302 if (flags.SecSelection()) glLoadName(qi.index());
303 glBegin(primitiveType);
304 glVertex3f(q.fX, z, q.fY);
305 glVertex3f(q.fX + q.fW, z, q.fY);
306 glVertex3f(q.fX + q.fW, z, q.fY + q.fH);
307 glVertex3f(q.fX, z, q.fY + q.fH);
314 case QuadSet::QT_RectangleXYFixedDimZ:
316 const Float_t& z = mQ.fDefCoord;
317 const Float_t& w = mQ.fDefWidth;
318 const Float_t& h = mQ.fDefHeight;
320 QuadSet::QRectFixDimC& q = * (QuadSet::QRectFixDimC*) qi();
323 if (flags.SecSelection()) glLoadName(qi.index());
324 glBegin(primitiveType);
325 glVertex3f(q.fX, q.fY, z);
326 glVertex3f(q.fX + w, q.fY, z);
327 glVertex3f(q.fX + w, q.fY + h, z);
328 glVertex3f(q.fX, q.fY + h, z);
335 case QuadSet::QT_RectangleXZFixedDimY:
337 const Float_t& z = mQ.fDefCoord;
338 const Float_t& w = mQ.fDefWidth;
339 const Float_t& h = mQ.fDefHeight;
341 QuadSet::QRectFixDimC& q = * (QuadSet::QRectFixDimC*) qi();
344 if (flags.SecSelection()) glLoadName(qi.index());
345 glBegin(primitiveType);
346 glVertex3f(q.fX, z, q.fY);
347 glVertex3f(q.fX + w, z, q.fY);
348 glVertex3f(q.fX + w, z, q.fY + h);
349 glVertex3f(q.fX, z, q.fY + h);
357 throw(eH + "unsupported quad-type.");
359 } // end switch quad-type
361 if (flags.SecSelection()) glPopName();
365 void QuadSetGL::RenderLines(const TGLDrawFlags &flags) const
367 static const Exc_t eH("QuadSetGL::RenderLines ");
371 VoidCPlex::iterator qi(mQ.fPlex);
373 if (flags.SecSelection()) glPushName(0);
375 switch (mQ.fQuadType)
378 case QuadSet::QT_LineXYFixedZ:
380 const Float_t& z = mQ.fDefCoord;
382 QuadSet::QLineFixC& q = * (QuadSet::QLineFixC*) qi();
385 if (flags.SecSelection()) glLoadName(qi.index());
387 glVertex3f(q.fX, q.fY, z);
388 glVertex3f(q.fX + q.fDx, q.fY + q.fDy, z);
395 case QuadSet::QT_LineXZFixedY:
397 const Float_t& z = mQ.fDefCoord;
399 QuadSet::QLineFixC& q = * (QuadSet::QLineFixC*) qi();
402 if (flags.SecSelection()) glLoadName(qi.index());
404 glVertex3f(q.fX, z, q.fY);
405 glVertex3f(q.fX + q.fDx, z, q.fY + q.fDy);
413 throw(eH + "unsupported quad-type.");
417 if (flags.SecSelection()) glPopName();
420 void QuadSetGL::RenderHexagons(const TGLDrawFlags &flags) const
422 static const Exc_t eH("QuadSetGL::RenderHexagons ");
424 const Float_t sqr3hf = 0.5*TMath::Sqrt(3);
428 GLenum primitveType = (mQ.fRenderMode != QuadSet::RM_Line) ?
429 GL_POLYGON : GL_LINE_LOOP;
433 VoidCPlex::iterator qi(mQ.fPlex);
435 if (flags.SecSelection()) glPushName(0);
437 switch (mQ.fQuadType)
440 case QuadSet::QT_HexagonXY:
443 QuadSet::QHex& q = * (QuadSet::QHex*) qi();
446 const Float_t rh = q.fR * 0.5;
447 const Float_t rs = q.fR * sqr3hf;
448 if (flags.SecSelection()) glLoadName(qi.index());
449 glBegin(primitveType);
450 glVertex3f( q.fR + q.fX, q.fY, q.fZ);
451 glVertex3f( rh + q.fX, rs + q.fY, q.fZ);
452 glVertex3f( -rh + q.fX, rs + q.fY, q.fZ);
453 glVertex3f(-q.fR + q.fX, q.fY, q.fZ);
454 glVertex3f( -rh + q.fX, -rs + q.fY, q.fZ);
455 glVertex3f( rh + q.fX, -rs + q.fY, q.fZ);
462 case QuadSet::QT_HexagonYX:
465 QuadSet::QHex& q = * (QuadSet::QHex*) qi();
468 const Float_t rh = q.fR * 0.5;
469 const Float_t rs = q.fR * sqr3hf;
470 if (flags.SecSelection()) glLoadName(qi.index());
471 glBegin(primitveType);
472 glVertex3f( rs + q.fX, rh + q.fY, q.fZ);
473 glVertex3f( q.fX, q.fR + q.fY, q.fZ);
474 glVertex3f(-rs + q.fX, rh + q.fY, q.fZ);
475 glVertex3f(-rs + q.fX, -rh + q.fY, q.fZ);
476 glVertex3f( q.fX, -q.fR + q.fY, q.fZ);
477 glVertex3f( rs + q.fX, -rh + q.fY, q.fZ);
485 throw(eH + "unsupported quad-type.");
487 } // end switch quad-type
489 if (flags.SecSelection()) glPopName();
492 /**************************************************************************/
493 /**************************************************************************/
495 //______________________________________________________________________________
496 void QuadSetGL::ProcessSelection(UInt_t* ptr, TGLViewer*, TGLScene*)
498 // Processes secondary selection from TGLViewer.
499 // Calls TPointSet3D::PointSelected(Int_t) with index of selected
500 // point as an argument.
502 if (ptr[0] < 2) return;
503 fM->QuadSelected(ptr[4]);