Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/visualisation/eve7/eve/boxset_test.C
40*/
41
42
43////////////////////////////////////////////////////////////////////////////////
44
45TEveBoxSet::TEveBoxSet(const char* n, const char* t) :
46 TEveDigitSet (n, t),
47
48 fBoxType (kBT_Undef),
49 fDefWidth (1),
50 fDefHeight (1),
51 fDefDepth (1),
52
53 fBoxSkip (0),
54
55 fDrawConeCap (kFALSE)
56{
57 // Constructor.
58
59 // Override from TEveDigitSet.
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Return size of data-structure describing a box of type bt.
65
67{
68 static const TEveException eH("TEveBoxSet::SizeofAtom ");
69
70 switch (bt) {
71 case kBT_Undef: return 0;
72 case kBT_FreeBox: return sizeof(BFreeBox_t);
73 case kBT_AABox: return sizeof(BAABox_t);
74 case kBT_AABoxFixedDim: return sizeof(BAABoxFixedDim_t);
75 case kBT_Cone: return sizeof(BCone_t);
76 case kBT_EllipticCone: return sizeof(BEllipticCone_t);
77 case kBT_Hex: return sizeof(BHex_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
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
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
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
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/// Create a hexagonal prism with center of one hexagon at pos, radius of
195/// hexagon vertices r, rotation angle angle (in degrees), and length along z
196/// of depth. To be used for box-type kBT_Hex.
197
199{
200 static const TEveException eH("TEveBoxSet::AddEllipticCone ");
201
202 if (fBoxType != kBT_Hex)
203 throw(eH + "expect hex box-type.");
204
205 BHex_t* hex = (BHex_t*) NewDigit();
206 hex->fPos = pos;
207 hex->fR = r;
208 hex->fAngle = angle;
209 hex->fDepth = depth;
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Fill bounding-box information of the base-class TAttBBox (virtual method).
214/// If member 'TEveFrameBox* fFrame' is set, frame's corners are used as bbox.
215
217{
218 static const TEveException eH("TEveBoxSet::ComputeBBox ");
219
220 if (fFrame != nullptr)
221 {
222 BBoxInit();
223 Int_t n = fFrame->GetFrameSize() / 3;
225 for (int i=0; i<n; ++i, bbps+=3)
227 return;
228 }
229
230 if(fPlex.Size() == 0)
231 {
232 BBoxZero();
233 return;
234 }
235
236 BBoxInit();
237
239 switch (fBoxType)
240 {
241
242 case kBT_FreeBox:
243 {
244 while (bi.next()) {
245 BFreeBox_t& b = * (BFreeBox_t*) bi();
246 for (Int_t i = 0; i < 8; ++i)
247 BBoxCheckPoint(b.fVertices[i]);
248 }
249 break;
250 }
251
252 case kBT_AABox:
253 {
254 while (bi.next()) {
255 BAABox_t& b = * (BAABox_t*) bi();
256 BBoxCheckPoint(b.fA, b.fB, b.fC);
257 BBoxCheckPoint(b.fA + b.fW, b.fB + b.fH , b.fC + b.fD);
258 }
259 break;
260 }
261
263 {
264 while (bi.next()) {
266 BBoxCheckPoint(b.fA, b.fB, b.fC);
267 BBoxCheckPoint(b.fA + fDefWidth, b.fB + fDefHeight , b.fC + fDefDepth);
268 }
269 break;
270 }
271
272 case kBT_Cone:
273 {
274 Float_t mag2=0, mag2Max=0, rMax=0;
275 while (bi.next()) {
276 BCone_t& b = * (BCone_t*) bi();
277 BBoxCheckPoint(b.fPos.fX, b.fPos.fY, b.fPos.fZ);
278 mag2 = b.fDir.Mag2();
279 if (mag2>mag2Max) mag2Max=mag2;
280 if (b.fR>rMax) rMax=b.fR;
281 }
283 fBBox[0] -= off;fBBox[2] -= off;fBBox[4] -= off;
284 fBBox[1] += off;fBBox[3] += off;fBBox[5] += off;
285 break;
286 }
287
288 case kBT_EllipticCone:
289 {
290 Float_t mag2=0, mag2Max=0, rMax=0;
291 while (bi.next()) {
293 BBoxCheckPoint(b.fPos.fX, b.fPos.fY, b.fPos.fZ);
294 mag2 = b.fDir.Mag2();
295 if (mag2>mag2Max) mag2Max=mag2;
296 if (b.fR > rMax) rMax = b.fR;
297 if (b.fR2 > rMax) rMax = b.fR2;
298 }
300 fBBox[0] -= off;fBBox[2] -= off;fBBox[4] -= off;
301 fBBox[1] += off;fBBox[3] += off;fBBox[5] += off;
302 break;
303 }
304
305 case kBT_Hex:
306 {
307 while (bi.next()) {
308 BHex_t& h = * (BHex_t*) bi();
309 BBoxCheckPoint(h.fPos.fX - h.fR, h.fPos.fY - h.fR, h.fPos.fZ);
310 BBoxCheckPoint(h.fPos.fX + h.fR, h.fPos.fY - h.fR, h.fPos.fZ);
311 BBoxCheckPoint(h.fPos.fX + h.fR, h.fPos.fY + h.fR, h.fPos.fZ);
312 BBoxCheckPoint(h.fPos.fX - h.fR, h.fPos.fY + h.fR, h.fPos.fZ);
313 BBoxCheckPoint(h.fPos.fX - h.fR, h.fPos.fY - h.fR, h.fPos.fZ + h.fDepth);
314 BBoxCheckPoint(h.fPos.fX + h.fR, h.fPos.fY - h.fR, h.fPos.fZ + h.fDepth);
315 BBoxCheckPoint(h.fPos.fX + h.fR, h.fPos.fY + h.fR, h.fPos.fZ + h.fDepth);
316 BBoxCheckPoint(h.fPos.fX - h.fR, h.fPos.fY + h.fR, h.fPos.fZ + h.fDepth);
317 }
318 break;
319 }
320
321 default:
322 {
323 throw(eH + "unsupported box-type.");
324 }
325
326 } // end switch box-type
327}
328
329////////////////////////////////////////////////////////////////////////////////
330/// Fill the structure with a random set of boxes.
331
333{
335 TRandom rnd(0);
336 const Float_t origin = 10, size = 2;
337 Int_t color;
338 for(Int_t i=0; i<nboxes; ++i)
339 {
340 AddBox(origin * rnd.Uniform(-1, 1),
341 origin * rnd.Uniform(-1, 1),
342 origin * rnd.Uniform(-1, 1),
343 size * rnd.Uniform(0.1, 1),
344 size * rnd.Uniform(0.1, 1),
345 size * rnd.Uniform(0.1, 1));
346
347 TEveUtil::ColorFromIdx(rnd.Integer(256), (UChar_t*)&color);
348 DigitValue(color);
349 }
350}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
constexpr Int_t kMinInt
Definition RtypesCore.h:120
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint angle
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition TAttBBox.h:69
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:41
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:28
Float_t * fBBox
Definition TAttBBox.h:20
Float_t fDefWidth
Definition TEveBoxSet.h:56
Float_t fDefDepth
Definition TEveBoxSet.h:58
void AddBox(const Float_t *verts)
Create a new box from a set of 8 vertices.
void AddHex(const TEveVector &pos, Float_t r, Float_t angle, Float_t depth)
Create a hexagonal prism with center of one hexagon at pos, radius of hexagon vertices r,...
Float_t fDefHeight
Definition TEveBoxSet.h:57
EBoxType_e fBoxType
Definition TEveBoxSet.h:54
void Test(Int_t nboxes)
Fill the structure with a random set of boxes.
void ComputeBBox() override
Fill bounding-box information of the base-class TAttBBox (virtual method).
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.
void AddCone(const TEveVector &pos, const TEveVector &dir, Float_t r)
Create a cone with apex at pos, axis dir and radius r.
@ 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.
void Reset()
Reset the data containers to zero size.
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
Base-class for storage of digit collections; provides transformation matrix (TEveTrans),...
Int_t fDefaultValue
Bool_t fDisableLighting
void DigitValue(Int_t value)
Set signal value for the last digit added.
void ReleaseIds()
Protected method.
TEveChunkManager fPlex
DigitBase_t * NewDigit()
Function providing highlight tooltips when always-sec-select is active.
TEveFrameBox * fFrame
Bool_t fValueIsColor
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
Int_t GetFrameSize() const
Float_t * GetFramePoints() const
static void CheckAndFixBoxOrientationFv(Float_t box[8][3])
Make sure box orientation is consistent with standard arrangement.
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:187
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
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)
Returns the largest of a and b.
Definition TMathBase.h:251
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673