Logo ROOT   6.16/01
Reference Guide
TEveBoxSet.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TEveBoxSet.h"
13#include "TEveShape.h"
14
15#include "TRandom.h"
16
17/** \class TEveBoxSet
18\ingroup TEve
19Collection of 3D primitives (fixed-size boxes, boxes of different
20sizes, or arbitrary sexto-epipeds, cones). Each primitive can be assigned
21a signal value and a TRef.
22
23A collection of 3D-markers. The way how they are defined depends
24on the fBoxType data-member.
25 - kBT_FreeBox arbitrary box: specify 8*(x,y,z) box corners
26 - kBT_AABox axis-aligned box: specify (x,y,z) and (w, h, d)
27 - kBT_AABoxFixedDim axis-aligned box w/ fixed dimensions: specify (x,y,z)
28 also set fDefWidth, fDefHeight and fDefDepth
29 - kBT_Cone cone defined with position, axis-vector and radius
30 - EllipticCone cone with elliptic base (specify another radius and angle in deg)
31
32Each primitive can be assigned:
33
34 1. Color or signal value. Thresholds and signal-to-color mapping
35 can then be set dynamically via the TEveRGBAPalette class.
36 2. External TObject* (stored as TRef).
37
38See also base-class TEveDigitSet for more information.
39Tutorial: tutorials/eve/boxset_test.C
40*/
41
43
44////////////////////////////////////////////////////////////////////////////////
45
46TEveBoxSet::TEveBoxSet(const char* n, const char* t) :
47 TEveDigitSet (n, t),
48
49 fBoxType (kBT_Undef),
50 fDefWidth (1),
51 fDefHeight (1),
52 fDefDepth (1),
53
54 fBoxSkip (0),
55
56 fDrawConeCap (kFALSE)
57{
58 // Constructor.
59
60 // Override from TEveDigitSet.
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Return size of data-structure describing a box of type bt.
66
68{
69 static const TEveException eH("TEveBoxSet::SizeofAtom ");
70
71 switch (bt) {
72 case kBT_Undef: return 0;
73 case kBT_FreeBox: return sizeof(BFreeBox_t);
74 case kBT_AABox: return sizeof(BAABox_t);
75 case kBT_AABoxFixedDim: return sizeof(BAABoxFixedDim_t);
76 case kBT_Cone: return sizeof(BCone_t);
77 case kBT_EllipticCone: return sizeof(BEllipticCone_t);
78 default: throw(eH + "unexpected atom type.");
79 }
80 return 0;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Reset the data containers to zero size.
85/// The arguments describe the basic parameters of data storage.
86
87void TEveBoxSet::Reset(TEveBoxSet::EBoxType_e boxType, Bool_t valIsCol, Int_t chunkSize)
88{
89 fBoxType = boxType;
90 fValueIsColor = valIsCol;
91 fDefaultValue = valIsCol ? 0 : kMinInt;
92 if (fOwnIds)
93 ReleaseIds();
94 fPlex.Reset(SizeofAtom(fBoxType), chunkSize);
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Reset the data containers to zero size.
99/// Keep the old data-storage parameters.
100
102{
103 if (fOwnIds)
104 ReleaseIds();
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Create a new box from a set of 8 vertices.
110/// To be used for box-type kBT_FreeBox.
111
112void TEveBoxSet::AddBox(const Float_t* verts)
113{
114 static const TEveException eH("TEveBoxSet::AddBox ");
115
116 if (fBoxType != kBT_FreeBox)
117 throw(eH + "expect free box-type.");
118
120 memcpy(b->fVertices, verts, sizeof(b->fVertices));
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Create a new axis-aligned box from at a given position and with
126/// specified dimensions.
127/// To be used for box-type kBT_AABox.
128
130{
131 static const TEveException eH("TEveBoxSet::AddBox ");
132
133 if (fBoxType != kBT_AABox)
134 throw(eH + "expect axis-aligned box-type.");
135
137 box->fA = a; box->fB = b; box->fC = c;
138 box->fW = w; box->fH = h; box->fD = d;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Create a new axis-aligned box from at a given position.
143/// To be used for box-type kBT_AABoxFixedDim.
144
146{
147 static const TEveException eH("TEveBoxSet::AddBox ");
148
150 throw(eH + "expect axis-aligned fixed-dimension box-type.");
151
153 box->fA = a; box->fB = b; box->fC = c;
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// Create a cone with apex at pos, axis dir and radius r.
158/// To be used for box-type kBT_Cone.
159
160void TEveBoxSet::AddCone(const TEveVector& pos, const TEveVector& dir, Float_t r)
161{
162 static const TEveException eH("TEveBoxSet::AddCone ");
163
164 if (fBoxType != kBT_Cone)
165 throw(eH + "expect cone box-type.");
166
167 BCone_t* cone = (BCone_t*) NewDigit();
168 cone->fPos = pos;
169 cone->fDir = dir;
170 cone->fR = r;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Create a cone with apex at pos, axis dir and radius r.
175/// To be used for box-type kBT_EllipticCone.
176
178 Float_t r, Float_t r2, Float_t angle)
179{
180 static const TEveException eH("TEveBoxSet::AddEllipticCone ");
181
183 throw(eH + "expect elliptic-cone box-type.");
184
186 cone->fPos = pos;
187 cone->fDir = dir;
188 cone->fR = r;
189 cone->fR2 = r2;
190 cone->fAngle = angle;
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Fill bounding-box information of the base-class TAttBBox (virtual method).
195/// If member 'TEveFrameBox* fFrame' is set, frame's corners are used as bbox.
196
198{
199 static const TEveException eH("TEveBoxSet::ComputeBBox ");
200
201 if (fFrame != 0)
202 {
203 BBoxInit();
204 Int_t n = fFrame->GetFrameSize() / 3;
205 Float_t *bbps = fFrame->GetFramePoints();
206 for (int i=0; i<n; ++i, bbps+=3)
207 BBoxCheckPoint(bbps);
208 return;
209 }
210
211 if(fPlex.Size() == 0)
212 {
213 BBoxZero();
214 return;
215 }
216
217 BBoxInit();
218
220 switch (fBoxType)
221 {
222
223 case kBT_FreeBox:
224 {
225 while (bi.next()) {
226 BFreeBox_t& b = * (BFreeBox_t*) bi();
227 for (Int_t i = 0; i < 8; ++i)
228 BBoxCheckPoint(b.fVertices[i]);
229 }
230 break;
231 }
232
233 case kBT_AABox:
234 {
235 while (bi.next()) {
236 BAABox_t& b = * (BAABox_t*) bi();
237 BBoxCheckPoint(b.fA, b.fB, b.fC);
238 BBoxCheckPoint(b.fA + b.fW, b.fB + b.fH , b.fC + b.fD);
239 }
240 break;
241 }
242
244 {
245 while (bi.next()) {
247 BBoxCheckPoint(b.fA, b.fB, b.fC);
248 BBoxCheckPoint(b.fA + fDefWidth, b.fB + fDefHeight , b.fC + fDefDepth);
249 }
250 break;
251 }
252 case kBT_Cone:
253 {
254 Float_t mag2=0, mag2Max=0, rMax=0;
255 while (bi.next()) {
256 BCone_t& b = * (BCone_t*) bi();
257 BBoxCheckPoint(b.fPos.fX, b.fPos.fY, b.fPos.fZ);
258 mag2 = b.fDir.Mag2();
259 if (mag2>mag2Max) mag2Max=mag2;
260 if (b.fR>rMax) rMax=b.fR;
261 }
262 Float_t off = TMath::Sqrt(mag2Max + rMax*rMax);
263 fBBox[0] -= off;fBBox[2] -= off;fBBox[4] -= off;
264 fBBox[1] += off;fBBox[3] += off;fBBox[5] += off;
265 break;
266 }
267 case kBT_EllipticCone:
268 {
269 Float_t mag2=0, mag2Max=0, rMax=0;
270 while (bi.next()) {
271 BEllipticCone_t& b = * (BEllipticCone_t*) bi();
272 BBoxCheckPoint(b.fPos.fX, b.fPos.fY, b.fPos.fZ);
273 mag2 = b.fDir.Mag2();
274 if (mag2>mag2Max) mag2Max=mag2;
275 if (b.fR > rMax) rMax = b.fR;
276 if (b.fR2 > rMax) rMax = b.fR2;
277 }
278 Float_t off = TMath::Sqrt(mag2Max + rMax*rMax);
279 fBBox[0] -= off;fBBox[2] -= off;fBBox[4] -= off;
280 fBBox[1] += off;fBBox[3] += off;fBBox[5] += off;
281 break;
282 }
283 default:
284 {
285 throw(eH + "unsupported box-type.");
286 }
287
288 } // end switch box-type
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Fill the structure with a random set of boxes.
293
295{
296 Reset(kBT_AABox, kTRUE, nboxes);
297 TRandom rnd(0);
298 const Float_t origin = 10, size = 2;
299 Int_t color;
300 for(Int_t i=0; i<nboxes; ++i)
301 {
302 AddBox(origin * rnd.Uniform(-1, 1),
303 origin * rnd.Uniform(-1, 1),
304 origin * rnd.Uniform(-1, 1),
305 size * rnd.Uniform(0.1, 1),
306 size * rnd.Uniform(0.1, 1),
307 size * rnd.Uniform(0.1, 1));
308
309 TEveUtil::ColorFromIdx(rnd.Integer(256), (UChar_t*)&color);
310 DigitValue(color);
311 }
312}
ROOT::R::TRInterface & r
Definition: Object.C:4
#define d(i)
Definition: RSha256.hxx:102
#define b(i)
Definition: RSha256.hxx:100
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
const Int_t kMinInt
Definition: RtypesCore.h:100
int Int_t
Definition: RtypesCore.h:41
unsigned char UChar_t
Definition: RtypesCore.h:34
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition: TAttBBox.h:58
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
Definition: TAttBBox.cxx:42
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition: TAttBBox.cxx:29
Float_t * fBBox
Definition: TAttBBox.h:20
Collection of 3D primitives (fixed-size boxes, boxes of different sizes, or arbitrary sexto-epipeds,...
Definition: TEveBoxSet.h:22
virtual void ComputeBBox()
Fill bounding-box information of the base-class TAttBBox (virtual method).
Definition: TEveBoxSet.cxx:197
Float_t fDefWidth
Definition: TEveBoxSet.h:53
Float_t fDefDepth
Definition: TEveBoxSet.h:55
void AddBox(const Float_t *verts)
Create a new box from a set of 8 vertices.
Definition: TEveBoxSet.cxx:112
Float_t fDefHeight
Definition: TEveBoxSet.h:54
EBoxType_e fBoxType
Definition: TEveBoxSet.h:51
void Test(Int_t nboxes)
Fill the structure with a random set of boxes.
Definition: TEveBoxSet.cxx:294
TEveBoxSet(const TEveBoxSet &)
void AddEllipticCone(const TEveVector &pos, const TEveVector &dir, Float_t r, Float_t r2, Float_t angle=0)
Create a cone with apex at pos, axis dir and radius r.
Definition: TEveBoxSet.cxx:177
void AddCone(const TEveVector &pos, const TEveVector &dir, Float_t r)
Create a cone with apex at pos, axis dir and radius r.
Definition: TEveBoxSet.cxx:160
@ kBT_EllipticCone
Definition: TEveBoxSet.h:35
@ kBT_AABoxFixedDim
Definition: TEveBoxSet.h:33
static Int_t SizeofAtom(EBoxType_e bt)
Return size of data-structure describing a box of type bt.
Definition: TEveBoxSet.cxx:67
void Reset()
Reset the data containers to zero size.
Definition: TEveBoxSet.cxx:101
void Reset(Int_t atom_size, Int_t chunk_size)
Empty the container and reset it with given atom and chunk sizes.
Int_t Size() const
Int_t N() const
Base-class for storage of digit collections; provides transformation matrix (TEveTrans),...
Definition: TEveDigitSet.h:34
Int_t fDefaultValue
Definition: TEveDigitSet.h:60
Bool_t fDisableLighting
Definition: TEveDigitSet.h:75
Bool_t fOwnIds
Definition: TEveDigitSet.h:64
void DigitValue(Int_t value)
Set signal value for the last digit added.
void ReleaseIds()
Protected method.
TEveChunkManager fPlex
Definition: TEveDigitSet.h:65
DigitBase_t * NewDigit()
Function providing highlight tooltips when always-sec-select is active.
TEveFrameBox * fFrame
Definition: TEveDigitSet.h:70
Bool_t fValueIsColor
Definition: TEveDigitSet.h:61
Exception class thrown by TEve classes and macros.
Definition: TEveUtil.h:103
Int_t GetFrameSize() const
Definition: TEveFrameBox.h:60
Float_t * GetFramePoints() const
Definition: TEveFrameBox.h:61
static void CheckAndFixBoxOrientationFv(Float_t box[8][3])
Make sure box orientation is consistent with standard arrangement.
Definition: TEveShape.cxx:261
static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE)
Fill col with RGBA values corresponding to index ci.
Definition: TEveUtil.cxx:192
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:627
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
Definition: TRandom.cxx:341
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
const Int_t n
Definition: legend1.C:16
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Double_t Sqrt(Double_t x)
Definition: TMath.h:679
TEveVector fPos
Definition: TEveBoxSet.h:46
TEveVector fDir
Definition: TEveBoxSet.h:46
Bool_t next()
Go to next atom.
auto * a
Definition: textangle.C:12