Contents Previous Next Geant4 User's Guide
For Application Developers
Visualization
8.4 Controlling Visualization from Commands



This section describes just a few of the more commonly used visualization commands. For the complete list of commands and options, see the Control...UICommands section of this user guide.

For simplicity, this section assumes that the Geant4 executable was compiled incorporating the DAWNFILE and the OpenGL-Xlib drivers. For details on creating an executable for visualization see Section 8.2 .

8.4.1 Scene, scene handler, and viewer

In using the visualization commands, it is useful to know the concept of "scene", "scene handler", and "viewer". A "scene" is a set of visualizable raw 3D data. A "scene handler" is a graphics-data modeler, which processes raw data in a scene for later visualization. And a "viewer" generates images based on data processed by a scene handler. Roughly speaking, a set of a scene handler and a viewer corresponds to a visualization driver.

The steps of performing Geant4 visualization are explained below, though some of these steps may be done for you so that in practice you may use as few as just two commands (such as /vis/open OGLIX plus /vis/drawVolume) The seven steps of visualization are: :

Step 1. Create a scene handler and a viewer.
Step 2. Create an empty scene.
Step 3. Add raw 3D data to the created scene.
Step 4. Attach the current scene handler to the current scene.
Step 5. Set camera parameters, drawing style (wireframe/surface), etc.
Step 6. Make the viewer execute visualization.
Step 7. Declare the end of visualization for flushing.

These seven steps can be controlled explicitly to create multiple scenes and multiple viewers, each with its own set of parameters, with easy switching from one scene to another. But for the most common case of just having one scene and one viewer, many steps are handled implicitly for you.

8.4.2 Create a scene handler and a viewer: /vis/open command

Command "/vis/open" creates a scene handler and a viewer, which corresponds to Step 1.

8.4.3 Create an empty scene: /vis/scene/create command

Command "/vis/scene/create" creates an empty scene, which corresponds to Step 2.

8.4.4 Visualization of a physical volume: /vis/drawVolume command

Command "/vis/drawVolume" adds a physical volume to the scene. It also does some of the other steps, if you haven't done them explicitly. It takes care of steps 2, 3, 4 and 6. Command "/vis/viewer/flush" should follow in order to do the final Step 7.

8.4.5 Visualization of a logical volume: /vis/specify command

Command "/vis/specify" visualizes a logical volume. If allows you to control how much details is shown and whether to show booleans, voxels and readout geometries. It also does some of the other steps, if you haven't done them explicitly. It takes care of steps 2, 3, 4 and 6. Command "/vis/viewer/flush" should follow the command in order to do the final Step 7. For more options, see the Control...UICommands section of this user guide.

8.4.6 Visualization of trajectories: /vis/scene/add/trajectories command

Command "/vis/scene/add/trajectories" adds trajectories to the current scene. Note that this automatically issues "/tracking/storeTrajectory 1" so that trajectories are stored (by default they are not). The visualization is performed with the command "/run/beamOn" unless you have non-default values for /vis/scene/endOfEventAction or /vis/scene/endOfRunAction (described below). For more options, see the Control...UICommands section of this user guide.

8.4.7 Visualization of hits: /vis/scene/add/hits command

Command "/vis/scene/add/hits" adds hits to the current scene, assuming that you have a hit class and that the hits have visualization information. The visualization is performed with the command "/run/beamOn" unless you have non-default values for /vis/scene/endOfEventAction or /vis/scene/endOfRunAction (described above).

8.4.8 HepRep Attributes for Hits

The HepRep file formats, HepRepFile and HepRepXML, attach various attributes to hits such that you can view these attributes, label trajectories by these attributes or make visibility cuts based on these attributes. Examples of adding HepRep attributes to hit classes can be found in examples /extended/analysis/A01 and /extended/runAndEvent/RE01.

For example, in example RE01's class RE01CalorimeterHit.cc, available attributes will be:

You can add additional attributes of your choosing by modifying the relevant part of the hit class (look for the methods GetAttDefs and CreateAttValues).

8.4.9 Basic camera workings: /vis/viewer/ commands

Commands in the command directory "/vis/viewer/" set camera parameters and drawing style of the current viewer, which corresponds to Step 5. Note that the camera parameters and the drawing style should be set separately for each viewer. They can be initialized to the default values with command "/vis/viewer/reset". Some visualization systems, such as the VRML and HepRep browsers also allow camera control from the standalone graphics application.

Just a few of the camera commands are described here. For more commands, see the Control...UICommands section of this user guide.




8.4.10 Declare the end of visualization for flushing: /vis/viewer/flush command

8.4.11 End of Event Action and End of Run Action: /vis/viewer/endOfEventAction and /vis/viewer/endOfEventAction commands

By default, a separate picture is created for each event. You can change this behavior to accumulate multiple events, or even multiple runs, in a single picture.

8.4.12 HepRep Attributes for Trajectories

The HepRep file formats, HepRepFile and HepRepXML, attach various attributes to trajectories such that you can view these attributes, label trajectories by these attributes or make visibility cuts based on these attributes. If you use the default Geant4 trajectory class, from /tracking/src/G4Trajectory.cc, available attributes will be: You can add additional attributes of your choosing by modifying the relevant part of G4Trajectory (look for the methods GetAttDefs and CreateAttValues). If you are using your own trajectory class, you may want to consider copying these methods from G4Trajectory.

8.4.13 How to save a visualized views to PostScript files

Most of the visualization drivers offer ways to save visualized views to PostScript files (or Encapsulated PostScript (EPS) files) by themselves.

The DAWNFILE driver, which co-works with Fukui Renderer DAWN, generates "vectorized" PostScript data with "analytical hidden-line/surface removal", and so it is well suited for technical high-quality outputs for presentation, documentation, and debugging geometry. In the default setting of the DAWNFILE drivers, EPS files named "g4_00.eps, g4_01.eps, g4_02.eps,..." are automatically generated in the current directory each time when visualization is performed, and then a PostScript viewer "gv"is automatically invoked to visualize the generated EPS files.

For large data sets, it may take time to generate the vectorized PostScript data. In such a case, visualize the 3D scene with a faster visualization driver beforehand for previewing, and then use the DAWNFILE drivers. For example, the following visualizes the whole detector with the OpenGL-Xlib driver (immediate mode) first, and then with the DAWNFILE driver to generate an EPS file g4_XX.eps to save the visualized view:

# Invoke the OpenGL visualization driver in its immediate mode
/vis/open OGLIX 

# Camera setting
/vis/viewer/set/viewpointThetaPhi 20 20

# Camera setting
/vis/drawVolume 
/vis/viewer/flush

# Invoke the DAWNFILE visualization driver 
/vis/open DAWNFILE

# Camera setting
/vis/viewer/set/viewpointThetaPhi 20 20

# Camera setting
/vis/drawVolume 
/vis/viewer/flush
This is a good example to show that the visualization drivers are complementary to each other.

In the OpenInventor drivers , you can simply click the "Print" button on their GUI to generate a PostScript file as a hard copy of a visualized view.

The OpenGL-Motif driver also has a menu to generate PostScript files. It can generate either vectorized or rasterized PostScript data. In generating vectorized PostScript data, hidden-surface removal is performed, based on the painter's algorithm after dividing facets of shapes into small sub-triangles.

The WIRED3 HepRep Browser and WIRED4 JAS Plug-In can generate a wide variety of bitmap and vector output formats including PostScript and PDF.

8.4.14 Culling

"Culling" means to skip visualizing parts of a 3D scene. Culling is useful for avoiding complexity of visualized views, keeping transparent features of the 3D scene, and for quick visualization.

Geant4 Visualization supports the following 3 kinds of culling:

In order that one or all types of the above culling are on, i.e., activated, the global culling flag should also be on.

Table 8.4.1 summarizes the default culling policies.

Culling Type Default Value
global ON
invisible ON
low density OFF
covered daughter OFF
Table 8.4.1
The default culling policies.

The default threshold density of the low-density culling is 0.01 g/cm3.

The default culling policies can be modified with the following visualization commands. (Below the argument flag takes a value of true or false.)

     # global
     /vis/viewer/set/culling  global  flag

     # invisible
     /vis/viewer/set/culling  invisible  flag

     # low density
     #   "value" is a proper value of a treshold density
     #   "unit" is either g/cm3, mg/cm3 or kg/m3
     /vis/viewer/set/culling  density  flag  value  unit 

     # covered daughter
     /vis/viewer/set/culling  coveredDaughters  flag     density
 

The HepRepFile graphic system will, by default, include culled objects in the file so that they can still be made visible later from controls in the HepRep browser. If this behavior would cause files to be too large, you can instead choose to have culled objects be omitted from the HepRep file. See details in the HepRepFile Driver section of this user guide.

8.4.15 Cut view

Sectioning

"Sectioning" means to make a thin slice of a 3D scene around a given plane. At present, this function is supported by the OpenGL drivers. The sectioning is realized by setting a sectioning plane before performing visualization. The sectioning plane can be set by the command,
     /vis/viewer/set/sectionPlane on x y z units nx ny nz
 
where the vector (x,y,z) defines a point on the sectioning plane, and the vector (nx,ny,nz) defines the normal vector of the sectioning plane. For example, the following sets a sectioning plane to a yz plane at x = 2 cm:
     Idle> /vis/viewer/set/sectionPlane  on  2.0  0.0  0.0  cm  1.0  0.0  0.0
 

Cutting away

"Cutting away" means to remove a half space, defined with a plane, from a 3D scene.


8.4.16 Tutorial macros

The followings are tutorial macros in the directory examples/novice/N03/visTutor/:
Next section
Back to contents