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
18std::string customTooltip(const ROOT::Experimental::REveDigitSet *digitSet, int n)
19{
20 auto d = digitSet->GetDigit(n);
21 return TString::Format("Custom tooltip:\n value %d idx %d\n", d->fValue, n).Data();
22}
23
24REveBoxSet *boxset_free(Int_t num = 100)
25{
26 TRandom r(0);
27
28 auto pal = new REveRGBAPalette(0, 130);
29 pal->SetMin(80);
30
31 auto q = new REveBoxSet("BoxSet");
32 q->SetPalette(pal);
33 q->Reset(REveBoxSet::kBT_FreeBox, kFALSE, 64);
34
35#define RND_BOX(x) (Float_t) r.Uniform(-(x), (x))
36
37 const float R = 500;
38 const float A = 40;
39 const float D = 1;
40 for (int i = 0; i < num; ++i) {
41 float x = RND_BOX(R);
42 float y = RND_BOX(R);
43 float z = RND_BOX(R);
44 float a = r.Uniform(0.2 * A, A);
45 float d = D;
46 float verts[24] = {x - a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d), x - a + RND_BOX(d),
47 y + a + RND_BOX(d), z - a + RND_BOX(d), x + a + RND_BOX(d), y + a + RND_BOX(d),
48 z - a + RND_BOX(d), x + a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d),
49 x - a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d), x - a + RND_BOX(d),
50 y + a + RND_BOX(d), z + a + RND_BOX(d), x + a + RND_BOX(d), y + a + RND_BOX(d),
51 z + a + RND_BOX(d), x + a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d)};
52 q->AddFreeBox(verts);
53 q->DigitValue(r.Uniform(0, 130));
54 }
55 q->RefitPlex();
56
57#undef RND_BOX
58
59 // Uncomment these two lines to get internal highlight / selection.
60 q->SetPickable(1);
61 q->SetAlwaysSecSelect(1);
62 q->SetTooltipCBFoo(customTooltip);
63
64 return q;
65}
66
67REveBoxSet *boxset_axisaligned(Float_t x = 0, Float_t y = 0, Float_t z = 0, Int_t num = 100)
68{
69 TRandom r(0);
70
71 auto pal = new REveRGBAPalette(0, 130);
72
73 auto frm = new REveFrameBox();
74 frm->SetAABoxCenterHalfSize(0, 0, 0, 12, 12, 12);
75 frm->SetFrameColor(kCyan);
76 frm->SetBackColorRGBA(120, 120, 120, 20);
77 frm->SetDrawBack(kTRUE);
78
79 auto q = new REveBoxSet("BoxSet");
80 q->SetPalette(pal);
81 q->SetFrame(frm);
82 q->Reset(REveBoxSet::kBT_InstancedScaled, kFALSE, 64);
83
84 for (Int_t i = 0; i < num; ++i) {
85 q->AddInstanceScaled(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(0.2, 1),
86 r.Uniform(0.2, 1), r.Uniform(0.2, 1));
87 q->DigitValue(r.Uniform(0, 130));
88 }
89 q->RefitPlex();
90
91 REveTrans &t = q->RefMainTrans();
92 t.SetPos(x, y, z);
93
94 // Uncomment these two lines to get internal highlight / selection.
95 q->SetPickable(1);
96 q->SetAlwaysSecSelect(1);
97 q->SetTooltipCBFoo(customTooltip);
98
99 return q;
100}
101
102REveBoxSet *boxset_colisval(Float_t x = 0, Float_t y = 0, Float_t z = 0, Int_t num = 100)
103{
104 TRandom r(0);
105
106 auto q = new REveBoxSet("BoxSet");
107 q->Reset(REveBoxSet::kBT_InstancedScaled, kTRUE, 64);
108 for (Int_t i = 0; i < num; ++i) {
109 q->AddInstanceScaled(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(0.2, 1),
110 r.Uniform(0.2, 1), r.Uniform(0.2, 1));
111 q->DigitColor(r.Uniform(20, 255), r.Uniform(20, 255), r.Uniform(20, 255), r.Uniform(20, 255));
112 }
113 q->RefitPlex();
114
115 REveTrans &t = q->RefMainTrans();
116 t.SetPos(x, y, z);
117
118 return q;
119}
120
121REveBoxSet *boxset_single_color(Float_t x = 0, Float_t y = 0, Float_t z = 0, Int_t num = 100)
122{
123 TRandom r(0);
124
125 auto q = new REveBoxSet("BoxSet");
126 q->UseSingleColor();
127 q->SetMainColorPtr(new Color_t);
128 q->SetMainColor(kRed);
129 q->SetMainTransparency(50);
130 q->Reset(REveBoxSet::kBT_InstancedScaled, kFALSE, 64);
131
132 for (Int_t i = 0; i < num; ++i) {
133 q->AddInstanceScaled(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(0.2, 1),
134 r.Uniform(0.2, 1), r.Uniform(0.2, 1));
135 }
136 q->RefitPlex();
137
138 REveTrans &t = q->RefMainTrans();
139 t.SetPos(x, y, z);
140
141 return q;
142}
143
144REveBoxSet *boxset_fixed_dim(Float_t x = 0, Float_t y = 0, Float_t z = 0, Int_t num = 100)
145{
146 TRandom r(0);
147
148 auto q = new REveBoxSet("BoxSet");
149 q->UseSingleColor();
150 q->SetMainColorPtr(new Color_t);
151 q->SetMainColor(kRed);
152 q->SetMainTransparency(50);
153 q->Reset(REveBoxSet::kBT_Instanced, kFALSE, 64);
154
155 for (Int_t i = 0; i < num; ++i) {
156 q->AddInstance(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10));
157 }
158 q->RefitPlex();
159
160 q->SetPickable(1);
161 q->SetAlwaysSecSelect(1);
162 REveTrans &t = q->RefMainTrans();
163 t.SetPos(x, y, z);
164 return q;
165}
166
167REveBoxSet *boxset_hex(Float_t x = 0, Float_t y = 0, Float_t z = 0, Int_t num = 100)
168{
169 TRandom r(0);
170
171 auto q = new REveBoxSet("BoxSet");
172 q->Reset(REveBoxSet::kBT_InstancedScaledRotated, kTRUE, 64);
173
174 for (Int_t i = 0; i < num; ++i) {
175 q->AddHex(REveVector(r.Uniform(-10, 10), r.Uniform(-10, 10), r.Uniform(-10, 10)), r.Uniform(0.2, 1),
176 r.Uniform(0, 60), r.Uniform(0.2, 5));
177 q->DigitColor(r.Uniform(20, 255), r.Uniform(20, 255), r.Uniform(20, 255), r.Uniform(20, 255));
178 }
179 q->RefitPlex();
180
181 q->SetPickable(true);
182 q->SetAlwaysSecSelect(true);
183
184 REveTrans &t = q->RefMainTrans();
185 t.SetPos(x, y, z);
186 return q;
187}
188
189REveBoxSet *boxset_gentrans(Float_t x = 0, Float_t y = 0, Float_t z = 0, int num = 10)
190{
191 auto q = new REveBoxSet("BoxSet-GenTrans");
192 q->Reset(REveBoxSet::kBT_InstancedScaledRotated, kTRUE, 64);
193
194 TRandom r(0);
195 for (Int_t i = 0; i < num; ++i) {
196 // Create per digit transformation
197 REveTrans t;
198 float x = 50 - i * 10;
199 t.Move3LF(x, 0, 0);
200 t.Scale(1, 1, 10);
201 t.RotateLF(1, 2, r.Uniform(3.14));
202 // t.Print();
203 float farr[16];
204 for (int m = 0; m < 16; m++)
205 farr[m] = t.Array()[m];
206
207 q->AddInstanceMat4(farr);
208 q->DigitColor(255, 0, 0, 100); // AMT how the treansparency handled, last ergument alpha
209 }
210 q->RefitPlex();
211 q->SetPickable(true);
212 q->SetAlwaysSecSelect(true);
213
214 REveTrans &t = q->RefMainTrans();
215 t.SetPos(x, y, z);
216
217 return q;
218}
219
220void boxset()
221{
222 enum EBoxDemo_t {
223 ScaledRotated,
224 Free,
225 AxisAligned,
226 Hexagon,
227 FixedDimension,
228 SingleColor
229 };
230
231 // EBoxDemo_t demo = ScaledRotated;
232 EBoxDemo_t demo = AxisAligned;
233
234 auto eveMng = REveManager::Create();
235 REveBoxSet *b = nullptr;
236 switch (demo) {
237 case ScaledRotated: b = boxset_gentrans(); break;
238 case Free: b = boxset_free(); break;
239 case AxisAligned: b = boxset_axisaligned(); break;
240 case FixedDimension: b = boxset_fixed_dim(); break;
241 case Hexagon: b = boxset_hex(); break;
242 case SingleColor: b = boxset_single_color(); break;
243 default: printf("Unsupported demo type. \n"); return;
244 }
245
247
248 // Add palette to scene to be streamed and edited in controller
249 if (b->GetPalette())
250 eveMng->GetEventScene()->AddElement(b->GetPalette());
251
252 eveMng->Show();
253
255 v->SetAxesType(REveViewer::kAxesOrigin);
256
257 // AMT temporary solution: add geo-shape to set scene bounding box
258 // digits at the moment have no bounding box calculation and lights are consequently
259 // in inital empty position at extend size of 1
260 auto b1 = new REveGeoShape("Bounding Box Barrel");
261 b1->SetShape(new TGeoTube(30, 32, 10));
262 b1->SetMainColor(kCyan);
263 b1->SetNSegments(80);
264 b1->SetMainTransparency(95);
266}
#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:85
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ 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.
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
TMarker m
Definition textangle.C:8