source: trunk/Documentation/geant4/UserDocumentation/UsersGuides/ForApplicationDeveloper/html/ch08s09.html @ 902

Last change on this file since 902 was 901, checked in by garnier, 16 years ago

Add Geant4 Documentation at 8.12.2008

File size: 13.3 KB
Line 
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">
2function 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. 
9Polylines, 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. 
11Visualization
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. 
13Polylines, 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
17visualization. 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. 
19Polylines
20</h3></div></div></div><p>
21A polyline is a set of successive line segments. It is defined with
22a class <span class="emphasis"><em>G4Polyline</em></span> defined in the
23<code class="literal">graphics_reps</code> category.
24A polyline is used to visualize tracking steps, particle
25trajectories, coordinate axes, and any other user-defined objects
26made 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.
30The vertex positions are set to a <span class="emphasis"><em>G4Polyline</em></span> 
31object with the <code class="literal">push_back()</code> method.
32</p><p>
33For example, an x-axis with length 5 cm and with red color is
34defined in <a href="ch08s09.html#programlist_VisPlylMrkTxt_1" title="Example 8.5. 
35Defining 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. 
39Defining 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
43G4Polyline  x_axis;
44
45// Set red line colour
46G4Colour         red(1.0, 0.0, 0.0);
47G4VisAttributes  att(red);     
48x_axis.SetVisAttributes(&amp;att);
49
50// Set vertex positions
51x_axis.push_back( G4Point3D(0., 0., 0.) );
52x_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. 
57Markers
58</h3></div></div></div><p>
59Here we explain how to use 3D markers in Geant4 Visualization.
60</p><h5><a name="id519964"></a>
61What are Markers?
62</h5><p>
63Markers set marks at arbitrary positions in the 3D space. They
64are often used to visualize hits of particles at detector
65components. A marker is a 2-dimensional primitive with shape
66(square, circle, etc), color, and special properties (a) of always
67facing the camera and (b) of having the possibility of a size
68defined in screen units (pixels). Here "size" means "overall size",
69e.g., diameter of circle and side of square (but diameter and
70radius access functions are defined to avoid ambiguity).
71</p><p>
72So the user who constructs a marker should decide whether or not
73it should be visualized to a given size in world coordinates by
74setting the world size. Alternatively, the user can set the screen
75size and the marker is visualized to its screen size. Finally, the
76user may decide not to set any size; in that case, it is drawn
77according to the sizes specified in the default marker specified in
78the class <span class="emphasis"><em>G4ViewParameters</em></span>.
79</p><p>
80By default, "square" and "circle" are supported in Geant4
81Visualization. The former is described with class <span class="emphasis"><em>G4Square</em></span>,
82and 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>
98These classes are inherited from class <span class="emphasis"><em>G4VMarker</em></span>.
99They have constructors as follows:
100
101</p><div class="informalexample"><pre class="programlisting">
102      //----- Constructors of G4Circle and G4Square
103      G4Circle::G4Circle (const G4Point3D&amp; pos );
104      G4Square::G4Square (const G4Point3D&amp; pos);
105</pre></div><p>
106</p><p>
107Access functions of class <span class="emphasis"><em>G4VMarker</em></span> are summarized below.
108</p><h5><a name="id520087"></a>
109Access functions of markers
110</h5><p>
111<a href="ch08s09.html#programlist_VisPlylMrkTxt_2" title="Example 8.6. 
112The access functions inherited from the base class
113G4VMarker.
114">Example 8.6</a> shows the access functions
115inherited 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. 
118The 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&amp; );
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. 
145Sample C++ source code to define a very small red circle.
146">Example 8.7</a> shows sample C++ source
147code to define a very small red circle, i.e., a dot with diameter 1.0 pixel.
148Such 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. 
151Sample 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. 
166Text
167</h3></div></div></div><p>
168Text, i.e., a character string, is used to visualize various kinds
169of description, particle name, energy, coordinate names etc. Text
170is described by the class <span class="emphasis"><em>G4Text</em></span> . The following
171constructors are supported:
172
173</p><div class="informalexample"><pre class="programlisting">
174     //----- Constructors of G4Text
175     G4Text (const G4String&amp; text);
176     G4Text (const G4String&amp; text, const G4Point3D&amp; pos);
177</pre></div><p>
178
179where the argument <code class="literal">text</code> is the text (string) to be
180visualized, and <code class="literal">pos</code> is the 3D position at which the text
181is visualized.
182</p><p>
183Note that class <span class="emphasis"><em>G4Text</em></span> also inherits <span class="emphasis"><em>G4VMarker</em></span>.
184Size of text is recognized as "font size", i.e., height of the
185text. All the access functions defined for class <span class="emphasis"><em>G4VMarker</em></span>
186mentioned above are available. In addition, the following access
187functions are available, too:
188
189</p><div class="informalexample"><pre class="programlisting">
190     //----- Set functions of G4Text
191     void G4Text::SetText ( const G4String&amp; 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>
200Method <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)
203offsets in the screen coordinates. By default, both offsets are
204zero, and the text starts from the 3D position given to the
205constructor or to the method <code class="literal">G4VMarker:SetPosition()</code>.
206Offsets should be given with the same units as the one adopted for
207the size, i.e., world-size or screen-size units.
208</p><p>
209<a href="ch08s09.html#programlist_VisPlylMrkTxt_4" title="Example 8.8. 
210An example of defining text.
211">Example 8.8</a> shows sample C++ source code
212to 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. 
227An 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. 
256Trajectory 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. 
258Making a Movie
259</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.