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