]> git.uio.no Git - u/mrichter/AliRoot.git/blob - GEODB/AliGPCone.cxx
This commit was generated by cvs2svn to compensate for changes in r209,
[u/mrichter/AliRoot.git] / GEODB / AliGPCone.cxx
1 // -*- C++ -*-
2 // 
3 // 1998/10/19
4 // ---------------------------------------------------------------------------
5 //
6 // AliGPCone Class
7 //
8 // This file is part of the ALICE Geometry Database .
9 //
10 // By:  Joana E. Santo & David Collados
11 //
12 // ---------------------------------------------------------------------------
13
14 #include <TView.h>
15 #include <TVirtualPad.h>
16 #include <iostream.h>
17 #include <TGLKernelABC.h>
18 #include <TCanvas.h>
19 #include "AliGPCone.h"
20 #include "TROOT.h"
21
22 ClassImp(AliGPCone)
23
24 AliGPCone::AliGPCone() : AliGShape()
25 {
26     /* Default Constructor */
27     
28     fPhi1  = 0.;
29     fDphi1 = 0.;
30     fNz    = 0;
31     fNdiv  = 0;
32     fRmin  = NULL;
33     fRmax  = NULL;
34     fDz    = NULL;
35     fCoTab = NULL;
36     fSiTab = NULL;
37 }
38
39 //-------------------------------------------------------------------------
40
41 AliGPCone::AliGPCone( AliGPCone* pcone )
42 {
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() );
46         return;
47     }
48
49     fName  = pcone->fName;
50     fTitle = pcone->fTitle;
51
52     fColor = pcone->fColor;
53     fPhi1  = pcone->fPhi1;
54     fDphi1 = pcone->fDphi1;
55     fNz    = pcone->fNz;
56     fNdiv  = pcone->fNdiv;
57
58     fRmin  = new Float_t [fNz+1];
59     fRmax  = new Float_t [fNz+1];
60     fDz    = new Float_t [fNz+1];
61
62     fCoTab = NULL;
63     fSiTab = NULL;
64
65     while (fDphi1 > 360) fDphi1 -= 360;
66
67     MakeTableOfCoSin();
68
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];
73     }
74
75 }
76
77 //-------------------------------------------------------------------------
78
79 AliGPCone::AliGPCone( Text_t *name, Text_t *title,  Float_t phi1, Float_t dphi1, Int_t nz ) : AliGShape(name, title)
80 {
81     /* Constructor */
82     
83     if (nz < 2 ) {
84         Error(name, "number of z planes for %s must be at least two !", name);
85         return;
86     }
87
88     fPhi1  = phi1;
89     fDphi1 = dphi1;
90     fNz    = nz;
91     fNdiv  = 0;
92     fRmin  = new Float_t [fNz+1];
93     fRmax  = new Float_t [fNz+1];
94     fDz    = new Float_t [fNz+1];
95
96     fCoTab = NULL;
97     fSiTab = NULL;
98
99     while (fDphi1 > 360) fDphi1 -= 360;
100
101     MakeTableOfCoSin();
102 }
103
104 //---------------------------------------------------------------------------
105
106 AliGPCone::AliGPCone( Text_t *name, Text_t* title,  Float_t *upar, Int_t np) : AliGShape(name, title)
107 {
108     if (upar[2] < 2 ) {
109         Error(name, "number of z planes for %s must be at least two !", name);
110         return;
111     }
112
113     fPhi1  = upar[0];
114     fDphi1 = upar[1];
115     fNz    = (Int_t) upar[2];
116     fNdiv  = 0;
117     fRmin  = new Float_t [fNz+1];
118     fRmax  = new Float_t [fNz+1];
119     fDz    = new Float_t [fNz+1];
120     fCoTab = NULL;
121     fSiTab = NULL;
122
123     while (fDphi1 > 360) fDphi1 -= 360;
124
125     MakeTableOfCoSin();
126
127     for( int j=3, k=0; k<fNz; k++ ) {
128         fDz[k]   = upar[j];
129         fRmin[k] = upar[j+1];
130         fRmax[k] = upar[j+2];
131         j+=3;
132     }
133 }
134
135 //-------------------------------------------------------------------------
136
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)
138 {       
139      cout << " ENTRA EN EL CONSTRUCTOR CHUNGO !!!!!! " << endl;
140     
141      //AliGPCone(name, title,  phi1, dphi1, nz);
142      
143      //for (int i= 0; i<nz; i++)
144          //DefineSection(i, Z[i], RMIN[i], RMAX[i]);
145 }
146
147 //---------------------------------------------------------------------------
148
149 AliGPCone::~AliGPCone() 
150 {
151     /* Destructor */
152     
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;
158
159     fRmin  = NULL;
160     fRmax  = NULL;
161     fDz    = NULL;
162     //fCoTab = NULL;
163     //fSiTab = NULL;
164 }
165
166 //-------------------------------------------------------------------------
167
168 void AliGPCone::DrawShape(Option_t *option)
169 {
170     Draw(option);
171     gPad->Update();
172 }
173
174 //-------------------------------------------------------------------------
175
176 void AliGPCone::Draw(Option_t *option)
177 {
178     //cout << " Entra en " << this->GetName() << "::Draw " << endl;
179
180     TString opt = option;
181     opt.ToLower();
182
183     if( !gPad ) {
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)
190     }
191     else {
192         if( !opt.Contains("same") ) {
193             gPad->Clear();
194             gPad->SetName("AliGPCone");
195             gPad->SetTitle("AliGPCone");
196         }
197         else {
198             gPad->SetName("AliShapes");
199             gPad->SetTitle("AliShapes"); 
200         }
201     }
202
203     AppendPad(option);
204     TView *view = gPad->GetView();
205
206     if (!view)
207         view = new TView(1);
208
209     view->SetAutoRange(kTRUE);
210     Paint(option);
211     view->SetAutoRange(kFALSE);
212     //cout << " Sale de " << this->GetName() << "::Draw " << endl;
213 }
214
215 //-------------------------------------------------------------------------
216
217 void AliGPCone::SetPoints(Float_t *buff)
218 {
219   //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Create PCON points*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
220 //*-*                            ==================
221
222     Int_t i, j;
223     Int_t indx = 0;
224
225     if (buff) {
226
227         Int_t n            = GetNumberOfDivisions()+1;
228
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();
232
233         for (i = 0; i < fNz; i++)
234         {
235             for (j = 0; j < n; j++)
236             {
237                 buff[indx++] = fRmin[i] * fCoTab[j];
238                 buff[indx++] = fRmin[i] * fSiTab[j];
239                 buff[indx++] = fDz[i];
240             }
241             for (j = 0; j < n; j++)
242             {
243                 buff[indx++] = fRmax[i] * fCoTab[j];
244                 buff[indx++] = fRmax[i] * fSiTab[j];
245                 buff[indx++] = fDz[i];
246             }
247         }
248     }
249 }
250
251 //-------------------------------------------------------------------------
252
253 void AliGPCone::Paint(Option_t *option)
254 {
255
256 //*-*-*-*-*-*-*-*Paint this 3-D shape with its current attributes*-*-*-*-*-*-*-*
257 //*-*            ================================================
258
259     Int_t i, j;
260     if (fNz < 2) return;
261     const Int_t n = GetNumberOfDivisions()+1;
262
263     SetLineColor( GetCol() );
264     
265     Int_t numpoints = fNz*2*n;
266     if (numpoints <= 0) return;
267     //*-* Allocate memory for points *-*
268
269     Float_t *points = new Float_t[3*numpoints];
270     if (!points) return;
271     SetPoints(points);
272
273     Bool_t rangeView = strcmp(option,"range")==0 ? kTRUE : kFALSE;
274     if (!rangeView && gPad->GetView3D()) PaintGLPoints(points);
275
276     //==  for (i = 0; i < numpoints; i++)
277     //==          gNode->Local2Master(&points[3*i],&points[3*i]);
278
279     Bool_t specialCase = kFALSE;
280
281     if (fDphi1 == 360)           //mark this as a very special case, when
282         specialCase = kTRUE;     //we have to draw this PCON like a TUBE
283
284     X3DBuffer *buff = new X3DBuffer;
285
286     if (buff) {
287         buff->numPoints = numpoints;
288         buff->numSegs   = 4*(fNz*n-1+(specialCase == kTRUE));
289         buff->numPolys  = 2*(fNz*n-1+(specialCase == kTRUE));
290     }
291
292     //*-* Allocate memory for points *-*
293
294     buff->points = points;
295
296     Int_t c = ((GetLineColor() % 8) - 1) * 4;     // Basic colors: 0, 1, ... 7
297     if (c < 0) c = 0;
298
299     //*-* Allocate memory for segments *-*
300
301     Int_t indx, indx2, k;
302     indx = indx2 = 0;
303
304     buff->segs = new Int_t[buff->numSegs*3];
305     if (buff->segs) {
306
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++) {
310             indx2 = i*n;
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;
315             }
316             if (specialCase) {
317                 buff->segs[indx++] = c;
318                 buff->segs[indx++] = indx2+j-1;
319                 buff->segs[indx++] = indx2;
320             }
321         }
322
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;
330             }
331         }
332
333         //inside & outside cilindres, number of segments: 2*(fNz-1)*n
334         for (i = 0; i < (fNz-1); i++) {
335
336             //inside cilinder
337             indx2 = i*n*2;
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;
342             }
343             //outside cilinder
344             indx2 = i*n*2+n;
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;
349             }
350         }
351
352         //left & right sections, number of segments: 2*(fNz-2)
353         //          special case number of segments: 0
354         if (!specialCase) {
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);
360                 }
361             }
362         }
363     }
364
365
366     Int_t m = n - 1 + (specialCase == kTRUE);
367
368 //*-* Allocate memory for polygons *-*
369
370     indx = 0;
371
372     buff->polys = new Int_t[buff->numPolys*6];
373
374     if (buff->polys) {
375
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;
386             }
387             if (specialCase) {
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;
394             }
395         }
396
397
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;
408                 }
409                 if (specialCase) {
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;
416                 }
417             }
418         }
419
420
421         //left & right sections, number of polygons: 2*(fNz-1)
422         //          special case number of polygons: 0
423         if (!specialCase) {
424             indx2 = fNz*2*(n-1);
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);
433                 }
434             }
435             buff->polys[indx-8] = indx2+n;
436             buff->polys[indx-2] = indx2+2*n-1;
437         }
438     }
439
440     //*-* Paint in the pad
441     
442     PaintShape(buff,rangeView);
443   
444     if (strstr(option, "x3d")) {
445         if(buff && buff->points && buff->segs)
446             FillX3DBuffer(buff);
447         else {
448             gSize3D.numPoints -= buff->numPoints;
449             gSize3D.numSegs   -= buff->numSegs;
450             gSize3D.numPolys  -= buff->numPolys;
451         }
452     }
453
454     delete [] points;
455     if (buff->segs)     delete [] buff->segs;
456     if (buff->polys)    delete [] buff->polys;
457     if (buff)           delete    buff;
458     
459     }
460     
461 //------------------------------------------------------------------------- 
462
463 void AliGPCone::MakeTableOfCoSin()
464 {
465     const Double_t PI  = TMath::ATan(1) * 4.0;
466     const Double_t ragrad  = PI/180.0;
467
468     Int_t j;
469     Int_t n = GetNumberOfDivisions () + 1;
470     if (fCoTab)
471         delete [] fCoTab; // Delete the old tab if any
472         fCoTab = new Double_t [n];
473     if (!fCoTab ) return;
474
475     if (fSiTab)
476         delete [] fSiTab; // Delete the old tab if any
477     fSiTab = new Double_t [n];
478     if (!fSiTab ) return;
479
480     Double_t range   = Double_t(fDphi1 * ragrad);
481     Double_t phi1    = Double_t(fPhi1  * ragrad);
482     Double_t angstep = range/(n-1);
483
484     Double_t ph = phi1;
485     for (j = 0; j < n; j++)
486     {
487         ph = phi1 + j*angstep;
488         fCoTab[j] = TMath::Cos(ph);
489         fSiTab[j] = TMath::Sin(ph);
490     }
491
492 }
493  
494 //----------------------------------------------------    
495     
496 void AliGPCone::SetNumberOfDivisions (Int_t p)
497 {
498     if (GetNumberOfDivisions () == p) return;
499     fNdiv=p;
500     MakeTableOfCoSin();
501 }   
502     
503 //-------------------------------------------------------   
504
505 void AliGPCone::DefineSection(Int_t secNum, Float_t z, Float_t rmin, Float_t rmax )
506 {
507
508 //*-*-*-*-*-*-*-*-*-*Defines section secNum of the polycone*-*-*-*-*-*-*-*-*-*-*
509 //*-*                ======================================
510 //
511 //     - rmin  radius of the inner circle in the cross-section
512 //
513 //     - rmax  radius of the outer circle in the cross-section
514 //
515 //     - z     z coordinate of the section
516
517     if ((secNum < 0) || (secNum >= fNz)) return;
518
519     fRmin[secNum] = rmin;
520     fRmax[secNum] = rmax;
521     fDz[secNum]   = z;
522 }
523
524 //-------------------------------------------------------   
525
526 void AliGPCone::Streamer(TBuffer &R__b)
527 {
528    // Stream an object of class AliGPCone.
529
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); //
535       R__b >> fPhi1;
536       R__b >> fDphi1;
537       R__b >> fNz;
538       R__b.ReadArray(fRmin); //
539       R__b.ReadArray(fRmax); //
540       R__b.ReadArray(fDz); //
541       R__b >> fNdiv;
542    } else {
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); //
547       R__b << fPhi1;
548       R__b << fDphi1;
549       R__b << fNz;
550       R__b.WriteArray(fRmin, fNz+1); //
551       R__b.WriteArray(fRmax, fNz+1); //
552       R__b.WriteArray(fDz, fNz+1); //
553       R__b << fNdiv;
554    }
555 }
556
557 //-------------------------------------------------------   
558
559