1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>2.10. How to Visualize the Detector and Events</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="ch02.html" title="Chapter 2. Getting Started with Geant4 - Running a Simple Example"><link rel="prev" href="ch02s09.html" title="2.9. How to Execute a Program"><link rel="next" href="ch03.html" title="Chapter 3. Toolkit Fundamentals"><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">2.10. |
---|
9 | How to Visualize the Detector and Events |
---|
10 | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s09.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 2. |
---|
11 | Getting Started with Geant4 - Running a Simple Example |
---|
12 | </th><td width="20%" align="right"> <a accesskey="n" href="ch03.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.HowToVis"></a>2.10. |
---|
13 | How to Visualize the Detector and Events |
---|
14 | </h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.HowToVis.Intro"></a>2.10.1. |
---|
15 | Introduction |
---|
16 | </h3></div></div></div><p> |
---|
17 | This section briefly explains how to perform Geant4 Visualization. |
---|
18 | The description here is based on the sample program |
---|
19 | <code class="literal">examples/novice/N03</code>. More details are given in |
---|
20 | <a href="ch08.html" title="Chapter 8. |
---|
21 | Visualization |
---|
22 | ">Chapter 8</a> "Visualization". |
---|
23 | Example macro files can be found in |
---|
24 | <code class="literal">examples/novice/N03/visTutor/exN03VisX.mac</code>. |
---|
25 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.HowToVis.VisDrivers"></a>2.10.2. |
---|
26 | Visualization Drivers |
---|
27 | </h3></div></div></div><p> |
---|
28 | The Geant4 visualization system was developed in response to a |
---|
29 | diverse set of requirements: |
---|
30 | |
---|
31 | </p><div class="orderedlist"><ol type="1" compact><li><p> |
---|
32 | Quick response to study geometries, trajectories and hits |
---|
33 | </p></li><li><p> |
---|
34 | High-quality output for publications |
---|
35 | </p></li><li><p> |
---|
36 | Flexible camera control to debug complex geometries |
---|
37 | </p></li><li><p> |
---|
38 | Tools to show volume overlap errors in detector geometries |
---|
39 | </p></li><li><p> |
---|
40 | Interactive picking to get more information on visualized objects |
---|
41 | </p></li></ol></div><p> |
---|
42 | </p><p> |
---|
43 | No one graphics system is ideal for all of these requirements, |
---|
44 | and many of the large software frameworks into which Geant4 has |
---|
45 | been incorporated already have their own visualization systems, so |
---|
46 | Geant4 visualization was designed around an abstract interface that |
---|
47 | supports a diverse family of graphics systems. Some of these |
---|
48 | graphics systems use a graphics library compiled with Geant4, such |
---|
49 | as OpenGL, while others involve a separate application, such as |
---|
50 | WIRED or DAWN. |
---|
51 | </p><p> |
---|
52 | You need not use all visualization drivers. You can select those |
---|
53 | suitable to your purposes. In the following, for simplicity, we |
---|
54 | assume that the Geant4 libraries are built (installed) with the |
---|
55 | "OpenGL-Xlib driver" and the "DAWNFILE driver" incorporated. |
---|
56 | </p><p> |
---|
57 | In order to use the DAWNFILE driver, you need Fukui Renderer |
---|
58 | DAWN, which is obtainable from the following Web site: |
---|
59 | <a href="http://geant4.kek.jp/GEANT4/vis" target="_top"> |
---|
60 | http://geant4.kek.jp/GEANT4/vis</a>. |
---|
61 | </p><p> |
---|
62 | In order to use the the OpenGL drivers, you need the OpenGL |
---|
63 | library, which is installed in many platforms by default. You also |
---|
64 | need to set an environmental variable |
---|
65 | <code class="literal">G4VIS_BUILD_OPENGLX_DRIVER</code> to <code class="literal">1</code> in |
---|
66 | building (installing) Genat4 libraries, and also set another environmental |
---|
67 | variable <code class="literal">G4VIS_USE_OPENGLX</code> to <code class="literal">1</code> |
---|
68 | in compiling your Geant4 executable. You may also have to set an |
---|
69 | environmental variable <code class="literal">OGLHOME</code> to the OpenGL root |
---|
70 | directory. For example, |
---|
71 | |
---|
72 | </p><div class="informalexample"><pre class="programlisting"> |
---|
73 | setenv G4VIS_BUILD_OPENGLX_DRIVER 1 |
---|
74 | setenv G4VIS_USE_OPENGLX 1 |
---|
75 | setenv OGLHOME /usr/X11R6 |
---|
76 | </pre></div><p> |
---|
77 | </p><p> |
---|
78 | Some other visualization drivers depending on external libraries |
---|
79 | are also required to set the similar environmental variables, |
---|
80 | <code class="literal">G4VIS_BUILD_DRIVERNAME_DRIVER</code> and |
---|
81 | <code class="literal">G4VIS_USE_DRIVERNAME</code>, to <code class="literal">1</code>. All |
---|
82 | visualization drivers independent of external libraries, e.g. DAWNFILE and |
---|
83 | VRMLFILE drivers, need not such setting. (But you must prepare a |
---|
84 | proper visualization manager class and a proper <code class="literal">main()</code> |
---|
85 | function, anyway. See below.) |
---|
86 | </p><p> |
---|
87 | For all visualization drivers available in your Geant4 |
---|
88 | executable, the C-pre-processor flags <code class="literal">G4VIS_USE_DRIVERNAME</code> |
---|
89 | are automatically set by <code class="literal">config/G4VIS_USE.gmk</code> in |
---|
90 | compilation. Similarly, for all visualization drivers incorporated |
---|
91 | into the Geant4 libraries, the C-pre-processor flags |
---|
92 | <code class="literal">G4VIS_BUILD_DRIVERNAME_DRIVER</code> are automatically set by |
---|
93 | <code class="literal">config/G4VIS_BUILD.gmk</code> in installation. |
---|
94 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.HowToVis.IncorpVisDrivers"></a>2.10.3. |
---|
95 | How to Incorporate Visualization Drivers into an Executable |
---|
96 | </h3></div></div></div><p> |
---|
97 | You can realize (use) visualization driver(s) you want in your |
---|
98 | Geant4 executable. These can only be from the set installed in the |
---|
99 | Geant4 libraries. You will be warned if the one you request is not |
---|
100 | available. |
---|
101 | </p><p> |
---|
102 | In order to realize visualization drivers, you must instantiate |
---|
103 | and initialize a subclass of <code class="literal">G4VisManager</code> that implements |
---|
104 | the pure virtual function <code class="literal">RegisterGraphicsSystems()</code>. This |
---|
105 | subclass must be compiled in the user's domain to force the loading |
---|
106 | of appropriate libraries in the right order. The easiest way to do |
---|
107 | this is to use <code class="literal">G4VisExecutive</code>, a provided class with |
---|
108 | included implementation. <code class="literal">G4VisExecutive</code> is sensitive to |
---|
109 | the <code class="literal">G4VIS_USE...</code> variables mentioned above. |
---|
110 | </p><p> |
---|
111 | If you do wish to write your own subclass, you may do so. You |
---|
112 | will see how to do this by looking at <code class="literal">G4VisExecutive.icc</code>. |
---|
113 | A typical extract is: |
---|
114 | |
---|
115 | </p><div class="informalexample"><pre class="programlisting"> |
---|
116 | ... |
---|
117 | RegisterGraphicsSystem (new G4DAWNFILE); |
---|
118 | ... |
---|
119 | #ifdef G4VIS_USE_OPENGLX |
---|
120 | RegisterGraphicsSystem (new G4OpenGLImmediateX); |
---|
121 | RegisterGraphicsSystem (new G4OpenGLStoredX); |
---|
122 | #endif |
---|
123 | ... |
---|
124 | </pre></div><p> |
---|
125 | </p><p> |
---|
126 | If you wish to use <code class="literal">G4VisExecutive</code> but register an |
---|
127 | additional graphics system, <code class="literal">XXX</code> say, you may do so either |
---|
128 | before or after initializing: |
---|
129 | |
---|
130 | </p><div class="informalexample"><pre class="programlisting"> |
---|
131 | visManager->RegisterGraphicsSytem(new XXX); |
---|
132 | visManager->Initialize(); |
---|
133 | </pre></div><p> |
---|
134 | </p><p> |
---|
135 | An example of a typical <code class="literal">main()</code> function is given |
---|
136 | below. |
---|
137 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.HowToVis.WritingMain"></a>2.10.4. |
---|
138 | Writing the <code class="literal">main()</code> Method to Include Visualization |
---|
139 | </h3></div></div></div><p> |
---|
140 | Now we explain how to write a visualization manager and the |
---|
141 | <code class="literal">main()</code> function for Geant4 visualization. In order that |
---|
142 | your Geant4 executable is able to perform visualization, you must |
---|
143 | instantiate and initialize <span class="emphasis"><em>your</em></span> Visualization Manager |
---|
144 | in the <code class="literal">main()</code> function. The typical |
---|
145 | <code class="literal">main()</code> |
---|
146 | function available for visualization is written in the following style: |
---|
147 | |
---|
148 | </p><div class="example"><a name="programlist_HowToVis_1"></a><p class="title"><b>Example 2.26. |
---|
149 | The typical <code class="literal">main()</code> routine available for visualization. |
---|
150 | </b></p><div class="example-contents"><pre class="programlisting"> |
---|
151 | //----- C++ source codes: main() function for visualization |
---|
152 | #ifdef G4VIS_USE |
---|
153 | #include "G4VisExecutive.hh" |
---|
154 | #endif |
---|
155 | |
---|
156 | ..... |
---|
157 | |
---|
158 | int main(int argc,char** argv) { |
---|
159 | |
---|
160 | ..... |
---|
161 | |
---|
162 | // Instantiation and initialization of the Visualization Manager |
---|
163 | #ifdef G4VIS_USE |
---|
164 | // visualization manager |
---|
165 | G4VisManager* visManager = new G4VisExecutive; |
---|
166 | visManager->Initialize(); |
---|
167 | #endif |
---|
168 | |
---|
169 | ..... |
---|
170 | |
---|
171 | // Job termination |
---|
172 | #ifdef G4VIS_USE |
---|
173 | delete visManager; |
---|
174 | #endif |
---|
175 | |
---|
176 | ..... |
---|
177 | |
---|
178 | return 0; |
---|
179 | } |
---|
180 | |
---|
181 | //----- end of C++ |
---|
182 | </pre></div></div><p><br class="example-break"> |
---|
183 | </p><p> |
---|
184 | In the instantiation, initialization, and deletion of the |
---|
185 | Visualization Manager, the use of the macro <code class="literal">G4VIS_USE</code> is |
---|
186 | recommended. This is set unless the environment variable |
---|
187 | <code class="literal">G4VIS_NONE</code> is set. This allows one easily to build an |
---|
188 | executable without visualization, if required, without changing the |
---|
189 | code (but remember you have to force recompilation whenever you |
---|
190 | change the environment). Note that it is your responsibility to |
---|
191 | delete the instantiated Visualization Manager by yourself. A |
---|
192 | complete description of a sample <code class="literal">main()</code> function is |
---|
193 | described in <code class="literal">examples/novice/N03/exampleN03.cc</code>. |
---|
194 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.HowToVis.SampleVis"></a>2.10.5. |
---|
195 | Sample Visualization Sessions |
---|
196 | </h3></div></div></div><p> |
---|
197 | In this section we present typical sessions of Geant4 |
---|
198 | visualization. You can test them with the sample program |
---|
199 | geant4/examples/novice/N03. Run a binary executable "exampleN03" |
---|
200 | without an argument, and then execute the commands below in the |
---|
201 | "Idle>" state. Explanation of each command will be described |
---|
202 | later. (Note that the OpenGL-Xlib driver and the DAWNFILE driver |
---|
203 | are incorporated into the executable, and that Fukui Renderer DAWN |
---|
204 | is installed in your machine. ) |
---|
205 | </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.HowToVis.SampleVis.VisDetector"></a>2.10.5.1. |
---|
206 | Visualization of detector components |
---|
207 | </h4></div></div></div><p> |
---|
208 | The following session visualizes detector components with the |
---|
209 | OpenGL-Xlib driver and then with the DAWNFILE driver. The former |
---|
210 | exhibits minimal visualization commands to visualize detector |
---|
211 | geometry, while the latter exhibits customized visualization |
---|
212 | (visualization of a selected physical volume, coordinate axes, |
---|
213 | texts, etc). |
---|
214 | |
---|
215 | </p><div class="informalexample"><pre class="programlisting"> |
---|
216 | ################################################### |
---|
217 | # vis1.mac: |
---|
218 | # A Sample macro to demonstrate visualization |
---|
219 | # of detector geometry. |
---|
220 | # |
---|
221 | # USAGE: |
---|
222 | # Save the commands below as a macro file, say, |
---|
223 | # "vis1.mac", and execute it as follows: |
---|
224 | # |
---|
225 | # % $(G4BINDIR)/exampleN03 |
---|
226 | # Idle> /control/execute vis1.mac |
---|
227 | ############################################# |
---|
228 | |
---|
229 | ############################################# |
---|
230 | # Visualization of detector geometry |
---|
231 | # with the OGLIX (OpenGL Immediate X) driver |
---|
232 | ############################################# |
---|
233 | |
---|
234 | # Invoke the OGLIX driver: |
---|
235 | # Create a scene handler and a viewer for the OGLIX driver |
---|
236 | /vis/open OGLIX |
---|
237 | |
---|
238 | # Visualize the whole detector geometry |
---|
239 | # with the default camera parameters. |
---|
240 | # Command "/vis/drawVolume" visualizes the detector geometry, |
---|
241 | # and command "/vis/viewer/flush" declares the end of visualization. |
---|
242 | # (The command /vis/viewer/flush can be omitted for the OGLIX |
---|
243 | # and OGLSX drivers.) |
---|
244 | # The default argument of "/vis/drawVolume" is "world". |
---|
245 | /vis/drawVolume |
---|
246 | /vis/viewer/flush |
---|
247 | |
---|
248 | ######################################### |
---|
249 | # Visualization with the DAWNFILE driver |
---|
250 | ######################################### |
---|
251 | |
---|
252 | # Invoke the DAWNFILE driver |
---|
253 | # Create a scene handler and a viewer for the DAWNFILE driver |
---|
254 | /vis/open DAWNFILE |
---|
255 | |
---|
256 | # Bird's-eye view of a detector component (Absorber) |
---|
257 | # drawing style: hidden-surface removal |
---|
258 | # viewpoint : (theta,phi) = (35*deg, 45*deg), |
---|
259 | # zoom factor: 1.1 of the full screen size |
---|
260 | # coordinate axes: |
---|
261 | # x-axis:red, y-axis:green, z-axis:blue |
---|
262 | # origin: (0,0,0), length: 500 mm |
---|
263 | # |
---|
264 | /vis/viewer/reset |
---|
265 | /vis/viewer/set/style surface |
---|
266 | /vis/viewer/zoom 1.1 |
---|
267 | /vis/viewer/set/viewpointThetaPhi 35 45 |
---|
268 | /vis/drawVolume Absorber |
---|
269 | /vis/scene/add/axes 0 0 0 500 mm |
---|
270 | /vis/scene/add/text 0 0 0 mm 40 -100 -140 Absorber |
---|
271 | /vis/viewer/flush |
---|
272 | |
---|
273 | # Bird's-eye view of the whole detector components |
---|
274 | # * "/vis/viewer/set/culling global false" makes the invisible |
---|
275 | # world volume visible. |
---|
276 | # (The invisibility of the world volume is set |
---|
277 | # in ExN03DetectorConstruction.cc.) |
---|
278 | /vis/viewer/set/style wireframe |
---|
279 | /vis/viewer/set/culling global false |
---|
280 | /vis/drawVolume |
---|
281 | /vis/scene/add/axes 0 0 0 500 mm |
---|
282 | /vis/scene/add/text 0 0 0 mm 50 -50 -200 world |
---|
283 | /vis/viewer/flush |
---|
284 | ################### END of vis1.mac ################### |
---|
285 | </pre></div><p> |
---|
286 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.HowToVis.SampleVis.VisEvents"></a>2.10.5.2. |
---|
287 | Visualization of events |
---|
288 | </h4></div></div></div><p> |
---|
289 | The following session visualizes events (tajectories) with the |
---|
290 | OpenGL-Xlib driver and then with the DAWNFILE driver. The former |
---|
291 | exhibits minimal visualization commands to visualize events, while |
---|
292 | the latter exhibits customized visualization. Note that the run |
---|
293 | action and event action classes should be described properly. (See, |
---|
294 | for example, the following classes: |
---|
295 | "examples/novice/N03/src/ExN03RunAction.cc", |
---|
296 | |
---|
297 | </p><div class="informalexample"><pre class="programlisting"> |
---|
298 | ################################################### |
---|
299 | # vis2.mac: |
---|
300 | # A Sample macro to demonstrate visualization |
---|
301 | # of events (trajectories). |
---|
302 | # |
---|
303 | # USAGE: |
---|
304 | # Save the commands below as a macro file, say, |
---|
305 | # "vis2.mac", and execute it as follows: |
---|
306 | # |
---|
307 | # % $(G4BINDIR)/exampleN03 |
---|
308 | # Idle> /control/execute vis1.mac |
---|
309 | ############################################# |
---|
310 | |
---|
311 | ##################################################### |
---|
312 | # Store particle trajectories for visualization |
---|
313 | /tracking/storeTrajectory 1 |
---|
314 | ##################################################### |
---|
315 | |
---|
316 | ######################################################## |
---|
317 | # Visualization with the OGLSX (OpenGL Stored X) driver |
---|
318 | ######################################################## |
---|
319 | |
---|
320 | # Invoke the OGLSX driver |
---|
321 | # Create a scene handler and a viewer for the OGLSX driver |
---|
322 | /vis/open OGLSX |
---|
323 | |
---|
324 | # Create an empty scene and add detector components to it |
---|
325 | /vis/drawVolume |
---|
326 | |
---|
327 | # Add trajectories to the current scene |
---|
328 | # Note: This command is not necessary in, e.g., |
---|
329 | # examples/novice/N03, since the C++ method DrawTrajectory() |
---|
330 | # is described in the event action. |
---|
331 | #/vis/scene/add/trajectories |
---|
332 | |
---|
333 | # Set viewing parameters |
---|
334 | /vis/viewer/reset |
---|
335 | /vis/viewer/set/viewpointThetaPhi 10 20 |
---|
336 | |
---|
337 | # Visualize one it. |
---|
338 | /run/beamOn 1 |
---|
339 | |
---|
340 | ########################################################## |
---|
341 | # Visualization with the DAWNFILE driver |
---|
342 | ########################################################## |
---|
343 | |
---|
344 | # Invoke the DAWNFILE driver |
---|
345 | # Create a scene handler and a viewer for the DAWNFILE driver |
---|
346 | /vis/open DAWNFILE |
---|
347 | |
---|
348 | # Create an empty scene and add detector components to it |
---|
349 | /vis/drawVolume |
---|
350 | |
---|
351 | # Add trajectories to the current scene |
---|
352 | # Note: This command is not necessary in exampleN03, |
---|
353 | # since the C++ method DrawTrajectory() is |
---|
354 | # described in the event action. |
---|
355 | #/vis/scene/add/trajectories |
---|
356 | |
---|
357 | # Visualize plural events (bird's eye view) |
---|
358 | # drawing style: wireframe |
---|
359 | # viewpoint : (theta,phi) = (45*deg, 45*deg) |
---|
360 | # zoom factor: 1.5 x (full screen size) |
---|
361 | /vis/viewer/reset |
---|
362 | /vis/viewer/set/style wireframe |
---|
363 | /vis/viewer/set/viewpointThetaPhi 45 45 |
---|
364 | /vis/viewer/zoom 1.5 |
---|
365 | /run/beamOn 2 |
---|
366 | |
---|
367 | # Set the drawing style to "surface" |
---|
368 | # Candidates: wireframe, surface |
---|
369 | /vis/viewer/set/style surface |
---|
370 | |
---|
371 | # Visualize plural events (bird's eye view) again |
---|
372 | # with another drawing style (surface) |
---|
373 | /run/beamOn 2 |
---|
374 | |
---|
375 | ################### END of vis2.mac ################### |
---|
376 | </pre></div><p> |
---|
377 | </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.HowToVis.MoreInfo"></a>2.10.6. |
---|
378 | For More Information on Geant4 Visualization |
---|
379 | </h3></div></div></div><p> |
---|
380 | See the <a href="ch08.html" title="Chapter 8. |
---|
381 | Visualization |
---|
382 | ">Chapter 8</a> "Visualization" |
---|
383 | part of this user guide. |
---|
384 | </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s09.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html"><img src="AllResources/IconsGIF/up.gif" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="ch03.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">2.9. |
---|
385 | How to Execute a Program |
---|
386 | </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"> Chapter 3. |
---|
387 | Toolkit Fundamentals |
---|
388 | </td></tr></table></div></body></html> |
---|