]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/StraightLineSetGL.cxx
Dummy methods DefineParticle required by the interface added.
[u/mrichter/AliRoot.git] / EVE / Reve / StraightLineSetGL.cxx
1 // $Header$
2
3 #include "StraightLineSetGL.h"
4 #include <Reve/StraightLineSet.h>
5 #include <Reve/GLUtilNS.h>
6
7 #include <TGLRnrCtx.h>
8 #include <TGLSelectRecord.h>
9
10 #include <TGLIncludes.h>
11
12 using namespace Reve;
13
14 //______________________________________________________________________
15 // StraightLineSetGL
16 //
17
18 ClassImp(StraightLineSetGL)
19
20 StraightLineSetGL::StraightLineSetGL() : TGLObject(), fM(0)
21 {
22   // fDLCache = false; // Disable display list.
23 }
24
25 StraightLineSetGL::~StraightLineSetGL()
26 {}
27
28 /**************************************************************************/
29
30 Bool_t StraightLineSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
31 {
32   if(SetModelCheckClass(obj, StraightLineSet::Class())) {
33     fM = dynamic_cast<StraightLineSet*>(obj);
34     return kTRUE;
35   }
36   return kFALSE;
37 }
38
39 void StraightLineSetGL::SetBBox()
40 {
41   // !! This ok if master sub-classed from TAttBBox
42   SetAxisAlignedBBox(((StraightLineSet*)fExternalObj)->AssertBBox());
43 }
44
45 //______________________________________________________________________________
46 Bool_t StraightLineSetGL::ShouldCache(TGLRnrCtx & rnrCtx) const
47 {
48    // Override from TGLDrawable.
49    // To account for large point-sizes we modify the projection matrix
50    // during selection and thus we need a direct draw.
51
52    if (rnrCtx.Selection()) return kFALSE;
53    return fDLCache;
54 }
55
56 /**************************************************************************/
57
58 void StraightLineSetGL::DirectDraw(TGLRnrCtx & rnrCtx) const
59 {
60   // printf("StraightLineSetGL::DirectDraw Style %d, LOD %d\n", flags.Style(), flags.LOD());
61
62   StraightLineSet& mL = * fM;
63
64   glPushAttrib(GL_POINT_BIT | GL_LINE_BIT | GL_ENABLE_BIT);
65
66   // lines
67   GLUtilNS::GL_Capability_Switch lights_off(GL_LIGHTING, false);
68   if(mL.GetRnrLines() && mL.GetLinePlex().Size() > 0)
69   {
70     glDisable(GL_LIGHTING);
71     glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
72     glEnable(GL_COLOR_MATERIAL);
73     UChar_t color[4];
74     Reve::ColorFromIdx(mL.GetLineColor(), color);
75     glColor4ubv(color);  
76     glLineWidth(mL.GetLineWidth());
77     if (mL.GetLineStyle() > 1) {
78       Int_t    fac = 1;
79       UShort_t pat = 0xffff;
80       switch (mL.GetLineStyle()) {
81         case 2:  pat = 0x3333; break;
82         case 3:  pat = 0x5555; break;
83         case 4:  pat = 0xf040; break;
84         case 5:  pat = 0xf4f4; break;
85         case 6:  pat = 0xf111; break;
86         case 7:  pat = 0xf0f0; break;
87         case 8:  pat = 0xff11; break;
88         case 9:  pat = 0x3fff; break;
89         case 10: pat = 0x08ff; fac = 2; break;
90       }
91       glLineStipple(1, pat);
92       glEnable(GL_LINE_STIPPLE);
93     }
94
95     VoidCPlex::iterator li(mL.GetLinePlex());
96     if(rnrCtx.SecSelection()) 
97     {  
98       GLuint name = 0;
99       glPushName(1);
100       glPushName(0);  
101       while (li.next()) 
102       {
103         StraightLineSet::Line& l = * (StraightLineSet::Line*) li();
104         glLoadName(name);
105         {
106           glBegin(GL_LINES);  
107           glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
108           glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
109           glEnd();
110         }
111         name ++;
112       }  
113       glPopName(); 
114       glPopName();
115     } 
116     else 
117     {
118       glBegin(GL_LINES);    
119       while (li.next()) 
120       {
121         StraightLineSet::Line& l = * (StraightLineSet::Line*) li();
122         glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
123         glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
124       }    
125       glEnd();
126     }
127   }
128   glPopAttrib();
129  
130
131   // markers
132   if(mL.GetRnrMarkers() && mL.GetMarkerPlex().Size() > 0)
133   {
134     VoidCPlex::iterator mi(mL.GetMarkerPlex());
135     Float_t* pnts = new Float_t[mL.GetMarkerPlex().Size()*3];
136     Float_t* pnt  = pnts;
137     Int_t lidx = -1; 
138     while (mi.next()) 
139     {
140       StraightLineSet::Marker& m = * (StraightLineSet::Marker*) mi();
141       lidx = m.fLineID;
142       StraightLineSet::Line& l = * (StraightLineSet::Line*) mL.GetLinePlex().Atom(lidx);
143       pnt[0] = l.fV1[0] + (l.fV2[0] - l.fV1[0])*m.fPos;
144       pnt[1] = l.fV1[1] + (l.fV2[1] - l.fV1[1])*m.fPos;
145       pnt[2] = l.fV1[2] + (l.fV2[2] - l.fV1[2])*m.fPos;;
146       pnt   += 3;
147     }
148     if(rnrCtx.SecSelection()) glPushName(2);
149     GLUtilNS::RenderPolyMarkers((TAttMarker&)mL, pnts, mL.GetMarkerPlex().Size(),
150                                 rnrCtx.Selection(), rnrCtx.SecSelection());
151     if(rnrCtx.SecSelection()) glPopName();
152     delete [] pnts;
153   }
154
155 }
156
157 /**************************************************************************/
158
159 void StraightLineSetGL::ProcessSelection(TGLRnrCtx       & /*rnrCtx*/,
160                                          TGLSelectRecord & rec)
161
162   if (rec.GetN() != 3) return;
163   if(rec.GetItem(1) == 1)
164   {
165     printf("selected line %d\n", rec.GetItem(2));
166   }
167   else 
168   {
169     StraightLineSet::Marker& m = * (StraightLineSet::Marker*) fM->GetMarkerPlex().Atom(rec.GetItem(2));
170     printf("Selected point %d on line %d\n", rec.GetItem(2), m.fLineID);
171   }
172 }