Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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 assembly 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 "TGeoManager.h"
17
18//____________________________________________________________________________
19void csgdemo()
20{
21 gSystem->Load("libGeom");
22
23 auto c = new TCanvas("composite shape", "A * B - C");
24 c->Iconify();
25
26 if (gGeoManager)
27 delete gGeoManager;
28
29 new TGeoManager("xtru", "poza12");
30 auto mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
31 auto med = new TGeoMedium("MED", 1, mat);
32 auto top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
33 gGeoManager->SetTopVolume(top);
34
35 // define shape components with names
36 auto box = new TGeoBBox("box", 20., 20., 20.);
37 auto box1 = new TGeoBBox("box1", 5., 5., 5.);
38 auto sph = new TGeoSphere("sph", 5., 25.);
39 auto sph1 = new TGeoSphere("sph1", 1., 15.);
40 // create the composite shape based on a Boolean expression
41 auto tr = new TGeoTranslation(0., 30., 0.);
42 auto tr1 = new TGeoTranslation(0., 40., 0.);
43 auto tr2 = new TGeoTranslation(0., 30., 0.);
44 auto tr3 = new TGeoTranslation(0., 30., 0.);
45 tr->SetName("tr");
46 tr1->SetName("tr1");
47 tr2->SetName("tr2");
48 tr3->SetName("tr3");
49 // register all used transformations
50 tr->RegisterYourself();
51 tr1->RegisterYourself();
52 tr2->RegisterYourself();
53 tr3->RegisterYourself();
54
55 TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "(sph * box) + (sph1:tr - box1:tr1)");
56
57 auto vol = new TGeoVolume("COMP4", cs);
58 vol->SetLineColor(kMagenta);
59 top->AddNode(vol, 1);
60 gGeoManager->CloseGeometry();
61 top->Draw();
62
63 gGeoManager->SetNsegments(40);
65
68
69 auto node = gGeoManager->GetTopNode();
70 auto en = new TEveGeoTopNode(gGeoManager, node);
71 en->SetVisLevel(4);
72 en->GetNode()->GetVolume()->SetVisibility(kFALSE);
73
74 gEve->AddGlobalElement(en);
75
76 gEve->Redraw3D(kTRUE);
77
78 en->ExpandIntoListTreesRecursively();
79 en->SaveExtract("csg.root", "CSG Demo", kFALSE);
80}
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kMagenta
Definition Rtypes.h:67
externTEveManager * gEve
externTGeoManager * gGeoManager
externTSystem * gSystem
Definition TSystem.h:582
The Canvas class.
Definition TCanvas.h:23
static void SetCSGExportNSeg(Int_t nseg)
Sets number of segments used for CSG export.
A wrapper over a TGeoNode, possibly displaced with a global trasformation stored in TEveElement.
Definition TEveGeoNode.h:90
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
static void SetEnforceTriangles(Bool_t e)
Set state of static flag EnforceTriangles.
Composite shapes are Boolean combinations of two or more shape components.
The manager class for any TGeo geometry.
Definition TGeoManager.h:46
Base class describing materials.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:23
Class describing translations.
Definition TGeoMatrix.h:117
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1