]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/NLTPolygonSetGL.cxx
Record changes.
[u/mrichter/AliRoot.git] / EVE / Reve / NLTPolygonSetGL.cxx
1 #include "NLTPolygonSetGL.h"
2 #include "NLTPolygonSet.h"
3 #include "PODs.h"
4
5 #include <TGLRnrCtx.h>
6 #include <TGLIncludes.h>
7
8
9 using namespace Reve;
10
11 /**************************************************************************/
12
13 NLTPolygonSetGL::NLTPolygonSetGL() : TGLObject()
14 {
15   // fDLCache = false; // Disable DL.
16 }
17
18 NLTPolygonSetGL::~NLTPolygonSetGL()
19 {}
20
21 /**************************************************************************/
22 Bool_t NLTPolygonSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
23 {
24   return SetModelCheckClass(obj, NLTPolygonSet::Class());
25 }
26
27 /**************************************************************************/
28
29 void NLTPolygonSetGL::SetBBox()
30 {
31   SetAxisAlignedBBox(((NLTPolygonSet*)fExternalObj)->AssertBBox());
32 }
33
34 /**************************************************************************/
35 static GLUtriangulatorObj *GetTesselator()
36 {
37    static struct Init {
38       Init()
39       {
40 #if defined(R__WIN32)
41          typedef void (CALLBACK *tessfuncptr_t)();
42 #elif defined(R__AIXGCC)
43          typedef void (*tessfuncptr_t)(...);
44 #else
45          typedef void (*tessfuncptr_t)();
46 #endif
47          fTess = gluNewTess();
48
49          if (!fTess) {
50             Error("GetTesselator::Init", "could not create tesselation object");
51          } else {
52             gluTessCallback(fTess, (GLenum)GLU_BEGIN, (tessfuncptr_t)glBegin);
53             gluTessCallback(fTess, (GLenum)GLU_END, (tessfuncptr_t)glEnd);
54             gluTessCallback(fTess, (GLenum)GLU_VERTEX, (tessfuncptr_t)glVertex3fv);
55          }
56       }
57       ~Init()
58       {
59          if(fTess)
60             gluDeleteTess(fTess);
61       }
62       GLUtriangulatorObj *fTess;
63    }singleton;
64
65    return singleton.fTess;
66 }
67
68 /**************************************************************************/
69 void NLTPolygonSetGL::DirectDraw(TGLRnrCtx & /*rnrCtx*/) const
70 {
71   //  printf("NLTPolygonSetGL::DirectDraw %s \n",fExternalObj->GetName() );
72   NLTPolygonSet& PS = * (NLTPolygonSet*) fExternalObj;
73   if(PS.fPols.size() == 0) return;
74
75   glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
76
77   glDisable(GL_LIGHTING);
78   glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
79   glEnable(GL_COLOR_MATERIAL);
80   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
81   glDisable(GL_CULL_FACE);
82
83   // polygons
84   glEnable(GL_POLYGON_OFFSET_FILL);
85   glPolygonOffset(1.,1.);
86   GLUtriangulatorObj *tessObj = GetTesselator();
87
88   Vector* pnts = PS.fPnts;
89   for (NLTPolygonSet::vpPolygon_ci i = PS.fPols.begin(); i!= PS.fPols.end(); i++)
90   {
91     Int_t vi; //current vertex index of curent polygon
92     Int_t N = (*i).fNPnts; // number of points in current polygon
93     if(N < 4) 
94     {
95       glBegin(GL_POLYGON);
96       for(Int_t k=0; k<N; k++)
97       {
98         vi = (*i).fPnts[k]; 
99         glVertex3fv(pnts[vi].c_vec());
100       }
101       glEnd();
102     }
103     else {
104       gluBeginPolygon(tessObj);
105       gluNextContour(tessObj, (GLenum)GLU_UNKNOWN);
106       glNormal3f(0., 0., 1.);
107       Double_t coords[3];
108       coords[2] = 0.;
109       for (Int_t k = 0; k<N; k++)
110       {
111         vi = (*i).fPnts[k];
112         coords[0] = pnts[vi].x;
113         coords[1] = pnts[vi].y;
114         gluTessVertex(tessObj, coords, pnts[vi].c_vec());
115       }
116       gluEndPolygon(tessObj);
117     }
118   }
119   glDisable(GL_POLYGON_OFFSET_FILL);
120
121   // outline 
122   UChar_t lcol[4];
123   ColorFromIdx(PS.fLineColor, lcol);
124   glColor4ubv(lcol);
125   glEnable(GL_LINE_SMOOTH);
126
127   glLineWidth(PS.fLineWidth);
128   Int_t vi;
129   for (NLTPolygonSet::vpPolygon_ci i = PS.fPols.begin(); i!= PS.fPols.end(); i++)
130   {
131     glBegin(GL_LINE_LOOP); 
132     for(Int_t k=0; k<(*i).fNPnts; k++)
133     {
134       vi = (*i).fPnts[k];
135       glVertex3fv(PS.fPnts[vi].c_vec());
136     }
137     glEnd();
138   }
139
140   glPopAttrib();
141 }
142