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