Scoring mesh visualization best practice


I was wondering if anyone knows about an established workflow for overlaying a scoring mesh with a visualization of the geometry.

My current attempt is using Python to plot a 2D projection of the mesh for a given value of the third bin/coordinate x3. Now I would like to create the corresponding orthographic projection of the geometry in Geant4 using e.g. the OpenGL visualizer. My idea was to add two cutaway planes at x3-d and x3+d but there seems to be a problem when adding two parallel cutaway planes - I’m not able to create my “slice” of the geometry around x3, instead the complete geometry is displayed (possible bug?)

Any suggestions? Other visualizers? VRML export? Solutions, also including third-party software, would be highly appreciated.


Mmm. Have yet to get my head round exactly what you want, but…using parallel cutaway planes shouldn’t be a problem, but they will (a) have to point in opposite directions and (b) point in the correct opposite directions - cutting away the outward stuff, otherwise you will be cutting away everything. If this problem persists please let us know and I’ll look into it.


Hi John

I tried something like:

/control/alias projX 0
/control/subtract projX_M {projX} 100 
/control/add projX_P {projX} 100 
/vis/viewer/addCutawayPlane {projX_M} 0 0 mm 1 0 0   # cuts way x < -100 
/vis/viewer/addCutawayPlane {projX_P} 0 0 mm -1 0 0  # cuts away x > 100

I attached some screenshots depening on whether the two last lines are commented or not. Basically I just want to keep the geometry for -100 < x < 100. Having both lines active does not seem to produce this slice I’m interested in (see cut_both.png).

What am I missing? Thanks for having a look!


export to vrml, convert mesh to hdf5 with geometry information (e.g., Matlab 3D array to ParaView (via HDF5 + XDMF) - File Exchange - MATLAB Central)
and visualize in ParaView

edit: makes me wonder, is there a way to directly export scoring meshes to for example as hdf5 in that context? i.e., including the geometric info in order to visualize/analyze externally, without having to manually carry the configuration parameters during construction of the mesh?

Thanks for the input! I had a look at ParaView yesterday, looks interesting. I’m using a customized ScoreWriter that writes the complete mesh information (binning, axis ranges, etc.) into a header. I then use a Python script to create a CSV file for ParaView. As you suggested, I can then load the VRML geometry model to be displayed along with the mesh.

To get a slice you have to

  /vis/viewer/set/cutawayMode intersection


Great! Many thanks, John

Hi John - a quick follow up question:
According to the manual, the cutaway feature is available for all drivers yet it does not seem to work with the ToolsSG drivers. Is this work in progress?

Hi Dominik

What version of Geant4 are you using? We implemented a generic algorithm in 11.1, so it should be available in all drivers. Let us know if it works for you.

Cheers, John.

Hi John

I was using 11.01, now just updated to 11.1.1. I forgot to mention that I would like to create a PNG using the TOOLSSG_OFFSCREEN driver. Unfortunately the cutaway features still does not seem to work, I still see the whole geometry:

/vis/tsg/offscreen/set/size 1400 1400
/vis/tsg/offscreen/set/file out.png
/vis/viewer/set/cutawayMode intersection
/vis/viewer/addCutawayPlane 0 1050 0 mm 0 1 0
/vis/viewer/addCutawayPlane 0 950 0 mm 0 -1 0

It’s working fine using the OpenGL driver. Am I missing something?


reversing the signs of the normal works for me edit: but also only in Qt

/vis/viewer/addCutawayPlane 0 1050 0 mm 0 -1 0
/vis/viewer/addCutawayPlane 0 950 0 mm 0 1 0

Sorry, I mixed up the signs when writing the example macro in the post - I’m not using an actual macro but code via UImanager->ApplyCommand(). I’m using the correct normals…

Mmm. You’re right, Dominik. At the moment I’m treating this as a bug in the generic cutaway algorithm, G4VSceneHandler::CreateCutawaySolid…or in G4PhysicalVolumeModel::DescribeSolid. Feel free to help debug it. I’m going to try to contact the original author. I’ll get to it myself hopefully later today.

So…apologies, and hoping we can fix this.


1 Like

Curiously, /vis/viewer/set/sectionPlane seems to work fine. Try

/vis/viewer/set/sectionPlane on 0 0 0 cm 1 0 0

Is this something that you can use?

I should really read the manual more carefully, sectionPlane was basically what I have been looking for. This works also with the TOOLSSG_OFFSCREEN driver, many thanks John!

I would be great though if the cutaway issue could be fixed at some point as it allows a more fine grained control over the “thickness” of the slice (I’m happy to test possible fixes and I will try to have a look myself) Also, in my case the sectionPlane produces a lot of warnings of the sort:

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : GeomMgt0001
      issued by : G4IntersectionSolid::BoundingLimits()
Bad bounding box (min >= max) for solid: sectioned_solid !
pMin = (5136.34,-19.05,-42.5)
pMax = (19.05,19.05,42.5)
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

    *** Dump for Boolean solid - sectioned_solid ***
 Solid type: G4IntersectionSolid
 Parameters of constituent solids: 
    *** Dump for solid - th_colli ***
Solid type: G4Box
   half length X: 19.05 mm 
   half length Y: 19.05 mm 
   half length Z: 42.5 mm 
    *** Dump for Displaced solid - placedB ***
 Solid type: G4DisplacedSolid
 Parameters of constituent solid: 
    *** Dump for solid - _sectioner ***
Solid type: G4Box
   half length X: 10828.20391385386 mm 
   half length Y: 10828.20391385386 mm 
   half length Z: 0.1082820391385386 mm 
    Direct transformation - translation : 
                          - rotation    : 
   [ ( -6.12323e-17             0            -1)
     (           0            -1             0)
     (          -1             0   6.12323e-17) ]


Hi Dominik

We have a fix for generic cutaway. I attach a diff file for Geant4 11.1.p1. Please give it a try.


CutawayFixOn11.1.1.diff.txt (2.8 KB)

Hi there
It seems that the generic cutaway does not works for cutting with parallel planes, but hopefully john’s diff works fine. I ran exampleb1 (with Qt3D) with the following macro:

/vis/viewer/set/cutawayMode intersection # union
/vis/viewer/addCutawayPlane 0 0 0 cm 0 1 0
/vis/viewer/addCutawayPlane 0 5 0 cm 0 -1 0

I also tested none-parallel cases and it is clear that the changes works.

Thanx Dominik for meticulous point.

Hi John

Brilliant, the patch seems to be working fine. I’ve tested on-screen OpenGL, OpenGL to PDF export and TOOLSSG_OFFSCREEN to PNG.

Many thanks