Download Geant4 User's Guide for Application Developers

Transcript
Visualization
8.9.3. 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.
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.
Example 8.8 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)
Example 8.8. An example of defining text.
//----- C++ source codes: 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 omissible)
G4Colour blue( 0., 0., 1. );
G4VisAttributes att ( blue );
text.SetVisAttributes ( att );
//----- end of C++ source codes
252