How to set filename of VRML2FILE?

Hello,

is it possible to set the filename of the VRML2FILE visualization driver from within a Geant4 application? At the moment I am only able to get files with the default filename g4_xx.wrl, where xx is an increasing number between 00 and 99.

I am sure, that it would be possible to rename the generated file from within the Geant4 application via the standard file/disc methods of C++, but I would prefer to set the filename directly, if possible.

Thank you,
Steffen

Hi Steffan

The short answer is: no.

But looking at the code in G4VRML2FileSceneHandler.cc, it does seem the author has built in some flexibility using environment variables (for example, you can change the destination directory) but the filename itself seems to be fixed.

You could change

l.66: const char WRL_FILE_HEADER [] = "g4_";

or, if you want to be more flexible, make this change at l.166:

--- a/source/visualization/VRML/src/G4VRML2FileSceneHandler.cc
+++ b/source/visualization/VRML/src/G4VRML2FileSceneHandler.cc
@ -166,2 +166,7 @@ void G4VRML2FileSceneHandler::connectPort()
-               filename
-               << fVRMLFileDestDir << WRL_FILE_HEADER
+         filename << fVRMLFileDestDir;
+         if ( std::getenv( "WRL_FILE_HEADER" ) == NULL ) {
+           filename << WRL_FILE_HEADER;
+         } else {
+           filename << std::getenv( "WRL_FILE_HEADER" );
+         }
+               filename << '_'

and set WRL_FILE_HEADER in your environment.

Let me know if the above is any use to you. I might submit the above change, or something like it, to Geant4 for the next release.

John

Hello John,

thank you for your quick and helpful reply! Your suggested solution is certainly of use for us, however, only if included to the Geant4 code base, since we do not want to patch every new Geant4 realease. So, if you could trigger, that this code is implemented into Geant4 I would really appreciate it.

Ideally it would be good if there is also a messenger command, e.g. /vis/vrml2file/setfilename output.wrl, then a more interactive work-flow would be possible. But the suggested method via the environment varible will do the trick for the moment.

Thank you,
Steffen

Hi Steffen

A patch will go into the next release. Since the VRML drivers already use environment variables I will stick to that method. I introduce two variables: one to change the “header” (as in the code above); and one to change the whole filename. Let me know if you would like a pre-release patch.

John

Thanks John. For the moment it is OK for us to know, that there will be a solution in the next release. In order to spare you any extra effort, I therefore do not need a pre-release patch (unless you want me to test it).

Steffen

Well, since you offer…I attach two cc files. The following augmented message tells you the names of the new environment variables. Thanks. Feedback welcome.
G4VRML2FileSceneHandler.cc (8.4 KB)
G4VRML1FileSceneHandler.cc (8.1 KB)

MESSAGE from VRML2FILE driver:
    Set an environmental variable  G4VRMLFILE_VIEWER
    if you want to visualize the generated VRML file
    automatically.  For example, 
    setenv  G4VRMLFILE_VIEWER  vrweb 
ALSO you may change the file header with G4VRMLFILE_HEADER
    or the whole filename with G4VRMLFILE_FILE_NAME

Tested with geant4.11.00.b01, works as expected. Thanks a lot!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.