Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
boxset_cones.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// Demonstrates usage of 'cone' mode in REveBoxSet class.
4///
5/// \image html eve_boxset_cones.png
6/// \macro_code
7///
8/// \author Alja Mrak-Tadel
9
10using namespace ROOT::Experimental;
11
12REveBoxSet *elliptic_boxset_cones(Float_t x = 0, Float_t y = 0, Float_t z = 0, Int_t num = 100)
13{
15
16 using namespace TMath;
17
19
21 lines->SetLineColor(kYellow);
22 lines->SetLineWidth(2);
23
24 TRandom r(0);
25
26 auto cones = new REveBoxSet("EllipticConeSet");
27 bool valIsColor = true;
28 cones->Reset(REveBoxSet::kBT_InstancedScaledRotated, valIsColor, 64);
29
30 cones->SetPickable(kTRUE);
31
32 Float_t a = 40; // max distance between cones
33 REveVector dir, pos;
34 Float_t theta, phi, height, rad;
35 for (Int_t i = 0; i < num; ++i) {
36 theta = r.Uniform(0, TMath::Pi());
37 phi = r.Uniform(-TMath::Pi(), TMath::Pi());
38 height = r.Uniform(5, 15);
39 rad = r.Uniform(3, 5);
40 dir.Set(Cos(phi) * Cos(theta), Sin(phi) * Cos(theta), Sin(theta));
41 dir *= height;
42 pos.Set(r.Uniform(-a, a), r.Uniform(-a, a), r.Uniform(-a, a));
43
44 cones->AddEllipticCone(pos, dir, rad, 0.5 * rad, r.Uniform(0, 360));
45 if (i % 2 == 0)
46 cones->DigitColor(kRed);
47 else
48 cones->DigitColor(kGreen);
49 // draw axis line 30% longer than cone height
50 REveVector end = pos + dir * 1.3f;
51 lines->AddLine(pos.fX, pos.fY, pos.fZ, end.fX, end.fY, end.fZ);
52 }
53
54 // by default cone cap not drawn
55 if (r.Integer(2) > 0)
56 cones->SetDrawConeCap(kTRUE);
57
58 cones->RefitPlex();
59 REveTrans &t = cones->RefMainTrans();
60 t.SetPos(x, y, z);
61 cones->SetPickable(1);
62 cones->SetAlwaysSecSelect(1);
63
64 eveMng->GetEventScene()->AddElement(cones);
65 eveMng->GetEventScene()->AddElement(lines);
66
67 REveViewer *v = (REveViewer *)eveMng->GetViewers()->FirstChild();
68 v->SetAxesType(REveViewer::kAxesOrigin);
69
70 eveMng->Show();
71 return cones;
72}
73
74REveBoxSet *boxset_cones(Float_t x = 0, Float_t y = 0, Float_t z = 0, Int_t num = 100)
75{
77
78 using namespace TMath;
79
81 lines->SetLineColor(kYellow);
82 lines->SetLineWidth(2);
83
84 TRandom r(0);
85 auto pal = new REveRGBAPalette(0, 500);
86 auto cones = new REveBoxSet("ConeSet");
87 cones->SetPalette(pal);
88 bool valIsColor = false;
89 cones->Reset(REveBoxSet::kBT_InstancedScaledRotated, valIsColor, 64);
90
91 Float_t a = 40; // max distance between cones
92 REveVector dir, pos;
93 Float_t theta, phi, height, rad;
94 for (Int_t i = 0; i < num; ++i) {
95 theta = r.Uniform(0, TMath::Pi());
96 phi = r.Uniform(-TMath::Pi(), TMath::Pi());
97 height = r.Uniform(5, 15);
98 rad = r.Uniform(3, 5);
99 dir.Set(Cos(phi) * Cos(theta), Sin(phi) * Cos(theta), Sin(theta));
100 dir *= height;
101 pos.Set(r.Uniform(-a, a), r.Uniform(-a, a), r.Uniform(-a, a));
102
103 cones->AddCone(pos, dir, rad);
104 cones->DigitValue(r.Uniform(0, 500));
105
106 // draw axis line 30% longer than cone height
107 REveVector end = pos + dir * 1.3f;
108 lines->AddLine(pos.fX, pos.fY, pos.fZ, end.fX, end.fY, end.fZ);
109 }
110
111 cones->SetPickable(1);
112 cones->SetAlwaysSecSelect(1);
113 // by default cone cap not drawn
114 if (r.Integer(2) > 0)
115 cones->SetDrawConeCap(kTRUE);
116
117 cones->RefitPlex();
118 REveTrans &t = cones->RefMainTrans();
119 t.SetPos(x, y, z);
120
121 eveMng->GetEventScene()->AddElement(cones);
122 eveMng->GetEventScene()->AddElement(lines);
123 eveMng->GetEventScene()->AddElement(pal);
124 eveMng->Show();
125
126 return cones;
127}
ROOT::R::TRInterface & r
Definition Object.C:4
#define a(i)
Definition RSha256.hxx:99
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kRed
Definition Rtypes.h:67
@ kGreen
Definition Rtypes.h:67
@ kYellow
Definition Rtypes.h:67
Collection of 3D primitives (fixed-size boxes, boxes of different sizes, or arbitrary sexto-epipeds,...
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.
static REveManager * Create()
If global REveManager* REX::gEve is not set initialize it.
REveStraightLineSet Set of straight lines with optional markers along the lines.
void Set(const Float_t *v)
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
ROOT::Experimental::REveManager * eveMng
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Namespace for ROOT features in testing.
Definition TROOT.h:100
REveVectorT< Float_t > REveVector
TMath.
Definition TMathBase.h:35
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:605
constexpr Double_t Pi()
Definition TMath.h:40
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:599