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