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