Introduction of the Copyright and cvs Log
[u/mrichter/AliRoot.git] / GEODB / AliGPCone.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
18*/
19
ab2f6604 20// -*- C++ -*-
21//
22// 1998/10/19
23// ---------------------------------------------------------------------------
24//
25// AliGPCone Class
26//
27// This file is part of the ALICE Geometry Database .
28//
29// By: Joana E. Santo & David Collados
30//
31// ---------------------------------------------------------------------------
32
33#include <TView.h>
34#include <TVirtualPad.h>
35#include <iostream.h>
36#include <TGLKernelABC.h>
37#include <TCanvas.h>
38#include "AliGPCone.h"
39#include "TROOT.h"
40
41ClassImp(AliGPCone)
42
43AliGPCone::AliGPCone() : AliGShape()
44{
45 /* Default Constructor */
46
47 fPhi1 = 0.;
48 fDphi1 = 0.;
49 fNz = 0;
50 fNdiv = 0;
51 fRmin = NULL;
52 fRmax = NULL;
53 fDz = NULL;
54 fCoTab = NULL;
55 fSiTab = NULL;
56}
57
58//-------------------------------------------------------------------------
59
60AliGPCone::AliGPCone( AliGPCone* pcone )
61{
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() );
65 return;
66 }
67
68 fName = pcone->fName;
69 fTitle = pcone->fTitle;
70
71 fColor = pcone->fColor;
72 fPhi1 = pcone->fPhi1;
73 fDphi1 = pcone->fDphi1;
74 fNz = pcone->fNz;
75 fNdiv = pcone->fNdiv;
76
77 fRmin = new Float_t [fNz+1];
78 fRmax = new Float_t [fNz+1];
79 fDz = new Float_t [fNz+1];
80
81 fCoTab = NULL;
82 fSiTab = NULL;
83
84 while (fDphi1 > 360) fDphi1 -= 360;
85
86 MakeTableOfCoSin();
87
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];
92 }
93
94}
95
96//-------------------------------------------------------------------------
97
98AliGPCone::AliGPCone( Text_t *name, Text_t *title, Float_t phi1, Float_t dphi1, Int_t nz ) : AliGShape(name, title)
99{
100 /* Constructor */
101
102 if (nz < 2 ) {
103 Error(name, "number of z planes for %s must be at least two !", name);
104 return;
105 }
106
107 fPhi1 = phi1;
108 fDphi1 = dphi1;
109 fNz = nz;
110 fNdiv = 0;
111 fRmin = new Float_t [fNz+1];
112 fRmax = new Float_t [fNz+1];
113 fDz = new Float_t [fNz+1];
114
115 fCoTab = NULL;
116 fSiTab = NULL;
117
118 while (fDphi1 > 360) fDphi1 -= 360;
119
120 MakeTableOfCoSin();
121}
122
123//---------------------------------------------------------------------------
124
125AliGPCone::AliGPCone( Text_t *name, Text_t* title, Float_t *upar, Int_t np) : AliGShape(name, title)
126{
127 if (upar[2] < 2 ) {
128 Error(name, "number of z planes for %s must be at least two !", name);
129 return;
130 }
131
132 fPhi1 = upar[0];
133 fDphi1 = upar[1];
134 fNz = (Int_t) upar[2];
135 fNdiv = 0;
136 fRmin = new Float_t [fNz+1];
137 fRmax = new Float_t [fNz+1];
138 fDz = new Float_t [fNz+1];
139 fCoTab = NULL;
140 fSiTab = NULL;
141
142 while (fDphi1 > 360) fDphi1 -= 360;
143
144 MakeTableOfCoSin();
145
146 for( int j=3, k=0; k<fNz; k++ ) {
147 fDz[k] = upar[j];
148 fRmin[k] = upar[j+1];
149 fRmax[k] = upar[j+2];
150 j+=3;
151 }
152}
153
154//-------------------------------------------------------------------------
155
156AliGPCone::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)
157{
158 cout << " ENTRA EN EL CONSTRUCTOR CHUNGO !!!!!! " << endl;
159
160 //AliGPCone(name, title, phi1, dphi1, nz);
161
162 //for (int i= 0; i<nz; i++)
163 //DefineSection(i, Z[i], RMIN[i], RMAX[i]);
164}
165
166//---------------------------------------------------------------------------
167
168AliGPCone::~AliGPCone()
169{
170 /* Destructor */
171
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;
177
178 fRmin = NULL;
179 fRmax = NULL;
180 fDz = NULL;
181 //fCoTab = NULL;
182 //fSiTab = NULL;
183}
184
185//-------------------------------------------------------------------------
186
187void AliGPCone::DrawShape(Option_t *option)
188{
189 Draw(option);
190 gPad->Update();
191}
192
193//-------------------------------------------------------------------------
194
195void AliGPCone::Draw(Option_t *option)
196{
197 //cout << " Entra en " << this->GetName() << "::Draw " << endl;
198
199 TString opt = option;
200 opt.ToLower();
201
202 if( !gPad ) {
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)
209 }
210 else {
211 if( !opt.Contains("same") ) {
212 gPad->Clear();
213 gPad->SetName("AliGPCone");
214 gPad->SetTitle("AliGPCone");
215 }
216 else {
217 gPad->SetName("AliShapes");
218 gPad->SetTitle("AliShapes");
219 }
220 }
221
222 AppendPad(option);
223 TView *view = gPad->GetView();
224
225 if (!view)
226 view = new TView(1);
227
228 view->SetAutoRange(kTRUE);
229 Paint(option);
230 view->SetAutoRange(kFALSE);
231 //cout << " Sale de " << this->GetName() << "::Draw " << endl;
232}
233
234//-------------------------------------------------------------------------
235
236void AliGPCone::SetPoints(Float_t *buff)
237{
238 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Create PCON points*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
239//*-* ==================
240
241 Int_t i, j;
242 Int_t indx = 0;
243
244 if (buff) {
245
246 Int_t n = GetNumberOfDivisions()+1;
247
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();
251
252 for (i = 0; i < fNz; i++)
253 {
254 for (j = 0; j < n; j++)
255 {
256 buff[indx++] = fRmin[i] * fCoTab[j];
257 buff[indx++] = fRmin[i] * fSiTab[j];
258 buff[indx++] = fDz[i];
259 }
260 for (j = 0; j < n; j++)
261 {
262 buff[indx++] = fRmax[i] * fCoTab[j];
263 buff[indx++] = fRmax[i] * fSiTab[j];
264 buff[indx++] = fDz[i];
265 }
266 }
267 }
268}
269
270//-------------------------------------------------------------------------
271
272void AliGPCone::Paint(Option_t *option)
273{
274
275//*-*-*-*-*-*-*-*Paint this 3-D shape with its current attributes*-*-*-*-*-*-*-*
276//*-* ================================================
277
278 Int_t i, j;
279 if (fNz < 2) return;
280 const Int_t n = GetNumberOfDivisions()+1;
281
282 SetLineColor( GetCol() );
283
284 Int_t numpoints = fNz*2*n;
285 if (numpoints <= 0) return;
286 //*-* Allocate memory for points *-*
287
288 Float_t *points = new Float_t[3*numpoints];
289 if (!points) return;
290 SetPoints(points);
291
292 Bool_t rangeView = strcmp(option,"range")==0 ? kTRUE : kFALSE;
293 if (!rangeView && gPad->GetView3D()) PaintGLPoints(points);
294
295 //== for (i = 0; i < numpoints; i++)
296 //== gNode->Local2Master(&points[3*i],&points[3*i]);
297
298 Bool_t specialCase = kFALSE;
299
300 if (fDphi1 == 360) //mark this as a very special case, when
301 specialCase = kTRUE; //we have to draw this PCON like a TUBE
302
303 X3DBuffer *buff = new X3DBuffer;
304
305 if (buff) {
306 buff->numPoints = numpoints;
307 buff->numSegs = 4*(fNz*n-1+(specialCase == kTRUE));
308 buff->numPolys = 2*(fNz*n-1+(specialCase == kTRUE));
309 }
310
311 //*-* Allocate memory for points *-*
312
313 buff->points = points;
314
315 Int_t c = ((GetLineColor() % 8) - 1) * 4; // Basic colors: 0, 1, ... 7
316 if (c < 0) c = 0;
317
318 //*-* Allocate memory for segments *-*
319
320 Int_t indx, indx2, k;
321 indx = indx2 = 0;
322
323 buff->segs = new Int_t[buff->numSegs*3];
324 if (buff->segs) {
325
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++) {
329 indx2 = i*n;
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;
334 }
335 if (specialCase) {
336 buff->segs[indx++] = c;
337 buff->segs[indx++] = indx2+j-1;
338 buff->segs[indx++] = indx2;
339 }
340 }
341
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;
349 }
350 }
351
352 //inside & outside cilindres, number of segments: 2*(fNz-1)*n
353 for (i = 0; i < (fNz-1); i++) {
354
355 //inside cilinder
356 indx2 = i*n*2;
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;
361 }
362 //outside cilinder
363 indx2 = i*n*2+n;
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;
368 }
369 }
370
371 //left & right sections, number of segments: 2*(fNz-2)
372 // special case number of segments: 0
373 if (!specialCase) {
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);
379 }
380 }
381 }
382 }
383
384
385 Int_t m = n - 1 + (specialCase == kTRUE);
386
387//*-* Allocate memory for polygons *-*
388
389 indx = 0;
390
391 buff->polys = new Int_t[buff->numPolys*6];
392
393 if (buff->polys) {
394
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;
405 }
406 if (specialCase) {
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;
413 }
414 }
415
416
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;
427 }
428 if (specialCase) {
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;
435 }
436 }
437 }
438
439
440 //left & right sections, number of polygons: 2*(fNz-1)
441 // special case number of polygons: 0
442 if (!specialCase) {
443 indx2 = fNz*2*(n-1);
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);
452 }
453 }
454 buff->polys[indx-8] = indx2+n;
455 buff->polys[indx-2] = indx2+2*n-1;
456 }
457 }
458
459 //*-* Paint in the pad
460
461 PaintShape(buff,rangeView);
462
463 if (strstr(option, "x3d")) {
464 if(buff && buff->points && buff->segs)
465 FillX3DBuffer(buff);
466 else {
467 gSize3D.numPoints -= buff->numPoints;
468 gSize3D.numSegs -= buff->numSegs;
469 gSize3D.numPolys -= buff->numPolys;
470 }
471 }
472
473 delete [] points;
474 if (buff->segs) delete [] buff->segs;
475 if (buff->polys) delete [] buff->polys;
476 if (buff) delete buff;
477
478 }
479
480//-------------------------------------------------------------------------
481
482void AliGPCone::MakeTableOfCoSin()
483{
484 const Double_t PI = TMath::ATan(1) * 4.0;
485 const Double_t ragrad = PI/180.0;
486
487 Int_t j;
488 Int_t n = GetNumberOfDivisions () + 1;
489 if (fCoTab)
490 delete [] fCoTab; // Delete the old tab if any
491 fCoTab = new Double_t [n];
492 if (!fCoTab ) return;
493
494 if (fSiTab)
495 delete [] fSiTab; // Delete the old tab if any
496 fSiTab = new Double_t [n];
497 if (!fSiTab ) return;
498
499 Double_t range = Double_t(fDphi1 * ragrad);
500 Double_t phi1 = Double_t(fPhi1 * ragrad);
501 Double_t angstep = range/(n-1);
502
503 Double_t ph = phi1;
504 for (j = 0; j < n; j++)
505 {
506 ph = phi1 + j*angstep;
507 fCoTab[j] = TMath::Cos(ph);
508 fSiTab[j] = TMath::Sin(ph);
509 }
510
511}
512
513//----------------------------------------------------
514
515void AliGPCone::SetNumberOfDivisions (Int_t p)
516{
517 if (GetNumberOfDivisions () == p) return;
518 fNdiv=p;
519 MakeTableOfCoSin();
520}
521
522//-------------------------------------------------------
523
524void AliGPCone::DefineSection(Int_t secNum, Float_t z, Float_t rmin, Float_t rmax )
525{
526
527//*-*-*-*-*-*-*-*-*-*Defines section secNum of the polycone*-*-*-*-*-*-*-*-*-*-*
528//*-* ======================================
529//
530// - rmin radius of the inner circle in the cross-section
531//
532// - rmax radius of the outer circle in the cross-section
533//
534// - z z coordinate of the section
535
536 if ((secNum < 0) || (secNum >= fNz)) return;
537
538 fRmin[secNum] = rmin;
539 fRmax[secNum] = rmax;
540 fDz[secNum] = z;
541}
542
543//-------------------------------------------------------
544
545void AliGPCone::Streamer(TBuffer &R__b)
546{
547 // Stream an object of class AliGPCone.
548
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); //
554 R__b >> fPhi1;
555 R__b >> fDphi1;
556 R__b >> fNz;
557 R__b.ReadArray(fRmin); //
558 R__b.ReadArray(fRmax); //
559 R__b.ReadArray(fDz); //
560 R__b >> fNdiv;
561 } else {
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); //
566 R__b << fPhi1;
567 R__b << fDphi1;
568 R__b << fNz;
569 R__b.WriteArray(fRmin, fNz+1); //
570 R__b.WriteArray(fRmax, fNz+1); //
571 R__b.WriteArray(fDz, fNz+1); //
572 R__b << fNdiv;
573 }
574}
575
576//-------------------------------------------------------
577
578