Logo ROOT  
Reference Guide
visualizeWavefrontObj.C File Reference

Detailed Description

Macro allowing to vizualize tessellations from Wavefront's .obj format.

#include <TROOT.h>
#include <TColor.h>
#include <TDatime.h>
#include <TRandom3.h>
#include <TGeoManager.h>
//______________________________________________________________________________
int randomColor()
{
gRandom = new TRandom3();
TDatime dt;
TColor *color = new TColor(ci, gRandom->Rndm(), gRandom->Rndm(), gRandom->Rndm());
return ci;
}
//______________________________________________________________________________
void visualizeWavefrontObj(const char *dot_obj_file="", bool check = false)
{
// Input a file in .obj format (https://en.wikipedia.org/wiki/Wavefront_.obj_file)
// The file should have a single object inside, only vertex and faces information is used
TString name = dot_obj_file;
TString sfile = dot_obj_file;
if (sfile.IsNull()) {
sfile = gROOT->GetTutorialsDir();
sfile += "/geom/teddy.obj";
}
name.ReplaceAll(".obj", "");
gROOT->GetListOfCanvases()->Delete();
delete gGeoManager;
new TGeoManager(name, "Imported from .obj file");
TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
TGeoMedium *med = new TGeoMedium("MED", 1, mat);
TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 10, 10, 10);
auto tsl = TGeoTessellated::ImportFromObjFormat(sfile.Data(), check);
if (!tsl) return;
tsl->ResizeCenter(5.);
TGeoVolume *vol = new TGeoVolume(name, tsl, med);
vol->SetLineColor(randomColor());
vol->SetLineWidth(2);
top->AddNode(vol, 1);
if (!gROOT->IsBatch()) top->Draw("ogl");
}
Author
Andrei Gheata

Definition in file visualizeWavefrontObj.C.

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
gGeoManager
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:602
TString::Data
const char * Data() const
Definition: TString.h:369
TDatime.h
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
TColor::GetFreeColorIndex
static Int_t GetFreeColorIndex()
Static function: Returns a free color index which can be used to define a user custom color.
Definition: TColor.cxx:2002
TGeoVolume::SetLineWidth
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TGeoVolume.cxx:2051
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
TColor.h
TDatime::GetTime
Int_t GetTime() const
Return time in form of 123623 (i.e. 12:36:23)
Definition: TDatime.cxx:259
TString
Definition: TString.h:136
TGeoMaterial
Definition: TGeoMaterial.h:34
TGeoTessellated::ResizeCenter
void ResizeCenter(double maxsize)
Resize and center the shape in a box of size maxsize.
Definition: TGeoTessellated.cxx:607
TROOT.h
TGeoManager::SetTopVolume
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
Definition: TGeoManager.cxx:3397
TColor
Definition: TColor.h:19
TRandom3
Definition: TRandom3.h:27
TGeoVolume::Draw
virtual void Draw(Option_t *option="")
draw top volume according to option
Definition: TGeoVolume.cxx:1146
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TRandom::SetSeed
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:597
TRandom3.h
TRandom::Rndm
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:541
TGeoManager.h
TString::IsNull
Bool_t IsNull() const
Definition: TString.h:407
name
char name[80]
Definition: TGX11.cxx:110
TGeoTessellated::ImportFromObjFormat
static TGeoTessellated * ImportFromObjFormat(const char *objfile, bool check=false, bool verbose=false)
Reader from .obj format.
Definition: TGeoTessellated.cxx:661
TDatime
Definition: TDatime.h:37
TGeoMedium
Definition: TGeoMedium.h:23
TGeoVolume::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TGeoVolume.cxx:2035
TGeoManager
Definition: TGeoManager.h:44
TGeoTessellated.h
TGeoVolume
Definition: TGeoVolume.h:44
gROOT
#define gROOT
Definition: TROOT.h:406