Exporting Geometry

Registry and GDML Output

Strictly speaking a registry class to store all of the GDML is not required. As with normal Geant4 given a lv pointer it should possible to form an aggregation hierarchy that contains all necessary objects. Now GDML breaks this as the structure is built up using name tags. For example a placement requires a position. In Geant4 this would just be a pointer to an transformation object, but GDML has two mechanisms to represent this, firstly child nodes of a PhysicalVolume tag or secondly a position define, see below

The registry class is a storage class for a complete GDML file. At the construction stage of almost all objects a registry is required. If the object is added to the registry then it will appear explicitly in the GDML output

GDML Output

To write an GDML file, a pyg4ometry.geant4.registy instance (reg here), must be supplied.

1import pyg4ometry
2w = p4gometry.gdml.Writer()
3w.addDetector(reg)
4w.write('file.gdml')
5# make a quick bdsim job for the one component in a beam line
6w.writeGmadTester('file.gmad', 'file.gdml')

Export scene to paraview/vtk

1import pyg4ometry

Export scene to unity/unreal

The quickest way to get geometry to Unity/Unreal is to use a standard asset format. This takes a vtkRenderer and creates a OBJ file. The vtkRenderer managed within pyg4ometry from the VtkViewer class, once a geometry is created (either from any source) then an OBJ file can be created. Taking the example in pyg4ometry/test/pythonCompoundExamples/

1import pyg4ometry
2r = pyg4ometry.gdml.Reader("./Chamber.gdml")
3l = r.getRegistry().getWorldVolume()
4v = pyg4ometry.visualisation.VtkViewer()
5v.addLogicalVolume(l)
6v.exportOBJScene("Chamber")

obj files are written Chamber.obj and Chamber.mtl.

For a FLUKA file, first it must be converted to Geant4 and then the same process should be followed.

1import pyg4ometry
2r = pyg4ometry.fluka.Reader("./Chamber.inp")
3greg = pyg4ometry.convert.fluka2geant4(r.getRegistry())
4l = greg.getWorldVolume()
5v = pyg4ometry.visualisation.VtkViewer()
6v.addLogicalVolume(l)
7v.exportOBJScene("Chamber")

As the meshing might need to changed for the visualisation application, the parameters for the meshing for each solid might need to changed.

An obj file for an entire experiment does not help with work flows where meshes have to be UV-ed and textured. Tools like Blender and Gaffer can be used for this workload but require meshes for each object and their placement. To enable there is a special writer

1import pyg4ometry
2r = pyg4ometry.gdml.Reader("./Chamber.gdml")
3l = r.getRegistry().getWorldVolume()
4w = pyg4ometry.visualisation.RenderWriter()
5w.addLogicalVolumeRecursive(l)
6w.write("./SphericalChamber")

The directory SphericalChamber contains all the meshes in OBJ format along with an instance file 0_instances.dat which contains a row for each instance of a mesh.