]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/BoxSet.cxx
Dummy methods DefineParticle required by the interface added.
[u/mrichter/AliRoot.git] / EVE / Reve / BoxSet.cxx
1 // $Header$
2
3 #include "BoxSet.h"
4 #include <TRandom.h>
5 #include <TBuffer3D.h>
6 #include <TBuffer3DTypes.h>
7 #include <TVirtualPad.h>
8 #include <TVirtualViewer3D.h>
9
10 using namespace Reve;
11
12
13 //______________________________________________________________________________
14 // BoxSet
15 //
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
22 //
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).
27 //
28 // See also base-class DigitSet for more information.
29
30 ClassImp(BoxSet)
31
32 //______________________________________________________________________________
33 BoxSet::BoxSet(const Text_t* n, const Text_t* t) :
34   DigitSet      (n, t),
35
36   fBoxType      (BT_Undef),
37   fDefWidth     (1),
38   fDefHeight    (1),
39   fDefDepth     (1)
40 {
41   // Constructor.
42
43   // Override from DigitSet.
44   fDisableLigting = kFALSE;
45 }
46
47 /******************************************************************************/
48
49 //______________________________________________________________________________
50 Int_t BoxSet::SizeofAtom(BoxSet::BoxType_e bt)
51 {
52   // Return size of data-structure describing a box of type bt.
53
54   static const Exc_t eH("BoxSet::SizeofAtom ");
55
56   switch (bt) {
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.");
62   }
63   return 0;
64 }
65
66 /**************************************************************************/
67
68 //______________________________________________________________________________
69 void BoxSet::Reset(BoxSet::BoxType_e boxType, Bool_t valIsCol, Int_t chunkSize)
70 {
71   // Reset the data containers to zero size.
72   // The arguments describe the basic parameters of data storage.
73
74   fBoxType      = boxType;
75   fValueIsColor = valIsCol;
76   fDefaultValue = valIsCol ? 0 : kMinInt;
77   if (fOwnIds)
78     ReleaseIds();
79   fPlex.Reset(SizeofAtom(fBoxType), chunkSize);
80 }
81
82 //______________________________________________________________________________
83 void BoxSet::Reset()
84 {
85   // Reset the data containers to zero size.
86   // Keep the old data-storage parameters.
87
88   if (fOwnIds)
89     ReleaseIds();
90   fPlex.Reset(SizeofAtom(fBoxType), TMath::Max(fPlex.N(), 64));
91 }
92
93 /**************************************************************************/
94
95 //______________________________________________________________________________
96 void BoxSet::AddBox(const Float_t* verts)
97 {
98   // Create a new box from a set of 8 vertices.
99   // To be used for box-type BT_FreeBox.
100
101   static const Exc_t eH("BoxSet::AddBox ");
102
103   if (fBoxType != BT_FreeBox)
104     throw(eH + "expect free box-type.");
105
106   BFreeBox* b = (BFreeBox*) NewDigit();
107   memcpy(b->fVertices, verts, sizeof(b->fVertices));
108 }
109
110 //______________________________________________________________________________
111 void BoxSet::AddBox(Float_t a, Float_t b, Float_t c, Float_t w, Float_t h, Float_t d)
112 {
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.
116
117   static const Exc_t eH("BoxSet::AddBox ");
118
119   if (fBoxType != BT_AABox)
120     throw(eH + "expect axis-aligned box-type.");
121
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;
125 }
126
127 //______________________________________________________________________________
128 void BoxSet::AddBox(Float_t a, Float_t b, Float_t c)
129 {
130   // Create a new axis-aligned box from at a given position.
131   // To be used for box-type BT_AABoxFixedDim.
132
133   static const Exc_t eH("BoxSet::AddBox ");
134
135   if (fBoxType != BT_AABoxFixedDim)
136     throw(eH + "expect axis-aligned fixed-dimension box-type.");
137
138   BAABoxFixedDim* box = (BAABoxFixedDim*) NewDigit();
139   box->fA = a; box->fB = b; box->fC = c;
140 }
141
142 /**************************************************************************/
143
144 //______________________________________________________________________________
145 void BoxSet::ComputeBBox()
146 {
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.
149
150   static const Exc_t eH("BoxSet::ComputeBBox ");
151
152   if (fFrame != 0)
153   {
154     BBoxInit();
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);
159     return;
160   }
161
162   if(fPlex.Size() == 0)
163   {
164     BBoxZero();
165     return;
166   }
167
168   BBoxInit();
169
170   VoidCPlex::iterator bi(fPlex);
171   switch (fBoxType)
172   {
173
174     case BT_FreeBox:
175     {
176       while (bi.next()) {
177         BFreeBox& b = * (BFreeBox*) bi();
178         Float_t * p = b.fVertices;
179         for(int i=0; i<8; ++i, p+=3)
180           BBoxCheckPoint(p);
181       }
182       break;
183     }
184
185     case BT_AABox:
186     {
187       while (bi.next()) {
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);
191       }
192       break;
193     }
194
195     case BT_AABoxFixedDim:
196     {
197       while (bi.next()) {
198         BAABoxFixedDim& b = * (BAABoxFixedDim*) bi();
199         BBoxCheckPoint(b.fA, b.fB, b.fC);
200         BBoxCheckPoint(b.fA + fDefWidth, b.fB + fDefHeight , b.fC + fDefDepth);
201       }
202       break;
203     }
204
205     default:
206     {
207       throw(eH + "unsupported box-type.");
208     }
209
210   } // end switch box-type
211
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]);
214 }
215
216 /**************************************************************************/
217
218 //______________________________________________________________________________
219 void BoxSet::Test(Int_t nboxes)
220 {
221   // Fill the structure with a random set of boxes.
222
223   Reset(BT_AABox, kTRUE, nboxes);
224   TRandom rnd(0);
225   const Float_t origin = 10, size = 2;
226   Int_t color;
227   for(Int_t i=0; i<nboxes; ++i)
228   {
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));
235
236     Reve::ColorFromIdx(rnd.Integer(256), (UChar_t*)&color);
237     DigitValue(color);
238   }
239 }