Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
glViewerLOD.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gl
3/// To set the Level Of Details when rendering geometry shapes.
4///
5/// \macro_code
6///
7/// \author Richard Maunder
8
9void glViewerLOD(Int_t reqNodes = 1000, Bool_t randomDist = kTRUE,
10 Bool_t reqSpheres = kTRUE, Bool_t reqTubes = kTRUE)
11{
12 TGeoManager * geom = new TGeoManager("LODTest", "GL viewer LOD test");
13 geom->SetNsegments(4); // Doesn't matter keep low
14 TGeoMaterial *matEmptySpace = new TGeoMaterial("EmptySpace", 0, 0, 0);
15 TGeoMaterial *matSolid = new TGeoMaterial("Solid" , .938, 1., 10000.);
16
17 TGeoMedium *medEmptySpace = new TGeoMedium("Empty", 1, matEmptySpace);
18 TGeoMedium *medSolid = new TGeoMedium("Solid", 1, matSolid);
19
20 Double_t sizeBase = 20.0;
21 Double_t worldRadius;
22 if (randomDist) {
23 worldRadius = pow(reqNodes,.5)*sizeBase;
24 } else {
25 worldRadius = pow(reqNodes,.3)*sizeBase;
26 }
27
28 TGeoVolume *top = geom->MakeBox
29 ("WORLD", medEmptySpace, worldRadius, worldRadius, worldRadius);
30 geom->SetTopVolume(top);
31
33
34 // Create random number of unique sphere shapes - up to 25% of
35 // total placed sphere requested
36 UInt_t volumeCount = gRandom->Integer(reqNodes/4)+1;
37 TGeoVolume ** volumes = new TGeoVolume *[volumeCount];
38 TGeoVolume * volume;
39 UInt_t i;
40 Double_t dummy;
41
42 for (i = 0; i < volumeCount; i++) {
43 char name[128];
44 sprintf(name, "Volume_%d", i);
45
46 // Random volume shape
47 Int_t type = -1;
48 if (reqSpheres && reqTubes) {
49 type = gRandom->Integer(2);
50 if (type == 1)
51 type += gRandom->Integer(3);
52 }
53 else if(reqSpheres)
54 type = 0;
55 else if(reqTubes)
56 type = 1 + gRandom->Integer(3);
57
58 // Random dimensions
59 Double_t rMin = gRandom->Rndm() * sizeBase;
60 Double_t rMax = rMin + gRandom->Rndm() * sizeBase * 2.0;
61 Double_t dz = pow(gRandom->Rndm(),2.0) * sizeBase * 15.0;
62 Double_t phi1 = gRandom->Rndm() * 90.0;
63 Double_t phi2 = phi1 + gRandom->Rndm() * 270.0;
64
65 // Pick random color (not black)
66 Int_t color = gRandom->Integer(50);
67 if (color == kBlack) color += 1;
68
69 switch (type) {
70 case 0: {
71 // GL viewer only supports solid spheres (0. inner radius)
72 volumes[i] = geom->MakeSphere(name, medSolid, 0., rMax);
73 printf("Volume %d : Color %d, Sphere, Radius %f\n", i, color, rMax);
74 break;
75 }
76 case 1: {
77 volumes[i] = geom->MakeTube(name, medSolid, rMin, rMax, dz);
78 printf("Volume %d : Color %d, Tube, Inner Radius %f, "
79 "Outer Radius %f, Length %f\n",
80 i, color, rMin, rMax, dz);
81 break;
82 }
83 case 2: {
84 volumes[i] = geom->MakeTubs(name, medSolid, rMin, rMax, dz,
85 phi1, phi2);
86 printf("Volume %d : Color %d, Tube Seg, Inner Radius %f, "
87 "Outer Radius %f, Length %f, Phi1 %f, Phi2 %f\n",
88 i, color, rMin, rMax, dz, phi1, phi2);
89 break;
90 }
91 case 3: {
92 Double_t n1[3], n2[3];
93 n1[0] = gRandom->Rndm()*.5;
94 n1[1] = gRandom->Rndm()*.5; n1[2] = -1.0 + gRandom->Rndm()*.5;
95 n2[0] = gRandom->Rndm()*.5;
96 n2[1] = gRandom->Rndm()*.5; n2[2] = 1.0 - gRandom->Rndm()*.5;
97
98 volumes[i] = geom->MakeCtub(name, medSolid, rMin, rMax, dz,
99 phi1, phi2, n1[0], n1[1], n1[2],
100 n2[0], n2[1], n2[2]);
101 printf("Volume %d : Color %d, Cut Tube, Inner Radius %f, "
102 "Outer Radius %f, Length %f, Phi1 %f, Phi2 %f, "
103 "n1 (%f,%f,%f), n2 (%f,%f,%f)\n",
104 i, color, rMin, rMax, dz, phi1, phi2,
105 n1[0], n1[1], n1[2], n2[0], n2[1], n2[2]);
106 break;
107 }
108 default: {
109 assert(kFALSE);
110 }
111 }
112
113 volumes[i]->SetLineColor(color);
114 }
115
116 printf("\nCreated %d volumes\n\n", volumeCount);
117
118 // Scatter reqSpheres placed sphere randomly in space
119 Double_t x, y, z;
120 for (i = 0; i < reqNodes; i++) {
121 // Pick random volume
122 UInt_t useVolume = gRandom->Integer(volumeCount);
123
124 TGeoTranslation * trans;
125 TGeoRotation * rot;
126 if (randomDist) {
127 // Random translation
128 gRandom->Rannor(x, y);
129 gRandom->Rannor(z,dummy);
130 trans = new TGeoTranslation(x*worldRadius, y*worldRadius, z*worldRadius);
131
132 // Random rotation
133 gRandom->Rannor(x, y);
134 gRandom->Rannor(z,dummy);
135 rot = new TGeoRotation("rot", x*360.0, y*360.0, z*360.0);
136 } else {
137 UInt_t perSide = pow(reqNodes,1.0/3.0)+0.5;
138 Double_t distance = sizeBase*5.0;
139 UInt_t xi, yi, zi;
140 zi = i / (perSide*perSide);
141 yi = (i / perSide) % perSide;
142 xi = i % perSide;
143 trans = new TGeoTranslation(xi*distance,yi*distance,zi*distance);
144 rot = new TGeoRotation("rot",0.0, 0.0, 0.0);
145 }
146 top->AddNode(volumes[useVolume], i, new TGeoCombiTrans(*trans, *rot));
147 //printf("Added node %d (Volume %d)\n", i, useVolume);
148 }
149 geom->CloseGeometry();
150 top->Draw("ogl");
151}
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
@ kBlack
Definition Rtypes.h:65
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
Class describing rotation + translation.
Definition TGeoMatrix.h:317
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
TGeoVolume * MakeTube(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t dz)
Make in one step a volume pointing to a tube shape with given medium.
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
TGeoVolume * MakeBox(const char *name, TGeoMedium *medium, Double_t dx, Double_t dy, Double_t dz)
Make in one step a volume pointing to a box shape with given medium.
TGeoVolume * MakeSphere(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t themin=0, Double_t themax=180, Double_t phimin=0, Double_t phimax=360)
Make in one step a volume pointing to a sphere shape with given medium.
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
TGeoVolume * MakeCtub(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2, Double_t lx, Double_t ly, Double_t lz, Double_t tx, Double_t ty, Double_t tz)
Make in one step a volume pointing to a tube segment shape with given medium.
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
TGeoVolume * MakeTubs(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2)
Make in one step a volume pointing to a tube segment shape with given medium.
Base class describing materials.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:23
Class describing rotations.
Definition TGeoMatrix.h:168
Class describing translations.
Definition TGeoMatrix.h:116
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
Add a TGeoNode to the list of nodes.
void Draw(Option_t *option="") override
draw top volume according to option
void SetLineColor(Color_t lcolor) override
Set the line color.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandom.cxx:615
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition TRandom.cxx:507
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition TRandom.cxx:361
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
Definition RVec.hxx:1846
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17