]>
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 | ||
16 | Box::Box(TRandom& rnd, Float_t origin, Float_t size) | |
17 | { | |
18 | Reve::ColorFromIdx(Int_t(30*rnd.Rndm()), color); | |
19 | Float_t x0 = 2*origin*(rnd.Rndm() - 0.5); | |
20 | Float_t y0 = 2*origin*(rnd.Rndm() - 0.5); | |
21 | Float_t z0 = 2*origin*(rnd.Rndm() - 0.5); | |
22 | Float_t xo = 2*size*(rnd.Rndm() - 0.5); | |
23 | Float_t yo = 2*size*(rnd.Rndm() - 0.5); | |
24 | Float_t zo = 2*size*(rnd.Rndm() - 0.5); | |
25 | Float_t* p = vertices; | |
26 | ||
27 | //bottom | |
28 | p[0] = x0 - xo; p[1] = y0 + yo, p[2] = z0 - zo; p += 3; | |
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 | //top | |
33 | 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; | |
37 | } | |
38 | ||
39 | ||
40 | //______________________________________________________________________ | |
41 | // BoxSet | |
42 | // | |
43 | ||
2aef44c1 | 44 | ClassImp(BoxSet) |
915dabe1 | 45 | |
092578a7 | 46 | BoxSet::BoxSet(const Text_t* n, const Text_t* t) : |
47 | TNamed(n, t), | |
48 | fTrans(kFALSE) | |
49 | {} | |
915dabe1 | 50 | |
51 | /**************************************************************************/ | |
52 | ||
53 | void BoxSet::ComputeBBox() | |
54 | { | |
55 | if(fBoxes.empty()) { | |
56 | bbox_zero(); | |
57 | return; | |
58 | } | |
59 | bbox_init(); | |
60 | for(std::vector<Box>::iterator q=fBoxes.begin(); q!=fBoxes.end(); ++q) { | |
61 | Float_t* p = q->vertices; | |
62 | for(int i=0; i<8; ++i, p+=3) | |
63 | bbox_check_point(p); | |
64 | } | |
65 | printf("%s BBox is x(%f,%f), y(%f,%f), z(%f,%f)\n", GetName(), | |
66 | fBBox[0], fBBox[1], fBBox[2], fBBox[3], fBBox[4], fBBox[5]); | |
67 | } | |
68 | ||
69 | void BoxSet::Paint(Option_t* /*option*/) | |
70 | { | |
71 | TBuffer3D buff(TBuffer3DTypes::kGeneric); | |
72 | ||
73 | // Section kCore | |
74 | buff.fID = this; | |
75 | buff.fColor = 1; | |
76 | buff.fTransparency = 0; | |
77 | buff.fLocalFrame = fTrans; | |
78 | if (fTrans) | |
79 | memcpy(buff.fLocalMaster, fMatrix, 16*sizeof(Double_t)); | |
80 | buff.SetSectionsValid(TBuffer3D::kCore); | |
81 | ||
82 | Int_t reqSections = gPad->GetViewer3D()->AddObject(buff); | |
83 | if (reqSections == TBuffer3D::kNone) { | |
84 | // printf("BoxSet::Paint viewer was happy with Core buff3d.\n"); | |
85 | return; | |
86 | } | |
87 | ||
88 | if (reqSections & TBuffer3D::kRawSizes) { | |
89 | Int_t nbPnts = fBoxes.size()*8; | |
90 | Int_t nbSegs = fBoxes.size()*12; | |
91 | Int_t nbPoly = fBoxes.size()*6; | |
92 | if (!buff.SetRawSizes(nbPnts, 3*nbPnts, nbSegs, 3*nbSegs, nbPoly, nbPoly*6)) { | |
93 | return; | |
94 | } | |
95 | buff.SetSectionsValid(TBuffer3D::kRawSizes); | |
96 | } | |
97 | ||
98 | if ((reqSections & TBuffer3D::kRaw) && buff.SectionsValid(TBuffer3D::kRawSizes)) { | |
99 | // Points | |
100 | Int_t pidx = 0; | |
101 | for (std::vector<Box>::iterator i=fBoxes.begin(); i!=fBoxes.end(); ++i) { | |
102 | for (Int_t k=0; k<24; ++k) { | |
103 | buff.fPnts[pidx] = (*i).vertices[k]; | |
104 | pidx++; | |
105 | } | |
106 | } | |
107 | Int_t c = 2; // color; !!! wrong | |
108 | Int_t eoff; // polygon or segment offset in fPols and fSegs array | |
109 | Int_t voff; // vertex offset | |
110 | Int_t soff; // offset in counting segments | |
111 | Int_t nspp = 4; // number of segments per polygon | |
112 | ||
113 | // Segments & Polygons | |
114 | for (Int_t q = 0; q < (Int_t)fBoxes.size(); ++q) { | |
115 | eoff = q*36; | |
116 | soff = q*12; | |
117 | voff = q*8; | |
118 | //bottom | |
119 | buff.fSegs[ 0 + eoff] = c; buff.fSegs[ 1 + eoff] = 0 + voff; buff.fSegs[ 2 + eoff] = 1 + voff; | |
120 | buff.fSegs[ 3 + eoff] = c; buff.fSegs[ 4 + eoff] = 1 + voff; buff.fSegs[ 5 + eoff] = 2 + voff; | |
121 | buff.fSegs[ 6 + eoff] = c; buff.fSegs[ 7 + eoff] = 2 + voff; buff.fSegs[ 8 + eoff] = 3 + voff; | |
122 | buff.fSegs[ 9 + eoff] = c; buff.fSegs[10 + eoff] = 3 + voff; buff.fSegs[11 + eoff] = 0 + voff; | |
123 | // top | |
124 | buff.fSegs[12 + eoff] = c; buff.fSegs[13 + eoff] = 4 + voff; buff.fSegs[14 + eoff] = 5 + voff; | |
125 | buff.fSegs[15 + eoff] = c; buff.fSegs[16 + eoff] = 5 + voff; buff.fSegs[17 + eoff] = 6 + voff; | |
126 | buff.fSegs[18 + eoff] = c; buff.fSegs[19 + eoff] = 6 + voff; buff.fSegs[20 + eoff] = 7 + voff; | |
127 | buff.fSegs[21 + eoff] = c; buff.fSegs[22 + eoff] = 7 + voff; buff.fSegs[23 + eoff] = 4 + voff; | |
128 | //sides | |
129 | buff.fSegs[24 + eoff] = c; buff.fSegs[25 + eoff] = 0 + voff; buff.fSegs[26 + eoff] = 4 + voff; | |
130 | buff.fSegs[27 + eoff] = c; buff.fSegs[28 + eoff] = 1 + voff; buff.fSegs[29 + eoff] = 5 + voff; | |
131 | buff.fSegs[30 + eoff] = c; buff.fSegs[31 + eoff] = 2 + voff; buff.fSegs[32 + eoff] = 6 + voff; | |
132 | buff.fSegs[33 + eoff] = c; buff.fSegs[34 + eoff] = 3 + voff; buff.fSegs[35 + eoff] = 7 + voff; | |
133 | ||
134 | buff.fPols[ 0 + eoff] = c; buff.fPols[ 1 + eoff] = nspp; | |
135 | buff.fPols[ 2 + eoff] = 0 + soff; buff.fPols[ 3 + eoff] = 9 + soff; | |
136 | buff.fPols[ 4 + eoff] = 4 + soff; buff.fPols[ 5 + eoff] = 8 + soff; | |
137 | buff.fPols[ 6 + eoff] = c; buff.fPols[ 7 + eoff] = nspp; | |
138 | buff.fPols[ 8 + eoff] = 1 + soff; buff.fPols[ 9 + eoff] = 10 + soff; | |
139 | buff.fPols[10 + eoff] = 5 + soff; buff.fPols[11 + eoff] = 9 + soff; | |
140 | buff.fPols[12 + eoff] = c; buff.fPols[13 + eoff] = nspp; | |
141 | buff.fPols[14 + eoff] = 2 + soff; buff.fPols[15 + eoff] = 11 + soff; | |
142 | buff.fPols[16 + eoff] = 6 + soff; buff.fPols[17 + eoff] = 10 + soff; | |
143 | buff.fPols[18 + eoff] = c; buff.fPols[19 + eoff] = nspp; | |
144 | buff.fPols[20 + eoff] = 3 + soff; buff.fPols[21 + eoff] = 8 + soff; | |
145 | buff.fPols[22 + eoff] = 7 + soff; buff.fPols[23 + eoff] = 11 + soff; | |
146 | buff.fPols[24 + eoff] = c; buff.fPols[25 + eoff] = nspp; | |
147 | buff.fPols[26 + eoff] = 0 + soff; buff.fPols[27 + eoff] = 3 + soff; | |
148 | buff.fPols[28 + eoff] = 2 + soff; buff.fPols[29 + eoff] = 1 + soff; | |
149 | buff.fPols[30 + eoff] = c; buff.fPols[31 + eoff] = nspp; | |
150 | buff.fPols[32 + eoff] = 4 + soff; buff.fPols[33 + eoff] = 5 + soff; | |
151 | buff.fPols[34 + eoff] = 6 + soff; buff.fPols[35 + eoff] = 7 + soff; | |
152 | } | |
153 | buff.fColor = 2; // colors on polygons are ignored | |
154 | buff.SetSectionsValid(TBuffer3D::kRaw); | |
155 | } | |
156 | gPad->GetViewer3D()->AddObject(buff); | |
157 | } | |
158 | ||
159 | /**************************************************************************/ | |
160 | ||
161 | void BoxSet::Test(Int_t nboxes) | |
162 | { | |
163 | TRandom rnd(0); | |
164 | fBoxes.resize(nboxes); | |
165 | for(Int_t i=0; i<nboxes; ++i) { | |
166 | new (&fBoxes[i]) Box(rnd, 10, 2); | |
167 | } | |
168 | } |