Logo ROOT   6.14/05
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 
10 TEveBoxSet* 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  TEveStraightLineSet* lines = new TEveStraightLineSet("StraightLines");
18  lines->SetLineColor(kYellow);
19  lines->SetLineWidth(2);
20 
21  TRandom r(0);
22  TEveRGBAPalette* pal = new TEveRGBAPalette(0, 500);
23  TEveBoxSet* 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  {
32  theta = r.Uniform(0,TMath::Pi());
33  phi = r.Uniform (-TMath::Pi(), TMath::Pi());
34  height = r.Uniform(5, 15);
35  rad = r.Uniform(3, 5);
36  dir.Set(Cos(phi)*Cos(theta), Sin(phi)*Cos(theta), Sin(theta));
37  dir *= height;
38  pos.Set(r.Uniform(-a,a), r.Uniform(-a, a), r.Uniform(-a, a));
39 
40  cones->AddCone(pos, dir, rad);
41  cones->DigitValue(r.Uniform(0, 500));
42 
43  // draw axis line 30% longer than cone height
44  TEveVector end = pos + dir*1.3f;
45  lines->AddLine(pos.fX, pos.fY, pos.fZ, end.fX, end.fY, end.fZ);
46  }
47 
48  // by default cone cap not drawn
49  if (r.Integer(2)>0) cones->SetDrawConeCap(kTRUE);
50 
51  cones->RefitPlex();
52  TEveTrans& t = cones->RefMainTrans();
53  t.SetPos(x, y, z);
54 
55  gEve->AddElement(cones);
56  gEve->AddElement(lines);
57 
59 
60  return cones;
61 }
62 
64 elliptic_boxset_cones(Float_t x=0, Float_t y=0, Float_t z=0,
65  Int_t num=100, Bool_t register=kTRUE)
66 {
68 
69  using namespace TMath;
70 
72 
73  TEveStraightLineSet* lines = new TEveStraightLineSet("StraightLines");
74  lines->SetLineColor(kYellow);
75  lines->SetLineWidth(2);
76 
77  TRandom r(0);
78 
79  TEveBoxSet* cones = new TEveBoxSet("EllipticConeSet");
81 
82  cones->SetPickable(kTRUE);
83 
84  Float_t a = 40; // max distance between cones
85  TEveVector dir, pos;
86  Float_t theta, phi, height, rad;
87  for (Int_t i=0; i<num; ++i)
88  {
89  theta = r.Uniform(0,TMath::Pi());
90  phi = r.Uniform (-TMath::Pi(), TMath::Pi());
91  height = r.Uniform(5, 15);
92  rad = r.Uniform(3, 5);
93  dir.Set(Cos(phi)*Cos(theta), Sin(phi)*Cos(theta), Sin(theta));
94  dir *= height;
95  pos.Set(r.Uniform(-a,a), r.Uniform(-a, a), r.Uniform(-a, a));
96 
97  cones->AddEllipticCone(pos, dir, rad, 0.5*rad, r.Uniform(0,360));
98  cones->DigitColor(r.Uniform(20, 255), r.Uniform(20, 255),
99  r.Uniform(20, 255), r.Uniform(20, 255));
100 
101  // draw axis line 30% longer than cone height
102  TEveVector end = pos + dir*1.3f;
103  lines->AddLine(pos.fX, pos.fY, pos.fZ, end.fX, end.fY, end.fZ);
104  }
105 
106  // by default cone cap not drawn
107  if (r.Integer(2)>0) cones->SetDrawConeCap(kTRUE);
108 
109  cones->RefitPlex();
110  TEveTrans& t = cones->RefMainTrans();
111  t.SetPos(x, y, z);
112 
113  gEve->AddElement(cones);
114  gEve->AddElement(lines);
115 
116  gEve->Redraw3D(kTRUE);
117 
118  return cones;
119 }
TEveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Definition: TEveTrans.h:26
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range t...
void Set(const Float_t *v)
Definition: TEveVector.h:78
float Float_t
Definition: RtypesCore.h:53
Collection of 3D primitives (fixed-size boxes, boxes of different sizes, or arbitrary sexto-epipeds...
Definition: TEveBoxSet.h:21
void SetPickable(Bool_t p)
Definition: TEveElement.h:340
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.
Definition: TEveBoxSet.cxx:177
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Definition: TEveManager.h:168
Definition: Rtypes.h:59
static constexpr double rad
void AddElement(TEveElement *element, TEveElement *parent=0)
Add an element.
Double_t x[n]
Definition: legend1.C:17
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual void SetLineColor(Color_t col)
Set the line color.
void DigitColor(Color_t ci)
Set color for the last digit added.
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
constexpr Double_t Pi()
Definition: TMath.h:38
ROOT::R::TRInterface & r
Definition: Object.C:4
auto * a
Definition: textangle.C:12
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
Double_t Cos(Double_t)
Definition: TMath.h:640
const Bool_t kFALSE
Definition: RtypesCore.h:88
void SetPos(Double_t x, Double_t y, Double_t z)
Set position (base-vec 4).
Definition: TEveTrans.cxx:507
void SetDrawConeCap(Bool_t x)
Definition: TEveBoxSet.h:90
void Reset(EBoxType_e boxType, Bool_t valIsCol, Int_t chunkSize)
Reset the data containers to zero size.
Definition: TEveBoxSet.cxx:87
void SetPalette(TEveRGBAPalette *p)
Set TEveRGBAPalette pointer.
void RefitPlex()
Instruct underlying memory allocator to regroup itself into a contiguous memory chunk.
Double_t y[n]
Definition: legend1.C:17
void AddCone(const TEveVector &pos, const TEveVector &dir, Float_t r)
Create a cone with apex at pos, axis dir and radius r.
Definition: TEveBoxSet.cxx:160
Line_t * AddLine(Float_t x1, Float_t y1, Float_t z1, Float_t x2, Float_t y2, Float_t z2)
Add a line.
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
Double_t Sin(Double_t)
Definition: TMath.h:636
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
TMath.
Definition: TMathBase.h:34
void DigitValue(Int_t value)
Set signal value for the last digit added.
const Bool_t kTRUE
Definition: RtypesCore.h:87
Set of straight lines with optional markers along the lines.