6 #include <TBuffer3DTypes.h>
7 #include <TVirtualPad.h>
8 #include <TVirtualViewer3D.h>
13 //______________________________________________________________________________
16 // A collection of 3D-boxes. The way how the boxes are defined depends
17 // on the fBoxType data-member.
18 // BT_FreeBox arbitrary box: specify 8*(x,y,z) box corners
19 // BT_AABox axis-aligned box: specify (x,y,z) and (w, h, d)
20 // BT_AABoxFixedDim axis-aligned box w/ fixed dimensions: specify (x,y,z)
21 // also set fDefWidth, fDefHeight and fDefDepth
23 // Each box can be assigned:
24 // a) Color or signal value. Thresholds and signal-to-color mapping
25 // can then be set dynamically via the RGBAPalette class.
26 // b) External TObject* (stored as TRef).
28 // See also base-class DigitSet for more information.
32 //______________________________________________________________________________
33 BoxSet::BoxSet(const Text_t* n, const Text_t* t) :
43 // Override from DigitSet.
44 fDisableLigting = kFALSE;
47 /******************************************************************************/
49 //______________________________________________________________________________
50 Int_t BoxSet::SizeofAtom(BoxSet::BoxType_e bt)
52 // Return size of data-structure describing a box of type bt.
54 static const Exc_t eH("BoxSet::SizeofAtom ");
57 case BT_Undef: return 0;
58 case BT_FreeBox: return sizeof(BFreeBox);
59 case BT_AABox: return sizeof(BAABox);
60 case BT_AABoxFixedDim: return sizeof(BAABoxFixedDim);
61 default: throw(eH + "unexpected atom type.");
66 /**************************************************************************/
68 //______________________________________________________________________________
69 void BoxSet::Reset(BoxSet::BoxType_e boxType, Bool_t valIsCol, Int_t chunkSize)
71 // Reset the data containers to zero size.
72 // The arguments describe the basic parameters of data storage.
75 fValueIsColor = valIsCol;
76 fDefaultValue = valIsCol ? 0 : kMinInt;
79 fPlex.Reset(SizeofAtom(fBoxType), chunkSize);
82 //______________________________________________________________________________
85 // Reset the data containers to zero size.
86 // Keep the old data-storage parameters.
90 fPlex.Reset(SizeofAtom(fBoxType), TMath::Max(fPlex.N(), 64));
93 /**************************************************************************/
95 //______________________________________________________________________________
96 void BoxSet::AddBox(const Float_t* verts)
98 // Create a new box from a set of 8 vertices.
99 // To be used for box-type BT_FreeBox.
101 static const Exc_t eH("BoxSet::AddBox ");
103 if (fBoxType != BT_FreeBox)
104 throw(eH + "expect free box-type.");
106 BFreeBox* b = (BFreeBox*) NewDigit();
107 memcpy(b->fVertices, verts, sizeof(b->fVertices));
110 //______________________________________________________________________________
111 void BoxSet::AddBox(Float_t a, Float_t b, Float_t c, Float_t w, Float_t h, Float_t d)
113 // Create a new axis-aligned box from at a given position and with
114 // specified dimensions.
115 // To be used for box-type BT_AABox.
117 static const Exc_t eH("BoxSet::AddBox ");
119 if (fBoxType != BT_AABox)
120 throw(eH + "expect axis-aligned box-type.");
122 BAABox* box = (BAABox*) NewDigit();
123 box->fA = a; box->fB = b; box->fC = c;
124 box->fW = w; box->fH = h; box->fD = d;
127 //______________________________________________________________________________
128 void BoxSet::AddBox(Float_t a, Float_t b, Float_t c)
130 // Create a new axis-aligned box from at a given position.
131 // To be used for box-type BT_AABoxFixedDim.
133 static const Exc_t eH("BoxSet::AddBox ");
135 if (fBoxType != BT_AABoxFixedDim)
136 throw(eH + "expect axis-aligned fixed-dimension box-type.");
138 BAABoxFixedDim* box = (BAABoxFixedDim*) NewDigit();
139 box->fA = a; box->fB = b; box->fC = c;
142 /**************************************************************************/
144 //______________________________________________________________________________
145 void BoxSet::ComputeBBox()
147 // Fill bounding-box information of the base-class TAttBBox (virtual method).
148 // If member 'FrameBox* fFrame' is set, frame's corners are used as bbox.
150 static const Exc_t eH("BoxSet::ComputeBBox ");
155 Int_t n = fFrame->GetFrameSize() / 3;
156 Float_t *bbps = fFrame->GetFramePoints();
157 for (int i=0; i<n; ++i, bbps+=3)
158 BBoxCheckPoint(bbps);
162 if(fPlex.Size() == 0)
170 VoidCPlex::iterator bi(fPlex);
177 BFreeBox& b = * (BFreeBox*) bi();
178 Float_t * p = b.fVertices;
179 for(int i=0; i<8; ++i, p+=3)
188 BAABox& b = * (BAABox*) bi();
189 BBoxCheckPoint(b.fA, b.fB, b.fC);
190 BBoxCheckPoint(b.fA + b.fW, b.fB + b.fH , b.fC + b.fD);
195 case BT_AABoxFixedDim:
198 BAABoxFixedDim& b = * (BAABoxFixedDim*) bi();
199 BBoxCheckPoint(b.fA, b.fB, b.fC);
200 BBoxCheckPoint(b.fA + fDefWidth, b.fB + fDefHeight , b.fC + fDefDepth);
207 throw(eH + "unsupported box-type.");
210 } // end switch box-type
212 printf("%s BBox is x(%f,%f), y(%f,%f), z(%f,%f)\n", GetName(),
213 fBBox[0], fBBox[1], fBBox[2], fBBox[3], fBBox[4], fBBox[5]);
216 /**************************************************************************/
218 //______________________________________________________________________________
219 void BoxSet::Test(Int_t nboxes)
221 // Fill the structure with a random set of boxes.
223 Reset(BT_AABox, kTRUE, nboxes);
225 const Float_t origin = 10, size = 2;
227 for(Int_t i=0; i<nboxes; ++i)
229 AddBox(origin * rnd.Uniform(-1, 1),
230 origin * rnd.Uniform(-1, 1),
231 origin * rnd.Uniform(-1, 1),
232 size * rnd.Uniform(0.1, 1),
233 size * rnd.Uniform(0.1, 1),
234 size * rnd.Uniform(0.1, 1));
236 Reve::ColorFromIdx(rnd.Integer(256), (UChar_t*)&color);