1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
23 // ---------------------------------------------------------------------------
27 // This file is part of the ALICE Geometry Database .
29 // By: Joana E. Santo & David Collados
31 // ---------------------------------------------------------------------------
33 #include <TVirtualPad.h>
37 #include <TGLKernelABC.h>
40 #include "AliGShape.h"
46 /* Default Constructor */
47 fCoTab = NULL; // Table of cos(fPhi1) .... cos(fPhil+fDphi1)
48 fAspectRatio = 1; // defines (the ellipse semi-axis in Y)/(the ellipse semi-axis in X)
49 fDz = 0.; // half length in z
51 fNdiv = 0; // number of segments (precision)
52 fRmax = 0.; // ellipse semi-axis in X outside
53 fRmin = 0.; // ellipse semi-axis in X inside
54 fSiTab = NULL; // Table of sin(fPhi1) .... sin(fPhil+fDphi1)
58 //-------------------------------------------------------------------------
60 AliGTube::AliGTube( Text_t *name, Text_t *title, Float_t rmin, Float_t rmax, Float_t dz, Float_t aspect ) : AliGShape(name, title)
63 fCoTab = NULL; // Table of cos(fPhi1) .... cos(fPhil+fDphi1)
64 fAspectRatio = aspect; // defines (the ellipse semi-axis in Y)/(the ellipse semi-axis in X)
65 fDz = dz; // half length in z
66 fNdiv = 0; // number of segments (precision)
67 fRmax = rmax; // ellipse semi-axis in X outside
68 fRmin = rmin; // ellipse semi-axis in X inside
69 fSiTab = NULL; // Table of sin(fPhi1) .... sin(fPhil+fDphi1)
75 //-------------------------------------------------------------------------
77 AliGTube::AliGTube( AliGTube *tube )
79 /* Copy Constructor */
80 fCoTab = NULL; // Table of cos(fPhi1) .... cos(fPhil+fDphi1)
81 fAspectRatio = tube->fAspectRatio; // defines (the ellipse semi-axis in Y)/(the ellipse semi-axis in X)
82 fDz = tube->fDz; // half length in z
83 fColor = tube->fColor;
85 fNdiv = 0; // number of segments (precision)
86 fRmax = tube->fRmax; // ellipse semi-axis in X outside
87 fRmin = tube->fRmin; // ellipse semi-axis in X inside
88 fSiTab = NULL; // Table of sin(fPhi1) .... sin(fPhil+fDphi1)
89 fTitle = tube->fTitle;
94 //-------------------------------------------------------------------------
96 AliGTube::AliGTube(Text_t *name, Text_t *title, Float_t rmax, Float_t dz) : AliGShape(name, title)
98 /* Tube simplified constructor */
99 fCoTab = NULL; // Table of cos(fPhi1) .... cos(fPhil+fDphi1)
100 fAspectRatio = 1; // defines (the ellipse semi-axis in Y)/(the ellipse semi-axis in X)
101 fDz = dz; // half length in z
102 fNdiv = 0; // number of segments (precision)
103 fRmax = rmax; // ellipse semi-axis in X outside
104 fRmin = 0.; // ellipse semi-axis in X inside
105 fSiTab = NULL; // Table of sin(fPhi1) .... sin(fPhil+fDphi1)
110 //-------------------------------------------------------------------------
112 AliGTube::~AliGTube()
119 //-------------------------------------------------------------------------
121 void AliGTube::MakeTableOfCoSin()
123 const Double_t PI = TMath::ATan(1) * 4.0;
124 const Double_t TWOPI = 2*PI;
127 Int_t n = GetNumberOfDivisions ();
130 delete [] fCoTab; // Delete the old tab if any
131 fCoTab = new Double_t [n];
134 Error("MakeTableOfCoSin()","No cos table done");
139 delete [] fSiTab; // Delete the old tab if any
140 fSiTab = new Double_t [n];
144 Error("MakeTableOfCoSin()","No sin table done");
148 Double_t range = TWOPI;
149 Double_t angstep = range/n;
152 for (j = 0; j < n; j++)
155 fCoTab[j] = TMath::Cos(ph);
156 fSiTab[j] = TMath::Sin(ph);
161 //-------------------------------------------------------------------------
163 void AliGTube::DrawShape(Option_t *option)
169 //-------------------------------------------------------------------------
171 void AliGTube::Draw(Option_t *option)
173 //cout << " Entra en " << this->GetName() << "::Draw " << endl;
174 TString opt = option;
178 gPad = new TCanvas("AliGTube","AliGTube",0,0,400,300);
179 gPad->Range(0,0,1,1);
180 gPad->SetFillColor(32); // Light Green
181 gPad->SetBorderSize(3);
182 gPad->SetBorderMode(0); // -1 (down) 0 (no) 1 (up)
185 if( !opt.Contains("same") ) {
187 gPad->SetName("AliGTube");
188 gPad->SetTitle("AliGTube");
191 gPad->SetName("AliShapes");
192 gPad->SetTitle("AliShapes");
197 TView *view = gPad->GetView();
202 view->SetAutoRange(kTRUE);
204 view->SetAutoRange(kFALSE);
206 cout << " Sale de " << this->GetName() << "::Draw " << endl;
209 //-------------------------------------------------------------------------
211 void AliGTube::Paint(Option_t *option)
213 //*-*-*-*-*-*-*-*Paint this 3-D shape with its current attributes*-*-*-*-*-*-*-*
214 //*-* ================================================
216 SetLineColor( GetCol() );
219 Int_t n = GetNumberOfDivisions();
220 const Int_t numpoints = 4*n;
222 //*-* Allocate memory for points *-*
224 Float_t *points = new Float_t[3*numpoints];
229 if (gPad->GetView3D()) PaintGLPoints(points);
231 //== for (i = 0; i < numpoints; i++)
232 //== gNode->Local2Master(&points[3*i],&points[3*i]);
234 X3DBuffer *buff = new X3DBuffer;
236 buff->numPoints = numpoints;
238 buff->numPolys = n*4;
242 //*-* Allocate memory for points *-*
244 buff->points = points;
246 Int_t c = ((GetLineColor() % 8) - 1) * 4; // Basic colors: 0, 1, ... 7
249 //*-* Allocate memory for segments *-*
251 buff->segs = new Int_t[buff->numSegs*3];
253 for (i = 0; i < 4; i++) {
254 for (j = 0; j < n; j++) {
255 buff->segs[(i*n+j)*3 ] = c;
256 buff->segs[(i*n+j)*3+1] = i*n+j;
257 buff->segs[(i*n+j)*3+2] = i*n+j+1;
259 buff->segs[(i*n+j-1)*3+2] = i*n;
261 for (i = 4; i < 6; i++) {
262 for (j = 0; j < n; j++) {
263 buff->segs[(i*n+j)*3 ] = c+1;
264 buff->segs[(i*n+j)*3+1] = (i-4)*n+j;
265 buff->segs[(i*n+j)*3+2] = (i-2)*n+j;
268 for (i = 6; i < 8; i++) {
269 for (j = 0; j < n; j++) {
270 buff->segs[(i*n+j)*3 ] = c;
271 buff->segs[(i*n+j)*3+1] = 2*(i-6)*n+j;
272 buff->segs[(i*n+j)*3+2] = (2*(i-6)+1)*n+j;
277 //*-* Allocate memory for polygons *-*
281 buff->polys = new Int_t[buff->numPolys*6];
283 for (i = 0; i < 2; i++) {
284 for (j = 0; j < n; j++) {
286 buff->polys[indx ] = c;
287 buff->polys[indx+1] = 4;
288 buff->polys[indx+2] = i*n+j;
289 buff->polys[indx+3] = (4+i)*n+j;
290 buff->polys[indx+4] = (2+i)*n+j;
291 buff->polys[indx+5] = (4+i)*n+j+1;
293 buff->polys[indx+5] = (4+i)*n;
295 for (i = 2; i < 4; i++) {
296 for (j = 0; j < n; j++) {
298 buff->polys[indx ] = c+(i-2)*2+1;
299 buff->polys[indx+1] = 4;
300 buff->polys[indx+2] = (i-2)*2*n+j;
301 buff->polys[indx+3] = (4+i)*n+j;
302 buff->polys[indx+4] = ((i-2)*2+1)*n+j;
303 buff->polys[indx+5] = (4+i)*n+j+1;
305 buff->polys[indx+5] = (4+i)*n;
309 //*-* Paint in the pad
310 //*-* Paint in the pad
311 Bool_t rangeView = strcmp(option,"range")==0 ? kTRUE : kFALSE;
313 PaintShape(buff,rangeView);
316 if (strstr(option, "x3d")) {
317 if(buff && buff->points && buff->segs)
320 gSize3D.numPoints -= buff->numPoints;
321 gSize3D.numSegs -= buff->numSegs;
322 gSize3D.numPolys -= buff->numPolys;
326 if( points ) delete [] points;
328 //if (buff->points) delete [] buff->points;
330 if (buff->segs) delete [] buff->segs;
332 if (buff->polys) delete [] buff->polys;
334 if (buff) delete buff;
338 //-------------------------------------------------------------------------
340 void AliGTube::PaintGLPoints(Float_t *vertex)
342 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Paint BRIK via OpenGL *-*-*-*-*-*-*-*-*-*-*-*-*
343 //*-* =====================
344 gGLKernel->PaintCone(vertex,GetNumberOfDivisions(),2);
347 //-------------------------------------------------------------------------
349 void AliGTube::SetPoints(Float_t *buff)
351 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Create TUBE points*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
352 //*-* ==================
357 n = GetNumberOfDivisions();
364 //*-* We've to checxk whether the table does exist and create it
365 //*-* since fCoTab/fSiTab are not saved with any TShape::Streamer function
366 if (!fCoTab) MakeTableOfCoSin();
368 for (j = 0; j < n; j++) {
369 buff[indx+6*n] = buff[indx] = fRmin * fCoTab[j];
371 buff[indx+6*n] = buff[indx] = fAspectRatio*fRmin * fSiTab[j];
377 for (j = 0; j < n; j++) {
378 buff[indx+6*n] = buff[indx] = fRmax * fCoTab[j];
380 buff[indx+6*n] = buff[indx] = fAspectRatio*fRmax * fSiTab[j];
389 //-------------------------------------------------------------------------
391 void AliGTube::Sizeof3D() const
393 //*-*-*-*-*-*Return total X3D size of this shape with its attributes*-*-*-*-*-*-*
394 //*-* =======================================================
396 cout << " Entra en AliGTube::Sizeof3D() " << endl;
398 Int_t n = GetNumberOfDivisions();
400 gSize3D.numPoints += n*4;
401 gSize3D.numSegs += n*8;
402 gSize3D.numPolys += n*4;
405 //-------------------------------------------------------------------------
407 void AliGTube::Streamer(TBuffer &R__b)
409 // Stream an object of class AliGTube.
411 if (R__b.IsReading()) {
412 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
413 AliGShape::Streamer(R__b);
414 R__b.ReadArray(fCoTab); //
415 R__b >> fAspectRatio;
420 R__b.ReadArray(fSiTab); //
422 R__b.WriteVersion(AliGTube::IsA());
423 AliGShape::Streamer(R__b);
424 R__b.WriteArray(fCoTab, GetNumberOfDivisions()); //
425 R__b << fAspectRatio;
430 R__b.WriteArray(fSiTab, GetNumberOfDivisions()); //
434 //-------------------------------------------------------------------------