6 #include <TBuffer3DTypes.h>
8 #include <TVirtualPad.h>
9 #include <TVirtualViewer3D.h>
13 /**************************************************************************/
15 /**************************************************************************/
17 Box::Box(TRandom& rnd, Float_t origin, Float_t size)
19 Reve::ColorFromIdx(Int_t(30*rnd.Rndm()), color);
20 Float_t x0 = 2*origin*(rnd.Rndm() - 0.5);
21 Float_t y0 = 2*origin*(rnd.Rndm() - 0.5);
22 Float_t z0 = 2*origin*(rnd.Rndm() - 0.5);
23 Float_t xo = 2*size*(rnd.Rndm() - 0.5);
24 Float_t yo = 2*size*(rnd.Rndm() - 0.5);
25 Float_t zo = 2*size*(rnd.Rndm() - 0.5);
26 Float_t* p = vertices;
29 p[0] = x0 - xo; p[1] = y0 + yo, p[2] = z0 - zo; p += 3;
30 p[0] = x0 + xo; p[1] = y0 + yo, p[2] = z0 - zo; p += 3;
31 p[0] = x0 + xo; p[1] = y0 - yo, p[2] = z0 - zo; p += 3;
32 p[0] = x0 - xo; p[1] = y0 - yo, p[2] = z0 - zo; p += 3;
34 p[0] = x0 - xo; p[1] = y0 + yo, p[2] = z0 + zo; p += 3;
35 p[0] = x0 + xo; p[1] = y0 + yo, p[2] = z0 + zo; p += 3;
36 p[0] = x0 + xo; p[1] = y0 - yo, p[2] = z0 + zo; p += 3;
37 p[0] = x0 - xo; p[1] = y0 - yo, p[2] = z0 + zo;
41 //______________________________________________________________________
53 /**************************************************************************/
55 void BoxSet::ComputeBBox()
62 for(std::vector<Box>::iterator q=fBoxes.begin(); q!=fBoxes.end(); ++q) {
63 Float_t* p = q->vertices;
64 for(int i=0; i<8; ++i, p+=3)
67 printf("%s BBox is x(%f,%f), y(%f,%f), z(%f,%f)\n", GetName(),
68 fBBox[0], fBBox[1], fBBox[2], fBBox[3], fBBox[4], fBBox[5]);
71 void BoxSet::Paint(Option_t* /*option*/)
73 TBuffer3D buff(TBuffer3DTypes::kGeneric);
78 buff.fTransparency = 0;
79 buff.fLocalFrame = fTrans;
81 memcpy(buff.fLocalMaster, fMatrix, 16*sizeof(Double_t));
82 buff.SetSectionsValid(TBuffer3D::kCore);
84 Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
85 if (reqSections == TBuffer3D::kNone) {
86 // printf("BoxSet::Paint viewer was happy with Core buff3d.\n");
90 if (reqSections & TBuffer3D::kRawSizes) {
91 Int_t nbPnts = fBoxes.size()*8;
92 Int_t nbSegs = fBoxes.size()*12;
93 Int_t nbPoly = fBoxes.size()*6;
94 if (!buff.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPoly, nbPoly*6)) {
97 buff.SetSectionsValid(TBuffer3D::kRawSizes);
100 if ((reqSections & TBuffer3D::kRaw) && buff.SectionsValid(TBuffer3D::kRawSizes)) {
103 for (std::vector<Box>::iterator i=fBoxes.begin(); i!=fBoxes.end(); ++i) {
104 for (Int_t k=0; k<24; ++k) {
105 buff.fPnts[pidx] = (*i).vertices[k];
109 Int_t c = 2; // color; !!! wrong
110 Int_t eoff; // polygon or segment offset in fPols and fSegs array
111 Int_t voff; // vertex offset
112 Int_t soff; // offset in counting segments
113 Int_t nspp = 4; // number of segments per polygon
115 // Segments & Polygons
116 for (Int_t q = 0; q < (Int_t)fBoxes.size(); ++q) {
121 buff.fSegs[ 0 + eoff] = c; buff.fSegs[ 1 + eoff] = 0 + voff; buff.fSegs[ 2 + eoff] = 1 + voff;
122 buff.fSegs[ 3 + eoff] = c; buff.fSegs[ 4 + eoff] = 1 + voff; buff.fSegs[ 5 + eoff] = 2 + voff;
123 buff.fSegs[ 6 + eoff] = c; buff.fSegs[ 7 + eoff] = 2 + voff; buff.fSegs[ 8 + eoff] = 3 + voff;
124 buff.fSegs[ 9 + eoff] = c; buff.fSegs[10 + eoff] = 3 + voff; buff.fSegs[11 + eoff] = 0 + voff;
126 buff.fSegs[12 + eoff] = c; buff.fSegs[13 + eoff] = 4 + voff; buff.fSegs[14 + eoff] = 5 + voff;
127 buff.fSegs[15 + eoff] = c; buff.fSegs[16 + eoff] = 5 + voff; buff.fSegs[17 + eoff] = 6 + voff;
128 buff.fSegs[18 + eoff] = c; buff.fSegs[19 + eoff] = 6 + voff; buff.fSegs[20 + eoff] = 7 + voff;
129 buff.fSegs[21 + eoff] = c; buff.fSegs[22 + eoff] = 7 + voff; buff.fSegs[23 + eoff] = 4 + voff;
131 buff.fSegs[24 + eoff] = c; buff.fSegs[25 + eoff] = 0 + voff; buff.fSegs[26 + eoff] = 4 + voff;
132 buff.fSegs[27 + eoff] = c; buff.fSegs[28 + eoff] = 1 + voff; buff.fSegs[29 + eoff] = 5 + voff;
133 buff.fSegs[30 + eoff] = c; buff.fSegs[31 + eoff] = 2 + voff; buff.fSegs[32 + eoff] = 6 + voff;
134 buff.fSegs[33 + eoff] = c; buff.fSegs[34 + eoff] = 3 + voff; buff.fSegs[35 + eoff] = 7 + voff;
136 buff.fPols[ 0 + eoff] = c; buff.fPols[ 1 + eoff] = nspp;
137 buff.fPols[ 2 + eoff] = 0 + soff; buff.fPols[ 3 + eoff] = 9 + soff;
138 buff.fPols[ 4 + eoff] = 4 + soff; buff.fPols[ 5 + eoff] = 8 + soff;
139 buff.fPols[ 6 + eoff] = c; buff.fPols[ 7 + eoff] = nspp;
140 buff.fPols[ 8 + eoff] = 1 + soff; buff.fPols[ 9 + eoff] = 10 + soff;
141 buff.fPols[10 + eoff] = 5 + soff; buff.fPols[11 + eoff] = 9 + soff;
142 buff.fPols[12 + eoff] = c; buff.fPols[13 + eoff] = nspp;
143 buff.fPols[14 + eoff] = 2 + soff; buff.fPols[15 + eoff] = 11 + soff;
144 buff.fPols[16 + eoff] = 6 + soff; buff.fPols[17 + eoff] = 10 + soff;
145 buff.fPols[18 + eoff] = c; buff.fPols[19 + eoff] = nspp;
146 buff.fPols[20 + eoff] = 3 + soff; buff.fPols[21 + eoff] = 8 + soff;
147 buff.fPols[22 + eoff] = 7 + soff; buff.fPols[23 + eoff] = 11 + soff;
148 buff.fPols[24 + eoff] = c; buff.fPols[25 + eoff] = nspp;
149 buff.fPols[26 + eoff] = 0 + soff; buff.fPols[27 + eoff] = 3 + soff;
150 buff.fPols[28 + eoff] = 2 + soff; buff.fPols[29 + eoff] = 1 + soff;
151 buff.fPols[30 + eoff] = c; buff.fPols[31 + eoff] = nspp;
152 buff.fPols[32 + eoff] = 4 + soff; buff.fPols[33 + eoff] = 5 + soff;
153 buff.fPols[34 + eoff] = 6 + soff; buff.fPols[35 + eoff] = 7 + soff;
155 buff.fColor = 2; // colors on polygons are ignored
156 buff.SetSectionsValid(TBuffer3D::kRaw);
158 gPad->GetViewer3D()->AddObject(buff);
161 /**************************************************************************/
163 void BoxSet::Test(Int_t nboxes)
166 fBoxes.resize(nboxes);
167 for(Int_t i=0; i<nboxes; ++i) {
168 new (&fBoxes[i]) Box(rnd, 10, 2);