SpecialRendering function does not update the viewer (11.01 beta)

It seems that there is a minor issue in the “SpecialRendering” function.

When I use SpecialRendering function to render the tetrahedral mesh to surface mesh, (1) I cannot see its mother volume and more importantly, (2) it does not updates the viewer when I change the tetrahedron vertices (between Runs).

I am not sure if this is only for tetrahedral mesh rendering or for all special rendering functions.

It would be very appreciated it this could be fixed!

1 Like

Dear Haegin

Thnakyou so much for this feedback. I really appreciate it - it finds bugs and leads to improvements.

  1. Yes, I see it. There are several issues:

i) There is a problem with mesh identification in the G4Mesh constructor. It was incorrectly finding the world as a two-deep parameterisation:
G4Mesh:
Container: worldPhysical
Type: tetrahedron
Depth: 2
Translation: (0.000000,0.000000,0.000000)
Rotation:
[ ( 1.000000 0.000000 0.000000)
( 0.000000 1.000000 0.000000)
( 0.000000 0.000000 1.000000) ]

I attach a patch to G4Mesh.cc that should fix it. Now it says:

G4Mesh:
Container: PhantomPhysical
Type: tetrahedron
Depth: 1
Translation: (0.000000,0.000000,0.000000)
Rotation:
[ ( 1.000000 0.000000 0.000000)
( 0.000000 1.000000 0.000000)
( 0.000000 0.000000 1.000000) ]

ii) The PhantomPhysical cannot be drawn on its own. When /vis/viewer/specialMeshRendering is on it is intercepted by the vis manager (actually by G4PhysicalVolumeModel) and passed for special mesh rendering. So "/vis/scene/add/volume PhantomPhysical” does not work.

iii) My proposed solution is to draw it in G4VSceneHandler::StandardSpecialMeshRendering unless the volume is marked invisible.

iv) PhantomPhysical is marked invisible in vis.mac:

/vis/geometry/set/visibility phantomLogical 0 false

Remove this or comment it out.

v) The default is white, so you need

/vis/viewer/set/background black

With all these changes you get the attached image. I have chosen to force wireframe mode - does this make sense?

  1. Mmmm. This is not easy for me to test. When you change geometry you must close the geometry and re-close it. Also notify the vis manager, I believe.
G4GeometryManager* geomMgr = G4GeometryManager::GetInstance();
geomMgr->OpenGeometry();
///////CHANGE YOUR GEOMETRY
geomMgr->CloseGeometry();
// Notify the VisManager as well
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
if (pVVisManager) pVVisManager->GeometryHasChanged();

Note one can close and open just a subtree. Also choose to optimise or not. See function prototypes in G4GeometryManager.hh.

But…there is a further issue that is particular to special mesh rendering - once established the map of G4Polyhedron objects once create, as things stand, cannot be changed. This is the code in G4VScenehandler.cc:

// This map is static so that once filled it stays filled.

static std::map<G4String,std::map<**const** G4Material*,G4Polyhedron>> surfacesByMaterialAndMesh;
auto& surfacesByMaterial = surfacesByMaterialAndMesh[mesh.GetContainerVolume()->GetName()];
// Fill map if not already filled
if (surfacesByMaterial.empty()) { // Fill it

I wrote it this way to speed redrawing. I did not imagine anyone would want to change the geometry. What is your use case? Of course, it can be changed, perhaps to respect GeometryHasChanged(). Let me know what you think and I can do this.

To get the polyhedron map to re-build you could simply remove the keyword “static” on line 1716. Let me know if this helps.

Again, thankyou for your feedback. Please try the attached versions.

John

G4Mesh.cc (7.0 KB)
G4VSceneHandler.cc (65.6 KB)

Dear John,

Thank you for your quick reply.
I often update the mesh geometry, because my research subject is about 4D dose calculation with animated phantoms.
I have tested my code by replacing the G4Mesh and G4VSceneHandler codes with the files you have attached, and it worked perfectly, although, as you already mentioned, it was a bit slower than before.


Phantom box also well appeared!

Thank you very much for your help!!

Best wishes,
Haegin

That’s great. I’ll get in touch with you offline for more discussions.

John

1 Like