]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/StraightLineSetGL.cxx
Added limit-getters, in ctor set limits to match min/max values.
[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 <TGLDrawFlags.h>
8
9 #ifdef WIN32
10 #include "Windows4root.h"
11 #endif
12 #include <GL/gl.h>
13 #include <GL/glu.h>
14
15 using namespace Reve;
16
17 //______________________________________________________________________
18 // StraightLineSetGL
19 //
20
21 ClassImp(StraightLineSetGL)
22
23 StraightLineSetGL::StraightLineSetGL() : TGLObject(), fM(0)
24 {
25   // fCached = false; // Disable display list.
26 }
27
28 StraightLineSetGL::~StraightLineSetGL()
29 {}
30
31 /**************************************************************************/
32
33 Bool_t StraightLineSetGL::SetModel(TObject* obj)
34 {
35   if(SetModelCheckClass(obj, StraightLineSet::Class())) {
36     fM = dynamic_cast<StraightLineSet*>(obj);
37     return kTRUE;
38   }
39   return kFALSE;
40 }
41
42 void StraightLineSetGL::SetBBox()
43 {
44   // !! This ok if master sub-classed from TAttBBox
45   SetAxisAlignedBBox(((StraightLineSet*)fExternalObj)->AssertBBox());
46 }
47
48 //______________________________________________________________________________
49 Bool_t StraightLineSetGL::ShouldCache(const TGLDrawFlags & flags) const
50 {
51    // Override from TGLDrawable.
52    // To account for large point-sizes we modify the projection matrix
53    // during selection and thus we need a direct draw.
54
55    if (flags.Selection()) return kFALSE;
56    return fCached;
57 }
58
59 /**************************************************************************/
60
61 void StraightLineSetGL::DirectDraw(const TGLDrawFlags & flags) const
62 {
63   // printf("StraightLineSetGL::DirectDraw Style %d, LOD %d\n", flags.Style(), flags.LOD());
64
65   StraightLineSet& mL = * fM;
66
67   glPushAttrib(GL_POINT_BIT | GL_LINE_BIT | GL_ENABLE_BIT);
68   GLUtilNS::GL_Capability_Switch lights_off(GL_LIGHTING, false);
69  
70   if(mL.fRnrLines) 
71   {
72     UChar_t color[4];
73     ColorFromIdx(mL.GetMainColor(), color);
74     glColor4ubv(color);
75
76     VoidCPlex::iterator li(mL.fLinePlex);
77     if(flags.SecSelection()) 
78     {  
79       GLuint name = 0;
80       glPushName(1);
81       glPushName(0);  
82       while (li.next()) 
83       {
84         StraightLineSet::Line& l = * (StraightLineSet::Line*) li();
85         glLoadName(name);
86         {
87           glBegin(GL_LINES);  
88           glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
89           glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
90           glEnd();
91         }
92         name ++;
93       }  
94       glPopName(); 
95       glPopName();
96     } 
97     else 
98     {
99       glBegin(GL_LINES);    
100       while (li.next()) 
101       {
102         StraightLineSet::Line& l = * (StraightLineSet::Line*) li();
103         glVertex3f(l.fV1[0], l.fV1[1], l.fV1[2]);
104         glVertex3f(l.fV2[0], l.fV2[1], l.fV2[2]);
105       }    
106       glEnd();
107     }
108   }
109
110   if(mL.fRnrMarkers)
111   {
112     UChar_t color[4];
113     ColorFromIdx(mL.GetMarkerColor(), color);
114     glColor4ubv(color);
115
116     VoidCPlex::iterator mi(mL.fMarkerPlex);
117     Float_t* pnts = new Float_t[mL.fMarkerPlex.Size()*3];
118     Float_t* pnt  = pnts;
119     Int_t lidx = -1; 
120     while (mi.next()) 
121     {
122       StraightLineSet::Marker& m = * (StraightLineSet::Marker*) mi();
123       lidx = m.fLineID;
124       StraightLineSet::Line& l = * (StraightLineSet::Line*) mL.fLinePlex.Atom(lidx);
125       pnt[0] = l.fV1[0] + (l.fV2[0] - l.fV1[0])*m.fPos;
126       pnt[1] = l.fV1[1] + (l.fV2[1] - l.fV1[1])*m.fPos;
127       pnt[2] = l.fV1[2] + (l.fV2[2] - l.fV1[2])*m.fPos;;
128       pnt   += 3;
129     }
130     if(flags.SecSelection()) glPushName(2);
131     GLUtilNS::RenderPolyMarkers((TAttMarker&)mL, pnts, mL.fLinePlex.Size(), flags.Selection(), flags.SecSelection());
132     if(flags.SecSelection()) glPopName();
133     delete [] pnts;
134   }
135
136   glPopAttrib();
137 }
138
139 /**************************************************************************/
140
141 void StraightLineSetGL::ProcessSelection(UInt_t* ptr, TGLViewer*, TGLScene*)
142
143   if (ptr[0] != 3) return;
144   ptr += 3; // skip n, zmin, zmax
145   if(ptr[1] == 1)
146   {
147     printf("selected line %d\n", ptr[2]);
148   }
149   else 
150   {
151    StraightLineSet::Marker& m = * (StraightLineSet::Marker*) fM->fMarkerPlex.Atom(ptr[2]);
152    printf("Selected point %d on line %d\n", ptr[2], m.fLineID);
153   }
154 }