Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 {
13  TEveManager::Create();
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 
57  gEve->Redraw3D(kTRUE);
58 
59  return cones;
60 }
61 
62 TEveBoxSet* 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 {
65  TEveManager::Create();
66 
67  using namespace TMath;
68 
69  TEveManager::Create();
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 
113  gEve->Redraw3D(kTRUE);
114 
115  return cones;
116 }