| 1 | <HTML>
|
|---|
| 2 | <TITLE>Polylines, Markers and Text</title>
|
|---|
| 3 | <HEAD>
|
|---|
| 4 | </HEAD>
|
|---|
| 5 | <BODY>
|
|---|
| 6 |
|
|---|
| 7 | <TABLE WIDTH="100%" >
|
|---|
| 8 | <TR>
|
|---|
| 9 | <TD>
|
|---|
| 10 | </A>
|
|---|
| 11 | <A HREF="index.html">
|
|---|
| 12 | <IMG SRC="../../../../resources/html/IconsGIF/Contents.gif" ALT="Contents" HEIGHT=16 WIDTH=59></A>
|
|---|
| 13 | <A HREF="filtering.html">
|
|---|
| 14 | <IMG SRC="../../../../resources/html/IconsGIF/Previous.gif" ALT="Previous" HEIGHT=16 WIDTH=59></A>
|
|---|
| 15 | <A HREF="makingamovie.html">
|
|---|
| 16 | <IMG SRC="../../../../resources/html/IconsGIF/Next.gif" ALT="Next" HEIGHT=16 WIDTH=59></A>
|
|---|
| 17 | </TD>
|
|---|
| 18 |
|
|---|
| 19 | <TD ALIGN="Right"><FONT COLOR="#238E23"><FONT SIZE=-1>
|
|---|
| 20 | <B>Geant4 User's Guide</B> <BR>
|
|---|
| 21 | <B>For Application Developers</B> <BR>
|
|---|
| 22 | <B>Visualization</B> </FONT></FONT> </TD>
|
|---|
| 23 | </TR>
|
|---|
| 24 | </TABLE>
|
|---|
| 25 |
|
|---|
| 26 | <CENTER><FONT COLOR="#238E23"><FONT SIZE=+3>
|
|---|
| 27 | <b>8.9 Polylines, Markers and Text</b><BR>
|
|---|
| 28 | </FONT></FONT></CENTER>
|
|---|
| 29 | <BR>
|
|---|
| 30 |
|
|---|
| 31 | <HR ALIGN="Center" SIZE="7%"><BR>
|
|---|
| 32 |
|
|---|
| 33 | <!-- ============================================== Section -->
|
|---|
| 34 |
|
|---|
| 35 | Polylines, markers and text are defined in the <tt>graphics_reps</tt> category,
|
|---|
| 36 | and are used only for visualization. Here we explain their definitions and usages.
|
|---|
| 37 |
|
|---|
| 38 | <h4>8.9.1 Polylines</h4>
|
|---|
| 39 |
|
|---|
| 40 | A polyline is a set of successive line segments. It is defined with
|
|---|
| 41 | a class <i>G4Polyline</i> defined in the <tt>graphics_reps</tt> category. A polyline
|
|---|
| 42 | is used to visualize tracking steps, particle trajectories, coordinate
|
|---|
| 43 | axes, and any other user-defined objects made of line segments.
|
|---|
| 44 | <P>
|
|---|
| 45 | <i>G4Polyline</i> is defined as a list of <i>G4Point3D</i> objects, i.e.,
|
|---|
| 46 | vertex positions.
|
|---|
| 47 | The vertex positions are set to a <i>G4Polyline</i>
|
|---|
| 48 | object with the <tt>push_back()</tt> method.
|
|---|
| 49 | <P>
|
|---|
| 50 | For example, an x-axis with length 5 cm and with red color is defined
|
|---|
| 51 | in Source listing 8.9.1.
|
|---|
| 52 | <P>
|
|---|
| 53 | <center>
|
|---|
| 54 | <table border=2 cellpadding=10>
|
|---|
| 55 | <tr>
|
|---|
| 56 | <td>
|
|---|
| 57 | <PRE>
|
|---|
| 58 | //----- C++ source codes: An example of defining a line segment
|
|---|
| 59 | // Instantiate an emply polyline object
|
|---|
| 60 | G4Polyline x_axis;
|
|---|
| 61 |
|
|---|
| 62 | // Set red line colour
|
|---|
| 63 | G4Colour red(1.0, 0.0, 0.0);
|
|---|
| 64 | G4VisAttributes att(red);
|
|---|
| 65 | x_axis.SetVisAttributes(&att);
|
|---|
| 66 |
|
|---|
| 67 | // Set vertex positions
|
|---|
| 68 | x_axis.push_back( G4Point3D(0., 0., 0.) );
|
|---|
| 69 | x_axis.push_back( G4Point3D(5.*cm, 0., 0.) );
|
|---|
| 70 |
|
|---|
| 71 | //----- end of C++ source codes
|
|---|
| 72 | </PRE>
|
|---|
| 73 | </td>
|
|---|
| 74 | </tr>
|
|---|
| 75 | <tr>
|
|---|
| 76 | <td align=center>
|
|---|
| 77 | Source listing 8.9.1<BR>
|
|---|
| 78 | Defining an x-axis with length 5 cm and with colour red.
|
|---|
| 79 | </td>
|
|---|
| 80 | </tr>
|
|---|
| 81 | </table></center>
|
|---|
| 82 | <P>
|
|---|
| 83 |
|
|---|
| 84 | <h4>8.9.2 Markers</h4>
|
|---|
| 85 |
|
|---|
| 86 | Here we explain how to use 3D markers in Geant4 Visualization.
|
|---|
| 87 | <p>
|
|---|
| 88 | <B>What are Markers?</B>
|
|---|
| 89 | <p>
|
|---|
| 90 | Markers set marks at arbitrary positions in the 3D space. They are often
|
|---|
| 91 | used to visualize hits of particles at detector components. A marker is
|
|---|
| 92 | a 2-dimensional primitive with shape (square, circle, etc), color, and
|
|---|
| 93 | special properties (a) of always facing the camera and (b) of having the
|
|---|
| 94 | possibility of a size defined in screen units (pixels). Here "size" means
|
|---|
| 95 | "overall size", e.g., diameter of circle and side of square (but diameter
|
|---|
| 96 | and radius access functions are defined to avoid ambiguity).
|
|---|
| 97 | <P>
|
|---|
| 98 | So the user who constructs a marker should decide whether or not it
|
|---|
| 99 | should be visualized to a given size in world coordinates by setting the
|
|---|
| 100 | world size. Alternatively, the user can set the screen size and the marker
|
|---|
| 101 | is visualized to its screen size. Finally, the user may decide not to set
|
|---|
| 102 | any size; in that case, it is drawn according to the sizes specified in
|
|---|
| 103 | the default marker specified in the class <i>G4ViewParameters</i>.
|
|---|
| 104 | <P>
|
|---|
| 105 | By default, "square" and "circle" are supported in Geant4 Visualization.
|
|---|
| 106 | The former is described with class <i>G4Square</i>, and the latter with class
|
|---|
| 107 | <i>G4Circle</i>:
|
|---|
| 108 | <p>
|
|---|
| 109 | <CENTER><TABLE BORDER=2 cellpadding=10>
|
|---|
| 110 | <TR>
|
|---|
| 111 | <TD><B>Marker Type</B></TD>
|
|---|
| 112 | <TD><B>Class Name</B></TD>
|
|---|
| 113 | </TR>
|
|---|
| 114 | <TR>
|
|---|
| 115 | <TD>circle</TD>
|
|---|
| 116 | <TD><i>G4Circle</i></TD>
|
|---|
| 117 | </TR>
|
|---|
| 118 | <TR>
|
|---|
| 119 | <TD>right square</TD>
|
|---|
| 120 | <TD><i>G4Square</i></TD>
|
|---|
| 121 | </TR>
|
|---|
| 122 | </TABLE></CENTER>
|
|---|
| 123 | <p>
|
|---|
| 124 | These classes are inherited from class <i>G4VMarker</i>. They have constructors
|
|---|
| 125 | as follows:
|
|---|
| 126 | <PRE>
|
|---|
| 127 | //----- Constructors of G4Circle and G4Square
|
|---|
| 128 | G4Circle::G4Circle (const G4Point3D& pos );
|
|---|
| 129 | G4Square::G4Square (const G4Point3D& pos);
|
|---|
| 130 | </PRE>
|
|---|
| 131 | Access functions of class <i>G4VMarker</i> are summarized below.
|
|---|
| 132 | <p>
|
|---|
| 133 | <b>Access functions of markers</B>
|
|---|
| 134 | <P>
|
|---|
| 135 | Source listing 8.9.2 shows the access functions inherited from the base class <i>G4VMarker</i>.
|
|---|
| 136 | <P>
|
|---|
| 137 | <center>
|
|---|
| 138 | <table border=2 cellpadding=10>
|
|---|
| 139 | <tr>
|
|---|
| 140 | <td>
|
|---|
| 141 | <PRE>
|
|---|
| 142 | //----- Set functions of G4VMarker
|
|---|
| 143 | void G4VMarker::SetPosition( const G4Point3D& );
|
|---|
| 144 | void G4VMarker::SetWorldSize( G4double );
|
|---|
| 145 | void G4VMarker::SetWorldDiameter( G4double );
|
|---|
| 146 | void G4VMarker::SetWorldRadius( G4double );
|
|---|
| 147 | void G4VMarker::SetScreenSize( G4double );
|
|---|
| 148 | void G4VMarker::SetScreenDiameter( G4double );
|
|---|
| 149 | void G4VMarker::SetScreenRadius( G4double );
|
|---|
| 150 | void G4VMarker::SetFillStyle( FillStyle );
|
|---|
| 151 | // Note: enum G4VMarker::FillStyle {noFill, hashed, filled};
|
|---|
| 152 |
|
|---|
| 153 | //----- Get functions of G4VMarker
|
|---|
| 154 | G4Point3D G4VMarker::GetPosition () const;
|
|---|
| 155 | G4double G4VMarker::GetWorldSize () const;
|
|---|
| 156 | G4double G4VMarker::GetWorldDiameter () const;
|
|---|
| 157 | G4double G4VMarker::GetWorldRadius () const;
|
|---|
| 158 | G4double G4VMarker::GetScreenSize () const;
|
|---|
| 159 | G4double G4VMarker::GetScreenDiameter () const;
|
|---|
| 160 | G4double G4VMarker::GetScreenRadius () const;
|
|---|
| 161 | FillStyle G4VMarker::GetFillStyle () const;
|
|---|
| 162 | // Note: enum G4VMarker::FillStyle {noFill, hashed, filled};
|
|---|
| 163 | </PRE>
|
|---|
| 164 | </td>
|
|---|
| 165 | </tr>
|
|---|
| 166 | <tr>
|
|---|
| 167 | <td align=center>
|
|---|
| 168 | Source listing 8.9.2<BR>
|
|---|
| 169 | The access functions inherited from the base class <i>G4VMarker</i>.
|
|---|
| 170 | </td>
|
|---|
| 171 | </tr>
|
|---|
| 172 | </table></center>
|
|---|
| 173 | <P>
|
|---|
| 174 | Source listing 8.9.3 shows sample C++ source code to define a very small red circle,
|
|---|
| 175 | i.e., a dot with diameter 1.0 pixel. Such a dot is often used to visualize
|
|---|
| 176 | a hit.
|
|---|
| 177 | <P>
|
|---|
| 178 | <center>
|
|---|
| 179 | <table border=2 cellpadding=10>
|
|---|
| 180 | <tr>
|
|---|
| 181 | <td>
|
|---|
| 182 | <PRE>
|
|---|
| 183 | //----- C++ source codes: An example of defining a red small maker
|
|---|
| 184 | G4Circle circle(position); // Instantiate a circle with its 3D
|
|---|
| 185 | // position. The argument "position"
|
|---|
| 186 | // is defined as G4Point3D instance
|
|---|
| 187 | circle.SetScreenDiameter (1.0); // Should be circle.SetScreenDiameter
|
|---|
| 188 | // (1.0 * pixels) - to be implemented
|
|---|
| 189 | circle.SetFillStyle (G4Circle::filled); // Make it a filled circle
|
|---|
| 190 | G4Colour colour(1.,0.,0.); // Define red color
|
|---|
| 191 | G4VisAttributes attribs(colour); // Define a red visualization attribute
|
|---|
| 192 | circle.SetVisAttributes(attribs); // Assign the red attribute to the circle
|
|---|
| 193 | //----- end of C++ source codes
|
|---|
| 194 | </PRE>
|
|---|
| 195 | </td>
|
|---|
| 196 | </tr>
|
|---|
| 197 | <tr>
|
|---|
| 198 | <td align=center>
|
|---|
| 199 | Source listing 8.9.3<BR>
|
|---|
| 200 | Sample C++ source code to define a very small red circle.
|
|---|
| 201 | </td>
|
|---|
| 202 | </tr>
|
|---|
| 203 | </table></center>
|
|---|
| 204 | <P>
|
|---|
| 205 |
|
|---|
| 206 | <h4>8.9.3 Text</h4>
|
|---|
| 207 |
|
|---|
| 208 | Text, i.e., a character string, is used to visualize various kinds of description,
|
|---|
| 209 | particle name, energy, coordinate names etc. Text is described by the class
|
|---|
| 210 | <i>G4Text</i> . The following constructors are supported:
|
|---|
| 211 | <PRE>
|
|---|
| 212 | //----- Constructors of G4Text
|
|---|
| 213 | G4Text (const G4String& text);
|
|---|
| 214 | G4Text (const G4String& text, const G4Point3D& pos);
|
|---|
| 215 | </PRE>
|
|---|
| 216 |
|
|---|
| 217 | where the argument <tt>text</tt> is the text (string) to be visualized, and <tt>pos</tt>
|
|---|
| 218 | is the 3D position at which the text is visualized.
|
|---|
| 219 | <P>
|
|---|
| 220 | Note that class <i>G4Text</i> also inherits <i>G4VMarker</i>. Size of text is recognized
|
|---|
| 221 | as "font size", i.e., height of the text. All the access functions defined
|
|---|
| 222 | for class <i>G4VMarker</i> mentioned above are available. In addition, the following
|
|---|
| 223 | access functions are available, too:
|
|---|
| 224 | <PRE>
|
|---|
| 225 | //----- Set functions of G4Text
|
|---|
| 226 | void G4Text::SetText ( const G4String& text ) ;
|
|---|
| 227 | void G4Text::SetOffset ( double dx, double dy ) ;
|
|---|
| 228 |
|
|---|
| 229 | //----- Get functions of G4Text
|
|---|
| 230 | G4String G4Text::GetText () const;
|
|---|
| 231 | G4double G4Text::GetXOffset () const;
|
|---|
| 232 | G4double G4Text::GetYOffset () const;
|
|---|
| 233 | </PRE>
|
|---|
| 234 |
|
|---|
| 235 | Method <tt>SetText()</tt> defines text to be visualized, and <tt>GetText()</tt> returns the
|
|---|
| 236 | defined text. Method <tt>SetOffset()</tt> defines x (horizontal) and y (vertical)
|
|---|
| 237 | offsets in the screen coordinates. By default, both offsets are zero, and
|
|---|
| 238 | the text starts from the 3D position given to the constructor or to the
|
|---|
| 239 | method <tt>G4VMarker:SetPosition()</tt>. Offsets should be given with the same units
|
|---|
| 240 | as the one adopted for the size, i.e., world-size or screen-size units.
|
|---|
| 241 | <P>
|
|---|
| 242 | Source listing 8.9.4 shows sample C++ source code to define text with the following properties:
|
|---|
| 243 |
|
|---|
| 244 | <UL>
|
|---|
| 245 | <LI>Text: "Welcome to Geant4 Visualization"</LI>
|
|---|
| 246 | <LI>Position: (0.,0.,0.) in the world coordinates</LI>
|
|---|
| 247 | <LI>Horizontal offset: 10 pixels</LI>
|
|---|
| 248 | <LI>Vertical offset: -20 pixels</LI>
|
|---|
| 249 | <LI>Colour: blue (default)</LI>
|
|---|
| 250 | </UL>
|
|---|
| 251 |
|
|---|
| 252 | <P>
|
|---|
| 253 | <center>
|
|---|
| 254 | <table border=2 cellpadding=10>
|
|---|
| 255 | <tr>
|
|---|
| 256 | <td>
|
|---|
| 257 | <PRE>
|
|---|
| 258 | //----- C++ source codes: An example of defining a visualizable text
|
|---|
| 259 |
|
|---|
| 260 | //----- Instantiation
|
|---|
| 261 | G4Text text ;
|
|---|
| 262 | text.SetText ( "Welcome to Geant4 Visualization");
|
|---|
| 263 | text.SetPosition ( G4Point3D(0.,0.,0.) );
|
|---|
| 264 | // These three lines are equivalent to:
|
|---|
| 265 | // G4Text text ( "Welcome to Geant4 Visualization",
|
|---|
| 266 | // G4Point3D(0.,0.,0.) );
|
|---|
| 267 |
|
|---|
| 268 | //----- Size (font size in units of pixels)
|
|---|
| 269 | G4double fontsize = 24.; // Should be 24. * pixels - to be implemented.
|
|---|
| 270 | text.SetScreenSize ( fontsize );
|
|---|
| 271 |
|
|---|
| 272 | //----- Offsets
|
|---|
| 273 | G4double x_offset = 10.; // Should be 10. * pixels - to be implemented.
|
|---|
| 274 | G4double y_offset = -20.; // Should be -20. * pixels - to be implemented.
|
|---|
| 275 | text.SetOffset( x_offset, y_offset );
|
|---|
| 276 |
|
|---|
| 277 | //----- Color (Blue is the default setting, and so the codes below are omissible)
|
|---|
| 278 | G4Colour blue( 0., 0., 1. );
|
|---|
| 279 | G4VisAttributes att ( blue );
|
|---|
| 280 | text.SetVisAttributes ( att );
|
|---|
| 281 |
|
|---|
| 282 | //----- end of C++ source codes
|
|---|
| 283 | </PRE>
|
|---|
| 284 | </td>
|
|---|
| 285 | </tr>
|
|---|
| 286 | <tr>
|
|---|
| 287 | <td align=center>
|
|---|
| 288 | Source listing 8.9.4<BR>
|
|---|
| 289 | An example of defining text.
|
|---|
| 290 | </td>
|
|---|
| 291 | </tr>
|
|---|
| 292 | </table></center>
|
|---|
| 293 | <P>
|
|---|
| 294 |
|
|---|
| 295 | <HR>
|
|---|
| 296 | <A HREF="makingamovie.html">Next section</A><BR>
|
|---|
| 297 | <A HREF="index.html">Back to contents</A>
|
|---|
| 298 |
|
|---|
| 299 | </BODY>
|
|---|
| 300 | </HTML>
|
|---|