4 // ---------------------------------------------------------------------------
8 // This file is part of the ALICE Geometry Database .
10 // By: Joana E. Santo & David Collados
12 // ---------------------------------------------------------------------------
15 #include <TVirtualPad.h>
17 #include <TGLKernelABC.h>
19 #include "AliGPCone.h"
24 AliGPCone::AliGPCone() : AliGShape()
26 /* Default Constructor */
39 //-------------------------------------------------------------------------
41 AliGPCone::AliGPCone( AliGPCone* pcone )
43 /* Copy Constructor */
44 if( pcone->fNz < 2 ) {
45 Error( pcone->GetName(), "number of z planes for %s must be at least two !", pcone->GetName() );
50 fTitle = pcone->fTitle;
52 fColor = pcone->fColor;
54 fDphi1 = pcone->fDphi1;
58 fRmin = new Float_t [fNz+1];
59 fRmax = new Float_t [fNz+1];
60 fDz = new Float_t [fNz+1];
65 while (fDphi1 > 360) fDphi1 -= 360;
69 for( int k=0; k<fNz; k++ ) {
70 fDz[k] = pcone->fDz[k];
71 fRmin[k] = pcone->fRmin[k];
72 fRmax[k] = pcone->fRmax[k];
77 //-------------------------------------------------------------------------
79 AliGPCone::AliGPCone( Text_t *name, Text_t *title, Float_t phi1, Float_t dphi1, Int_t nz ) : AliGShape(name, title)
84 Error(name, "number of z planes for %s must be at least two !", name);
92 fRmin = new Float_t [fNz+1];
93 fRmax = new Float_t [fNz+1];
94 fDz = new Float_t [fNz+1];
99 while (fDphi1 > 360) fDphi1 -= 360;
104 //---------------------------------------------------------------------------
106 AliGPCone::AliGPCone( Text_t *name, Text_t* title, Float_t *upar, Int_t np) : AliGShape(name, title)
109 Error(name, "number of z planes for %s must be at least two !", name);
115 fNz = (Int_t) upar[2];
117 fRmin = new Float_t [fNz+1];
118 fRmax = new Float_t [fNz+1];
119 fDz = new Float_t [fNz+1];
123 while (fDphi1 > 360) fDphi1 -= 360;
127 for( int j=3, k=0; k<fNz; k++ ) {
129 fRmin[k] = upar[j+1];
130 fRmax[k] = upar[j+2];
135 //-------------------------------------------------------------------------
137 AliGPCone::AliGPCone( Text_t *name, Text_t* title, Float_t phi1, Float_t dphi1, Int_t nz, Float_t Z[10], Float_t RMIN[10], Float_t RMAX[10] ) : AliGShape(name, title)
139 cout << " ENTRA EN EL CONSTRUCTOR CHUNGO !!!!!! " << endl;
141 //AliGPCone(name, title, phi1, dphi1, nz);
143 //for (int i= 0; i<nz; i++)
144 //DefineSection(i, Z[i], RMIN[i], RMAX[i]);
147 //---------------------------------------------------------------------------
149 AliGPCone::~AliGPCone()
153 if( fRmin ) delete [] fRmin;
154 if( fRmax ) delete [] fRmax;
155 if( fDz ) delete [] fDz;
156 //if( fSiTab ) delete fSiTab;
157 //if( fCoTab ) delete fCoTab;
166 //-------------------------------------------------------------------------
168 void AliGPCone::DrawShape(Option_t *option)
174 //-------------------------------------------------------------------------
176 void AliGPCone::Draw(Option_t *option)
178 //cout << " Entra en " << this->GetName() << "::Draw " << endl;
180 TString opt = option;
184 //TCanvas* Cone = new TCanvas("AliGPCone","AliGPCone",0,0,400,300);
185 gPad = new TCanvas("AliGPCone","AliGPCone",0,0,400,300);
186 gPad->Range(0,0,1,1);
187 gPad->SetFillColor(32); // Light Green
188 gPad->SetBorderSize(3);
189 gPad->SetBorderMode(0); // -1 (down) 0 (no) 1 (up)
192 if( !opt.Contains("same") ) {
194 gPad->SetName("AliGPCone");
195 gPad->SetTitle("AliGPCone");
198 gPad->SetName("AliShapes");
199 gPad->SetTitle("AliShapes");
204 TView *view = gPad->GetView();
209 view->SetAutoRange(kTRUE);
211 view->SetAutoRange(kFALSE);
212 //cout << " Sale de " << this->GetName() << "::Draw " << endl;
215 //-------------------------------------------------------------------------
217 void AliGPCone::SetPoints(Float_t *buff)
219 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Create PCON points*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
220 //*-* ==================
227 Int_t n = GetNumberOfDivisions()+1;
229 //*-* We've to check whether the table does exist and create it
230 //*-* since fCoTab/fSiTab are not saved with any TShape::Streamer function
231 if (!fCoTab) MakeTableOfCoSin();
233 for (i = 0; i < fNz; i++)
235 for (j = 0; j < n; j++)
237 buff[indx++] = fRmin[i] * fCoTab[j];
238 buff[indx++] = fRmin[i] * fSiTab[j];
239 buff[indx++] = fDz[i];
241 for (j = 0; j < n; j++)
243 buff[indx++] = fRmax[i] * fCoTab[j];
244 buff[indx++] = fRmax[i] * fSiTab[j];
245 buff[indx++] = fDz[i];
251 //-------------------------------------------------------------------------
253 void AliGPCone::Paint(Option_t *option)
256 //*-*-*-*-*-*-*-*Paint this 3-D shape with its current attributes*-*-*-*-*-*-*-*
257 //*-* ================================================
261 const Int_t n = GetNumberOfDivisions()+1;
263 SetLineColor( GetCol() );
265 Int_t numpoints = fNz*2*n;
266 if (numpoints <= 0) return;
267 //*-* Allocate memory for points *-*
269 Float_t *points = new Float_t[3*numpoints];
273 Bool_t rangeView = strcmp(option,"range")==0 ? kTRUE : kFALSE;
274 if (!rangeView && gPad->GetView3D()) PaintGLPoints(points);
276 //== for (i = 0; i < numpoints; i++)
277 //== gNode->Local2Master(&points[3*i],&points[3*i]);
279 Bool_t specialCase = kFALSE;
281 if (fDphi1 == 360) //mark this as a very special case, when
282 specialCase = kTRUE; //we have to draw this PCON like a TUBE
284 X3DBuffer *buff = new X3DBuffer;
287 buff->numPoints = numpoints;
288 buff->numSegs = 4*(fNz*n-1+(specialCase == kTRUE));
289 buff->numPolys = 2*(fNz*n-1+(specialCase == kTRUE));
292 //*-* Allocate memory for points *-*
294 buff->points = points;
296 Int_t c = ((GetLineColor() % 8) - 1) * 4; // Basic colors: 0, 1, ... 7
299 //*-* Allocate memory for segments *-*
301 Int_t indx, indx2, k;
304 buff->segs = new Int_t[buff->numSegs*3];
307 //inside & outside circles, number of segments: 2*fNz*(n-1)
308 // special case number of segments: 2*fNz*n
309 for (i = 0; i < fNz*2; i++) {
311 for (j = 1; j < n; j++) {
312 buff->segs[indx++] = c;
313 buff->segs[indx++] = indx2+j-1;
314 buff->segs[indx++] = indx2+j;
317 buff->segs[indx++] = c;
318 buff->segs[indx++] = indx2+j-1;
319 buff->segs[indx++] = indx2;
323 //bottom & top lines, number of segments: 2*n
324 for (i = 0; i < 2; i++) {
325 indx2 = i*(fNz-1)*2*n;
326 for (j = 0; j < n; j++) {
327 buff->segs[indx++] = c;
328 buff->segs[indx++] = indx2+j;
329 buff->segs[indx++] = indx2+n+j;
333 //inside & outside cilindres, number of segments: 2*(fNz-1)*n
334 for (i = 0; i < (fNz-1); i++) {
338 for (j = 0; j < n; j++) {
339 buff->segs[indx++] = c+2;
340 buff->segs[indx++] = indx2+j;
341 buff->segs[indx++] = indx2+n*2+j;
345 for (j = 0; j < n; j++) {
346 buff->segs[indx++] = c+3;
347 buff->segs[indx++] = indx2+j;
348 buff->segs[indx++] = indx2+n*2+j;
352 //left & right sections, number of segments: 2*(fNz-2)
353 // special case number of segments: 0
355 for (i = 1; i < (fNz-1); i++) {
356 for (j = 0; j < 2; j++) {
357 buff->segs[indx++] = c;
358 buff->segs[indx++] = 2*i * n + j*(n-1);
359 buff->segs[indx++] = (2*i+1) * n + j*(n-1);
366 Int_t m = n - 1 + (specialCase == kTRUE);
368 //*-* Allocate memory for polygons *-*
372 buff->polys = new Int_t[buff->numPolys*6];
376 //bottom & top, number of polygons: 2*(n-1)
377 // special case number of polygons: 2*n
378 for (i = 0; i < 2; i++) {
379 for (j = 0; j < n-1; j++) {
380 buff->polys[indx++] = c+3;
381 buff->polys[indx++] = 4;
382 buff->polys[indx++] = 2*fNz*m+i*n+j;
383 buff->polys[indx++] = i*(fNz*2-2)*m+m+j;
384 buff->polys[indx++] = 2*fNz*m+i*n+j+1;
385 buff->polys[indx++] = i*(fNz*2-2)*m+j;
388 buff->polys[indx++] = c+3;
389 buff->polys[indx++] = 4;
390 buff->polys[indx++] = 2*fNz*m+i*n+j;
391 buff->polys[indx++] = i*(fNz*2-2)*m+m+j;
392 buff->polys[indx++] = 2*fNz*m+i*n;
393 buff->polys[indx++] = i*(fNz*2-2)*m+j;
398 //inside & outside, number of polygons: (fNz-1)*2*(n-1)
399 for (k = 0; k < (fNz-1); k++) {
400 for (i = 0; i < 2; i++) {
401 for (j = 0; j < n-1; j++) {
402 buff->polys[indx++] = c+i;
403 buff->polys[indx++] = 4;
404 buff->polys[indx++] = (2*k+i*1)*m+j;
405 buff->polys[indx++] = fNz*2*m+(2*k+i*1+2)*n+j;
406 buff->polys[indx++] = (2*k+i*1+2)*m+j;
407 buff->polys[indx++] = fNz*2*m+(2*k+i*1+2)*n+j+1;
410 buff->polys[indx++] = c+i;
411 buff->polys[indx++] = 4;
412 buff->polys[indx++] = (2*k+i*1)*m+j;
413 buff->polys[indx++] = fNz*2*m+(2*k+i*1+2)*n+j;
414 buff->polys[indx++] = (2*k+i*1+2)*m+j;
415 buff->polys[indx++] = fNz*2*m+(2*k+i*1+2)*n;
421 //left & right sections, number of polygons: 2*(fNz-1)
422 // special case number of polygons: 0
425 for (k = 0; k < (fNz-1); k++) {
426 for (i = 0; i < 2; i++) {
427 buff->polys[indx++] = c+2;
428 buff->polys[indx++] = 4;
429 buff->polys[indx++] = k==0 ? indx2+i*(n-1) : indx2+2*fNz*n+2*(k-1)+i;
430 buff->polys[indx++] = indx2+2*(k+1)*n+i*(n-1);
431 buff->polys[indx++] = indx2+2*fNz*n+2*k+i;
432 buff->polys[indx++] = indx2+(2*k+3)*n+i*(n-1);
435 buff->polys[indx-8] = indx2+n;
436 buff->polys[indx-2] = indx2+2*n-1;
440 //*-* Paint in the pad
442 PaintShape(buff,rangeView);
444 if (strstr(option, "x3d")) {
445 if(buff && buff->points && buff->segs)
448 gSize3D.numPoints -= buff->numPoints;
449 gSize3D.numSegs -= buff->numSegs;
450 gSize3D.numPolys -= buff->numPolys;
455 if (buff->segs) delete [] buff->segs;
456 if (buff->polys) delete [] buff->polys;
457 if (buff) delete buff;
461 //-------------------------------------------------------------------------
463 void AliGPCone::MakeTableOfCoSin()
465 const Double_t PI = TMath::ATan(1) * 4.0;
466 const Double_t ragrad = PI/180.0;
469 Int_t n = GetNumberOfDivisions () + 1;
471 delete [] fCoTab; // Delete the old tab if any
472 fCoTab = new Double_t [n];
473 if (!fCoTab ) return;
476 delete [] fSiTab; // Delete the old tab if any
477 fSiTab = new Double_t [n];
478 if (!fSiTab ) return;
480 Double_t range = Double_t(fDphi1 * ragrad);
481 Double_t phi1 = Double_t(fPhi1 * ragrad);
482 Double_t angstep = range/(n-1);
485 for (j = 0; j < n; j++)
487 ph = phi1 + j*angstep;
488 fCoTab[j] = TMath::Cos(ph);
489 fSiTab[j] = TMath::Sin(ph);
494 //----------------------------------------------------
496 void AliGPCone::SetNumberOfDivisions (Int_t p)
498 if (GetNumberOfDivisions () == p) return;
503 //-------------------------------------------------------
505 void AliGPCone::DefineSection(Int_t secNum, Float_t z, Float_t rmin, Float_t rmax )
508 //*-*-*-*-*-*-*-*-*-*Defines section secNum of the polycone*-*-*-*-*-*-*-*-*-*-*
509 //*-* ======================================
511 // - rmin radius of the inner circle in the cross-section
513 // - rmax radius of the outer circle in the cross-section
515 // - z z coordinate of the section
517 if ((secNum < 0) || (secNum >= fNz)) return;
519 fRmin[secNum] = rmin;
520 fRmax[secNum] = rmax;
524 //-------------------------------------------------------
526 void AliGPCone::Streamer(TBuffer &R__b)
528 // Stream an object of class AliGPCone.
530 if (R__b.IsReading()) {
531 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
532 AliGShape::Streamer(R__b);
533 R__b.ReadArray(fSiTab); //
534 R__b.ReadArray(fCoTab); //
538 R__b.ReadArray(fRmin); //
539 R__b.ReadArray(fRmax); //
540 R__b.ReadArray(fDz); //
543 R__b.WriteVersion(AliGPCone::IsA());
544 AliGShape::Streamer(R__b);
545 R__b.WriteArray(fSiTab, GetNumberOfDivisions()+1); //
546 R__b.WriteArray(fCoTab, GetNumberOfDivisions()+1); //
550 R__b.WriteArray(fRmin, fNz+1); //
551 R__b.WriteArray(fRmax, fNz+1); //
552 R__b.WriteArray(fDz, fNz+1); //
557 //-------------------------------------------------------