OpenGATE / Gate

Official public repository of Gate
http://www.opengatecollaboration.org
GNU Lesser General Public License v3.0
236 stars 263 forks source link

Visualisation bug with Geant4 v11 #511

Open tbaudier opened 2 years ago

tbaudier commented 2 years ago

Describe the bug With Geant4 v11, the visualisation is not correct: eg: the world wireframes are not display

Desktop (please complete the following information):

Minimal example main.mac:

## visu
/vis/open                     OGLI
/vis/drawVolume
/vis/viewer/flush
/tracking/storeTrajectory     1
/vis/scene/add/trajectories
/vis/scene/endOfEventAction   accumulate

/vis/scene/add/axes            0 0 0 500 mm
/vis/scene/add/text            10 0 0 cm  20 0 0   X
/vis/scene/add/text            0 10 0 cm  20 0 0   Y
/vis/scene/add/text            0 0 10 cm  20 0 0   Z

## verbose
/control/verbose 0
/run/verbose 0
/event/verbose 0
/tracking/verbose 0
/gate/application/verbose 0
/gate/generator/verbose   0
/gate/source/verbose      0
/gate/random/verbose      0
/gate/output/verbose      0
/gate/verbose Physic      0
/gate/verbose Cuts        1
/gate/verbose SD          0
/gate/verbose Actions     0
/gate/verbose Actor       0
/gate/verbose Step        0
/gate/verbose Error       0
/gate/verbose Warning     0
/gate/verbose Output      0
/gate/verbose Beam        1
/gate/verbose Volume      1
/gate/verbose Image       0
/gate/verbose Geometry    1
/gate/verbose Core        1

## world
/gate/geometry/setMaterialDatabase GateMaterials.db
/gate/world/geometry/setXLength 2 m
/gate/world/geometry/setYLength 2 m
/gate/world/geometry/setZLength 2 m
/gate/world/vis/setColor white
/gate/world/vis/forceWireframe
/gate/world/setMaterial Air

## initialize
/gate/run/initialize

Expected behavior With Geant4 10.7, we can see the world wireframe:

Screenshot 2022-04-20 at 12 58 06

With Geant4 v11.0, we cannot see the wireframe anymore:

Screenshot 2022-04-20 at 13 00 09

Moreover with Geant4 v11.0, we can see a warning:

...
[Core-0] Initialization of geometry

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : modeling0015
      issued by : G4PhysicalVolumeModel::Validate
Attempt to validate a volume that is no longer in the physical volume store.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

WARNING: Model "G4PhysicalVolumeModel world_phys:0 BasePath: TOP" is no longer valid - being removed
  from scene "scene-0"
[Core-0] Initialization of physics
...

Additional context It seems the bug come from that function in Geant4: https://github.com/Geant4/geant4/blob/master/source/visualization/modeling/src/G4PhysicalVolumeModel.cc#L835

With Geant4 v11, this part of the code is new https://github.com/Geant4/geant4/blob/v11.0.0/source/visualization/modeling/src/G4PhysicalVolumeModel.cc#L837-L854 Before, with Geant4 v10.7, it was that part of the code that was used: https://github.com/Geant4/geant4/blob/v10.7.3/source/visualization/modeling/src/G4PhysicalVolumeModel.cc#L792-L841

Maybe the world is not added to G4PhysicalVolumeStore

tbaudier commented 2 years ago

To complete, I found that the pointer in Geant4 "fpTopPV" is initialized in Gate and deleted and created again in Gate when you execute "/gate/run/initialize" here without be updated in Geant4.

A workaroud is to write the visualization part after "/gate/run/initialize" in the macro. For example: main.mac:

## verbose
/control/verbose 0
/run/verbose 0
/event/verbose 0
/tracking/verbose 0
/gate/application/verbose 0
/gate/generator/verbose   0
/gate/source/verbose      0
/gate/random/verbose      0
/gate/output/verbose      0
/gate/verbose Physic      0
/gate/verbose Cuts        1
/gate/verbose SD          0
/gate/verbose Actions     0
/gate/verbose Actor       0
/gate/verbose Step        0
/gate/verbose Error       0
/gate/verbose Warning     0
/gate/verbose Output      0
/gate/verbose Beam        1
/gate/verbose Volume      1
/gate/verbose Image       0
/gate/verbose Geometry    1
/gate/verbose Core        1

## world
/gate/geometry/setMaterialDatabase GateMaterials.db
/gate/world/geometry/setXLength 2 m
/gate/world/geometry/setYLength 2 m
/gate/world/geometry/setZLength 2 m
/gate/world/vis/setColor white
/gate/world/vis/forceWireframe
/gate/world/setMaterial Air

## initialize
/gate/run/initialize

## visu
/vis/open                     OGLI
/vis/drawVolume
/vis/viewer/flush
/tracking/storeTrajectory     1
/vis/scene/add/trajectories
/vis/scene/endOfEventAction   accumulate

/vis/scene/add/axes            0 0 0 500 mm
/vis/scene/add/text            10 0 0 cm  20 0 0   X
/vis/scene/add/text            0 10 0 cm  20 0 0   Y
/vis/scene/add/text            0 0 10 cm  20 0 0   Z
dsarrut commented 2 years ago

Visu must be after initialize

tbaudier commented 2 years ago

The bug still exist with CT image. But with visu before initialize and without the axis:

#/vis/scene/add/axes            0 0 0 500 mm
#/vis/scene/add/text            10 0 0 cm  20 0 0   X
#/vis/scene/add/text            0 10 0 cm  20 0 0   Y
#/vis/scene/add/text            0 0 10 cm  20 0 0   Z

Everything works