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 // ---------------------------------------------------------------------------
34 #include <TVirtualPad.h>
36 #include <TGLKernelABC.h>
38 #include "AliGPCone.h"
43 AliGPCone::AliGPCone() : AliGShape()
45 /* Default Constructor */
58 //-------------------------------------------------------------------------
60 AliGPCone::AliGPCone( AliGPCone* pcone )
62 /* Copy Constructor */
63 if( pcone->fNz < 2 ) {
64 Error( pcone->GetName(), "number of z planes for %s must be at least two !", pcone->GetName() );
69 fTitle = pcone->fTitle;
71 fColor = pcone->fColor;
73 fDphi1 = pcone->fDphi1;
77 fRmin = new Float_t [fNz+1];
78 fRmax = new Float_t [fNz+1];
79 fDz = new Float_t [fNz+1];
84 while (fDphi1 > 360) fDphi1 -= 360;
88 for( int k=0; k<fNz; k++ ) {
89 fDz[k] = pcone->fDz[k];
90 fRmin[k] = pcone->fRmin[k];
91 fRmax[k] = pcone->fRmax[k];
96 //-------------------------------------------------------------------------
98 AliGPCone::AliGPCone( Text_t *name, Text_t *title, Float_t phi1, Float_t dphi1, Int_t nz ) : AliGShape(name, title)
103 Error(name, "number of z planes for %s must be at least two !", name);
111 fRmin = new Float_t [fNz+1];
112 fRmax = new Float_t [fNz+1];
113 fDz = new Float_t [fNz+1];
118 while (fDphi1 > 360) fDphi1 -= 360;
123 //---------------------------------------------------------------------------
125 AliGPCone::AliGPCone( Text_t *name, Text_t* title, Float_t *upar, Int_t np) : AliGShape(name, title)
128 Error(name, "number of z planes for %s must be at least two !", name);
134 fNz = (Int_t) upar[2];
136 fRmin = new Float_t [fNz+1];
137 fRmax = new Float_t [fNz+1];
138 fDz = new Float_t [fNz+1];
142 while (fDphi1 > 360) fDphi1 -= 360;
146 for( int j=3, k=0; k<fNz; k++ ) {
148 fRmin[k] = upar[j+1];
149 fRmax[k] = upar[j+2];
154 //-------------------------------------------------------------------------
156 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)
158 cout << " ENTRA EN EL CONSTRUCTOR CHUNGO !!!!!! " << endl;
160 //AliGPCone(name, title, phi1, dphi1, nz);
162 //for (int i= 0; i<nz; i++)
163 //DefineSection(i, Z[i], RMIN[i], RMAX[i]);
166 //---------------------------------------------------------------------------
168 AliGPCone::~AliGPCone()
172 if( fRmin ) delete [] fRmin;
173 if( fRmax ) delete [] fRmax;
174 if( fDz ) delete [] fDz;
175 //if( fSiTab ) delete fSiTab;
176 //if( fCoTab ) delete fCoTab;
185 //-------------------------------------------------------------------------
187 void AliGPCone::DrawShape(Option_t *option)
193 //-------------------------------------------------------------------------
195 void AliGPCone::Draw(Option_t *option)
197 //cout << " Entra en " << this->GetName() << "::Draw " << endl;
199 TString opt = option;
203 //TCanvas* Cone = new TCanvas("AliGPCone","AliGPCone",0,0,400,300);
204 gPad = new TCanvas("AliGPCone","AliGPCone",0,0,400,300);
205 gPad->Range(0,0,1,1);
206 gPad->SetFillColor(32); // Light Green
207 gPad->SetBorderSize(3);
208 gPad->SetBorderMode(0); // -1 (down) 0 (no) 1 (up)
211 if( !opt.Contains("same") ) {
213 gPad->SetName("AliGPCone");
214 gPad->SetTitle("AliGPCone");
217 gPad->SetName("AliShapes");
218 gPad->SetTitle("AliShapes");
223 TView *view = gPad->GetView();
228 view->SetAutoRange(kTRUE);
230 view->SetAutoRange(kFALSE);
231 //cout << " Sale de " << this->GetName() << "::Draw " << endl;
234 //-------------------------------------------------------------------------
236 void AliGPCone::SetPoints(Float_t *buff)
238 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Create PCON points*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
239 //*-* ==================
246 Int_t n = GetNumberOfDivisions()+1;
248 //*-* We've to check whether the table does exist and create it
249 //*-* since fCoTab/fSiTab are not saved with any TShape::Streamer function
250 if (!fCoTab) MakeTableOfCoSin();
252 for (i = 0; i < fNz; i++)
254 for (j = 0; j < n; j++)
256 buff[indx++] = fRmin[i] * fCoTab[j];
257 buff[indx++] = fRmin[i] * fSiTab[j];
258 buff[indx++] = fDz[i];
260 for (j = 0; j < n; j++)
262 buff[indx++] = fRmax[i] * fCoTab[j];
263 buff[indx++] = fRmax[i] * fSiTab[j];
264 buff[indx++] = fDz[i];
270 //-------------------------------------------------------------------------
272 void AliGPCone::Paint(Option_t *option)
275 //*-*-*-*-*-*-*-*Paint this 3-D shape with its current attributes*-*-*-*-*-*-*-*
276 //*-* ================================================
280 const Int_t n = GetNumberOfDivisions()+1;
282 SetLineColor( GetCol() );
284 Int_t numpoints = fNz*2*n;
285 if (numpoints <= 0) return;
286 //*-* Allocate memory for points *-*
288 Float_t *points = new Float_t[3*numpoints];
292 Bool_t rangeView = strcmp(option,"range")==0 ? kTRUE : kFALSE;
293 if (!rangeView && gPad->GetView3D()) PaintGLPoints(points);
295 //== for (i = 0; i < numpoints; i++)
296 //== gNode->Local2Master(&points[3*i],&points[3*i]);
298 Bool_t specialCase = kFALSE;
300 if (fDphi1 == 360) //mark this as a very special case, when
301 specialCase = kTRUE; //we have to draw this PCON like a TUBE
303 X3DBuffer *buff = new X3DBuffer;
306 buff->numPoints = numpoints;
307 buff->numSegs = 4*(fNz*n-1+(specialCase == kTRUE));
308 buff->numPolys = 2*(fNz*n-1+(specialCase == kTRUE));
311 //*-* Allocate memory for points *-*
313 buff->points = points;
315 Int_t c = ((GetLineColor() % 8) - 1) * 4; // Basic colors: 0, 1, ... 7
318 //*-* Allocate memory for segments *-*
320 Int_t indx, indx2, k;
323 buff->segs = new Int_t[buff->numSegs*3];
326 //inside & outside circles, number of segments: 2*fNz*(n-1)
327 // special case number of segments: 2*fNz*n
328 for (i = 0; i < fNz*2; i++) {
330 for (j = 1; j < n; j++) {
331 buff->segs[indx++] = c;
332 buff->segs[indx++] = indx2+j-1;
333 buff->segs[indx++] = indx2+j;
336 buff->segs[indx++] = c;
337 buff->segs[indx++] = indx2+j-1;
338 buff->segs[indx++] = indx2;
342 //bottom & top lines, number of segments: 2*n
343 for (i = 0; i < 2; i++) {
344 indx2 = i*(fNz-1)*2*n;
345 for (j = 0; j < n; j++) {
346 buff->segs[indx++] = c;
347 buff->segs[indx++] = indx2+j;
348 buff->segs[indx++] = indx2+n+j;
352 //inside & outside cilindres, number of segments: 2*(fNz-1)*n
353 for (i = 0; i < (fNz-1); i++) {
357 for (j = 0; j < n; j++) {
358 buff->segs[indx++] = c+2;
359 buff->segs[indx++] = indx2+j;
360 buff->segs[indx++] = indx2+n*2+j;
364 for (j = 0; j < n; j++) {
365 buff->segs[indx++] = c+3;
366 buff->segs[indx++] = indx2+j;
367 buff->segs[indx++] = indx2+n*2+j;
371 //left & right sections, number of segments: 2*(fNz-2)
372 // special case number of segments: 0
374 for (i = 1; i < (fNz-1); i++) {
375 for (j = 0; j < 2; j++) {
376 buff->segs[indx++] = c;
377 buff->segs[indx++] = 2*i * n + j*(n-1);
378 buff->segs[indx++] = (2*i+1) * n + j*(n-1);
385 Int_t m = n - 1 + (specialCase == kTRUE);
387 //*-* Allocate memory for polygons *-*
391 buff->polys = new Int_t[buff->numPolys*6];
395 //bottom & top, number of polygons: 2*(n-1)
396 // special case number of polygons: 2*n
397 for (i = 0; i < 2; i++) {
398 for (j = 0; j < n-1; j++) {
399 buff->polys[indx++] = c+3;
400 buff->polys[indx++] = 4;
401 buff->polys[indx++] = 2*fNz*m+i*n+j;
402 buff->polys[indx++] = i*(fNz*2-2)*m+m+j;
403 buff->polys[indx++] = 2*fNz*m+i*n+j+1;
404 buff->polys[indx++] = i*(fNz*2-2)*m+j;
407 buff->polys[indx++] = c+3;
408 buff->polys[indx++] = 4;
409 buff->polys[indx++] = 2*fNz*m+i*n+j;
410 buff->polys[indx++] = i*(fNz*2-2)*m+m+j;
411 buff->polys[indx++] = 2*fNz*m+i*n;
412 buff->polys[indx++] = i*(fNz*2-2)*m+j;
417 //inside & outside, number of polygons: (fNz-1)*2*(n-1)
418 for (k = 0; k < (fNz-1); k++) {
419 for (i = 0; i < 2; i++) {
420 for (j = 0; j < n-1; j++) {
421 buff->polys[indx++] = c+i;
422 buff->polys[indx++] = 4;
423 buff->polys[indx++] = (2*k+i*1)*m+j;
424 buff->polys[indx++] = fNz*2*m+(2*k+i*1+2)*n+j;
425 buff->polys[indx++] = (2*k+i*1+2)*m+j;
426 buff->polys[indx++] = fNz*2*m+(2*k+i*1+2)*n+j+1;
429 buff->polys[indx++] = c+i;
430 buff->polys[indx++] = 4;
431 buff->polys[indx++] = (2*k+i*1)*m+j;
432 buff->polys[indx++] = fNz*2*m+(2*k+i*1+2)*n+j;
433 buff->polys[indx++] = (2*k+i*1+2)*m+j;
434 buff->polys[indx++] = fNz*2*m+(2*k+i*1+2)*n;
440 //left & right sections, number of polygons: 2*(fNz-1)
441 // special case number of polygons: 0
444 for (k = 0; k < (fNz-1); k++) {
445 for (i = 0; i < 2; i++) {
446 buff->polys[indx++] = c+2;
447 buff->polys[indx++] = 4;
448 buff->polys[indx++] = k==0 ? indx2+i*(n-1) : indx2+2*fNz*n+2*(k-1)+i;
449 buff->polys[indx++] = indx2+2*(k+1)*n+i*(n-1);
450 buff->polys[indx++] = indx2+2*fNz*n+2*k+i;
451 buff->polys[indx++] = indx2+(2*k+3)*n+i*(n-1);
454 buff->polys[indx-8] = indx2+n;
455 buff->polys[indx-2] = indx2+2*n-1;
459 //*-* Paint in the pad
461 PaintShape(buff,rangeView);
463 if (strstr(option, "x3d")) {
464 if(buff && buff->points && buff->segs)
467 gSize3D.numPoints -= buff->numPoints;
468 gSize3D.numSegs -= buff->numSegs;
469 gSize3D.numPolys -= buff->numPolys;
474 if (buff->segs) delete [] buff->segs;
475 if (buff->polys) delete [] buff->polys;
476 if (buff) delete buff;
480 //-------------------------------------------------------------------------
482 void AliGPCone::MakeTableOfCoSin()
484 const Double_t PI = TMath::ATan(1) * 4.0;
485 const Double_t ragrad = PI/180.0;
488 Int_t n = GetNumberOfDivisions () + 1;
490 delete [] fCoTab; // Delete the old tab if any
491 fCoTab = new Double_t [n];
492 if (!fCoTab ) return;
495 delete [] fSiTab; // Delete the old tab if any
496 fSiTab = new Double_t [n];
497 if (!fSiTab ) return;
499 Double_t range = Double_t(fDphi1 * ragrad);
500 Double_t phi1 = Double_t(fPhi1 * ragrad);
501 Double_t angstep = range/(n-1);
504 for (j = 0; j < n; j++)
506 ph = phi1 + j*angstep;
507 fCoTab[j] = TMath::Cos(ph);
508 fSiTab[j] = TMath::Sin(ph);
513 //----------------------------------------------------
515 void AliGPCone::SetNumberOfDivisions (Int_t p)
517 if (GetNumberOfDivisions () == p) return;
522 //-------------------------------------------------------
524 void AliGPCone::DefineSection(Int_t secNum, Float_t z, Float_t rmin, Float_t rmax )
527 //*-*-*-*-*-*-*-*-*-*Defines section secNum of the polycone*-*-*-*-*-*-*-*-*-*-*
528 //*-* ======================================
530 // - rmin radius of the inner circle in the cross-section
532 // - rmax radius of the outer circle in the cross-section
534 // - z z coordinate of the section
536 if ((secNum < 0) || (secNum >= fNz)) return;
538 fRmin[secNum] = rmin;
539 fRmax[secNum] = rmax;
543 //-------------------------------------------------------
545 void AliGPCone::Streamer(TBuffer &R__b)
547 // Stream an object of class AliGPCone.
549 if (R__b.IsReading()) {
550 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
551 AliGShape::Streamer(R__b);
552 R__b.ReadArray(fSiTab); //
553 R__b.ReadArray(fCoTab); //
557 R__b.ReadArray(fRmin); //
558 R__b.ReadArray(fRmax); //
559 R__b.ReadArray(fDz); //
562 R__b.WriteVersion(AliGPCone::IsA());
563 AliGShape::Streamer(R__b);
564 R__b.WriteArray(fSiTab, GetNumberOfDivisions()+1); //
565 R__b.WriteArray(fCoTab, GetNumberOfDivisions()+1); //
569 R__b.WriteArray(fRmin, fNz+1); //
570 R__b.WriteArray(fRmax, fNz+1); //
571 R__b.WriteArray(fDz, fNz+1); //
576 //-------------------------------------------------------