Logo ROOT   6.16/01
Reference Guide
csgdemo.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve
3/// Combinatorial Solid Geometry example
4///
5/// Stripped down to demonstrate EVE shape-extracts.
6/// 1. `Run root csgdemo.C`
7/// This will produce csg.root containing the extract.
8/// 2. Display the assebly as:
9/// `root show_extract.C("csg.root")`
10///
11/// \image html eve_csgdemo.png
12/// \macro_code
13///
14/// \author Andrei Gheata
15
16#include "TSystem.h"
17
18#include "TGeoManager.h"
19#include "TGeoCompositeShape.h"
20#include "TGeoSphere.h"
21
22#include <ROOT/REveManager.hxx>
23#include <ROOT/REveGeoShapeExtract.hxx>
24#include <ROOT/REveGeoShape.hxx>
25#include <ROOT/REveGeoPolyShape.hxx>
26
27R__LOAD_LIBRARY(libGeom);
28
29namespace REX = ROOT::Experimental;
30
31REX::REveGeoPolyShape *eve_pshape = nullptr;
32REX::REveGeoShape *eve_shape = nullptr;
33
34//____________________________________________________________________________
35void csgdemo ()
36{
37 //TCanvas *c = new TCanvas("composite shape", "A * B - C");
38 // c->Iconify();
39
40 if (gGeoManager) delete gGeoManager;
41
42 new TGeoManager("xtru", "poza12");
43 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
44 TGeoMedium *med = new TGeoMedium("MED",1,mat);
45 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
47
48 // define shape components with names
49 TGeoBBox *box = new TGeoBBox("box", 20., 20., 20.);
50 TGeoBBox *box1 = new TGeoBBox("box1", 5., 5., 5.);
51 TGeoSphere *sph = new TGeoSphere("sph", 5., 25.);
52 TGeoSphere *sph1 = new TGeoSphere("sph1", 1., 15.);
53 // create the composite shape based on a Boolean expression
54 TGeoTranslation *tr = new TGeoTranslation(0., 30., 0.);
55 TGeoTranslation *tr1 = new TGeoTranslation(0., 40., 0.);
56 TGeoTranslation *tr2 = new TGeoTranslation(0., 30., 0.);
57 TGeoTranslation *tr3 = new TGeoTranslation(0., 30., 0.);
58 tr->SetName("tr");
59 tr1->SetName("tr1");
60 tr2->SetName("tr2");
61 tr3->SetName("tr3");
62 // register all used transformations
63 tr->RegisterYourself();
64 tr1->RegisterYourself();
65 tr2->RegisterYourself();
66 tr3->RegisterYourself();
67
69 ("mir", "(sph * box) + (sph1:tr - box1:tr1)");
70
71 TGeoVolume *vol = new TGeoVolume("COMP4", cs);
73 top->AddNode(vol,1);
75
76 // To draw original
77 // gGeoManager->SetNsegments(80);
78 // top->Draw("ogl");
79
80 REX::REveManager::Create();
81
82 REX::REveGeoPolyShape::SetAutoEnforceTriangles(true);
83
84 auto node = gGeoManager->GetTopNode();
85 auto geo_cshape = dynamic_cast<TGeoCompositeShape*>(node->GetDaughter(0)->GetVolume()->GetShape());
86
87 if ( ! geo_cshape) throw std::runtime_error("The first vshape is not a CSG shape.");
88
89 bool poly_first = false;
90 if (poly_first)
91 {
92 eve_pshape = REX::REveGeoPolyShape::Construct(geo_cshape, 40);
93
94 eve_shape = new REX::REveGeoShape("CSG_Result");
95 eve_shape->SetShape(eve_pshape);
96 }
97 else
98 {
99 eve_shape = new REX::REveGeoShape("CSG_Result");
100 eve_shape->SetNSegments(40);
101 eve_shape->SetShape(geo_cshape);
102
103 eve_pshape = dynamic_cast<REX::REveGeoPolyShape*>(eve_shape->GetShape());
104 }
105 eve_shape->SetMainColor(kMagenta);
106
107 // If one doesn't enable triangles globally, one can do it on per shape basis:
108 // eve_pshape->EnforceTriangles();
109
110 eve_pshape->Draw("ogl");
111
112 eve_shape->SaveExtract("csg.root", "CSG Demo");
113}
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:471
@ kMagenta
Definition: Rtypes.h:63
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:572
Box class.
Definition: TGeoBBox.h:18
Class handling Boolean composition of shapes.
The manager class for any TGeo geometry.
Definition: TGeoManager.h:39
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.
TGeoNode * GetTopNode() const
Definition: TGeoManager.h:514
Base class describing materials.
Definition: TGeoMaterial.h:31
virtual void RegisterYourself()
Register the matrix in the current manager, which will become the owner.
Definition: TGeoMatrix.cxx:526
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:24
Spherical shell class.
Definition: TGeoSphere.h:18
Class describing translations.
Definition: TGeoMatrix.h:122
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:53
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:984
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
TCppObject_t Construct(TCppType_t type)
Definition: Cppyy.cxx:282