Skip to content

Commit

Permalink
Added code to check if any solids are subtraction solids. Hide these …
Browse files Browse the repository at this point in the history
…volumes from visualization (NOT deleting anything)
  • Loading branch information
ggalgoczi committed Oct 15, 2024
1 parent daa3e05 commit f05cc8c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/g4app.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <filesystem>

Check notice on line 1 in src/g4app.h

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/g4app.h

File src/g4app.h does not conform to Microsoft style guidelines. (lines 3, 34, 37, 43, 47, 50, 51, 76, 78, 80, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 96, 97, 98, 99, 100)

#include "G4BooleanSolid.hh"
#include "G4SubtractionSolid.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4Event.hh"
#include "G4GDMLParser.hh"
#include "G4OpBoundaryProcess.hh"
Expand Down Expand Up @@ -30,6 +33,32 @@
#include "U4/U4Touchable.h"
#include "U4/U4Track.h"


bool IsSubtractionSolid(G4VSolid* solid)
{
if (!solid)
return false;

// Check if the solid is directly a G4SubtractionSolid
if (dynamic_cast<G4SubtractionSolid*>(solid))
return true;

// If the solid is a Boolean solid, check its constituent solids
G4BooleanSolid* booleanSolid = dynamic_cast<G4BooleanSolid*>(solid);
if (booleanSolid)
{
G4VSolid* solidA = booleanSolid->GetConstituentSolid(0);
G4VSolid* solidB = booleanSolid->GetConstituentSolid(1);

// Recursively check the constituent solids
if (IsSubtractionSolid(solidA) || IsSubtractionSolid(solidB))
return true;
}

// For other solid types, return false
return false;
}

struct DetectorConstruction : G4VUserDetectorConstruction
{

Expand All @@ -46,6 +75,30 @@ struct DetectorConstruction : G4VUserDetectorConstruction

G4CXOpticks::SetGeometry(world);

G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();

static G4VisAttributes invisibleVisAttr(false);

// Check if the store is not empty
if (lvStore && !lvStore->empty())
{
// Iterate over all logical volumes in the store
for (auto& logicalVolume : *lvStore)
{
G4VSolid* solid = logicalVolume->GetSolid();

// Check if the solid uses subtraction
if (IsSubtractionSolid(solid))
{
// Assign the invisible visual attributes to the logical volume
logicalVolume->SetVisAttributes(&invisibleVisAttr);

// Optionally, print out the name of the logical volume
G4cout << "Hiding logical volume: " << logicalVolume->GetName() << G4endl;
}
}
}

return world;
}

Expand Down

0 comments on commit f05cc8c

Please sign in to comment.