Logo ROOT  
Reference Guide
boxset_cones.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve
3/// Demonstrates usage of 'cone' mode in TEveBoxSet class.
4///
5/// \image html eve_boxset_cones.png
6/// \macro_code
7///
8/// \author Alja Mrak-Tadel
9
10TEveBoxSet* boxset_cones(Float_t x=0, Float_t y=0, Float_t z=0,
11 Int_t num=100, Bool_t register=kTRUE)
12{
14
15 using namespace TMath;
16
17 auto lines = new TEveStraightLineSet("StraightLines");
18 lines->SetLineColor(kYellow);
19 lines->SetLineWidth(2);
20
21 TRandom r(0);
22 auto pal = new TEveRGBAPalette(0, 500);
23 auto cones = new TEveBoxSet("ConeSet");
24 cones->SetPalette(pal);
25 cones->Reset(TEveBoxSet::kBT_Cone, kFALSE, 64);
26
27 Float_t a = 40; // max distance between cones
28 TEveVector dir, pos;
29 Float_t theta, phi, height, rad;
30 for (Int_t i=0; i<num; ++i) {
31 theta = r.Uniform(0,TMath::Pi());
32 phi = r.Uniform (-TMath::Pi(), TMath::Pi());
33 height = r.Uniform(5, 15);
34 rad = r.Uniform(3, 5);
35 dir.Set(Cos(phi)*Cos(theta), Sin(phi)*Cos(theta), Sin(theta));
36 dir *= height;
37 pos.Set(r.Uniform(-a,a), r.Uniform(-a, a), r.Uniform(-a, a));
38
39 cones->AddCone(pos, dir, rad);
40 cones->DigitValue(r.Uniform(0, 500));
41
42 // draw axis line 30% longer than cone height
43 TEveVector end = pos + dir*1.3f;
44 lines->AddLine(pos.fX, pos.fY, pos.fZ, end.fX, end.fY, end.fZ);
45 }
46
47 // by default cone cap not drawn
48 if (r.Integer(2)>0) cones->SetDrawConeCap(kTRUE);
49
50 cones->RefitPlex();
51 TEveTrans& t = cones->RefMainTrans();
52 t.SetPos(x, y, z);
53
54 gEve->AddElement(cones);
55 gEve->AddElement(lines);
56
58
59 return cones;
60}
61
62TEveBoxSet* elliptic_boxset_cones(Float_t x=0, Float_t y=0, Float_t z=0,
63 Int_t num=100, Bool_t register=kTRUE)
64{
66
67 using namespace TMath;
68
70
71 auto lines = new TEveStraightLineSet("StraightLines");
72 lines->SetLineColor(kYellow);
73 lines->SetLineWidth(2);
74
75 TRandom r(0);
76
77 auto cones = new TEveBoxSet("EllipticConeSet");
78 cones->Reset(TEveBoxSet::kBT_EllipticCone, kTRUE, 64);
79
80 cones->SetPickable(kTRUE);
81
82 Float_t a = 40; // max distance between cones
83 TEveVector dir, pos;
84 Float_t theta, phi, height, rad;
85 for (Int_t i=0; i<num; ++i) {
86 theta = r.Uniform(0,TMath::Pi());
87 phi = r.Uniform (-TMath::Pi(), TMath::Pi());
88 height = r.Uniform(5, 15);
89 rad = r.Uniform(3, 5);
90 dir.Set(Cos(phi)*Cos(theta), Sin(phi)*Cos(theta), Sin(theta));
91 dir *= height;
92 pos.Set(r.Uniform(-a,a), r.Uniform(-a, a), r.Uniform(-a, a));
93
94 cones->AddEllipticCone(pos, dir, rad, 0.5*rad, r.Uniform(0,360));
95 cones->DigitColor(r.Uniform(20, 255), r.Uniform(20, 255),
96 r.Uniform(20, 255), r.Uniform(20, 255));
97
98 // draw axis line 30% longer than cone height
99 TEveVector end = pos + dir*1.3f;
100 lines->AddLine(pos.fX, pos.fY, pos.fZ, end.fX, end.fY, end.fZ);
101 }
102
103 // by default cone cap not drawn
104 if (r.Integer(2)>0) cones->SetDrawConeCap(kTRUE);
105
106 cones->RefitPlex();
107 TEveTrans& t = cones->RefMainTrans();
108 t.SetPos(x, y, z);
109
110 gEve->AddElement(cones);
111 gEve->AddElement(lines);
112
114
115 return cones;
116}
ROOT::R::TRInterface & r
Definition: Object.C:4
int Int_t
Definition: RtypesCore.h:41
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
@ kYellow
Definition: Rtypes.h:64
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
Collection of 3D primitives (fixed-size boxes, boxes of different sizes, or arbitrary sexto-epipeds,...
Definition: TEveBoxSet.h:22
@ kBT_EllipticCone
Definition: TEveBoxSet.h:35
void AddElement(TEveElement *element, TEveElement *parent=0)
Add an element.
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Definition: TEveManager.h:168
A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range t...
Set of straight lines with optional markers along the lines.
TEveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Definition: TEveTrans.h:27
void SetPos(Double_t x, Double_t y, Double_t z)
Set position (base-vec 4).
Definition: TEveTrans.cxx:507
void Set(const Float_t *v)
Definition: TEveVector.h:81
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
static constexpr double rad
TMath.
Definition: TMathBase.h:35
Double_t Cos(Double_t)
Definition: TMath.h:631
constexpr Double_t Pi()
Definition: TMath.h:38
Double_t Sin(Double_t)
Definition: TMath.h:627
auto * a
Definition: textangle.C:12