]> git.uio.no Git - u/mrichter/AliRoot.git/blame - GEODB/AliGTube.cxx
Inheritance from TObject. Automatic streamers.
[u/mrichter/AliRoot.git] / GEODB / AliGTube.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// AliTube 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 <TVirtualPad.h>
34#include <TView.h>
35#include <TCanvas.h>
36#include <iostream.h>
37#include <TGLKernelABC.h>
38#include "TROOT.h"
39#include "AliGTube.h"
40#include "AliGShape.h"
41
42ClassImp(AliGTube)
43
44AliGTube::AliGTube()
45{
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
50 fName = "";
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)
55 fTitle = "";
56}
57
58//-------------------------------------------------------------------------
59
60AliGTube::AliGTube( Text_t *name, Text_t *title, Float_t rmin, Float_t rmax, Float_t dz, Float_t aspect ) : AliGShape(name, title)
61{
62 /* Constructor */
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)
70
71 MakeTableOfCoSin();
72}
73
74
75//-------------------------------------------------------------------------
76
77AliGTube::AliGTube( AliGTube *tube )
78{
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;
84 fName = tube->fName;
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;
90
91 MakeTableOfCoSin();
92}
93
94//-------------------------------------------------------------------------
95
96AliGTube::AliGTube(Text_t *name, Text_t *title, Float_t rmax, Float_t dz) : AliGShape(name, title)
97{
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)
106
107 MakeTableOfCoSin();
108}
109
110//-------------------------------------------------------------------------
111
112AliGTube::~AliGTube()
113{
114 /* Destructor */
115 delete [] fCoTab;
116 delete [] fSiTab;
117}
118
119//-------------------------------------------------------------------------
120
121void AliGTube::MakeTableOfCoSin()
122{
123 const Double_t PI = TMath::ATan(1) * 4.0;
124 const Double_t TWOPI = 2*PI;
125
126 Int_t j;
127 Int_t n = GetNumberOfDivisions ();
128
129 if (fCoTab)
130 delete [] fCoTab; // Delete the old tab if any
131 fCoTab = new Double_t [n];
132
133 if (!fCoTab ) {
134 Error("MakeTableOfCoSin()","No cos table done");
135 return;
136 }
137
138 if (fSiTab)
139 delete [] fSiTab; // Delete the old tab if any
140 fSiTab = new Double_t [n];
141
142 if (!fSiTab )
143 {
144 Error("MakeTableOfCoSin()","No sin table done");
145 return;
146 }
147
148 Double_t range = TWOPI;
149 Double_t angstep = range/n;
150
151 Double_t ph = 0;
152 for (j = 0; j < n; j++)
153 {
154 ph = j*angstep;
155 fCoTab[j] = TMath::Cos(ph);
156 fSiTab[j] = TMath::Sin(ph);
157 }
158
159}
160
161//-------------------------------------------------------------------------
162
163void AliGTube::DrawShape(Option_t *option)
164{
165 Draw(option);
166 gPad->Update();
167}
168
169//-------------------------------------------------------------------------
170
171void AliGTube::Draw(Option_t *option)
172{
173 //cout << " Entra en " << this->GetName() << "::Draw " << endl;
174 TString opt = option;
175 opt.ToLower();
176
177 if( !gPad ) {
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)
183 }
184 else {
185 if( !opt.Contains("same") ) {
186 gPad->Clear();
187 gPad->SetName("AliGTube");
188 gPad->SetTitle("AliGTube");
189 }
190 else {
191 gPad->SetName("AliShapes");
192 gPad->SetTitle("AliShapes");
193 }
194 }
195
196 AppendPad(option);
197 TView *view = gPad->GetView();
198
199 if (!view)
200 view = new TView(1);
201
202 view->SetAutoRange(kTRUE);
203 Paint(option);
204 view->SetAutoRange(kFALSE);
205
206 cout << " Sale de " << this->GetName() << "::Draw " << endl;
207}
208
209//-------------------------------------------------------------------------
210
211void AliGTube::Paint(Option_t *option)
212{
213//*-*-*-*-*-*-*-*Paint this 3-D shape with its current attributes*-*-*-*-*-*-*-*
214//*-* ================================================
215
216 SetLineColor( GetCol() );
217
218 Int_t i, j;
219 Int_t n = GetNumberOfDivisions();
220 const Int_t numpoints = 4*n;
221
222//*-* Allocate memory for points *-*
223
224 Float_t *points = new Float_t[3*numpoints];
225 if (!points) return;
226
227 SetPoints(points);
228
229 if (gPad->GetView3D()) PaintGLPoints(points);
230
231//== for (i = 0; i < numpoints; i++)
232//== gNode->Local2Master(&points[3*i],&points[3*i]);
233
234 X3DBuffer *buff = new X3DBuffer;
235 if (buff) {
236 buff->numPoints = numpoints;
237 buff->numSegs = n*8;
238 buff->numPolys = n*4;
239 }
240
241
242//*-* Allocate memory for points *-*
243
244 buff->points = points;
245
246 Int_t c = ((GetLineColor() % 8) - 1) * 4; // Basic colors: 0, 1, ... 7
247 if (c < 0) c = 0;
248
249//*-* Allocate memory for segments *-*
250
251 buff->segs = new Int_t[buff->numSegs*3];
252 if (buff->segs) {
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;
258 }
259 buff->segs[(i*n+j-1)*3+2] = i*n;
260 }
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;
266 }
267 }
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;
273 }
274 }
275 }
276
277//*-* Allocate memory for polygons *-*
278
279 Int_t indx = 0;
280
281 buff->polys = new Int_t[buff->numPolys*6];
282 if (buff->polys) {
283 for (i = 0; i < 2; i++) {
284 for (j = 0; j < n; j++) {
285 indx = 6*(i*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;
292 }
293 buff->polys[indx+5] = (4+i)*n;
294 }
295 for (i = 2; i < 4; i++) {
296 for (j = 0; j < n; j++) {
297 indx = 6*(i*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;
304 }
305 buff->polys[indx+5] = (4+i)*n;
306 }
307 }
308
309 //*-* Paint in the pad
310 //*-* Paint in the pad
311 Bool_t rangeView = strcmp(option,"range")==0 ? kTRUE : kFALSE;
312
313 PaintShape(buff,rangeView);
314 //PaintShape(buff);
315
316 if (strstr(option, "x3d")) {
317 if(buff && buff->points && buff->segs)
318 FillX3DBuffer(buff);
319 else {
320 gSize3D.numPoints -= buff->numPoints;
321 gSize3D.numSegs -= buff->numSegs;
322 gSize3D.numPolys -= buff->numPolys;
323 }
324 }
325
326 if( points ) delete [] points;
327
328 //if (buff->points) delete [] buff->points;
329
330 if (buff->segs) delete [] buff->segs;
331
332 if (buff->polys) delete [] buff->polys;
333
334 if (buff) delete buff;
335
336}
337
338//-------------------------------------------------------------------------
339
340void AliGTube::PaintGLPoints(Float_t *vertex)
341{
342//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Paint BRIK via OpenGL *-*-*-*-*-*-*-*-*-*-*-*-*
343//*-* =====================
344 gGLKernel->PaintCone(vertex,GetNumberOfDivisions(),2);
345}
346
347//-------------------------------------------------------------------------
348
349void AliGTube::SetPoints(Float_t *buff)
350{
351//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Create TUBE points*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
352//*-* ==================
353
354 Float_t dz;
355 Int_t j, n;
356
357 n = GetNumberOfDivisions();
358
359 dz = fDz;
360
361 Int_t indx = 0;
362
363 if (buff) {
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();
367
368 for (j = 0; j < n; j++) {
369 buff[indx+6*n] = buff[indx] = fRmin * fCoTab[j];
370 indx++;
371 buff[indx+6*n] = buff[indx] = fAspectRatio*fRmin * fSiTab[j];
372 indx++;
373 buff[indx+6*n] = dz;
374 buff[indx] =-dz;
375 indx++;
376 }
377 for (j = 0; j < n; j++) {
378 buff[indx+6*n] = buff[indx] = fRmax * fCoTab[j];
379 indx++;
380 buff[indx+6*n] = buff[indx] = fAspectRatio*fRmax * fSiTab[j];
381 indx++;
382 buff[indx+6*n]= dz;
383 buff[indx] =-dz;
384 indx++;
385 }
386 }
387}
388
389//-------------------------------------------------------------------------
390
391void AliGTube::Sizeof3D() const
392{
393//*-*-*-*-*-*Return total X3D size of this shape with its attributes*-*-*-*-*-*-*
394//*-* =======================================================
395
396 cout << " Entra en AliGTube::Sizeof3D() " << endl;
397
398 Int_t n = GetNumberOfDivisions();
399
400 gSize3D.numPoints += n*4;
401 gSize3D.numSegs += n*8;
402 gSize3D.numPolys += n*4;
403}
404
405//-------------------------------------------------------------------------
406
407void AliGTube::Streamer(TBuffer &R__b)
408{
409 // Stream an object of class AliGTube.
410
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;
416 R__b >> fDz;
417 R__b >> fNdiv;
418 R__b >> fRmax;
419 R__b >> fRmin;
420 R__b.ReadArray(fSiTab); //
421 } else {
422 R__b.WriteVersion(AliGTube::IsA());
423 AliGShape::Streamer(R__b);
424 R__b.WriteArray(fCoTab, GetNumberOfDivisions()); //
425 R__b << fAspectRatio;
426 R__b << fDz;
427 R__b << fNdiv;
428 R__b << fRmax;
429 R__b << fRmin;
430 R__b.WriteArray(fSiTab, GetNumberOfDivisions()); //
431 }
432}
433
434//-------------------------------------------------------------------------
435