]> git.uio.no Git - u/mrichter/AliRoot.git/blob - GEODB/AliGBox.cxx
Update for coding convensions
[u/mrichter/AliRoot.git] / GEODB / AliGBox.cxx
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
20 // -*- C++ -*-
21 // 
22 // 1998/10/19
23 // ---------------------------------------------------------------------------
24 //
25 // AliGBox Class
26 //
27 // This file is part of the ALICE Geometry Database .
28 //
29 // Author:  Joana E. Santo & company...
30 //
31 // ---------------------------------------------------------------------------
32
33 #include <TView.h>
34 #include <TCanvas.h>
35 #include <TVirtualPad.h>
36 #include <iostream.h>
37 #include <TGLKernelABC.h>
38 #include "AliGBox.h"
39 #include <TROOT.h>
40
41 ClassImp(AliGBox)
42
43
44 //-------------------------------------------------------------------------
45
46 AliGBox::AliGBox(Text_t* name,Text_t* title, Float_t Dx, Float_t Dy, Float_t Dz) : AliGShape(name, title)
47 {
48     /* Constructor */
49     fDx = Dx;
50     fDy = Dy;
51     fDz = Dz;
52 }
53
54 //-------------------------------------------------------------------------   
55
56 AliGBox::AliGBox( AliGBox* box )
57 {
58     if( box ) {
59         /* Copy Constructor */
60         fDx    = box->fDx;
61         fDy    = box->fDy; 
62         fDz    = box->fDz;
63         fName  = box->fName;
64         fTitle = box->fTitle;
65         fColor = box->fColor;
66     }
67     else{
68         /* Default Constructor */
69         fDx    = 0;
70         fDy    = 0;
71         fDz    = 0;
72         fName  = "";
73         fTitle = "";
74     }
75 }
76
77 //-------------------------------------------------------------------------
78
79 AliGBox* AliGBox::operator=(const AliGBox *box)
80 {
81     /* Operator = */
82     if( this == box) return this; // special case.
83
84     fDx    = box->fDx;
85     fDy    = box->fDy; 
86     fDz    = box->fDz; 
87     fName  = box->fName;
88     fTitle = box->fTitle;
89     fColor = box->fColor;
90
91     return this;
92 }
93
94 //-------------------------------------------------------------------------
95
96 void AliGBox::DrawShape(Option_t *option)
97 {
98     Draw(option);
99     gPad->Update();
100 }
101
102 //-------------------------------------------------------------------------
103
104 void AliGBox::Paint(Option_t *option)
105 {
106     SetLineColor( GetCol() );
107     const Int_t numpoints = 8;
108
109     //*-* Allocate memory for points *-*
110
111     Float_t *points = new Float_t[3*numpoints];
112     if (!points) return;
113
114     SetPoints(points);
115
116     if (gPad->GetView3D()) PaintGLPoints(points);
117
118     //==  for (Int_t i = 0; i < numpoints; i++)
119     //            gNode->Local2Master(&points[3*i],&points[3*i]);
120
121     Int_t c = ((GetLineColor() % 8) - 1) * 4;     // Basic colors: 0, 1, ... 7
122     if (c < 0) c = 0;
123
124     //*-* Allocate memory for segments *-*
125
126     X3DBuffer *buff = new X3DBuffer;
127     if (buff) {
128         buff->numPoints = 8;
129         buff->numSegs   = 12;
130         buff->numPolys  = 6;
131     }
132
133 //*-* Allocate memory for points *-*
134
135     buff->points = points;
136     buff->segs = new Int_t[buff->numSegs*3];
137     if (buff->segs) {
138         buff->segs[ 0] = c;    buff->segs[ 1] = 0;    buff->segs[ 2] = 1;
139         buff->segs[ 3] = c+1;  buff->segs[ 4] = 1;    buff->segs[ 5] = 2;
140         buff->segs[ 6] = c+1;  buff->segs[ 7] = 2;    buff->segs[ 8] = 3;
141         buff->segs[ 9] = c;    buff->segs[10] = 3;    buff->segs[11] = 0;
142         buff->segs[12] = c+2;  buff->segs[13] = 4;    buff->segs[14] = 5;
143         buff->segs[15] = c+2;  buff->segs[16] = 5;    buff->segs[17] = 6;
144         buff->segs[18] = c+3;  buff->segs[19] = 6;    buff->segs[20] = 7;
145         buff->segs[21] = c+3;  buff->segs[22] = 7;    buff->segs[23] = 4;
146         buff->segs[24] = c;    buff->segs[25] = 0;    buff->segs[26] = 4;
147         buff->segs[27] = c+2;  buff->segs[28] = 1;    buff->segs[29] = 5;
148         buff->segs[30] = c+1;  buff->segs[31] = 2;    buff->segs[32] = 6;
149         buff->segs[33] = c+3;  buff->segs[34] = 3;    buff->segs[35] = 7;
150     }
151
152 //*-* Allocate memory for polygons *-*
153
154     buff->polys = new Int_t[buff->numPolys*6];
155     if (buff->polys) {
156         buff->polys[ 0] = c;   buff->polys[ 1] = 4;  buff->polys[ 2] = 0;
157         buff->polys[ 3] = 9;   buff->polys[ 4] = 4;  buff->polys[ 5] = 8;
158         buff->polys[ 6] = c+1; buff->polys[ 7] = 4;  buff->polys[ 8] = 1;
159         buff->polys[ 9] = 10;  buff->polys[10] = 5;  buff->polys[11] = 9;
160         buff->polys[12] = c;   buff->polys[13] = 4;  buff->polys[14] = 2;
161         buff->polys[15] = 11;  buff->polys[16] = 6;  buff->polys[17] = 10;
162         buff->polys[18] = c+1; buff->polys[19] = 4;  buff->polys[20] = 3;
163         buff->polys[21] = 8;   buff->polys[22] = 7;  buff->polys[23] = 11;
164         buff->polys[24] = c+2; buff->polys[25] = 4;  buff->polys[26] = 0;
165         buff->polys[27] = 3;   buff->polys[28] = 2;  buff->polys[29] = 1;
166         buff->polys[30] = c+3; buff->polys[31] = 4;  buff->polys[32] = 4;
167         buff->polys[33] = 5;   buff->polys[34] = 6;  buff->polys[35] = 7;
168     }
169
170     //*-* Paint in the pad
171     Bool_t rangeView = strcmp(option,"range")==0 ? kTRUE : kFALSE;
172     PaintShape(buff,rangeView);
173
174     if (strstr(option, "x3d")) {
175         if(buff && buff->points && buff->segs)
176             FillX3DBuffer(buff);
177         else {
178             gSize3D.numPoints -= buff->numPoints;
179             gSize3D.numSegs   -= buff->numSegs;
180             gSize3D.numPolys  -= buff->numPolys;
181         }
182     }
183
184     delete [] points;
185     if (buff->segs)     delete [] buff->segs;
186     if (buff->polys)    delete [] buff->polys;
187     if (buff)           delete    buff;
188    
189
190 }
191
192
193
194
195 // ---------------------------------------------------------------------------
196
197 void AliGBox::PaintGLPoints(Float_t *vertex)
198 {
199 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Paint BRIK via OpenGL *-*-*-*-*-*-*-*-*-*-*-*-*
200 //*-*                            =====================
201     gGLKernel->PaintBrik(vertex);
202 }
203
204
205 // ---------------------------------------------------------------------------
206
207 void AliGBox::SetPoints(Float_t *buff)
208 {
209 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Create AliGBox points*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
210 //*-*                            =====================
211  
212     if (buff) {
213         buff[ 0] = -fDx;    buff[ 1] = -fDy;    buff[ 2] = -fDz;
214         buff[ 3] =  fDx;    buff[ 4] = -fDy;    buff[ 5] = -fDz;
215         buff[ 6] =  fDx;    buff[ 7] =  fDy;    buff[ 8] = -fDz;
216         buff[ 9] = -fDx;    buff[10] =  fDy;    buff[11] = -fDz;
217         buff[12] = -fDx;    buff[13] = -fDy;    buff[14] =  fDz;
218         buff[15] =  fDx;    buff[16] = -fDy;    buff[17] =  fDz;
219         buff[18] =  fDx;    buff[19] =  fDy;    buff[20] =  fDz;
220         buff[21] = -fDx;    buff[22] =  fDy;    buff[23] =  fDz;
221     }
222 }
223
224 //-------------------------------------------------------------------------
225
226 void AliGBox::Sizeof3D() const
227 {
228 //*-*-*-*-*-*-*Return total X3D size of this shape with its attributes*-*-*-*-*-*
229 //*-*          =======================================================
230
231   //cout << " Entra en AliGBox::Sizeof3D() " << endl;
232
233     gSize3D.numPoints += 8;
234     gSize3D.numSegs   += 12;
235     gSize3D.numPolys  += 6;
236 }
237
238
239
240
241
242
243
244