OpenGATE / opengate

Gate 10 (beta)
http://www.opengatecollaboration.org
GNU Lesser General Public License v3.0
43 stars 38 forks source link

Restructure engines #309

Closed nkrah closed 9 months ago

nkrah commented 9 months ago

The main purpose of this PR is to move subprocess handling to the Simulation class. Parts of the SimulationEngine can then be simplified. Ideally, the PR will also implement other operations in the Simulation class which require some degree of G4 initialization, e.g. geometry-only visualization.

nkrah commented 9 months ago

DO NOT MERGE YET! still adding some features

nkrah commented 9 months ago

This PR restructures the engines to disentangle simulation engine runs (and related operations), context handling, and sub processing. In particular:

In other words:

nkrah commented 9 months ago

The PR also implements Simulation.voxelize_geometry() which replaces a utility function previously implemented in opengate.image. Simulation.voxelize_geometry() correctly handles the simulation engine necessary for the voxelization and runs the voxelization in a subprocess. The subprocess is necessary because the user could otherwise not run multiple voxelizations in one script because the previously created G4 UISession instances would collide with those of the subsequent engine. This does not happen if voxelization is capsulated within a subprocess.

The new implementation of Simulation.voxelize_geometry() is flexible in terms of the extent within the world to be voxelized. It can either be a tuple of two points in space (3-vectors) specifying the opposite corners of the box to be voxelized. Or it can be a volume or list volumes whose bounding box is used to determine the box to be voxelized. The PR corrects a bug here, namely that the volumes translation was previously not taken into account. Finally, the user can specify extent='auto' (the default), which prompts Gate to choose the voxelized box in order to enclose all volumes which are attached to the world (or parallel worlds).

The default spacing is now (3,3,3) to avoid large files and long voxelization times. The user can make this smaller if requested.

Simulation.voxelize_geometry() returns the voxelized image and associated labels, but also write this to disk if the keyword argument filename is provided. Unless filename is an absolute path, it is relative to the simulation's global output directory, specified via 'sim.output_dir'.