<!-- ******************************************************** -->
<!--                                                          -->
<!--  [History]                                               -->
<!--    Proof read by: Joe Chuma,  6-Jul-1999                 -->
<!--    Changed by: Katsuya Amako, 15-Jul-2000                -->
<!--    Changed by: Dennis Wright, 27-Nov-2001                -->
<!--    Converted to DocBook: Katsuya Amako, Aug-2006         -->
<!--    Corrected Get methods: Joseph Perl, 17-Mar-2009       -->
<!--                                                          -->
<!-- ******************************************************** -->


<!-- ******************* Section (Level#1) ****************** -->
<sect1 id="sect.VisCntCmpl">
<title>
Controlling Visualization from Compiled Code
</title>


<para>
While a Geant4 simulation is running, visualization can be
performed without user intervention. This is accomplished by
calling methods of the Visualization Manager from methods of the
user action classes (<emphasis>G4UserRunAction</emphasis> and
<emphasis>G4UserEventAction</emphasis>, for example). In this section methods of
the class <emphasis>G4VVisManager</emphasis>, which is part of the
<literal>graphics_reps</literal> category, are described and examples of
their use are given.
</para>

<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.VsMng">
<title>
G4VVisManager
</title>

<para>
The Visualization Manager is implemented by classes
<emphasis>G4VisManager</emphasis> and <emphasis>G4VisExecutive</emphasis>. 
See <xref linkend="sect.VisAddExe" />
"<emphasis role="bold">Making a Visualization Executable</emphasis>". In order 
that your Geant4 be compilable either with or without the visualization
category, you should not use these classes directly in your C++
source code, other than in the <literal>main()</literal> function. Instead,
you should use their abstract base class <emphasis>G4VVisManager</emphasis>,
defined in the <literal>intercoms</literal> category.
</para>

<para>
The pointer to the concrete instance of the real Visualization
Manager can be obtained as follows:

<informalexample>
<programlisting>
  //----- Getting a pointer to the concrete Visualization Manager instance
  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
</programlisting>
</informalexample> 
</para>

<para>
The method <literal>G4VVisManager::GetConcreteInstance()</literal> returns
<literal>NULL</literal> if Geant4 is not ready for visualization. Thus your
C++ source code should be protected as follows:

<informalexample>
<programlisting>
  //----- How to protect your C++ source codes in visualization
  if (pVVisManager) { 
      ....
      pVVisManager -&gt;Draw (...); 
      ....
  }
</programlisting>
</informalexample> 
</para>

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.DtcCmp">
<title>
Visualization of detector components
</title>

<para>
If you have already constructed detector components with logical
volumes to which visualization attributes are properly assigned,
you are almost ready for visualizing detector components. All you
have to do is to describe proper visualization commands within your
C++ codes, using the <literal>ApplyCommand()</literal> method.
</para>

<para>
For example, the following is sample C++ source codes to
visualize the detector components:

<informalexample>
<programlisting>
  //----- C++ source code: How to visualize detector components (2)
  //                       ... using visualization commands in source codes
  
  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance() ;

  if(pVVisManager)
  {
      ... (camera setting etc) ...
      G4UImanager::GetUIpointer()-&gt;ApplyCommand("/vis/drawVolume");
      G4UImanager::GetUIpointer()-&gt;ApplyCommand("/vis/viewer/flush");
  }

  //-----  end of C++ source code
 
</programlisting>
</informalexample>
</para>

<para>
In the above, you should also describe <literal>/vis/open</literal> command
somewhere in your C++ codes or execute the command from (G)UI at
the executing stage.
</para>

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.Trjct">
<title>
Visualization of trajectories
</title>

<para>
In order to visualize trajectories, you can use the method <literal>void
G4Trajectory::DrawTrajectory()</literal> defined in the tracking
category. In the implementation of this method, the following
drawing method of <emphasis>G4VVisManager</emphasis> is used:

<informalexample>
<programlisting>
    //----- A drawing method of G4Polyline
    virtual void G4VVisManager::Draw (const G4Polyline&amp;, ...) ;
</programlisting>
</informalexample>
</para>

<para>
The real implementation of this method is described in the class
<emphasis>G4VisManager</emphasis>.
</para>

<para>
At the end of one event, a set of trajectories can be stored as
a list of <emphasis>G4Trajectory</emphasis> objects. Therefore you can visualize
trajectories, for example, at the end of each event, by
implementing the method <literal>MyEventAction::EndOfEventAction()</literal>
as follows:

<informalexample>
<programlisting>
  //----- C++ source codes 
  void ExN03EventAction::EndOfEventAction(const G4Event* evt)
  {
    .....  
    // extract the trajectories and draw them
    if (G4VVisManager::GetConcreteInstance())
      {
       G4TrajectoryContainer* trajectoryContainer = evt-&gt;GetTrajectoryContainer();
       G4int n_trajectories = 0;
       if (trajectoryContainer) n_trajectories = trajectoryContainer-&gt;entries();
  
       for (G4int i=0; i &lt; n_trajectories; i++) 
          { G4Trajectory* trj=(G4Trajectory*)((*(evt-&gt;GetTrajectoryContainer()))[i]);
            if (drawFlag == "all") trj-&gt;DrawTrajectory(50);
            else if ((drawFlag == "charged")&amp;&amp;(trj-&gt;GetCharge() != 0.))
                                    trj-&gt;DrawTrajectory(50);
            else if ((drawFlag == "neutral")&amp;&amp;(trj-&gt;GetCharge() == 0.))
                                    trj-&gt;DrawTrajectory(50);
          }
    }
  }  
  //----- end of C++ source codes
</programlisting>
</informalexample>
</para>

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.EnhTrjct">
<title>
Enhanced trajectory drawing
</title>

<para>
It is possible to use the enhanced trajectory drawing functionality
in compiled code as well as from commands. Multiple trajectory
models can be instantiated, configured and registered with
G4VisManager. For details, see the section on 
<xref linkend="sect.VisEnhTrj.CntlCmpl" /> 
Enhanced Trajectory Drawing.
</para>

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.AttTrjct">
<title>
HepRep Attributes for Trajectories
</title>

<para>
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:

<itemizedlist spacing="compact">
  <listitem><para>
    Track ID
  </para></listitem>
  <listitem><para>
    Parent ID
  </para></listitem>
  <listitem><para>
    Particle Name
  </para></listitem>
  <listitem><para>
    Charge
  </para></listitem>
  <listitem><para>
    PDG Encoding
  </para></listitem>
  <listitem><para>
    Momentum 3-Vector
  </para></listitem>
  <listitem><para>
    Momentum magnitude
  </para></listitem>
  <listitem><para>
    Number of points
  </para></listitem>
</itemizedlist>
</para>

<para>
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.
</para>

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.Hits">
<title>
Visualization of hits
</title>

<para>
Hits are visualized with classes <emphasis>G4Square</emphasis> or
<emphasis>G4Circle</emphasis>, or other user-defined classes inheriting the
abstract base class <emphasis>G4VMarker</emphasis>. Drawing methods for hits are
not supported by default. Instead, ways of their implementation are
guided by virtual methods, <literal>G4VHit::Draw()</literal> and
<literal>G4VHitsCollection::DrawAllHits()</literal>, of the abstract base
classes <emphasis>G4VHit</emphasis> and <emphasis>G4VHitsCollection</emphasis>. 
These methods are defined as empty functions in the <literal>digits+hits</literal>
category. You can overload these methods, using the following
drawing methods of class <emphasis>G4VVisManager</emphasis>, in order to
visualize hits:

<informalexample>
<programlisting>
  //----- Drawing methods of G4Square and G4Circle
  virtual void G4VVisManager::Draw (const G4Circle&amp;, ...) ;
  virtual void G4VVisManager::Draw (const G4Square&amp;, ...) ;
</programlisting>
</informalexample>
</para>

<para>
The real implementations of these <literal>Draw()</literal> methods are
described in class <emphasis>G4VisManager</emphasis>.
</para>

<para>
The overloaded implementation of <literal>G4VHits::Draw()</literal> will
be held by, for example, class <emphasis>MyTrackerHits</emphasis> inheriting
<emphasis>G4VHit</emphasis> as follows:

<informalexample>
<programlisting>
  //----- C++ source codes: An example of giving concrete implementation of
  //       G4VHit::Draw(), using  class MyTrackerHit : public G4VHit {...}
  //      
 void MyTrackerHit::Draw()
 {
    G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
    if(pVVisManager)
    {
      // define a circle in a 3D space
      G4Circle circle(pos);
      circle.SetScreenSize(0.3);
      circle.SetFillStyle(G4Circle::filled);

      // make the circle red
      G4Colour colour(1.,0.,0.);
      G4VisAttributes attribs(colour);
      circle.SetVisAttributes(attribs);

      // make a 3D data for visualization 
      pVVisManager-&gt;Draw(circle);
    }
  }

  //----- end of C++ source codes
 
</programlisting>
</informalexample>
</para>

<para>
The overloaded implementation of
<literal>G4VHitsCollection::DrawAllHits()</literal> will be held by, for
example, class <emphasis>MyTrackerHitsCollection</emphasis> inheriting class
<emphasis>G4VHitsCollection</emphasis> as follows:

<informalexample>
<programlisting>
  //----- C++ source codes: An example of giving concrete implementation of
  //       G4VHitsCollection::Draw(), 
  //       using  class MyTrackerHit : public G4VHitsCollection{...}
  //      
  void MyTrackerHitsCollection::DrawAllHits()
  {
    G4int n_hit = theCollection.entries();
    for(G4int i=0;i &lt; n_hit;i++)
    { 
      theCollection[i].Draw(); 
    }
  }

  //----- end of C++ source codes
 
</programlisting>
</informalexample>
</para>

<para>
Thus, you can visualize hits as well as trajectories, for
example, at the end of each event by implementing the method
<literal>MyEventAction::EndOfEventAction()</literal> as follows:

<informalexample>
<programlisting>
  void MyEventAction::EndOfEventAction()
  {
    const G4Event* evt = fpEventManager-&gt;GetConstCurrentEvent();

    G4SDManager * SDman = G4SDManager::GetSDMpointer();
    G4String colNam;
    G4int trackerCollID = SDman-&gt;GetCollectionID(colNam="TrackerCollection");
    G4int calorimeterCollID = SDman-&gt;GetCollectionID(colNam="CalCollection");

    G4TrajectoryContainer * trajectoryContainer = evt-&gt;GetTrajectoryContainer();
    G4int n_trajectories = 0;
    if(trajectoryContainer)
    { n_trajectories = trajectoryContainer-&gt;entries(); }

    G4HCofThisEvent * HCE = evt-&gt;GetHCofThisEvent();
    G4int n_hitCollection = 0;
    if(HCE)
    { n_hitCollection = HCE-&gt;GetCapacity(); }
 
    G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();

    if(pVVisManager)
    {
 
      // Declare begininng of visualization
      G4UImanager::GetUIpointer()-&gt;ApplyCommand("/vis/scene/notifyHandlers");

      // Draw trajectories
      for(G4int i=0; i &lt; n_trajectories; i++)
      { 
          (*(evt-&gt;GetTrajectoryContainer()))[i]-&gt;DrawTrajectory(); 
      }

      // Construct 3D data for hits
      MyTrackerHitsCollection* THC 
        = (MyTrackerHitsCollection*)(HCE-&gt;GetHC(trackerCollID));
      if(THC) THC-&gt;DrawAllHits();
      MyCalorimeterHitsCollection* CHC
        = (MyCalorimeterHitsCollection*)(HCE-&gt;GetHC(calorimeterCollID));
      if(CHC) CHC-&gt;DrawAllHits();

      // Declare end of visualization
      G4UImanager::GetUIpointer()-&gt;ApplyCommand("/vis/viewer/update");
    
    } 

  }

  //----- end of C++ codes
 
</programlisting>
</informalexample>
</para>

<para>
You can re-visualize a physical volume, where a hit is detected,
with a highlight color, in addition to the whole set of detector
components. It is done by calling a drawing method of a physical
volume directly. The method is:

<informalexample>
<programlisting>

  //----- Drawing methods of a physical volume
  virtual void Draw (const G4VPhysicalVolume&amp;, ...) ;
 
</programlisting>
</informalexample>
</para>

<para>
This method is, for example, called in a method
<literal>MyXXXHit::Draw()</literal>, describing the visualization of hits
with markers. The following is an example for this:

<informalexample>
<programlisting>
  //----- C++ source codes: An example of visualizing hits with 
  void MyCalorimeterHit::Draw()
  {
    G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
    if(pVVisManager)
    {
      G4Transform3D trans(rot,pos);
      G4VisAttributes attribs;
      G4LogicalVolume* logVol = pPhys-&gt;GetLogicalVolume();
      const G4VisAttributes* pVA = logVol-&gt;GetVisAttributes();
      if(pVA) attribs = *pVA;
      G4Colour colour(1.,0.,0.);
      attribs.SetColour(colour);
      attribs.SetForceSolid(true);

      //----- Re-visualization of a selected physical volume with red color
      pVVisManager-&gt;Draw(*pPhys,attribs,trans);

    }
  }

  //----- end of C++ codes
 
</programlisting>
</informalexample>
</para>

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.AttHits">
<title>
HepRep Attributes for Hits
</title>

<para>
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.
</para>

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

<itemizedlist spacing="compact">
  <listitem><para>
    Hit Type
  </para></listitem>
  <listitem><para>
    Track ID
  </para></listitem>
  <listitem><para>
    Z Cell ID
  </para></listitem>
  <listitem><para>
    Phi Cell ID
  </para></listitem>
  <listitem><para>
    Energy Deposited
  </para></listitem>
  <listitem><para>
    Energy Deposited by Track
  </para></listitem>
  <listitem><para>
    Position
  </para></listitem>
  <listitem><para>
    Logical Volume
  </para></listitem>
</itemizedlist>
</para>

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

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.txt">
<title>
Visualization of text
</title>

<para>
In Geant4 Visualization, a text, i.e., a character string, is
described by class <emphasis>G4Text</emphasis> inheriting 
<emphasis>G4VMarker</emphasis> as well as <emphasis>G4Square</emphasis> 
and <emphasis>G4Circle</emphasis>. Therefore, the way to
visualize text is the same as for hits. The corresponding drawing
method of <emphasis>G4VVisManager</emphasis> is:

<informalexample>
<programlisting>
  //----- Drawing methods of G4Text
  virtual void G4VVisManager::Draw (const G4Text&amp;, ...);
 
</programlisting>
</informalexample>
</para>

<para>
The real implementation of this method is described in class
<emphasis>G4VisManager</emphasis>.
</para>

</sect2>


<!-- ******************* Section (Level#) ****************** -->
<sect2 id="sect.VisCntCmpl.PlyTrkStp">
<title>
Visualization of polylines and tracking steps
</title>

<para>
Polylines, i.e., sets of successive line segments, are described by
class <emphasis>G4Polyline</emphasis>. For <emphasis>G4Polyline</emphasis>, 
the following drawing method of class <emphasis>G4VVisManager</emphasis> 
is prepared:

<informalexample>
<programlisting>
   //----- A drawing method of G4Polyline
    virtual void G4VVisManager::Draw (const G4Polyline&amp;, ...) ;
 
</programlisting>
</informalexample>
</para>

<para>
The real implementation of this method is described in class
<emphasis>G4VisManager</emphasis>.
</para>

<para>
Using this method, C++ source codes to visualize
<emphasis>G4Polyline</emphasis> are described as follows:

<informalexample>
<programlisting>
 //----- C++ source code: How to visualize a polyline
  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
 
  if (pVVisManager) {
      G4Polyline polyline ;
   
      ..... (C++ source codes to set vertex positions, color, etc)
  
      pVVisManager -&gt; Draw(polyline); 
   
  }
  
  //----- end of C++ source codes
 
</programlisting>
</informalexample>
</para>

<para>
Tracking steps are able to be visualized based on the above
visualization of <emphasis>G4Polyline</emphasis>. You can visualize tracking
steps at each step automatically by writing a proper implementation
of class <emphasis>MySteppingAction</emphasis> inheriting
<emphasis>G4UserSteppingAction</emphasis>, and also with the help of the Run
Manager.
</para>

<para>
First, you must implement a method,
<literal>MySteppingAction::UserSteppingAction()</literal>. A typical
implementation of this method is as follows:

<informalexample>
<programlisting>
  //----- C++ source code: An example of visualizing tracking steps
  void MySteppingAction::UserSteppingAction()
  {
      G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();

      if (pVVisManager) {

        //----- Get the Stepping Manager
        const G4SteppingManager* pSM = GetSteppingManager();

        //----- Define a line segment 
        G4Polyline polyline;
        G4double charge = pSM-&gt;GetTrack()-&gt;GetDefinition()-&gt;GetPDGCharge();
        G4Colour colour;
        if      (charge &lt; 0.) colour = G4Colour(1., 0., 0.);
        else if (charge &lt; 0.) colour = G4Colour(0., 0., 1.);
        else                  colour = G4Colour(0., 1., 0.);
        G4VisAttributes attribs(colour);
        polyline.SetVisAttributes(attribs);
        polyline.push_back(pSM-&gt;GetStep()-&gt;GetPreStepPoint()-&gt;GetPosition());
        polyline.push_back(pSM-&gt;GetStep()-&gt;GetPostStepPoint()-&gt;GetPosition());

        //----- Call a drawing method for G4Polyline 
        pVVisManager -&gt; Draw(polyline); 
      
      } 
  }

  //----- end of C++ source code
 
</programlisting>
</informalexample>
</para>

<para>
Next, in order that the above C++ source code works, you have to
pass the information of the <emphasis>MySteppingAction</emphasis> to the Run
Manager in the <literal>main()</literal> function:

<informalexample>
<programlisting>
  
  //----- C++ source code: Passing what to do at each step to the Run Manager

  int main()
  {
     ...
  
     // Run Manager
     G4RunManager * runManager = new G4RunManager;

     // User initialization classes
     ...
     runManager-&gt;SetUserAction(new MySteppingAction);
     ...
  }

  //----- end of C++ source code
 
</programlisting>
</informalexample>
</para>

<para>
Thus you can visualize tracking steps with various visualization
attributes, e.g., color, at each step, automatically.
</para>

<para>
As well as tracking steps, you can visualize any kind 3D object
made of line segments, using class <emphasis>G4Polyline</emphasis> and its
drawing method, defined in class <emphasis>G4VVisManager</emphasis>. See, for
example, the implementation of the <literal>/vis/scene/add/axes</literal>
command.
</para>

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.UsrAct">
<title>
Visualization User Action
</title>

<para>
You can implement the <literal>Draw</literal> method of
<literal>G4VUserVisAction</literal>, e.g., the class definition could be:

<informalexample>
<programlisting>
class StandaloneVisAction: public G4VUserVisAction {
  void Draw();
};
</programlisting>
</informalexample>

and the implementation:

<informalexample>
<programlisting>
void StandaloneVisAction::Draw() {
  G4VVisManager* pVisManager = G4VVisManager::GetConcreteInstance();
  if (pVisManager) {

    // Simple box...
    pVisManager-&gt;Draw(G4Box("box",2*m,2*m,2*m),
                      G4VisAttributes(G4Colour(1,1,0)));

    // Boolean solid...
    G4Box boxA("boxA",3*m,3*m,3*m);
    G4Box boxB("boxB",1*m,1*m,1*m);
    G4SubtractionSolid subtracted("subtracted_boxes",&amp;boxA,&amp;boxB,
                       G4Translate3D(3*m,3*m,3*m));
    pVisManager-&gt;Draw(subtracted,
                      G4VisAttributes(G4Colour(0,1,1)),
                      G4Translate3D(6*m,6*m,6*m));
  }
}
</programlisting>
</informalexample>
</para>

<para>
Explicit use of polyhedron objects is equivalent, e.g.:

<informalexample>
<programlisting>

    // Same, but explicit polyhedron...
    G4Polyhedron* pA = G4Box("boxA",3*m,3*m,3*m).CreatePolyhedron();
    G4Polyhedron* pB = G4Box("boxB",1*m,1*m,1*m).CreatePolyhedron();
    pB-&gt;Transform(G4Translate3D(3*m,3*m,3*m));
    G4Polyhedron* pSubtracted = new G4Polyhedron(pA-&gt;subtract(*pB));
    G4VisAttributes subVisAtts(G4Colour(0,1,1));
    pSubtracted-&gt;SetVisAttributes(&amp;subVisAtts);
    pVisManager-&gt;Draw(*pSubtracted,G4Translate3D(6*m,6*m,6*m));
    delete pA;
    delete pB;
    delete pSubtracted;
</programlisting>
</informalexample>
</para>

<para>
If efficiency is an issue, create the objects in the constructor,
delete them in the destructor and draw them in your <literal>Draw</literal>
method. Anyway, an instance of your class needs to be registered
with the vis manager, e.g.:

<informalexample>
<programlisting>
  ...
  G4VisManager* visManager = new G4VisExecutive;
  visManager-&gt;Initialize ();

  visManager-&gt;SetUserAction
    (new StandaloneVisAction,
     G4VisExtent(-5*m,5*m,-5*m,5*m,-5*m,5*m));  // 2nd argument optional.
  ...
</programlisting>
</informalexample>

then activate by adding to a scene, e.g:

<informalexample>
<programlisting>
/control/verbose 2
/vis/verbose c
/vis/open OGLSXm
/vis/scene/create
#/vis/scene/add/userAction
/vis/scene/add/userAction -10 10 -10 10 -10 10 m
#/vis/scene/add/axes 0 0 0 10 m
#/vis/scene/add/scale 10 m
/vis/sceneHandler/attach
/vis/viewer/refresh
</programlisting>
</informalexample>
</para>

<para>
The extent can be added on registration or on the command line or
neither (if the extent of the scene is set by other components).
Your <literal>Draw</literal> method will be called whenever needed to refresh
the screen or rebuild a graphics database, for any chosen viewer.
The scene can be attached to any scene handler and your drawing
will be shown.
</para>

</sect2>


<!-- ******************* Section (Level#2) ****************** -->
<sect2 id="sect.VisCntCmpl.StdAln">
<title>
Standalone Visualization
</title>

<para>
The above raises the possibility of using Geant4 as a "standalone"
graphics package without invoking the run manager. The following
main program, together with a user visualization action and a macro
file, will allow you to view your drawing interactively on any of
the supported graphics systems.

<informalexample>
<programlisting>
#include "globals.hh"
#include "G4VisExecutive.hh"
#include "G4VisExtent.hh"
#include "G4UImanager.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"

#include "StandaloneVisAction.hh"

int main() {

  G4VisManager* visManager = new G4VisExecutive;
  visManager-&gt;Initialize ();

  visManager-&gt;SetUserAction
    (new StandaloneVisAction,
     G4VisExtent(-5*m,5*m,-5*m,5*m,-5*m,5*m));  // 2nd argument optional.

  G4UImanager* UI = G4UImanager::GetUIpointer ();
  UI-&gt;ApplyCommand ("/control/execute standalone.g4m");

  G4UIsession* session = new G4UIterminal(new G4UItcsh);
  session-&gt;SessionStart();

  delete session;
  delete visManager;
}
</programlisting>
</informalexample>
</para>


</sect2>
</sect1>