| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>8.9. Polylines, Markers and Text</title><link rel="stylesheet" href="../xml/XSLCustomizationLayer/G4HTMLStylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="Geant4 User's Guide for Application Developers"><link rel="up" href="ch08.html" title="Chapter 8. Visualization"><link rel="prev" href="ch08s08.html" title="8.8. Trajectory Filtering"><link rel="next" href="ch08s10.html" title="8.10. Making a Movie"><script language="JavaScript">
|
|---|
| 2 | function remote_win(fName)
|
|---|
| 3 | {
|
|---|
| 4 | var url = "AllResources/Detector/geometry.src/" + fName;
|
|---|
| 5 | RemoteWin=window.open(url,"","resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=520,height=520")
|
|---|
| 6 | RemoteWin.creator=self
|
|---|
| 7 | }
|
|---|
| 8 | </script></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">8.9.
|
|---|
| 9 | Polylines, Markers and Text
|
|---|
| 10 | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch08s08.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 8.
|
|---|
| 11 | Visualization
|
|---|
| 12 | </th><td width="20%" align="right"> <a accesskey="n" href="ch08s10.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sect.VisPlylMrkTxt"></a>8.9.
|
|---|
| 13 | Polylines, Markers and Text
|
|---|
| 14 | </h2></div></div></div><p>
|
|---|
| 15 | Polylines, markers and text are defined in the
|
|---|
| 16 | <code class="literal">graphics_reps</code> category, and are used only for
|
|---|
| 17 | visualization. Here we explain their definitions and usages.
|
|---|
| 18 | </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisPlylMrkTxt.Plyl"></a>8.9.1.
|
|---|
| 19 | Polylines
|
|---|
| 20 | </h3></div></div></div><p>
|
|---|
| 21 | A polyline is a set of successive line segments. It is defined with
|
|---|
| 22 | a class <span class="emphasis"><em>G4Polyline</em></span> defined in the
|
|---|
| 23 | <code class="literal">graphics_reps</code> category.
|
|---|
| 24 | A polyline is used to visualize tracking steps, particle
|
|---|
| 25 | trajectories, coordinate axes, and any other user-defined objects
|
|---|
| 26 | made of line segments.
|
|---|
| 27 | </p><p>
|
|---|
| 28 | <span class="emphasis"><em>G4Polyline</em></span> is defined as a list of
|
|---|
| 29 | <span class="emphasis"><em>G4Point3D</em></span> objects, i.e., vertex positions.
|
|---|
| 30 | The vertex positions are set to a <span class="emphasis"><em>G4Polyline</em></span>
|
|---|
| 31 | object with the <code class="literal">push_back()</code> method.
|
|---|
| 32 | </p><p>
|
|---|
| 33 | For example, an x-axis with length 5 cm and with red color is
|
|---|
| 34 | defined in <a href="ch08s09.html#programlist_VisPlylMrkTxt_1" title="Example 8.5.
|
|---|
| 35 | Defining an x-axis with length 5 cm and with colour red.
|
|---|
| 36 | ">Example 8.5</a>.
|
|---|
| 37 |
|
|---|
| 38 | </p><div class="example"><a name="programlist_VisPlylMrkTxt_1"></a><p class="title"><b>Example 8.5.
|
|---|
| 39 | Defining an x-axis with length 5 cm and with colour red.
|
|---|
| 40 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 41 | //----- C++ source codes: An example of defining a line segment
|
|---|
| 42 | // Instantiate an emply polyline object
|
|---|
| 43 | G4Polyline x_axis;
|
|---|
| 44 |
|
|---|
| 45 | // Set red line colour
|
|---|
| 46 | G4Colour red(1.0, 0.0, 0.0);
|
|---|
| 47 | G4VisAttributes att(red);
|
|---|
| 48 | x_axis.SetVisAttributes(&att);
|
|---|
| 49 |
|
|---|
| 50 | // Set vertex positions
|
|---|
| 51 | x_axis.push_back( G4Point3D(0., 0., 0.) );
|
|---|
| 52 | x_axis.push_back( G4Point3D(5.*cm, 0., 0.) );
|
|---|
| 53 |
|
|---|
| 54 | //----- end of C++ source codes
|
|---|
| 55 | </pre></div></div><p><br class="example-break">
|
|---|
| 56 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisPlylMrkTxt.Mrk"></a>8.9.2.
|
|---|
| 57 | Markers
|
|---|
| 58 | </h3></div></div></div><p>
|
|---|
| 59 | Here we explain how to use 3D markers in Geant4 Visualization.
|
|---|
| 60 | </p><h5><a name="id519964"></a>
|
|---|
| 61 | What are Markers?
|
|---|
| 62 | </h5><p>
|
|---|
| 63 | Markers set marks at arbitrary positions in the 3D space. They
|
|---|
| 64 | are often used to visualize hits of particles at detector
|
|---|
| 65 | components. A marker is a 2-dimensional primitive with shape
|
|---|
| 66 | (square, circle, etc), color, and special properties (a) of always
|
|---|
| 67 | facing the camera and (b) of having the possibility of a size
|
|---|
| 68 | defined in screen units (pixels). Here "size" means "overall size",
|
|---|
| 69 | e.g., diameter of circle and side of square (but diameter and
|
|---|
| 70 | radius access functions are defined to avoid ambiguity).
|
|---|
| 71 | </p><p>
|
|---|
| 72 | So the user who constructs a marker should decide whether or not
|
|---|
| 73 | it should be visualized to a given size in world coordinates by
|
|---|
| 74 | setting the world size. Alternatively, the user can set the screen
|
|---|
| 75 | size and the marker is visualized to its screen size. Finally, the
|
|---|
| 76 | user may decide not to set any size; in that case, it is drawn
|
|---|
| 77 | according to the sizes specified in the default marker specified in
|
|---|
| 78 | the class <span class="emphasis"><em>G4ViewParameters</em></span>.
|
|---|
| 79 | </p><p>
|
|---|
| 80 | By default, "square" and "circle" are supported in Geant4
|
|---|
| 81 | Visualization. The former is described with class <span class="emphasis"><em>G4Square</em></span>,
|
|---|
| 82 | and the latter with class <span class="emphasis"><em>G4Circle</em></span>:
|
|---|
| 83 |
|
|---|
| 84 | </p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><tbody><tr><td>
|
|---|
| 85 | <span class="bold"><strong>Marker Type</strong></span>
|
|---|
| 86 | </td><td>
|
|---|
| 87 | <span class="bold"><strong>Class Name</strong></span>
|
|---|
| 88 | </td></tr><tr><td>
|
|---|
| 89 | circle
|
|---|
| 90 | </td><td>
|
|---|
| 91 | <span class="emphasis"><em>G4Circle</em></span>
|
|---|
| 92 | </td></tr><tr><td>
|
|---|
| 93 | right square
|
|---|
| 94 | </td><td>
|
|---|
| 95 | <span class="emphasis"><em>G4Square</em></span>
|
|---|
| 96 | </td></tr></tbody></table></div><p>
|
|---|
| 97 | </p><p>
|
|---|
| 98 | These classes are inherited from class <span class="emphasis"><em>G4VMarker</em></span>.
|
|---|
| 99 | They have constructors as follows:
|
|---|
| 100 |
|
|---|
| 101 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 102 | //----- Constructors of G4Circle and G4Square
|
|---|
| 103 | G4Circle::G4Circle (const G4Point3D& pos );
|
|---|
| 104 | G4Square::G4Square (const G4Point3D& pos);
|
|---|
| 105 | </pre></div><p>
|
|---|
| 106 | </p><p>
|
|---|
| 107 | Access functions of class <span class="emphasis"><em>G4VMarker</em></span> are summarized below.
|
|---|
| 108 | </p><h5><a name="id520087"></a>
|
|---|
| 109 | Access functions of markers
|
|---|
| 110 | </h5><p>
|
|---|
| 111 | <a href="ch08s09.html#programlist_VisPlylMrkTxt_2" title="Example 8.6.
|
|---|
| 112 | The access functions inherited from the base class
|
|---|
| 113 | G4VMarker.
|
|---|
| 114 | ">Example 8.6</a> shows the access functions
|
|---|
| 115 | inherited from the base class <span class="emphasis"><em>G4VMarker</em></span>.
|
|---|
| 116 |
|
|---|
| 117 | </p><div class="example"><a name="programlist_VisPlylMrkTxt_2"></a><p class="title"><b>Example 8.6.
|
|---|
| 118 | The access functions inherited from the base class
|
|---|
| 119 | <span class="emphasis"><em>G4VMarker</em></span>.
|
|---|
| 120 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 121 | //----- Set functions of G4VMarker
|
|---|
| 122 | void G4VMarker::SetPosition( const G4Point3D& );
|
|---|
| 123 | void G4VMarker::SetWorldSize( G4double );
|
|---|
| 124 | void G4VMarker::SetWorldDiameter( G4double );
|
|---|
| 125 | void G4VMarker::SetWorldRadius( G4double );
|
|---|
| 126 | void G4VMarker::SetScreenSize( G4double );
|
|---|
| 127 | void G4VMarker::SetScreenDiameter( G4double );
|
|---|
| 128 | void G4VMarker::SetScreenRadius( G4double );
|
|---|
| 129 | void G4VMarker::SetFillStyle( FillStyle );
|
|---|
| 130 | // Note: enum G4VMarker::FillStyle {noFill, hashed, filled};
|
|---|
| 131 |
|
|---|
| 132 | //----- Get functions of G4VMarker
|
|---|
| 133 | G4Point3D G4VMarker::GetPosition () const;
|
|---|
| 134 | G4double G4VMarker::GetWorldSize () const;
|
|---|
| 135 | G4double G4VMarker::GetWorldDiameter () const;
|
|---|
| 136 | G4double G4VMarker::GetWorldRadius () const;
|
|---|
| 137 | G4double G4VMarker::GetScreenSize () const;
|
|---|
| 138 | G4double G4VMarker::GetScreenDiameter () const;
|
|---|
| 139 | G4double G4VMarker::GetScreenRadius () const;
|
|---|
| 140 | FillStyle G4VMarker::GetFillStyle () const;
|
|---|
| 141 | // Note: enum G4VMarker::FillStyle {noFill, hashed, filled};
|
|---|
| 142 | </pre></div></div><p><br class="example-break">
|
|---|
| 143 | </p><p>
|
|---|
| 144 | <a href="ch08s09.html#programlist_VisPlylMrkTxt_3" title="Example 8.7.
|
|---|
| 145 | Sample C++ source code to define a very small red circle.
|
|---|
| 146 | ">Example 8.7</a> shows sample C++ source
|
|---|
| 147 | code to define a very small red circle, i.e., a dot with diameter 1.0 pixel.
|
|---|
| 148 | Such a dot is often used to visualize a hit.
|
|---|
| 149 |
|
|---|
| 150 | </p><div class="example"><a name="programlist_VisPlylMrkTxt_3"></a><p class="title"><b>Example 8.7.
|
|---|
| 151 | Sample C++ source code to define a very small red circle.
|
|---|
| 152 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 153 | //----- C++ source codes: An example of defining a red small maker
|
|---|
| 154 | G4Circle circle(position); // Instantiate a circle with its 3D
|
|---|
| 155 | // position. The argument "position"
|
|---|
| 156 | // is defined as G4Point3D instance
|
|---|
| 157 | circle.SetScreenDiameter (1.0); // Should be circle.SetScreenDiameter
|
|---|
| 158 | // (1.0 * pixels) - to be implemented
|
|---|
| 159 | circle.SetFillStyle (G4Circle::filled); // Make it a filled circle
|
|---|
| 160 | G4Colour colour(1.,0.,0.); // Define red color
|
|---|
| 161 | G4VisAttributes attribs(colour); // Define a red visualization attribute
|
|---|
| 162 | circle.SetVisAttributes(attribs); // Assign the red attribute to the circle
|
|---|
| 163 | //----- end of C++ source codes
|
|---|
| 164 | </pre></div></div><p><br class="example-break">
|
|---|
| 165 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisPlylMrkTxt.Txt"></a>8.9.3.
|
|---|
| 166 | Text
|
|---|
| 167 | </h3></div></div></div><p>
|
|---|
| 168 | Text, i.e., a character string, is used to visualize various kinds
|
|---|
| 169 | of description, particle name, energy, coordinate names etc. Text
|
|---|
| 170 | is described by the class <span class="emphasis"><em>G4Text</em></span> . The following
|
|---|
| 171 | constructors are supported:
|
|---|
| 172 |
|
|---|
| 173 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 174 | //----- Constructors of G4Text
|
|---|
| 175 | G4Text (const G4String& text);
|
|---|
| 176 | G4Text (const G4String& text, const G4Point3D& pos);
|
|---|
| 177 | </pre></div><p>
|
|---|
| 178 |
|
|---|
| 179 | where the argument <code class="literal">text</code> is the text (string) to be
|
|---|
| 180 | visualized, and <code class="literal">pos</code> is the 3D position at which the text
|
|---|
| 181 | is visualized.
|
|---|
| 182 | </p><p>
|
|---|
| 183 | Note that class <span class="emphasis"><em>G4Text</em></span> also inherits <span class="emphasis"><em>G4VMarker</em></span>.
|
|---|
| 184 | Size of text is recognized as "font size", i.e., height of the
|
|---|
| 185 | text. All the access functions defined for class <span class="emphasis"><em>G4VMarker</em></span>
|
|---|
| 186 | mentioned above are available. In addition, the following access
|
|---|
| 187 | functions are available, too:
|
|---|
| 188 |
|
|---|
| 189 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 190 | //----- Set functions of G4Text
|
|---|
| 191 | void G4Text::SetText ( const G4String& text ) ;
|
|---|
| 192 | void G4Text::SetOffset ( double dx, double dy ) ;
|
|---|
| 193 |
|
|---|
| 194 | //----- Get functions of G4Text
|
|---|
| 195 | G4String G4Text::GetText () const;
|
|---|
| 196 | G4double G4Text::GetXOffset () const;
|
|---|
| 197 | G4double G4Text::GetYOffset () const;
|
|---|
| 198 | </pre></div><p>
|
|---|
| 199 | </p><p>
|
|---|
| 200 | Method <code class="literal">SetText()</code> defines text to be visualized, and
|
|---|
| 201 | <code class="literal">GetText()</code> returns the defined text. Method
|
|---|
| 202 | <code class="literal">SetOffset()</code> defines x (horizontal) and y (vertical)
|
|---|
| 203 | offsets in the screen coordinates. By default, both offsets are
|
|---|
| 204 | zero, and the text starts from the 3D position given to the
|
|---|
| 205 | constructor or to the method <code class="literal">G4VMarker:SetPosition()</code>.
|
|---|
| 206 | Offsets should be given with the same units as the one adopted for
|
|---|
| 207 | the size, i.e., world-size or screen-size units.
|
|---|
| 208 | </p><p>
|
|---|
| 209 | <a href="ch08s09.html#programlist_VisPlylMrkTxt_4" title="Example 8.8.
|
|---|
| 210 | An example of defining text.
|
|---|
| 211 | ">Example 8.8</a> shows sample C++ source code
|
|---|
| 212 | to define text with the following properties:
|
|---|
| 213 |
|
|---|
| 214 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 215 | Text: "Welcome to Geant4 Visualization"
|
|---|
| 216 | </p></li><li><p>
|
|---|
| 217 | Position: (0.,0.,0.) in the world coordinates
|
|---|
| 218 | </p></li><li><p>
|
|---|
| 219 | Horizontal offset: 10 pixels
|
|---|
| 220 | </p></li><li><p>
|
|---|
| 221 | Vertical offset: -20 pixels
|
|---|
| 222 | </p></li><li><p>
|
|---|
| 223 | Colour: blue (default)
|
|---|
| 224 | </p></li></ul></div><p>
|
|---|
| 225 | </p><p>
|
|---|
| 226 | </p><div class="example"><a name="programlist_VisPlylMrkTxt_4"></a><p class="title"><b>Example 8.8.
|
|---|
| 227 | An example of defining text.
|
|---|
| 228 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 229 | //----- C++ source codes: An example of defining a visualizable text
|
|---|
| 230 |
|
|---|
| 231 | //----- Instantiation
|
|---|
| 232 | G4Text text ;
|
|---|
| 233 | text.SetText ( "Welcome to Geant4 Visualization");
|
|---|
| 234 | text.SetPosition ( G4Point3D(0.,0.,0.) );
|
|---|
| 235 | // These three lines are equivalent to:
|
|---|
| 236 | // G4Text text ( "Welcome to Geant4 Visualization",
|
|---|
| 237 | // G4Point3D(0.,0.,0.) );
|
|---|
| 238 |
|
|---|
| 239 | //----- Size (font size in units of pixels)
|
|---|
| 240 | G4double fontsize = 24.; // Should be 24. * pixels - to be implemented.
|
|---|
| 241 | text.SetScreenSize ( fontsize );
|
|---|
| 242 |
|
|---|
| 243 | //----- Offsets
|
|---|
| 244 | G4double x_offset = 10.; // Should be 10. * pixels - to be implemented.
|
|---|
| 245 | G4double y_offset = -20.; // Should be -20. * pixels - to be implemented.
|
|---|
| 246 | text.SetOffset( x_offset, y_offset );
|
|---|
| 247 |
|
|---|
| 248 | //----- Color (Blue is the default setting, and so the codes below are omissible)
|
|---|
| 249 | G4Colour blue( 0., 0., 1. );
|
|---|
| 250 | G4VisAttributes att ( blue );
|
|---|
| 251 | text.SetVisAttributes ( att );
|
|---|
| 252 |
|
|---|
| 253 | //----- end of C++ source codes
|
|---|
| 254 | </pre></div></div><p><br class="example-break">
|
|---|
| 255 | </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch08s08.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="ch08.html"><img src="AllResources/IconsGIF/up.gif" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="ch08s10.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">8.8.
|
|---|
| 256 | Trajectory Filtering
|
|---|
| 257 | </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="AllResources/IconsGIF/home.gif" alt="Home"></a></td><td width="40%" align="right" valign="top"> 8.10.
|
|---|
| 258 | Making a Movie
|
|---|
| 259 | </td></tr></table></div></body></html>
|
|---|