]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/StraightLineSetGL.cxx
Follow-up on gl/ changes introduced in ROOT-5.16.
[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   GLUtilNS::GL_Capability_Switch lights_off(GL_LIGHTING, false);
66  
67   if(mL.fRnrLines && mL.fLinePlex.Size() > 0)
68   {
69     UChar_t color[4];
70     ColorFromIdx(mL.GetMainColor(), color);
71     glColor4ubv(color);
72
73     VoidCPlex::iterator li(mL.fLinePlex);
74     if(rnrCtx.SecSelection()) 
75     {  
76       GLuint name = 0;
77       glPushName(1);
78       glPushName(0);  
79       while (li.next()) 
80       {
81         StraightLineSet::Line& l = * (StraightLineSet::Line*) li();
82         glLoadName(name);
83         {
84           glBegin(GL_LINES);  
85           glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
86           glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
87           glEnd();
88         }
89         name ++;
90       }  
91       glPopName(); 
92       glPopName();
93     } 
94     else 
95     {
96       glBegin(GL_LINES);    
97       while (li.next()) 
98       {
99         StraightLineSet::Line& l = * (StraightLineSet::Line*) li();
100         glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
101         glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
102       }    
103       glEnd();
104     }
105   }
106
107   if(mL.fRnrMarkers && mL.fMarkerPlex.Size() > 0)
108   {
109     UChar_t color[4];
110     ColorFromIdx(mL.GetMarkerColor(), color);
111     glColor4ubv(color);
112
113     VoidCPlex::iterator mi(mL.fMarkerPlex);
114     Float_t* pnts = new Float_t[mL.fMarkerPlex.Size()*3];
115     Float_t* pnt  = pnts;
116     Int_t lidx = -1; 
117     while (mi.next()) 
118     {
119       StraightLineSet::Marker& m = * (StraightLineSet::Marker*) mi();
120       lidx = m.fLineID;
121       StraightLineSet::Line& l = * (StraightLineSet::Line*) mL.fLinePlex.Atom(lidx);
122       pnt[0] = l.fV1[0] + (l.fV2[0] - l.fV1[0])*m.fPos;
123       pnt[1] = l.fV1[1] + (l.fV2[1] - l.fV1[1])*m.fPos;
124       pnt[2] = l.fV1[2] + (l.fV2[2] - l.fV1[2])*m.fPos;;
125       pnt   += 3;
126     }
127     if(rnrCtx.SecSelection()) glPushName(2);
128     GLUtilNS::RenderPolyMarkers((TAttMarker&)mL, pnts, mL.fMarkerPlex.Size(),
129                                 rnrCtx.Selection(), rnrCtx.SecSelection());
130     if(rnrCtx.SecSelection()) glPopName();
131     delete [] pnts;
132   }
133
134   glPopAttrib();
135 }
136
137 /**************************************************************************/
138
139 void StraightLineSetGL::ProcessSelection(TGLRnrCtx       & /*rnrCtx*/,
140                                          TGLSelectRecord & rec)
141
142   if (rec.GetN() != 3) return;
143   if(rec.GetItem(1) == 1)
144   {
145     printf("selected line %d\n", rec.GetItem(2));
146   }
147   else 
148   {
149     StraightLineSet::Marker& m = * (StraightLineSet::Marker*) fM->fMarkerPlex.Atom(rec.GetItem(2));
150     printf("Selected point %d on line %d\n", rec.GetItem(2), m.fLineID);
151   }
152 }