Combinatorial Solid Geometry example.
Stripped down to demonstrate EVE shape-extracts.
TCanvas *create_canvas(
const char *title,
bool divide =
true)
{
auto c = (
TCanvas *)
gROOT->GetListOfCanvases()->FindObject(
"csg_canvas");
} else {
c =
new TCanvas(
"csg_canvas", title, 700, 1000);
}
if (divide) {
gPad->SetPad(0, 0, 1, 0.4);
gPad->SetPad(0, 0.4, 1, 1);
}
}
void MakePicture()
{
if (is_raytracing != raytracing) {
gGeoManager->GetTopVolume()->SetVisRaytrace(raytracing);
}
}
void s_union()
{
auto c = create_canvas(
"Union boolean operation");
MakePicture();
TText *
text =
pt->AddText(
"TGeoCompositeShape - composite shape class");
pt->AddText(
"----- It's an example of boolean union operation : A + B");
pt->AddText(
"----- A == part of sphere (5-175, 0-340), B == pgon");
pt->SetAllWith(
"-----",
"color", 4);
pt->SetAllWith(
"-----",
"font", 72);
pt->SetAllWith(
"-----",
"size", 0.04);
}
void s_intersection()
{
auto c = create_canvas(
"Intersection boolean operation");
MakePicture();
TText *
text =
pt->AddText(
"TGeoCompositeShape - composite shape class");
pt->AddText(
"----- Here is an example of boolean intersection operation : A * B");
pt->AddText(
"----- A == sphere (with inner radius non-zero), B == box");
pt->SetAllWith(
"-----",
"color", 4);
pt->SetAllWith(
"-----",
"font", 72);
pt->SetAllWith(
"-----",
"size", 0.04);
}
void s_difference()
{
auto c = create_canvas(
"Difference boolean operation");
MakePicture();
TText *
text =
pt->AddText(
"TGeoCompositeShape - composite shape class");
pt->AddText(
"----- It's an example of boolean difference: A - B");
pt->AddText(
"----- A == part of sphere (0-180, 0-270), B == partial torus (45-145)");
pt->SetAllWith(
"-----",
"color", 4);
pt->SetAllWith(
"-----",
"font", 72);
pt->SetAllWith(
"-----",
"size", 0.04);
}
void s_complex()
{
auto c = create_canvas(
"A * B - C");
MakePicture();
TText *
text =
pt->AddText(
"TGeoCompositeShape - composite shape class");
pt->AddText(
"----- (sphere * box) + (sphere - box) ");
pt->SetAllWith(
"-----",
"color", 4);
pt->SetAllWith(
"-----",
"font", 72);
pt->SetAllWith(
"-----",
"size", 0.04);
}
void raytrace()
{
bool drawn =
gPad->GetListOfPrimitives()->FindObject(top);
if (drawn)
printf("raytrace %d\n", raytracing);
}
}
void help()
{
auto c = create_canvas(
"Help to run demos",
false);
welcome->
AddText(
"Welcome to the new geometry package");
hdemo->
AddText(
"- Demo for building TGeo composite shapes");
hdemo->
AddText(
" .... s_union() : Union boolean operation");
hdemo->
AddText(
" .... s_difference() : Difference boolean operation");
hdemo->
AddText(
" .... s_intersection() : Intersection boolean operation");
hdemo->
AddText(
" .... s_complex() : Combination of (A * B) + (C - D)");
}
void csgdemo()
{
bar->
AddButton(
"How to run ",
"help()",
"Instructions ");
bar->
AddButton(
"Union ",
"s_union()",
"A + B ");
bar->
AddButton(
"Intersection ",
"s_intersection()",
"A * B ");
bar->
AddButton(
"Difference ",
"s_difference()",
"A - B ");
bar->
AddButton(
"Complex composite",
"s_complex()",
"(A * B) + (C - D)");
bar->
AddButton(
"RAY-TRACE ON/OFF",
"raytrace()",
"Toggle ray-tracing mode");
}
bool Bool_t
Boolean (0=false, 1=true) (bool).
externTGeoManager * gGeoManager
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
void Show()
Show control bar.
void AddButton(TControlBarButton *button)
Add button.
void SetVisRaytrace(Bool_t flag=kTRUE)
Composite shapes are Boolean combinations of two or more shape components.
The manager class for any TGeo geometry.
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 ...
virtual void DefineSection(Int_t snum, Double_t z, Double_t rmin, Double_t rmax)
Class describing translations.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
Add a TGeoNode to the list of nodes.
void Draw(Option_t *option="") override
draw top volume according to option
virtual void SetName(const char *name)
Set the name of the TNamed.
void Draw(Option_t *option="") override
Draw this pave with its current attributes.
virtual void SetAllWith(const char *text, Option_t *option, Double_t value)
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)