8#include <display/EveGeometry.h>
10#include <geometry/GeometryManager.h>
11#include <framework/logging/Logger.h>
12#include <framework/utilities/FileSystem.h>
13#include <framework/utilities/ColorPalette.h>
15#include <TGeoManager.h>
17#include <TEveManager.h>
18#include <TEveGeoNode.h>
19#include <TEveGeoShape.h>
20#include <TEveGeoShapeExtract.h>
29 static TEveGeoTopNode* s_eveTopNode =
nullptr;
30 static TEveGeoShape* s_simplifiedShape =
nullptr;
31 static std::vector<std::string> s_hideVolumes = {};
32 static std::vector<std::string> s_deleteVolumes = {};
33 static std::string s_eveGeometryExtractPath =
"/data/display/geometry_extract.root";
38 B2DEBUG(100,
"Setting up geometry for TEve...");
40 B2FATAL(
"gEve must be set up before EveGeometry!");
48 B2FATAL(
"Couldn't create TGeo geometry! Please make sure you add the Geometry module before Display");
53 gGeoManager->DefaultColors();
64 for (
auto& volume : s_hideVolumes)
67 TGeoNode* top_node = gGeoManager->GetTopNode();
68 assert(top_node != NULL);
69 s_eveTopNode =
new TEveGeoTopNode(gGeoManager, top_node);
70 s_eveTopNode->IncDenyDestroy();
71 s_eveTopNode->SetVisLevel(2);
73 gEve->AddGlobalElement(s_eveTopNode);
76 s_eveTopNode->ExpandIntoListTreesRecursively();
79 B2DEBUG(100,
"Loading geometry projections...");
82 TFile* f = TFile::Open(extractPath.c_str(),
"READ");
83 TEveGeoShapeExtract* gse =
dynamic_cast<TEveGeoShapeExtract*
>(f->Get(
"Extract"));
84 s_simplifiedShape = TEveGeoShape::ImportShapeExtract(gse, 0);
85 s_simplifiedShape->SetRnrSelf(
false);
86 s_simplifiedShape->IncDenyDestroy();
87 s_simplifiedShape->SetName(
"Minimal geometry extract");
92 gEve->AddGlobalElement(s_simplifiedShape);
98 for (
auto& volumeRegExp : s_deleteVolumes) {
103 B2DEBUG(100,
"Done.");
108 TPRegexp reAll(
".*");
109 bool onlyChildren =
false;
110 std::string regexp = pattern;
114 if (pattern.substr(0, 1) == std::string(
"#")) {
115 regexp = pattern.substr(1);
119 TPRegexp reMatch(regexp.c_str());
121 std::list<TEveElement*> children;
122 parent->FindChildren(children, reAll);
124 for (TEveElement* child : children) {
125 if (reMatch.MatchB(child->GetElementName())) {
127 B2INFO(
"Removing children of " << child->GetElementName());
128 child->DestroyElements();
130 B2INFO(
"Removing " << child->GetElementName());
141 bool fullgeo = (visMode ==
c_Full);
143 s_eveTopNode->SetRnrSelfChildren(fullgeo, fullgeo);
144 s_simplifiedShape->SetRnrSelfChildren(
false, !fullgeo);
149 if (!gGeoManager)
return;
150 TGeoVolume* vol = gGeoManager->FindVolumeFast(name);
153 vol->SetVisibility(enable);
154 vol->SetVisDaughters(enable);
156 B2DEBUG(100,
"Volume " << name <<
" not found?");
164 if (!gGeoManager)
return;
165 TGeoVolume* vol = gGeoManager->FindVolumeFast(name);
168 vol->SetLineColor(col);
170 B2DEBUG(100,
"Volume " << name <<
" not found?");
176 if (!gGeoManager)
return;
177 TObjArray* volumes = gGeoManager->GetListOfVolumes();
178 for (
int i = 0; i < volumes->GetEntriesFast(); i++) {
179 TGeoVolume* volume =
static_cast<TGeoVolume*
>(volumes->At(i));
180 volume->SetTransparency(percent);
186 if (gGeoManager && gGeoManager->GetTopNode()) {
187 TGeoVolume* top_node = gGeoManager->GetTopNode()->GetVolume();
188 double p[3] = { 380.0, 0.0, 0.0 };
189 while (!top_node->Contains(p)) {
193 }
else if (s_simplifiedShape) {
194 s_simplifiedShape->ComputeBBox();
195 const float* bbox = s_simplifiedShape->GetBBox();
196 return std::min(380.f, std::max({std::abs(bbox[0]), bbox[1], std::abs(bbox[2]), bbox[2]}));
204 TGeoManager* my_tgeomanager = gGeoManager;
206 B2ERROR(
"Couldn't find TEveGeoTopNode");
209 s_eveTopNode->ExpandIntoListTrees();
210 s_eveTopNode->SaveExtract(
"geometry_extract.root",
"Extract",
false);
215 gGeoManager = my_tgeomanager;
220 s_eveGeometryExtractPath = extractPath;
225 s_hideVolumes = volumes;
230 s_deleteVolumes = volumes;
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Class to manage the creation and conversion of the geometry.
static GeometryManager & getInstance()
Return a reference to the instance.
void createTGeoRepresentation()
Create a TGeo representation of the native geometry description.
void setVolumeColor(const char *name, Color_t col)
set fill color of the volume 'name' to 'col'.
void setTransparency(int percent)
Recursively set transparency of geometry (0: opaque, 100: fully transparent).
void disableVolume(const char *name, bool only_daughters=false)
disable rendering of the volume 'name', or only its daughters if only_daughters is set.
void addGeometry(EType visMode)
Add TGeo geometry to Eve (only needs to be done once.)
void setDeleteVolumes(const std::vector< std::string > &volumes)
List of volumes to be removed.
void setVisualisationMode(EType visMode)
switch to given visualisation mode.
void enableVolume(const char *name, bool only_daughters=false, bool enable=true)
enable/disable rendering of the volume 'name', or only its daughters if only_daughters is set.
void setCustomExtractPath(const std::string &extractPath)
Set custom path to the geometry extract (to change originally hard-coded value)
void setHideVolumes(const std::vector< std::string > &volumes)
List of volumes to be hidden (can be re-enabled in Eve panel / Geometry scene.
void saveExtract()
Save a geometry extract from the current state of the TGeo geometry.
EType
Type of geometry shown.
@ c_Full
Full geometry converted from Geant4 (use this for non-standard Belle II setups!).
void removeChildrenByRegExp(TEveElement *parent, const std::string &pattern)
Recursive removal of volumes based on regular expression pattern.
double getMaxR()
find a point that is inside the top node.
Implements a colour palette, see http://sobac.com/sobac/tangocolors.htm.
int getTColorID(const std::string &tangoName, int tangoId=1)
Get TColor ID for given name in tango colour palette.
Abstract base class for different kinds of events.