Skip to content

Commit d94fe26

Browse files
committed
TGeoVGConverter: Introduce shape-type filtering for conversion process
- Added functions 'SelectShapeType()' and 'ExcludeShapeType()'. Conversion is performed only on selected shapes (if set), and excluded shapes are always skipped. - TGeoVGShape: Disabled conversion for problematic edge cases not covered by exclusion: 'TGeoBBox' with shifted origin and 'TGeoScaledShape'.
1 parent 619dfe8 commit d94fe26

File tree

4 files changed

+96
-10
lines changed

4 files changed

+96
-10
lines changed

geom/geom/inc/TVirtualGeoConverter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define ROOT_TVirtualGeoConverter
1313

1414
#include "TObject.h"
15+
#include "TGeoShape.h"
1516

1617
class TGeoManager;
1718

@@ -25,6 +26,8 @@ class TVirtualGeoConverter : public TObject {
2526
~TVirtualGeoConverter() override;
2627

2728
virtual void ConvertGeometry() {}
29+
virtual void SelectShapeType(TGeoShape::EShapeType) {}
30+
virtual void ExcludeShapeType(TGeoShape::EShapeType) {}
2831
static TVirtualGeoConverter *Instance(TGeoManager *geom = nullptr);
2932
static void SetConverter(const TVirtualGeoConverter *conv);
3033
void SetGeometry(TGeoManager *geom) { fGeom = geom; }

geom/vecgeom/inc/TGeoVGConverter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@
2222

2323
#include "TGeoManager.h"
2424

25+
#include <set>
26+
2527
class TGeoVGConverter : public TVirtualGeoConverter {
2628
public:
2729
TGeoVGConverter(TGeoManager *manager);
2830
~TGeoVGConverter() override;
2931

3032
void ConvertGeometry() override;
3133

34+
void SelectShapeType(TGeoShape::EShapeType) override;
35+
void ExcludeShapeType(TGeoShape::EShapeType) override;
36+
37+
std::set<TGeoShape::EShapeType> fSelectedShapeTypes;
38+
std::set<TGeoShape::EShapeType> fExcludedShapeTypes;
39+
3240
ClassDefOverride(TGeoVGConverter, 0) // VecGeom geometry converter
3341
};
3442

geom/vecgeom/src/TGeoVGConverter.cxx

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,34 @@ Geometry converter to VecGeom
1616

1717
#include "TGeoVGConverter.h"
1818
#include "TGeoVGShape.h"
19+
#include "TGeoBBox.h"
20+
#include "TClass.h"
1921

22+
#include <iostream>
23+
24+
namespace {
25+
26+
Bool_t isInSelection(const TGeoShape* shape, const std::set<TGeoShape::EShapeType>& selection) {
27+
for (auto element : selection) {
28+
29+
// Special treatment of TGeo::kGeoBox, which is base class for all other shapes
30+
if (element == TGeoShape::kGeoBox) {
31+
if (typeid(*shape) == typeid(TGeoBBox) ) {
32+
return true;
33+
} else {
34+
continue;
35+
}
36+
}
37+
38+
// Just test bit for other shapes
39+
if (shape->TestShapeBit(element)) {
40+
return true;
41+
}
42+
}
43+
return false;
44+
}
45+
46+
}
2047

2148
////////////////////////////////////////////////////////////////////////////////
2249
/// Default constructor.
@@ -48,14 +75,37 @@ void TGeoVGConverter::ConvertGeometry()
4875
nconverted++;
4976
top->SetShape(vgshape);
5077
}
78+
79+
// Uncomment to print info about selected/excluded shapes
80+
// if ( ! fSelectedShapeTypes.empty()) {
81+
// printf("# %zu selected shape type for conversion \n", fSelectedShapeTypes.size());
82+
// }
83+
// if ( ! fExcludedShapeTypes.empty()) {
84+
// printf("# %zu shape types excluded from conversion \n", fExcludedShapeTypes.size());
85+
// }
86+
5187
// Now iterate the active geometry tree
5288
TGeoIterator next(fGeom->GetTopVolume());
5389
TGeoNode *node;
5490
while ((node = next.Next())) {
5591
TGeoVolume *vol = node->GetVolume();
56-
// If shape not already converted, convert it
92+
// Skip shape if already converted
5793
if (vol->GetShape()->IsVecGeom())
5894
continue;
95+
96+
// If fSelectedShapeTypes is not empty, convert only selected shapes
97+
if ((! fSelectedShapeTypes.empty()) &&
98+
(! isInSelection(vol->GetShape(), fSelectedShapeTypes))) {
99+
printf("# Shape type %s is not selected for conversion\n", vol->GetShape()->IsA()->GetName());
100+
continue;
101+
}
102+
103+
// Skip shapes excluded from conversion
104+
if (isInSelection(vol->GetShape(), fExcludedShapeTypes)) {
105+
printf("# Shape type %s is excluded from conversion\n", vol->GetShape()->IsA()->GetName());
106+
continue;
107+
}
108+
59109
// printf("Converting %s\n", vol->GetName());
60110
vgshape = TGeoVGShape::Create(vol->GetShape());
61111
if (vgshape) {
@@ -65,3 +115,20 @@ void TGeoVGConverter::ConvertGeometry()
65115
}
66116
printf("# Converted %d shapes to VecGeom ones\n", nconverted);
67117
}
118+
119+
////////////////////////////////////////////////////////////////////////////////
120+
/// Select shape(s) for conversion.
121+
/// Conversion is performed only on selected shapes (if set)
122+
123+
void TGeoVGConverter::SelectShapeType(TGeoShape::EShapeType shapeType)
124+
{
125+
fSelectedShapeTypes.insert(shapeType);
126+
}
127+
128+
////////////////////////////////////////////////////////////////////////////////
129+
/// Exclude shape(s) from conversion.
130+
131+
void TGeoVGConverter::ExcludeShapeType(TGeoShape::EShapeType shapeType)
132+
{
133+
fExcludedShapeTypes.insert(shapeType);
134+
}

geom/vecgeom/src/TGeoVGShape.cxx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ vecgeom::cxx::VUnplacedVolume *TGeoVGShape::Convert(TGeoShape const *const shape
138138
// THE BOX
139139
if (shape->IsA() == TGeoBBox::Class()) {
140140
TGeoBBox const *const box = static_cast<TGeoBBox const *>(shape);
141-
unplaced_volume = GeoManager::MakeInstance<UnplacedBox>(box->GetDX(), box->GetDY(), box->GetDZ());
141+
if ((box->GetOrigin()[0] != 0.0) || (box->GetOrigin()[1] != 0.0) || (box->GetOrigin()[2] != 0.0)) {
142+
// skip solids with shifted origin
143+
printf("Unsupported box shape with shifted origin\n");
144+
} else {
145+
unplaced_volume = GeoManager::MakeInstance<UnplacedBox>(box->GetDX(), box->GetDY(), box->GetDZ());
146+
}
142147
}
143148

144149
// THE TUBE
@@ -288,14 +293,17 @@ vecgeom::cxx::VUnplacedVolume *TGeoVGShape::Convert(TGeoShape const *const shape
288293

289294
// THE SCALED SHAPE
290295
if (shape->IsA() == TGeoScaledShape::Class()) {
291-
TGeoScaledShape const *const p = static_cast<TGeoScaledShape const *>(shape);
292-
// First convert the referenced shape
293-
VUnplacedVolume *referenced_shape = Convert(p->GetShape());
294-
if (!referenced_shape)
295-
return nullptr;
296-
const double *scale_root = p->GetScale()->GetScale();
297-
unplaced_volume =
298-
GeoManager::MakeInstance<UnplacedScaledShape>(referenced_shape, scale_root[0], scale_root[1], scale_root[2]);
296+
// TGeoScaledShape const *const p = static_cast<TGeoScaledShape const *>(shape);
297+
// // First convert the referenced shape
298+
// VUnplacedVolume *referenced_shape = Convert(p->GetShape());
299+
// if (!referenced_shape)
300+
// return nullptr;
301+
// const double *scale_root = p->GetScale()->GetScale();
302+
// unplaced_volume =
303+
// GeoManager::MakeInstance<UnplacedScaledShape>(referenced_shape, scale_root[0], scale_root[1], scale_root[2]);
304+
305+
// temporarily skip scaled solids which cannot be excluded via EShapeType selection
306+
printf("Unsupported scaled shape\n");
299307
}
300308

301309
// THE CUT TUBE

0 commit comments

Comments
 (0)