4 // ---------------------------------------------------------------------------
8 // This file is part of the ALICE Geometry Database .
10 // By: Joana E. Santo & David Collados
12 // ---------------------------------------------------------------------------
14 #include <TVirtualPad.h>
18 #include <TGLKernelABC.h>
21 #include "AliGShape.h"
27 /* Default Constructor */
28 fCoTab = NULL; // Table of cos(fPhi1) .... cos(fPhil+fDphi1)
29 fAspectRatio = 1; // defines (the ellipse semi-axis in Y)/(the ellipse semi-axis in X)
30 fDz = 0.; // half length in z
32 fNdiv = 0; // number of segments (precision)
33 fRmax = 0.; // ellipse semi-axis in X outside
34 fRmin = 0.; // ellipse semi-axis in X inside
35 fSiTab = NULL; // Table of sin(fPhi1) .... sin(fPhil+fDphi1)
39 //-------------------------------------------------------------------------
41 AliGTube::AliGTube( Text_t *name, Text_t *title, Float_t rmin, Float_t rmax, Float_t dz, Float_t aspect ) : AliGShape(name, title)
44 fCoTab = NULL; // Table of cos(fPhi1) .... cos(fPhil+fDphi1)
45 fAspectRatio = aspect; // defines (the ellipse semi-axis in Y)/(the ellipse semi-axis in X)
46 fDz = dz; // half length in z
47 fNdiv = 0; // number of segments (precision)
48 fRmax = rmax; // ellipse semi-axis in X outside
49 fRmin = rmin; // ellipse semi-axis in X inside
50 fSiTab = NULL; // Table of sin(fPhi1) .... sin(fPhil+fDphi1)
56 //-------------------------------------------------------------------------
58 AliGTube::AliGTube( AliGTube *tube )
60 /* Copy Constructor */
61 fCoTab = NULL; // Table of cos(fPhi1) .... cos(fPhil+fDphi1)
62 fAspectRatio = tube->fAspectRatio; // defines (the ellipse semi-axis in Y)/(the ellipse semi-axis in X)
63 fDz = tube->fDz; // half length in z
64 fColor = tube->fColor;
66 fNdiv = 0; // number of segments (precision)
67 fRmax = tube->fRmax; // ellipse semi-axis in X outside
68 fRmin = tube->fRmin; // ellipse semi-axis in X inside
69 fSiTab = NULL; // Table of sin(fPhi1) .... sin(fPhil+fDphi1)
70 fTitle = tube->fTitle;
75 //-------------------------------------------------------------------------
77 AliGTube::AliGTube(Text_t *name, Text_t *title, Float_t rmax, Float_t dz) : AliGShape(name, title)
79 /* Tube simplified constructor */
80 fCoTab = NULL; // Table of cos(fPhi1) .... cos(fPhil+fDphi1)
81 fAspectRatio = 1; // defines (the ellipse semi-axis in Y)/(the ellipse semi-axis in X)
82 fDz = dz; // half length in z
83 fNdiv = 0; // number of segments (precision)
84 fRmax = rmax; // ellipse semi-axis in X outside
85 fRmin = 0.; // ellipse semi-axis in X inside
86 fSiTab = NULL; // Table of sin(fPhi1) .... sin(fPhil+fDphi1)
91 //-------------------------------------------------------------------------
100 //-------------------------------------------------------------------------
102 void AliGTube::MakeTableOfCoSin()
104 const Double_t PI = TMath::ATan(1) * 4.0;
105 const Double_t TWOPI = 2*PI;
108 Int_t n = GetNumberOfDivisions ();
111 delete [] fCoTab; // Delete the old tab if any
112 fCoTab = new Double_t [n];
115 Error("MakeTableOfCoSin()","No cos table done");
120 delete [] fSiTab; // Delete the old tab if any
121 fSiTab = new Double_t [n];
125 Error("MakeTableOfCoSin()","No sin table done");
129 Double_t range = TWOPI;
130 Double_t angstep = range/n;
133 for (j = 0; j < n; j++)
136 fCoTab[j] = TMath::Cos(ph);
137 fSiTab[j] = TMath::Sin(ph);
142 //-------------------------------------------------------------------------
144 void AliGTube::DrawShape(Option_t *option)
150 //-------------------------------------------------------------------------
152 void AliGTube::Draw(Option_t *option)
154 //cout << " Entra en " << this->GetName() << "::Draw " << endl;
155 TString opt = option;
159 gPad = new TCanvas("AliGTube","AliGTube",0,0,400,300);
160 gPad->Range(0,0,1,1);
161 gPad->SetFillColor(32); // Light Green
162 gPad->SetBorderSize(3);
163 gPad->SetBorderMode(0); // -1 (down) 0 (no) 1 (up)
166 if( !opt.Contains("same") ) {
168 gPad->SetName("AliGTube");
169 gPad->SetTitle("AliGTube");
172 gPad->SetName("AliShapes");
173 gPad->SetTitle("AliShapes");
178 TView *view = gPad->GetView();
183 view->SetAutoRange(kTRUE);
185 view->SetAutoRange(kFALSE);
187 cout << " Sale de " << this->GetName() << "::Draw " << endl;
190 //-------------------------------------------------------------------------
192 void AliGTube::Paint(Option_t *option)
194 //*-*-*-*-*-*-*-*Paint this 3-D shape with its current attributes*-*-*-*-*-*-*-*
195 //*-* ================================================
197 SetLineColor( GetCol() );
200 Int_t n = GetNumberOfDivisions();
201 const Int_t numpoints = 4*n;
203 //*-* Allocate memory for points *-*
205 Float_t *points = new Float_t[3*numpoints];
210 if (gPad->GetView3D()) PaintGLPoints(points);
212 //== for (i = 0; i < numpoints; i++)
213 //== gNode->Local2Master(&points[3*i],&points[3*i]);
215 X3DBuffer *buff = new X3DBuffer;
217 buff->numPoints = numpoints;
219 buff->numPolys = n*4;
223 //*-* Allocate memory for points *-*
225 buff->points = points;
227 Int_t c = ((GetLineColor() % 8) - 1) * 4; // Basic colors: 0, 1, ... 7
230 //*-* Allocate memory for segments *-*
232 buff->segs = new Int_t[buff->numSegs*3];
234 for (i = 0; i < 4; i++) {
235 for (j = 0; j < n; j++) {
236 buff->segs[(i*n+j)*3 ] = c;
237 buff->segs[(i*n+j)*3+1] = i*n+j;
238 buff->segs[(i*n+j)*3+2] = i*n+j+1;
240 buff->segs[(i*n+j-1)*3+2] = i*n;
242 for (i = 4; i < 6; i++) {
243 for (j = 0; j < n; j++) {
244 buff->segs[(i*n+j)*3 ] = c+1;
245 buff->segs[(i*n+j)*3+1] = (i-4)*n+j;
246 buff->segs[(i*n+j)*3+2] = (i-2)*n+j;
249 for (i = 6; i < 8; i++) {
250 for (j = 0; j < n; j++) {
251 buff->segs[(i*n+j)*3 ] = c;
252 buff->segs[(i*n+j)*3+1] = 2*(i-6)*n+j;
253 buff->segs[(i*n+j)*3+2] = (2*(i-6)+1)*n+j;
258 //*-* Allocate memory for polygons *-*
262 buff->polys = new Int_t[buff->numPolys*6];
264 for (i = 0; i < 2; i++) {
265 for (j = 0; j < n; j++) {
267 buff->polys[indx ] = c;
268 buff->polys[indx+1] = 4;
269 buff->polys[indx+2] = i*n+j;
270 buff->polys[indx+3] = (4+i)*n+j;
271 buff->polys[indx+4] = (2+i)*n+j;
272 buff->polys[indx+5] = (4+i)*n+j+1;
274 buff->polys[indx+5] = (4+i)*n;
276 for (i = 2; i < 4; i++) {
277 for (j = 0; j < n; j++) {
279 buff->polys[indx ] = c+(i-2)*2+1;
280 buff->polys[indx+1] = 4;
281 buff->polys[indx+2] = (i-2)*2*n+j;
282 buff->polys[indx+3] = (4+i)*n+j;
283 buff->polys[indx+4] = ((i-2)*2+1)*n+j;
284 buff->polys[indx+5] = (4+i)*n+j+1;
286 buff->polys[indx+5] = (4+i)*n;
290 //*-* Paint in the pad
291 //*-* Paint in the pad
292 Bool_t rangeView = strcmp(option,"range")==0 ? kTRUE : kFALSE;
294 PaintShape(buff,rangeView);
297 if (strstr(option, "x3d")) {
298 if(buff && buff->points && buff->segs)
301 gSize3D.numPoints -= buff->numPoints;
302 gSize3D.numSegs -= buff->numSegs;
303 gSize3D.numPolys -= buff->numPolys;
307 if( points ) delete [] points;
309 //if (buff->points) delete [] buff->points;
311 if (buff->segs) delete [] buff->segs;
313 if (buff->polys) delete [] buff->polys;
315 if (buff) delete buff;
319 //-------------------------------------------------------------------------
321 void AliGTube::PaintGLPoints(Float_t *vertex)
323 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Paint BRIK via OpenGL *-*-*-*-*-*-*-*-*-*-*-*-*
324 //*-* =====================
325 gGLKernel->PaintCone(vertex,GetNumberOfDivisions(),2);
328 //-------------------------------------------------------------------------
330 void AliGTube::SetPoints(Float_t *buff)
332 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Create TUBE points*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
333 //*-* ==================
338 n = GetNumberOfDivisions();
345 //*-* We've to checxk whether the table does exist and create it
346 //*-* since fCoTab/fSiTab are not saved with any TShape::Streamer function
347 if (!fCoTab) MakeTableOfCoSin();
349 for (j = 0; j < n; j++) {
350 buff[indx+6*n] = buff[indx] = fRmin * fCoTab[j];
352 buff[indx+6*n] = buff[indx] = fAspectRatio*fRmin * fSiTab[j];
358 for (j = 0; j < n; j++) {
359 buff[indx+6*n] = buff[indx] = fRmax * fCoTab[j];
361 buff[indx+6*n] = buff[indx] = fAspectRatio*fRmax * fSiTab[j];
370 //-------------------------------------------------------------------------
372 void AliGTube::Sizeof3D() const
374 //*-*-*-*-*-*Return total X3D size of this shape with its attributes*-*-*-*-*-*-*
375 //*-* =======================================================
377 cout << " Entra en AliGTube::Sizeof3D() " << endl;
379 Int_t n = GetNumberOfDivisions();
381 gSize3D.numPoints += n*4;
382 gSize3D.numSegs += n*8;
383 gSize3D.numPolys += n*4;
386 //-------------------------------------------------------------------------
388 void AliGTube::Streamer(TBuffer &R__b)
390 // Stream an object of class AliGTube.
392 if (R__b.IsReading()) {
393 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
394 AliGShape::Streamer(R__b);
395 R__b.ReadArray(fCoTab); //
396 R__b >> fAspectRatio;
401 R__b.ReadArray(fSiTab); //
403 R__b.WriteVersion(AliGTube::IsA());
404 AliGShape::Streamer(R__b);
405 R__b.WriteArray(fCoTab, GetNumberOfDivisions()); //
406 R__b << fAspectRatio;
411 R__b.WriteArray(fSiTab, GetNumberOfDivisions()); //
415 //-------------------------------------------------------------------------