Polylines, Markers and Text

Polylines, markers and text are defined in the graphics_reps category, and are used only for visualization (Controlling Visualization from Compiled Code). Users may create any of these objects with local scope; once drawn, they may safely be deleted or allowed to go out of scope.

Polylines

A polyline is a set of successive line segments. It is defined with a class G4Polyline defined in the graphics_reps category. A polyline is used to visualize tracking steps, particle trajectories, coordinate axes, and any other user-defined objects made of line segments.

G4Polyline is defined as a list of G4Point3D objects, i.e., vertex positions. The vertex positions are set to a G4Polyline object with the push_back() method.

For example, an x-axis with length 5 cm and with red color is defined in shown in the Listing 100.

Listing 100 Defining an x-axis with length 5 cm and with colour red.
//-----  An example of defining a line segment
// Instantiate an empty polyline object
G4Polyline  x_axis;

// Set red line colour
G4Colour         red(1.0, 0.0, 0.0);
G4VisAttributes  att(red);
x_axis.SetVisAttributes(&att);

// Set vertex positions
x_axis.push_back( G4Point3D(0., 0., 0.) );
x_axis.push_back( G4Point3D(5.*cm, 0., 0.) );

Markers

Here we explain how to use 3D markers in Geant4 Visualization.

What are Markers?

Markers set marks at arbitrary positions in the 3D space. They are often used to visualize hits of particles at detector components. A marker is a 2-dimensional primitive with shape (square, circle, etc), color, and special properties (a) of always facing the camera and (b) of having the possibility of a size defined in screen units (pixels). Here “size” means “overall size”, e.g., diameter of circle and side of square (but diameter and radius access functions are defined to avoid ambiguity).

So the user who constructs a marker should decide whether or not it should be visualized to a given size in world coordinates by setting the world size. Alternatively, the user can set the screen size and the marker is visualized to its screen size. Finally, the user may decide not to set any size; in that case, it is drawn according to the sizes specified in the default marker specified in the class G4ViewParameters.

By default, “square” and “circle” are supported in Geant4 Visualization. The former is described with class G4Square, and the latter with class G4Circle:

Marker Type

Class Name

circle

G4Circle

right square

G4Square

These classes are inherited from class G4VMarker. They have constructors as follows:

//----- Constructors of G4Circle and G4Square
G4Circle::G4Circle (const G4Point3D& pos );
G4Square::G4Square (const G4Point3D& pos);

Access functions of class G4VMarker are summarized below.

Access functions of markers

Listing 101 shows the access functions inherited from the base class G4VMarker.

Listing 101 The access functions inherited from the base class G4VMarker.
//----- Set functions of G4VMarker
void G4VMarker::SetPosition( const G4Point3D& );
void G4VMarker::SetWorldSize( G4double );
void G4VMarker::SetWorldDiameter( G4double );
void G4VMarker::SetWorldRadius( G4double );
void G4VMarker::SetScreenSize( G4double );
void G4VMarker::SetScreenDiameter( G4double );
void G4VMarker::SetScreenRadius( G4double );
void G4VMarker::SetFillStyle( FillStyle );
// Note: enum G4VMarker::FillStyle {noFill, hashed, filled};

//----- Get functions of G4VMarker
G4Point3D G4VMarker::GetPosition () const;
G4double G4VMarker::GetWorldSize () const;
G4double G4VMarker::GetWorldDiameter () const;
G4double G4VMarker::GetWorldRadius () const;
G4double G4VMarker::GetScreenSize () const;
G4double G4VMarker::GetScreenDiameter () const;
G4double G4VMarker::GetScreenRadius () const;
FillStyle G4VMarker::GetFillStyle () const;
// Note: enum G4VMarker::FillStyle {noFill, hashed, filled};

Listing 102 shows sample C++ source code to define a very small red circle, i.e., a dot with diameter 1.0 pixel. Such a dot is often used to visualize a hit.

Listing 102 Sample C++ source code to define a very small red circle.
//----- An example of defining a red small maker
G4Circle circle(position); // Instantiate a circle with its 3D
                           // position. The argument "position"
                           // is defined as G4Point3D instance
circle.SetScreenDiameter (1.0); // Should be circle.SetScreenDiameter
                                //  (1.0 * pixels) - to be implemented
circle.SetFillStyle (G4Circle::filled); // Make it a filled circle
G4Colour colour(1.,0.,0.);              // Define red color
G4VisAttributes attribs(colour);        // Define a red visualization attribute
circle.SetVisAttributes(attribs);       // Assign the red attribute to the circle

Text

Text, i.e., a character string, is used to visualize various kinds of description, particle name, energy, coordinate names etc. Text is described by the class G4Text . The following constructors are supported:

//----- Constructors of G4Text
G4Text (const G4String& text);
G4Text (const G4String& text, const G4Point3D& pos);

where the argument text is the text (string) to be visualized, and pos is the 3D position at which the text is visualized.

Text is currently drawn only by the OpenGL drivers, such as OGLIX, OGLIXm and OpenInventor. It is not yet supported on other drivers, including the Windows OpenGL drivers, HepRep, etc.

Note that class G4Text also inherits G4VMarker. Size of text is recognized as “font size”, i.e., height of the text. All the access functions defined for class G4VMarker mentioned above are available. In addition, the following access functions are available, too:

//----- Set functions of G4Text
void G4Text::SetText ( const G4String& text ) ;
void G4Text::SetOffset ( double dx, double dy ) ;

//----- Get functions of G4Text
G4String G4Text::GetText () const;
G4double G4Text::GetXOffset () const;
G4double G4Text::GetYOffset () const;

Method SetText() defines text to be visualized, and GetText() returns the defined text. Method SetOffset() defines x (horizontal) and y (vertical) offsets in the screen coordinates. By default, both offsets are zero, and the text starts from the 3D position given to the constructor or to the method G4VMarker:SetPosition(). Offsets should be given with the same units as the one adopted for the size, i.e., world-size or screen-size units.

Listing 103 shows sample C++ source code to define text with the following properties:

  • Text: “Welcome to Geant4 Visualization”

  • Position: (0.,0.,0.) in the world coordinates

  • Horizontal offset: 10 pixels

  • Vertical offset: -20 pixels

  • Colour: blue (default)

Listing 103 An example of defining text.
//-----  An example of defining a visualizable text

//----- Instantiation
G4Text text ;
text.SetText ( "Welcome to Geant4 Visualization");
text.SetPosition ( G4Point3D(0.,0.,0.) );
// These three lines are equivalent to:
//  G4Text text ( "Welcome to Geant4 Visualization",
//                 G4Point3D(0.,0.,0.) );

//----- Size (font size in units of pixels)
G4double fontsize = 24.; // Should be 24. * pixels - to be implemented.
text.SetScreenSize ( fontsize );

//----- Offsets
G4double x_offset = 10.; // Should be 10. * pixels - to be implemented.
G4double y_offset = -20.; // Should be -20. * pixels - to be implemented.
text.SetOffset( x_offset, y_offset );

//----- Color (Blue is the default setting, and so the codes below are omittable)
G4Colour blue( 0., 0., 1. );
G4VisAttributes att ( blue );
text.SetVisAttributes ( att );