]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/BoxSet.cxx
Removed support for old ROOT versions.
[u/mrichter/AliRoot.git] / EVE / Reve / BoxSet.cxx
1 // $Header$
2
3 #include "BoxSet.h"
4 #include <TRandom.h>
5 #include <TBuffer3D.h>
6 #include <TBuffer3DTypes.h>
7 #include <TVirtualPad.h>
8 #include <TVirtualViewer3D.h>
9
10 using namespace Reve;
11
12 /**************************************************************************/
13 // Box
14 /**************************************************************************/
15
16 Box::Box(Color_t col)
17 {
18   Reve::ColorFromIdx(col, color);
19 }
20
21 Box::Box(Color_t col, Float_t* p)
22 {
23   Reve::ColorFromIdx(col, color);
24   memcpy(vertices, p, 24*sizeof(Float_t));
25 }
26
27 Box::Box(Color_t col, Float_t  x, Float_t  y, Float_t  z,
28                       Float_t dx, Float_t dy, Float_t dz)
29 {
30   Reve::ColorFromIdx(col, color);
31   MakeAxisAlignedBox(x, y, z, dx, dy, dz);
32 }
33
34 Box::Box(TRandom& rnd, Float_t origin, Float_t size)
35 {
36   Reve::ColorFromIdx(Int_t(30*rnd.Rndm()), color);
37   Float_t  x = 2*origin*(rnd.Rndm() - 0.5);
38   Float_t  y = 2*origin*(rnd.Rndm() - 0.5);
39   Float_t  z = 2*origin*(rnd.Rndm() - 0.5);
40   Float_t dx = 2*size*(rnd.Rndm() - 0.5);
41   Float_t dy = 2*size*(rnd.Rndm() - 0.5);
42   Float_t dz = 2*size*(rnd.Rndm() - 0.5);
43   MakeAxisAlignedBox(x, y, z, dx, dy, dz);
44 }
45
46 void Box::MakeAxisAlignedBox(Float_t  x, Float_t  y, Float_t  z,
47                              Float_t dx, Float_t dy, Float_t dz)
48 {
49   Float_t* p = vertices;
50   //bottom
51   p[0] = x - dx;  p[1] = y + dy;  p[2] = z - dz;  p += 3;
52   p[0] = x + dx;  p[1] = y + dy;  p[2] = z - dz;  p += 3;
53   p[0] = x + dx;  p[1] = y - dy;  p[2] = z - dz;  p += 3;
54   p[0] = x - dx;  p[1] = y - dy;  p[2] = z - dz;  p += 3;
55   //top
56   p[0] = x - dx;  p[1] = y + dy;  p[2] = z + dz;  p += 3;
57   p[0] = x + dx;  p[1] = y + dy;  p[2] = z + dz;  p += 3;
58   p[0] = x + dx;  p[1] = y - dy;  p[2] = z + dz;  p += 3;
59   p[0] = x - dx;  p[1] = y - dy;  p[2] = z + dz;
60  
61 }
62
63 //______________________________________________________________________
64 // BoxSet
65 //
66
67 ClassImp(BoxSet)
68
69 BoxSet::BoxSet(const Text_t* n, const Text_t* t) :
70   RenderElement(fDefaultColor),
71   TNamed(n, t),
72   fRenderMode (RM_AsIs)
73 {}
74
75 /**************************************************************************/
76
77 void BoxSet::ComputeBBox()
78 {
79   if(fBoxes.empty()) {
80     BBoxZero();
81     return;
82   }
83   BBoxInit();
84   for(std::vector<Box>::iterator q=fBoxes.begin(); q!=fBoxes.end(); ++q) {
85     Float_t* p = q->vertices;
86     for(int i=0; i<8; ++i, p+=3)
87       BBoxCheckPoint(p);
88   }
89   // printf("%s BBox is x(%f,%f), y(%f,%f), z(%f,%f)\n", GetName(),
90   //        fBBox[0], fBBox[1], fBBox[2], fBBox[3], fBBox[4], fBBox[5]);
91 }
92
93 void BoxSet::Paint(Option_t* /*option*/)
94 {
95   TBuffer3D buff(TBuffer3DTypes::kGeneric);
96
97   // Section kCore
98   buff.fID           = this;
99   buff.fColor        = 1;
100   buff.fTransparency = 0;
101   fHMTrans.SetBuffer3D(buff);
102   buff.SetSectionsValid(TBuffer3D::kCore);
103
104   Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
105   if (reqSections == TBuffer3D::kNone) {
106     // printf("BoxSet::Paint viewer was happy with Core buff3d.\n");
107     return;
108   }
109
110   if (reqSections & TBuffer3D::kRawSizes) {
111     Int_t nbPnts = fBoxes.size()*8;
112     Int_t nbSegs = fBoxes.size()*12;
113     Int_t nbPoly = fBoxes.size()*6;
114     if (!buff.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPoly, nbPoly*6)) {
115       return;
116     }
117     buff.SetSectionsValid(TBuffer3D::kRawSizes);
118   }
119
120   if ((reqSections & TBuffer3D::kRaw) && buff.SectionsValid(TBuffer3D::kRawSizes)) {
121     // Points
122     Int_t pidx = 0;
123     for (std::vector<Box>::iterator i=fBoxes.begin(); i!=fBoxes.end(); ++i) {
124       for (Int_t k=0; k<24; ++k) {
125         buff.fPnts[pidx] = (*i).vertices[k];
126         pidx++;
127       }
128     }
129     Int_t c = 2;   // color; !!! wrong
130     Int_t eoff;    // polygon or segment offset in fPols and fSegs array
131     Int_t voff;    // vertex offset
132     Int_t soff;    // offset in counting segments
133     Int_t nspp = 4; // number of segments per polygon
134
135     // Segments & Polygons
136     for (Int_t q = 0; q < (Int_t)fBoxes.size(); ++q) {
137       eoff = q*36;
138       soff = q*12;
139       voff = q*8;
140       //bottom
141       buff.fSegs[ 0 + eoff] = c;  buff.fSegs[ 1 + eoff] = 0 + voff;  buff.fSegs[ 2 + eoff] = 1 + voff;
142       buff.fSegs[ 3 + eoff] = c;  buff.fSegs[ 4 + eoff] = 1 + voff;  buff.fSegs[ 5 + eoff] = 2 + voff;
143       buff.fSegs[ 6 + eoff] = c;  buff.fSegs[ 7 + eoff] = 2 + voff;  buff.fSegs[ 8 + eoff] = 3 + voff;
144       buff.fSegs[ 9 + eoff] = c;  buff.fSegs[10 + eoff] = 3 + voff;  buff.fSegs[11 + eoff] = 0 + voff;
145       // top
146       buff.fSegs[12 + eoff] = c;  buff.fSegs[13 + eoff] = 4 + voff;  buff.fSegs[14 + eoff] = 5 + voff;
147       buff.fSegs[15 + eoff] = c;  buff.fSegs[16 + eoff] = 5 + voff;  buff.fSegs[17 + eoff] = 6 + voff;
148       buff.fSegs[18 + eoff] = c;  buff.fSegs[19 + eoff] = 6 + voff;  buff.fSegs[20 + eoff] = 7 + voff;
149       buff.fSegs[21 + eoff] = c;  buff.fSegs[22 + eoff] = 7 + voff;  buff.fSegs[23 + eoff] = 4 + voff;
150       //sides
151       buff.fSegs[24 + eoff] = c;  buff.fSegs[25 + eoff] = 0 + voff;  buff.fSegs[26 + eoff] = 4 + voff;
152       buff.fSegs[27 + eoff] = c;  buff.fSegs[28 + eoff] = 1 + voff;  buff.fSegs[29 + eoff] = 5 + voff;
153       buff.fSegs[30 + eoff] = c;  buff.fSegs[31 + eoff] = 2 + voff;  buff.fSegs[32 + eoff] = 6 + voff;
154       buff.fSegs[33 + eoff] = c;  buff.fSegs[34 + eoff] = 3 + voff;  buff.fSegs[35 + eoff] = 7 + voff;
155
156       buff.fPols[ 0 + eoff] = c;         buff.fPols[ 1 + eoff] = nspp;
157       buff.fPols[ 2 + eoff] = 0 + soff;  buff.fPols[ 3 + eoff] = 9  + soff;
158       buff.fPols[ 4 + eoff] = 4 + soff;  buff.fPols[ 5 + eoff] = 8  + soff;
159       buff.fPols[ 6 + eoff] = c;         buff.fPols[ 7 + eoff] = nspp;
160       buff.fPols[ 8 + eoff] = 1 + soff;  buff.fPols[ 9 + eoff] = 10 + soff;
161       buff.fPols[10 + eoff] = 5 + soff;  buff.fPols[11 + eoff] = 9  + soff;
162       buff.fPols[12 + eoff] = c;         buff.fPols[13 + eoff] = nspp;
163       buff.fPols[14 + eoff] = 2 + soff;  buff.fPols[15 + eoff] = 11 + soff;
164       buff.fPols[16 + eoff] = 6 + soff;  buff.fPols[17 + eoff] = 10 + soff;
165       buff.fPols[18 + eoff] = c;         buff.fPols[19 + eoff] = nspp;
166       buff.fPols[20 + eoff] = 3 + soff;  buff.fPols[21 + eoff] = 8  + soff;
167       buff.fPols[22 + eoff] = 7 + soff;  buff.fPols[23 + eoff] = 11 + soff;
168       buff.fPols[24 + eoff] = c;         buff.fPols[25 + eoff] = nspp;
169       buff.fPols[26 + eoff] = 0 + soff;  buff.fPols[27 + eoff] = 3  + soff;
170       buff.fPols[28 + eoff] = 2 + soff;  buff.fPols[29 + eoff] = 1  + soff;
171       buff.fPols[30 + eoff] = c;         buff.fPols[31 + eoff] = nspp;
172       buff.fPols[32 + eoff] = 4 + soff;  buff.fPols[33 + eoff] = 5  + soff;
173       buff.fPols[34 + eoff] = 6 + soff;  buff.fPols[35 + eoff] = 7  + soff;
174     }
175     buff.fColor = 2; // colors on polygons are ignored
176     buff.SetSectionsValid(TBuffer3D::kRaw);
177   }
178   gPad->GetViewer3D()->AddObject(buff);
179 }
180
181 /**************************************************************************/
182
183 void BoxSet::Test(Int_t nboxes)
184 {
185   TRandom rnd(0);
186   fBoxes.resize(nboxes);
187   for(Int_t i=0; i<nboxes; ++i) {
188     new (&fBoxes[i]) Box(rnd, 10, 2);
189   }
190 }