]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/GLUtilNS.cxx
Dummy methods DefineParticle required by the interface added.
[u/mrichter/AliRoot.git] / EVE / Reve / GLUtilNS.cxx
1 #include "GLUtilNS.h"
2 #include "Reve.h"
3
4 #include <TAttMarker.h>
5 #include <TAttLine.h>
6 #include <TGLIncludes.h>
7
8 namespace GLUtilNS {
9
10 void RenderLine(const TAttLine& aline, Float_t* p, Int_t n,
11                 Bool_t /*selection*/, Bool_t /*sec_selection*/)
12 {
13   if(n == 0) return;
14
15   glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT);
16   glDisable(GL_LIGHTING);
17   glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
18   glEnable(GL_COLOR_MATERIAL);
19   UChar_t color[4];
20   Reve::ColorFromIdx(aline.GetLineColor(), color);
21   glColor4ubv(color);  
22   glLineWidth(aline.GetLineWidth());
23   if (aline.GetLineStyle() > 1) {
24     Int_t    fac = 1;
25     UShort_t pat = 0xffff;
26     switch (aline.GetLineStyle()) {
27       case 2:  pat = 0x3333; break;
28       case 3:  pat = 0x5555; break;
29       case 4:  pat = 0xf040; break;
30       case 5:  pat = 0xf4f4; break;
31       case 6:  pat = 0xf111; break;
32       case 7:  pat = 0xf0f0; break;
33       case 8:  pat = 0xff11; break;
34       case 9:  pat = 0x3fff; break;
35       case 10: pat = 0x08ff; fac = 2; break;
36     }
37
38     glLineStipple(1, pat);
39     glEnable(GL_LINE_STIPPLE);
40   }
41
42   Float_t* tp = p;
43   glBegin(GL_LINE_STRIP);
44   for (Int_t i=0; i<n; ++i, tp+=3)
45     glVertex3fv(tp);
46   glEnd();
47
48   glPopAttrib();
49 }
50
51 void RenderPolyMarkers(const TAttMarker& marker, Float_t* p, Int_t n,
52                        Bool_t selection, Bool_t sec_selection)
53 {
54   // Store attributes GL_POINT_BIT and GL_LINE_BIT before call this function !
55   glPushAttrib(GL_ENABLE_BIT |GL_POINT_BIT | GL_LINE_BIT);
56   glDisable(GL_LIGHTING);
57   glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
58   glEnable(GL_COLOR_MATERIAL);
59   UChar_t color[4];
60   Reve::ColorFromIdx(marker.GetMarkerColor(), color);
61   glColor4ubv(color);
62
63   Int_t s = marker.GetMarkerStyle(); 
64   if (s == 2 || s == 3 || s == 5 || s == 28)
65     RenderCrosses(marker, p, n, sec_selection); 
66   else
67     RenderPoints(marker, p, n, selection, sec_selection); 
68
69   glPopAttrib();
70 }
71
72 //______________________________________________________________________________
73 void RenderPoints(const TAttMarker& marker, Float_t* op, Int_t n,
74                   Bool_t selection, Bool_t sec_selection)
75 {
76   // Render markers as circular or square points.
77   
78   Int_t ms = marker.GetMarkerStyle();
79   Float_t size = 5*marker.GetMarkerSize();
80   if (ms == 4 || ms == 20 || ms == 24) 
81   {
82     if (ms == 4 || ms == 24)
83       glEnable(GL_BLEND);
84     glEnable(GL_POINT_SMOOTH);
85   } else 
86   {
87     glDisable(GL_POINT_SMOOTH);
88     if      (ms == 1) size = 1;
89     else if (ms == 6) size = 2;
90     else if (ms == 7) size = 3;
91   }
92   glPointSize(size);
93    
94   // During selection extend picking region for large point-sizes.
95   static const Int_t sPickRadius = 3; // Hardcoded also in TGLViewer::RequestSelect()
96   Bool_t changePM = kFALSE;
97   if (selection && size > sPickRadius) 
98   {
99     changePM = kTRUE;
100     glMatrixMode(GL_PROJECTION);
101     glPushMatrix();
102     Float_t pm[16];
103     glGetFloatv(GL_PROJECTION_MATRIX, pm);
104     Float_t scale = (Float_t) sPickRadius / size;
105     for (Int_t i=0; i<=12; i+=4) {
106       pm[i] *= scale; pm[i+1] *= scale;
107     }
108     glLoadMatrixf(pm);
109   }
110
111   Float_t* p = op;
112   if (sec_selection) 
113   {
114     glPushName(0);
115     for (Int_t i=0; i<n; ++i, p+=3) 
116     {
117       glLoadName(i);
118       glBegin(GL_POINTS);
119       glVertex3fv(p);
120       glEnd();
121     }
122     glPopName();
123   } 
124   else 
125   {
126     glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
127     glVertexPointer(3, GL_FLOAT, 0, p);
128     glEnableClientState(GL_VERTEX_ARRAY);
129     { // Circumvent bug in ATI's linux drivers.
130       Int_t nleft = n;
131       Int_t ndone = 0;
132       const Int_t maxChunk = 8192;
133       while (nleft > maxChunk) 
134       {
135         glDrawArrays(GL_POINTS, ndone, maxChunk);
136         nleft -= maxChunk;
137         ndone += maxChunk;
138       }
139       glDrawArrays(GL_POINTS, ndone, nleft);
140     }
141     glPopClientAttrib();
142   }
143
144   if (changePM) 
145   {
146     glPopMatrix();
147     glMatrixMode(GL_MODELVIEW);
148   }
149   
150 }
151
152 //______________________________________________________________________________
153 void RenderCrosses(const TAttMarker& marker, Float_t* op, Int_t n,
154                    Bool_t sec_selection)
155 {
156   // Render markers as crosses.
157   //
158   if (marker.GetMarkerStyle() == 28) 
159   {
160     glEnable(GL_BLEND);
161     glEnable(GL_LINE_SMOOTH);
162     glLineWidth(2);
163   } 
164   else 
165   {
166     glDisable(GL_LINE_SMOOTH);
167   }
168
169   // cross dim
170   const Float_t  d = 2*marker.GetMarkerSize();
171   Float_t* p = op;
172   if (sec_selection) 
173   {
174     glPushName(0);
175     for (Int_t i=0; i<n; ++i, p+=3) 
176     {
177       glLoadName(i);
178       glBegin(GL_LINES);
179       glVertex3f(p[0]-d, p[1], p[2]); glVertex3f(p[0]+d, p[1], p[2]);
180       glVertex3f(p[0], p[1]-d, p[2]); glVertex3f(p[0], p[1]+d, p[2]);
181       glVertex3f(p[0], p[1], p[2]-d); glVertex3f(p[0], p[1], p[2]+d);
182       glEnd();
183     }
184     glPopName();
185   } 
186   else 
187   {
188     glBegin(GL_LINES);
189     for (Int_t i=0; i<n; ++i, p+=3) 
190     {
191       glVertex3f(p[0]-d, p[1], p[2]); glVertex3f(p[0]+d, p[1], p[2]);
192       glVertex3f(p[0], p[1]-d, p[2]); glVertex3f(p[0], p[1]+d, p[2]);
193       glVertex3f(p[0], p[1], p[2]-d); glVertex3f(p[0], p[1], p[2]+d);
194     }
195     glEnd();
196   }
197 }
198
199 /**************************************************************************/
200 } // end namespace GLUtilNS