]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTPCSector3DGL.cxx
-Fixed bug in offline buffer that deleted event object.
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTPCSector3DGL.cxx
1 // $Id$
2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4 /**************************************************************************
5  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #include "AliEveTPCSector3DGL.h"
11 #include <EveDet/AliEveTPCSector3D.h>
12
13 #include <TEveBoxSetGL.h>
14
15 #include <TGLIncludes.h>
16 #include <TGLRnrCtx.h>
17 #include <TGLSelectRecord.h>
18
19 //______________________________________________________________________________
20 //
21 // GL renderer for AliEveTPCSector3D.
22
23 ClassImp(AliEveTPCSector3DGL)
24
25 AliEveTPCSector3DGL::AliEveTPCSector3DGL() :
26   TGLObject(),
27   fSector(0), fBoxRnr(0),
28   fRTS(0)
29 {
30   // Constructor.
31
32   fDLCache = false; // Disable display list.
33 }
34
35 AliEveTPCSector3DGL::~AliEveTPCSector3DGL()
36 {
37   // Destructor.
38
39   delete fBoxRnr;
40 }
41
42 /******************************************************************************/
43
44 //______________________________________________________________________________
45 Short_t AliEveTPCSector3DGL::QuantizeShapeLOD(Short_t shapeLOD, Short_t combiLOD) const
46 {
47    // Factor in scene/viewer LOD and quantize.
48
49    Int_t lod = ((Int_t)shapeLOD * (Int_t)combiLOD) / 100;
50
51    if (lod >= 100)
52      return 100;
53    else
54      return (Short_t)(10 * TMath::Nint(0.1*lod));
55 }
56
57 /******************************************************************************/
58
59 Bool_t AliEveTPCSector3DGL::SetModel(TObject* obj, const Option_t* /*opt*/)
60 {
61   // Set model object.
62
63   if(SetModelCheckClass(obj, AliEveTPCSector3D::Class())) {
64     fSector = (AliEveTPCSector3D*) fExternalObj;
65     if(fBoxRnr == 0) {
66       fBoxRnr = new TEveBoxSetGL;
67       fBoxRnr->SetModel(&fSector->fBoxSet);
68     }
69     return kTRUE;
70   }
71   return kFALSE;
72 }
73
74 void AliEveTPCSector3DGL::SetBBox()
75 {
76   // Set bounding-box.
77
78   SetAxisAlignedBBox(((AliEveTPCSector3D*)fExternalObj)->AssertBBox());
79 }
80
81 /******************************************************************************/
82
83 void AliEveTPCSector3DGL::DirectDraw(TGLRnrCtx & rnrCtx) const
84 {
85   // Render object.
86
87   // printf("AliEveTPCSector3DGL::DirectDraw Style %d, LOD %d\n", rnrCtx.Style(), rnrCtx.LOD());
88
89   if(fRTS < fSector->fRTS) {
90     fSector->UpdateBoxesAndPoints();
91     fRTS = fSector->fRTS;
92   }
93
94   if (rnrCtx.SecSelection()) glPushName(0);
95
96   Bool_t hasData = (fSector->GetSectorData() != 0);
97
98   if(hasData)
99   {
100     if (rnrCtx.SecSelection()) glLoadName(9999);
101     fBoxRnr->Render(rnrCtx);
102   }
103
104   glPushAttrib(GL_CURRENT_BIT | GL_POINT_BIT | GL_ENABLE_BIT);
105   glDisable(GL_LIGHTING);
106
107   if(hasData && fSector->fPointSetOn)
108   {
109     glEnable(GL_BLEND);
110     glEnable(GL_POINT_SMOOTH);
111     glPointSize(fSector->fPointSize);
112
113     glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
114     glEnableClientState(GL_VERTEX_ARRAY);
115
116     const TEvePointSetArray& psa = fSector->fPointSetArray;
117     for(Int_t b=0; b<psa.GetNBins(); ++b)
118     {
119       TEvePointSet* ps = psa.GetBin(b);
120       if(ps->Size() > 0)
121       {
122         TGLUtil::Color(ps->GetMarkerColor());
123
124         if (rnrCtx.SecSelection()) glLoadName(b + 1);
125         glVertexPointer(3, GL_FLOAT, 0, ps->GetP());
126         glDrawArrays(GL_POINTS, 0, ps->Size());
127       }
128     }
129
130     glPopClientAttrib();
131   }
132
133   if(fSector->fRnrFrame && ! rnrCtx.SecSelection())
134   {
135     TGLUtil::Color(fSector->fFrameColor);
136
137     if(fSector->fRnrInn)
138       DrawSegmentFrame(AliEveTPCSectorData::GetInnSeg(),  0, 2);
139     if(fSector->fRnrOut1)
140       DrawSegmentFrame(AliEveTPCSectorData::GetOut1Seg(), 2, 1);
141     if(fSector->fRnrOut2)
142       DrawSegmentFrame(AliEveTPCSectorData::GetOut2Seg(), 2, 2);
143   }
144
145   glPopAttrib();
146 }
147
148 void AliEveTPCSector3DGL::DrawSegmentFrame(const AliEveTPCSectorData::SegmentInfo& s,
149                                            Int_t botExtraPads, Int_t topExtraPads) const
150 {
151   // Draw frame of given segment.
152
153   Float_t xl, xh, yl, yh, zl, zh;
154   xl = 0.5*s.GetPadWidth()*(AliEveTPCSectorData::GetNPadsInRow(s.GetFirstRow()) + botExtraPads);
155   xh = 0.5*s.GetPadWidth()*(AliEveTPCSectorData::GetNPadsInRow(s.GetLastRow())  + topExtraPads);
156   yl = s.GetRLow();
157   yh = yl + s.GetNRows()*s.GetPadHeight();
158   zl = 0;
159   zh = AliEveTPCSectorData::GetZLength();
160
161   glBegin(GL_LINE_LOOP);
162   glVertex3f( xl, yl, zl);  glVertex3f( xh, yh, zl);
163   glVertex3f(-xh, yh, zl);  glVertex3f(-xl, yl, zl);
164   glEnd();
165   glBegin(GL_LINE_LOOP);
166   glVertex3f( xl, yl, zh);  glVertex3f( xh, yh, zh);
167   glVertex3f(-xh, yh, zh);  glVertex3f(-xl, yl, zh);
168   glEnd();
169   glBegin(GL_LINES);
170   glVertex3f( xl, yl, zl);  glVertex3f( xl, yl, zh);
171   glVertex3f( xh, yh, zl);  glVertex3f( xh, yh, zh);
172   glVertex3f(-xh, yh, zl);  glVertex3f(-xh, yh, zh);
173   glVertex3f(-xl, yl, zl);  glVertex3f(-xl, yl, zh);
174   glEnd();
175 }
176
177 /******************************************************************************/
178 /******************************************************************************/
179
180 //______________________________________________________________________________
181 void AliEveTPCSector3DGL::ProcessSelection(TGLRnrCtx & /*rnrCtx*/, TGLSelectRecord & rec)
182 {
183   // Processes secondary selection from TGLViewer.
184   // Calls TPointSet3D::PointSelected(Int_t) with index of selected
185   // point as an argument.
186
187   if (rec.GetN() < 3) return;
188
189   if (rec.GetItem(1) == 9999)
190   {
191     printf("TPC3D Box selected idx=%u\n", rec.GetItem(2));
192     return;
193   }
194
195   const TEvePointSetArray& psa = fSector->fPointSetArray;
196
197   if (rec.GetItem(1) > 0 && rec.GetItem(1) <= (UInt_t) psa.GetNBins())
198   {
199     // TEvePointSet& ps = * psa.GetBin(rec.GetItem(1) - 1);
200     printf("TPC3D Point selected, bin=%u, idx=%u\n", rec.GetItem(1) - 1, rec.GetItem(2));
201     return;
202   }
203 }