Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
boxset.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve
3/// Demonstrates usage of REveBoxSet class.
4///
5/// \image html eve_boxset.png
6/// \macro_code
7///
8/// \author Matevz Tadel
9
10#include "TRandom.h"
11#include <ROOT/REveElement.hxx>
12#include <ROOT/REveScene.hxx>
13#include <ROOT/REveManager.hxx>
14#include <ROOT/REveBoxSet.hxx>
15
16using namespace ROOT::Experimental;
17
18
19std::string customTooltip(const ROOT::Experimental::REveDigitSet *digitSet, int n)
20{
21 auto d = digitSet->GetDigit(n);
22 return TString::Format("Custom tooltip:\n value %d idx %d\n", d->fValue, n).Data();
23}
24
25REveBoxSet* boxset_free(Int_t num=100)
26{
27 TRandom r(0);
28
29 auto pal = new REveRGBAPalette(0, 130);
30 pal->SetMin(80);
31
32
33 auto q = new REveBoxSet("BoxSet");
34 q->SetPalette(pal);
35 q->Reset(REveBoxSet::kBT_FreeBox, kFALSE, 64);
36
37#define RND_BOX(x) (Float_t)r.Uniform(-(x), (x))
38
39 const float R = 500;
40 const float A = 40;
41 const float D = 1;
42 for (int i = 0; i < num; ++i) {
43 float x = RND_BOX(R);
44 float y = RND_BOX(R);
45 float z = RND_BOX(R);
46 float a = r.Uniform(0.2*A, A);
47 float d = D;
48 float verts[24] = {
49 x - a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d),
50 x - a + RND_BOX(d), y + a + RND_BOX(d), z - a + RND_BOX(d),
51 x + a + RND_BOX(d), y + a + RND_BOX(d), z - a + RND_BOX(d),
52 x + a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d),
53 x - a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d),
54 x - a + RND_BOX(d), y + a + RND_BOX(d), z + a + RND_BOX(d),
55 x + a + RND_BOX(d), y + a + RND_BOX(d), z + a + RND_BOX(d),
56 x + a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d) };
57 q->AddFreeBox(verts);
58 q->DigitValue(r.Uniform(0, 130));
59 }
60 q->RefitPlex();
61
62#undef RND_BOX
63
64 // Uncomment these two lines to get internal highlight / selection.
65 q->SetPickable(1);
66 q->SetAlwaysSecSelect(1);
67 q->SetTooltipCBFoo(customTooltip);
68
69 return q;
70}
71
72REveBoxSet* boxset_axisaligned(Float_t x=0, Float_t y=0, Float_t z=0, Int_t num=100)
73{
74 TRandom r(0);
75
76 auto pal = new REveRGBAPalette(0, 130);
77
78 auto frm = new REveFrameBox();
79 frm->SetAABoxCenterHalfSize(0, 0, 0, 12, 12, 12);
80 frm->SetFrameColor(kCyan);
81 frm->SetBackColorRGBA(120,120,120,20);
82 frm->SetDrawBack(kTRUE);
83
84 auto q = new REveBoxSet("BoxSet");
85 q->SetPalette(pal);
86 q->SetFrame(frm);
87 q->Reset(REveBoxSet::kBT_InstancedScaled, kFALSE, 64);
88
89 for (Int_t i=0; i<num; ++i) {
90 q->AddInstanceScaled(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10),
91 r.Uniform(0.2, 1), r.Uniform(0.2, 1), r.Uniform(0.2, 1));
92 q->DigitValue(r.Uniform(0, 130));
93 }
94 q->RefitPlex();
95
96 REveTrans& t = q->RefMainTrans();
97 t.SetPos(x, y, z);
98
99 // Uncomment these two lines to get internal highlight / selection.
100 q->SetPickable(1);
101 q->SetAlwaysSecSelect(1);
102 q->SetTooltipCBFoo(customTooltip);
103
104 return q;
105}
106
107REveBoxSet* boxset_colisval(Float_t x=0, Float_t y=0, Float_t z=0, Int_t num=100)
108{
109 TRandom r(0);
110
111 auto q = new REveBoxSet("BoxSet");
112 q->Reset(REveBoxSet::kBT_InstancedScaled, kTRUE, 64);
113 for (Int_t i=0; i<num; ++i) {
114 q->AddInstanceScaled(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10),
115 r.Uniform(0.2, 1), r.Uniform(0.2, 1), r.Uniform(0.2, 1));
116 q->DigitColor(r.Uniform(20, 255), r.Uniform(20, 255),
117 r.Uniform(20, 255), r.Uniform(20, 255));
118 }
119 q->RefitPlex();
120
121 REveTrans& t = q->RefMainTrans();
122 t.SetPos(x, y, z);
123
124 return q;
125}
126
127REveBoxSet* boxset_single_color(Float_t x=0, Float_t y=0, Float_t z=0, Int_t num=100)
128{
129 TRandom r(0);
130
131 auto q = new REveBoxSet("BoxSet");
132 q->UseSingleColor();
133 q->SetMainColorPtr(new Color_t);
134 q->SetMainColor(kRed);
135 q->SetMainTransparency(50);
136 q->Reset(REveBoxSet::kBT_InstancedScaled, kFALSE, 64);
137
138 for (Int_t i=0; i<num; ++i) {
139 q->AddInstanceScaled(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10),
140 r.Uniform(0.2, 1), r.Uniform(0.2, 1), r.Uniform(0.2, 1));
141 }
142 q->RefitPlex();
143
144 REveTrans& t = q->RefMainTrans();
145 t.SetPos(x, y, z);
146
147 return q;
148}
149
150REveBoxSet* boxset_fixed_dim(Float_t x=0, Float_t y=0, Float_t z=0, Int_t num=100)
151{
152 TRandom r(0);
153
154 auto q = new REveBoxSet("BoxSet");
155 q->UseSingleColor();
156 q->SetMainColorPtr(new Color_t);
157 q->SetMainColor(kRed);
158 q->SetMainTransparency(50);
159 q->Reset(REveBoxSet::kBT_Instanced, kFALSE, 64);
160
161 for (Int_t i=0; i<num; ++i) {
162 q->AddInstance(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10));
163 }
164 q->RefitPlex();
165
166 q->SetPickable(1);
167 q->SetAlwaysSecSelect(1);
168 REveTrans& t = q->RefMainTrans();
169 t.SetPos(x, y, z);
170 return q;
171}
172
173REveBoxSet* boxset_hex(Float_t x=0, Float_t y=0, Float_t z=0, Int_t num=100)
174{
175 TRandom r(0);
176
177 auto q = new REveBoxSet("BoxSet");
178 q->Reset(REveBoxSet::kBT_InstancedScaledRotated, kTRUE, 64);
179
180 for (Int_t i=0; i<num; ++i) {
181 q->AddHex(REveVector(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10)),
182 r.Uniform(0.2, 1), r.Uniform(0, 60), r.Uniform(0.2, 5));
183 q->DigitColor(r.Uniform(20, 255), r.Uniform(20, 255),
184 r.Uniform(20, 255), r.Uniform(20, 255));
185 }
186 q->RefitPlex();
187
188 q->SetPickable(true);
189 q->SetAlwaysSecSelect(true);
190
191 REveTrans& t = q->RefMainTrans();
192 t.SetPos(x, y, z);
193 return q;
194}
195
196
197REveBoxSet* boxset_gentrans(Float_t x=0, Float_t y=0, Float_t z=0, int num = 10)
198{
199 auto q = new REveBoxSet("BoxSet-GenTrans");
200 q->Reset(REveBoxSet::kBT_InstancedScaledRotated, kTRUE, 64);
201
202 TRandom r(0);
203 for (Int_t i=0; i< num; ++i)
204 {
205 // Create per digit transformation
206 REveTrans t;
207 float x = 50 - i*10;
208 t.Move3LF(x, 0, 0);
209 t.Scale(1, 1, 10);
210 t.RotateLF(1, 2, r.Uniform(3.14));
211 // t.Print();
212 float farr[16];
213 for (int m=0; m<16; m++)
214 farr[m] = t.Array()[m];
215
216 q->AddInstanceMat4(farr);
217 q->DigitColor(255, 0, 0, 100); // AMT how the treansparency handled, last ergument alpha
218 }
219 q->RefitPlex();
220 q->SetPickable(true);
221 q->SetAlwaysSecSelect(true);
222
223 REveTrans& t = q->RefMainTrans();
224 t.SetPos(x, y, z);
225
226 return q;
227}
228
229void boxset()
230{
231 enum EBoxDemo_t {ScaledRotated, Free, AxisAligned, Hexagon, FixedDimension, SingleColor};
232
233 // EBoxDemo_t demo = ScaledRotated;
234 EBoxDemo_t demo = AxisAligned;
235
236 auto eveMng = REveManager::Create();
237 REveBoxSet* b = nullptr;
238 switch (demo)
239 {
240 case ScaledRotated:
241 b = boxset_gentrans();
242 break;
243 case Free:
244 b = boxset_free();
245 break;
246 case AxisAligned:
247 b = boxset_axisaligned();
248 break;
249 case FixedDimension:
250 b = boxset_fixed_dim();
251 break;
252 case Hexagon:
253 b = boxset_hex();
254 break;
255 case SingleColor:
256 b = boxset_single_color();
257 break;
258 default:
259 printf("Unsupported demo type. \n");
260 return;
261 }
262
263
265
266 // Add palette to scene to be streamed and edited in controller
267 if (b->GetPalette())
268 eveMng->GetEventScene()->AddElement(b->GetPalette());
269
270 eveMng->Show();
271
273 v->SetAxesType(REveViewer::kAxesOrigin);
274
275 // AMT temporary solution: add geo-shape to set scene bounding box
276 // digits at the moment have no bounding box calculation and lights are consequently
277 // in inital empty position at extend size of 1
278 auto b1 = new REveGeoShape("Bounding Box Barrel");
279 b1->SetShape(new TGeoTube(30, 32, 10));
280 b1->SetMainColor(kCyan);
281 b1->SetNSegments(80);
282 b1->SetMainTransparency(95);
284}
285
286
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:92
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
@ kRed
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
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
float * q
Collection of 3D primitives (fixed-size boxes, boxes of different sizes, or arbitrary sexto-epipeds,...
Description of a 2D or 3D frame that can be used to visually group a set of objects.
Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TG...
A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range t...
REveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Eve representation of a GL view.
DigitBase_t * GetDigit(Int_t n) const
virtual void AddElement(REveElement *el)
Add el to the list of children.
REveScene * GetEventScene() const
REveScene * GetGlobalScene() const
REveViewer * GetDefaultViewer() const
Get the default viewer.
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
Cylindrical tube class.
Definition TGeoTube.h:17
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
const char * Data() const
Definition TString.h:376
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
ROOT::Experimental::REveManager * eveMng
#define RND_BOX(x)
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve
Definition demo.py:1
TMarker m
Definition textangle.C:8