Logo ROOT  
Reference Guide
visualizeWavefrontObj.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_geom
3/// Macro allowing to vizualize tessellations from Wavefront's .obj format.
4///
5/// \macro_code
6///
7/// \author Andrei Gheata
8
9#include <TROOT.h>
10#include <TColor.h>
11#include <TDatime.h>
12#include <TRandom3.h>
13#include <TGeoManager.h>
14#include <TGeoTessellated.h>
15
16//______________________________________________________________________________
17int randomColor()
18{
19 gRandom = new TRandom3();
20 TDatime dt;
21 gRandom->SetSeed(dt.GetTime());
23 TColor *color = new TColor(ci, gRandom->Rndm(), gRandom->Rndm(), gRandom->Rndm());
24 return ci;
25}
26
27//______________________________________________________________________________
28void visualizeWavefrontObj(const char *dot_obj_file="", bool check = false)
29{
30 // Input a file in .obj format (https://en.wikipedia.org/wiki/Wavefront_.obj_file)
31 // The file should have a single object inside, only vertex and faces information is used
32
33 TString name = dot_obj_file;
34 TString sfile = dot_obj_file;
35 if (sfile.IsNull()) {
36 sfile = gROOT->GetTutorialsDir();
37 sfile += "/geom/teddy.obj";
38 }
39 name.ReplaceAll(".obj", "");
40 gROOT->GetListOfCanvases()->Delete();
41 if (gGeoManager)
42 delete gGeoManager;
43 new TGeoManager(name, "Imported from .obj file");
44 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
45 TGeoMedium *med = new TGeoMedium("MED", 1, mat);
46 TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 10, 10, 10);
48
49 auto tsl = TGeoTessellated::ImportFromObjFormat(sfile.Data(), check);
50 if (!tsl) return;
51 tsl->ResizeCenter(5.);
52
53 TGeoVolume *vol = new TGeoVolume(name, tsl, med);
54 vol->SetLineColor(randomColor());
55 vol->SetLineWidth(2);
56 top->AddNode(vol, 1);
58 if (!gROOT->IsBatch()) top->Draw("ogl");
59}
char name[80]
Definition: TGX11.cxx:109
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:600
#define gROOT
Definition: TROOT.h:406
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
The color creation and management class.
Definition: TColor.h:19
static Int_t GetFreeColorIndex()
Static function: Returns a free color index which can be used to define a user custom color.
Definition: TColor.cxx:2005
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
Int_t GetTime() const
Return time in form of 123623 (i.e. 12:36:23)
Definition: TDatime.cxx:258
The manager class for any TGeo geometry.
Definition: TGeoManager.h:43
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.
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
Base class describing materials.
Definition: TGeoMaterial.h:31
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:24
static TGeoTessellated * ImportFromObjFormat(const char *objfile, bool check=false, bool verbose=false)
Reader from .obj format.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:47
virtual void Draw(Option_t *option="")
draw top volume according to option
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
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:931
Random number generator class based on M.
Definition: TRandom3.h:27
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:597
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:541
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
Bool_t IsNull() const
Definition: TString.h:402