The Geant4 boolean processor often fails to compute a resulting mesh. There are other meshing tools available but many suffer from robustness issues. g4cgalboolean uses CGAL mesh boolean and refinement to perform boolean operations. The CGAL license is not compatible with Geant4 license and so is distributed separately from Geant4. If your Geant4 application is compatible with GPL then you are free to distribute g4cgal in accordance with that license.
An virtual base class G4VBooleanProcessor
can be implemented to provide the
boolean processing functionality. In the case of g4cgalboolean
this class is called G4BooleanProcessorCGAL
and Geant4 can be informed to use it via a static method of G4Boolean
so
...
#include "G4BooleanProcessorCGAL.hh"
...
int main(int argc, char** argv) {
G4BooleanSolid::SetExternalBooleanProcessor(new G4BooleanProcessorCGAL());
...
...
NOTE The external processor interface in only available in Geant4 11.2.0 and later
- Copy the
src
andinclude
code over to your geant4 application (G4BooleanProcessorCGAL
,G4SurfaceMeshCGAL
andG4VSurfaceMesh
) - Install CGAL using your package manager
- Add CGAL to your
CMakeLists.txt
see example in github repository - Compile and enjoy