Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 //____________________________________________________________________________
19 void csgdemo ()
20 {
21  gSystem->Load("libGeom");
22 
23  auto c = new TCanvas("composite shape", "A * B - C");
24  c->Iconify();
25 
26  if (gGeoManager) delete gGeoManager;
27 
28  new TGeoManager("xtru", "poza12");
29  auto mat = new TGeoMaterial("Al", 26.98,13,2.7);
30  auto med = new TGeoMedium("MED",1,mat);
31  auto top = gGeoManager->MakeBox("TOP",med,100,100,100);
32  gGeoManager->SetTopVolume(top);
33 
34  // define shape components with names
35  auto box = new TGeoBBox("box", 20., 20., 20.);
36  auto box1 = new TGeoBBox("box1", 5., 5., 5.);
37  auto sph = new TGeoSphere("sph", 5., 25.);
38  auto sph1 = new TGeoSphere("sph1", 1., 15.);
39  // create the composite shape based on a Boolean expression
40  auto tr = new TGeoTranslation(0., 30., 0.);
41  auto tr1 = new TGeoTranslation(0., 40., 0.);
42  auto tr2 = new TGeoTranslation(0., 30., 0.);
43  auto tr3 = new TGeoTranslation(0., 30., 0.);
44  tr->SetName("tr");
45  tr1->SetName("tr1");
46  tr2->SetName("tr2");
47  tr3->SetName("tr3");
48  // register all used transformations
49  tr->RegisterYourself();
50  tr1->RegisterYourself();
51  tr2->RegisterYourself();
52  tr3->RegisterYourself();
53 
54  TGeoCompositeShape *cs = new TGeoCompositeShape
55  ("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);
64  TEveGeoNode::SetCSGExportNSeg(40);
65 
66  TGLFaceSet::SetEnforceTriangles(kTRUE);
67  TEveManager::Create();
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 }