6 #include <TBuffer3DTypes.h>
7 #include <TVirtualPad.h>
8 #include <TVirtualViewer3D.h>
12 /**************************************************************************/
14 /**************************************************************************/
18 Reve::ColorFromIdx(col, color);
21 Box::Box(Color_t col, Float_t* p)
23 Reve::ColorFromIdx(col, color);
24 memcpy(vertices, p, 24*sizeof(Float_t));
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)
30 Reve::ColorFromIdx(col, color);
31 MakeAxisAlignedBox(x, y, z, dx, dy, dz);
34 Box::Box(TRandom& rnd, Float_t origin, Float_t size)
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);
46 void Box::MakeAxisAlignedBox(Float_t x, Float_t y, Float_t z,
47 Float_t dx, Float_t dy, Float_t dz)
49 Float_t* p = vertices;
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;
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;
63 //______________________________________________________________________
69 BoxSet::BoxSet(const Text_t* n, const Text_t* t) :
70 RenderElement(fDefaultColor),
75 /**************************************************************************/
77 void BoxSet::ComputeBBox()
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)
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]);
93 void BoxSet::Paint(Option_t* /*option*/)
95 TBuffer3D buff(TBuffer3DTypes::kGeneric);
100 buff.fTransparency = 0;
101 fHMTrans.SetBuffer3D(buff);
102 buff.SetSectionsValid(TBuffer3D::kCore);
104 Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
105 if (reqSections == TBuffer3D::kNone) {
106 // printf("BoxSet::Paint viewer was happy with Core buff3d.\n");
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)) {
117 buff.SetSectionsValid(TBuffer3D::kRawSizes);
120 if ((reqSections & TBuffer3D::kRaw) && buff.SectionsValid(TBuffer3D::kRawSizes)) {
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];
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
135 // Segments & Polygons
136 for (Int_t q = 0; q < (Int_t)fBoxes.size(); ++q) {
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;
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;
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;
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;
175 buff.fColor = 2; // colors on polygons are ignored
176 buff.SetSectionsValid(TBuffer3D::kRaw);
178 gPad->GetViewer3D()->AddObject(buff);
181 /**************************************************************************/
183 void BoxSet::Test(Int_t nboxes)
186 fBoxes.resize(nboxes);
187 for(Int_t i=0; i<nboxes; ++i) {
188 new (&fBoxes[i]) Box(rnd, 10, 2);