Logo ROOT  
Reference Guide
glViewerLOD.C File Reference

Detailed Description

To set the Level Of Details when rendering geometry shapes.

void glViewerLOD(Int_t reqNodes = 1000, Bool_t randomDist = kTRUE,
Bool_t reqSpheres = kTRUE, Bool_t reqTubes = kTRUE)
{
TGeoManager * geom = new TGeoManager("LODTest", "GL viewer LOD test");
geom->SetNsegments(4); // Doesn't matter keep low
TGeoMaterial *matEmptySpace = new TGeoMaterial("EmptySpace", 0, 0, 0);
TGeoMaterial *matSolid = new TGeoMaterial("Solid" , .938, 1., 10000.);
TGeoMedium *medEmptySpace = new TGeoMedium("Empty", 1, matEmptySpace);
TGeoMedium *medSolid = new TGeoMedium("Solid", 1, matSolid);
Double_t sizeBase = 20.0;
Double_t worldRadius;
if (randomDist) {
worldRadius = pow(reqNodes,.5)*sizeBase;
} else {
worldRadius = pow(reqNodes,.3)*sizeBase;
}
TGeoVolume *top = geom->MakeBox
("WORLD", medEmptySpace, worldRadius, worldRadius, worldRadius);
geom->SetTopVolume(top);
// Create random number of unique sphere shapes - up to 25% of
// total placed sphere requested
UInt_t volumeCount = gRandom->Integer(reqNodes/4)+1;
TGeoVolume ** volumes = new TGeoVolume *[volumeCount];
TGeoVolume * volume;
UInt_t i;
for (i = 0; i < volumeCount; i++) {
char name[128];
sprintf(name, "Volume_%d", i);
// Random volume shape
Int_t type = -1;
if (reqSpheres && reqTubes) {
if (type == 1)
}
else if(reqSpheres)
type = 0;
else if(reqTubes)
type = 1 + gRandom->Integer(3);
// Random dimensions
Double_t rMin = gRandom->Rndm() * sizeBase;
Double_t rMax = rMin + gRandom->Rndm() * sizeBase * 2.0;
Double_t dz = pow(gRandom->Rndm(),2.0) * sizeBase * 15.0;
Double_t phi1 = gRandom->Rndm() * 90.0;
Double_t phi2 = phi1 + gRandom->Rndm() * 270.0;
// Pick random color (not black)
Int_t color = gRandom->Integer(50);
if (color == kBlack) color += 1;
switch (type) {
case 0: {
// GL viewer only supports solid spheres (0. inner radius)
volumes[i] = geom->MakeSphere(name, medSolid, 0., rMax);
printf("Volume %d : Color %d, Sphere, Radius %f\n", i, color, rMax);
break;
}
case 1: {
volumes[i] = geom->MakeTube(name, medSolid, rMin, rMax, dz);
printf("Volume %d : Color %d, Tube, Inner Radius %f, "
"Outer Radius %f, Length %f\n",
i, color, rMin, rMax, dz);
break;
}
case 2: {
volumes[i] = geom->MakeTubs(name, medSolid, rMin, rMax, dz,
phi1, phi2);
printf("Volume %d : Color %d, Tube Seg, Inner Radius %f, "
"Outer Radius %f, Length %f, Phi1 %f, Phi2 %f\n",
i, color, rMin, rMax, dz, phi1, phi2);
break;
}
case 3: {
Double_t n1[3], n2[3];
n1[0] = gRandom->Rndm()*.5;
n1[1] = gRandom->Rndm()*.5; n1[2] = -1.0 + gRandom->Rndm()*.5;
n2[0] = gRandom->Rndm()*.5;
n2[1] = gRandom->Rndm()*.5; n2[2] = 1.0 - gRandom->Rndm()*.5;
volumes[i] = geom->MakeCtub(name, medSolid, rMin, rMax, dz,
phi1, phi2, n1[0], n1[1], n1[2],
n2[0], n2[1], n2[2]);
printf("Volume %d : Color %d, Cut Tube, Inner Radius %f, "
"Outer Radius %f, Length %f, Phi1 %f, Phi2 %f, "
"n1 (%f,%f,%f), n2 (%f,%f,%f)\n",
i, color, rMin, rMax, dz, phi1, phi2,
n1[0], n1[1], n1[2], n2[0], n2[1], n2[2]);
break;
}
default: {
assert(kFALSE);
}
}
volumes[i]->SetLineColor(color);
}
printf("\nCreated %d volumes\n\n", volumeCount);
// Scatter reqSpheres placed sphere randomly in space
Double_t x, y, z;
for (i = 0; i < reqNodes; i++) {
// Pick random volume
UInt_t useVolume = gRandom->Integer(volumeCount);
TGeoTranslation * trans;
TGeoRotation * rot;
if (randomDist) {
// Random translation
trans = new TGeoTranslation(x*worldRadius, y*worldRadius, z*worldRadius);
// Random rotation
rot = new TGeoRotation("rot", x*360.0, y*360.0, z*360.0);
} else {
UInt_t perSide = pow(reqNodes,1.0/3.0)+0.5;
Double_t distance = sizeBase*5.0;
UInt_t xi, yi, zi;
zi = i / (perSide*perSide);
yi = (i / perSide) % perSide;
xi = i % perSide;
trans = new TGeoTranslation(xi*distance,yi*distance,zi*distance);
rot = new TGeoRotation("rot",0.0, 0.0, 0.0);
}
top->AddNode(volumes[useVolume], i, new TGeoCombiTrans(*trans, *rot));
//printf("Added node %d (Volume %d)\n", i, useVolume);
}
geom->CloseGeometry();
top->Draw("ogl");
}
Author
Richard Maunder

Definition in file glViewerLOD.C.

kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGeoCombiTrans
Definition: TGeoMatrix.h:291
TGeoManager::MakeBox
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.
Definition: TGeoManager.cxx:2918
TGeoManager::CloseGeometry
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
Definition: TGeoManager.cxx:1359
Int_t
int Int_t
Definition: RtypesCore.h:45
TGeoVolume::AddNode
virtual void AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:932
x
Double_t x[n]
Definition: legend1.C:17
TGeoManager::MakeCtub
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.
Definition: TGeoManager.cxx:3003
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGeoTranslation
Definition: TGeoMatrix.h:121
TGeoMaterial
Definition: TGeoMaterial.h:34
TGeoManager::SetNsegments
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
Definition: TGeoManager.cxx:3339
TRandom::Rannor
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:489
kBlack
@ kBlack
Definition: Rtypes.h:65
TGeoManager::SetTopVolume
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
Definition: TGeoManager.cxx:3397
TGeoVolume::Draw
virtual void Draw(Option_t *option="")
draw top volume according to option
Definition: TGeoVolume.cxx:1146
TGeoRotation
Definition: TGeoMatrix.h:174
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TGeoManager::MakeSphere
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.
Definition: TGeoManager.cxx:2937
TRandom::SetSeed
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:597
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TRandom::Rndm
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:541
y
Double_t y[n]
Definition: legend1.C:17
TRandom::Integer
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition: TRandom.cxx:349
Double_t
double Double_t
Definition: RtypesCore.h:59
dummy
static RooMathCoreReg dummy
Definition: RooMathCoreReg.cxx:27
name
char name[80]
Definition: TGX11.cxx:110
TGeoManager::MakeTubs
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.
Definition: TGeoManager.cxx:2966
TGeoMedium
Definition: TGeoMedium.h:23
type
int type
Definition: TGX11.cxx:121
TGeoVolume::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TGeoVolume.cxx:2035
pow
double pow(double, double)
TGeoManager
Definition: TGeoManager.h:44
TGeoManager::MakeTube
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.
Definition: TGeoManager.cxx:2956
TGeoVolume
Definition: TGeoVolume.h:44