Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
csgdemo.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve7
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>
24#include <ROOT/REveGeoShape.hxx>
26
27namespace REX = ROOT::Experimental;
28
29REX::REveGeoPolyShape *eve_pshape = nullptr;
30REX::REveGeoShape *eve_shape = nullptr;
31
32//____________________________________________________________________________
33void csgdemo()
34{
35 // TCanvas *c = new TCanvas("composite shape", "A * B - C");
36 // c->Iconify();
37
38 if (gGeoManager)
39 delete gGeoManager;
40
41 new TGeoManager("xtru", "poza12");
42 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
43 TGeoMedium *med = new TGeoMedium("MED", 1, mat);
44 TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
46
47 // define shape components with names
48 TGeoBBox *box = new TGeoBBox("box", 20., 20., 20.);
49 TGeoBBox *box1 = new TGeoBBox("box1", 5., 5., 5.);
50 TGeoSphere *sph = new TGeoSphere("sph", 5., 25.);
51 TGeoSphere *sph1 = new TGeoSphere("sph1", 1., 15.);
52 // create the composite shape based on a Boolean expression
53 TGeoTranslation *tr = new TGeoTranslation(0., 30., 0.);
54 TGeoTranslation *tr1 = new TGeoTranslation(0., 40., 0.);
55 TGeoTranslation *tr2 = new TGeoTranslation(0., 30., 0.);
56 TGeoTranslation *tr3 = new TGeoTranslation(0., 30., 0.);
57 tr->SetName("tr");
58 tr1->SetName("tr1");
59 tr2->SetName("tr2");
60 tr3->SetName("tr3");
61 // register all used transformations
62 tr->RegisterYourself();
63 tr1->RegisterYourself();
64 tr2->RegisterYourself();
65 tr3->RegisterYourself();
66
67 auto cs = new TGeoCompositeShape("mir", "(sph * box) + (sph1:tr - box1:tr1)");
68
69 TGeoVolume *vol = new TGeoVolume("COMP4", cs);
71 top->AddNode(vol, 1);
73
74 // To draw original
75 // gGeoManager->SetNsegments(80);
76 // top->Draw("ogl");
77
78 REX::REveManager::Create();
79
80 REX::REveGeoPolyShape::SetAutoEnforceTriangles(true);
81
82 auto node = gGeoManager->GetTopNode();
83 auto geo_cshape = dynamic_cast<TGeoCompositeShape *>(node->GetDaughter(0)->GetVolume()->GetShape());
84
85 if (!geo_cshape)
86 throw std::runtime_error("The first vshape is not a CSG shape.");
87
88 bool poly_first = false;
89 if (poly_first) {
90 eve_pshape = new REX::REveGeoPolyShape;
91 eve_pshape->BuildFromComposite(geo_cshape, 40);
92
93 eve_shape = new REX::REveGeoShape("CSG_Result");
94 eve_shape->SetShape(eve_pshape);
95 } else {
96 eve_shape = new REX::REveGeoShape("CSG_Result");
97 eve_shape->SetNSegments(40);
98 eve_shape->SetShape(geo_cshape);
99
100 eve_pshape = dynamic_cast<REX::REveGeoPolyShape *>(eve_shape->GetShape());
101 }
102 eve_shape->SetMainColor(kMagenta);
103
104 // If one doesn't enable triangles globally, one can do it on per shape basis:
105 // eve_pshape->EnforceTriangles();
106
107 eve_pshape->Draw("ogl");
108
109 eve_shape->SaveExtract("csg.root", "CSG Demo");
110}
@ kMagenta
Definition Rtypes.h:66
R__EXTERN TGeoManager * gGeoManager
void BuildFromComposite(TGeoCompositeShape *cshp, Int_t n_seg=60)
Produce all polygons from composite shape.
void SetNSegments(Int_t s)
Set number of segments.
void SaveExtract(const char *file, const char *name)
Save the shape tree as REveGeoShapeExtract.
void SetShape(TGeoShape *s)
Set TGeoShape shown by this object.
void SetMainColor(Color_t color) override
Set main color.
Definition REveShape.cxx:70
Composite shapes are Boolean combinations of two or more shape components.
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
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
Base class describing materials.
virtual void RegisterYourself()
Register the matrix in the current manager, which will become the owner.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:23
void Draw(Option_t *option="") override
Draw this shape.
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 SetLineColor(Color_t lcolor) override
Set the line color.
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