1 | <!-- ******************************************************** --> |
---|
2 | <!-- --> |
---|
3 | <!-- [History] --> |
---|
4 | <!-- Converted to DocBook: Katsuya Amako, Aug-2006 --> |
---|
5 | <!-- Changed by: Katsuya Amako, 30-Nov-1998 --> |
---|
6 | <!-- Changed by: Satoshi Tanaka, 1-Jun-2000 --> |
---|
7 | <!-- Changed by: Dennis Wright, 29-Nov-2001 --> |
---|
8 | <!-- Proof read by: Joe Chuma, 15-Jun-1999 --> |
---|
9 | <!-- --> |
---|
10 | <!-- ******************************************************** --> |
---|
11 | |
---|
12 | <!-- ******************* Section (Level#1) ****************** --> |
---|
13 | <sect1 id="sect.HowToVis"> |
---|
14 | <title> |
---|
15 | How to Visualize the Detector and Events |
---|
16 | </title> |
---|
17 | |
---|
18 | |
---|
19 | <!-- ******************* Section (Level#2) ****************** --> |
---|
20 | <sect2 id="sect.HowToVis.Intro"> |
---|
21 | <title> |
---|
22 | Introduction |
---|
23 | </title> |
---|
24 | |
---|
25 | <para> |
---|
26 | This section briefly explains how to perform Geant4 Visualization. |
---|
27 | The description here is based on the sample program |
---|
28 | <literal>examples/novice/N03</literal>. More details are given in |
---|
29 | <xref linkend="chap.Visualization" /> "Visualization". |
---|
30 | Example macro files can be found in |
---|
31 | <literal>examples/novice/N03/visTutor/exN03VisX.mac</literal>. |
---|
32 | </para> |
---|
33 | |
---|
34 | </sect2> |
---|
35 | |
---|
36 | |
---|
37 | <!-- ******************* Section (Level#2) ****************** --> |
---|
38 | <sect2 id="sect.HowToVis.VisDrivers"> |
---|
39 | <title> |
---|
40 | Visualization Drivers |
---|
41 | </title> |
---|
42 | |
---|
43 | <para> |
---|
44 | The Geant4 visualization system was developed in response to a |
---|
45 | diverse set of requirements: |
---|
46 | |
---|
47 | <orderedlist spacing="compact"> |
---|
48 | <listitem><para> |
---|
49 | Quick response to study geometries, trajectories and hits |
---|
50 | </para></listitem> |
---|
51 | <listitem><para> |
---|
52 | High-quality output for publications |
---|
53 | </para></listitem> |
---|
54 | <listitem><para> |
---|
55 | Flexible camera control to debug complex geometries |
---|
56 | </para></listitem> |
---|
57 | <listitem><para> |
---|
58 | Tools to show volume overlap errors in detector geometries |
---|
59 | </para></listitem> |
---|
60 | <listitem><para> |
---|
61 | Interactive picking to get more information on visualized objects |
---|
62 | </para></listitem> |
---|
63 | </orderedlist> |
---|
64 | </para> |
---|
65 | |
---|
66 | <para> |
---|
67 | No one graphics system is ideal for all of these requirements, |
---|
68 | and many of the large software frameworks into which Geant4 has |
---|
69 | been incorporated already have their own visualization systems, so |
---|
70 | Geant4 visualization was designed around an abstract interface that |
---|
71 | supports a diverse family of graphics systems. Some of these |
---|
72 | graphics systems use a graphics library compiled with Geant4, such |
---|
73 | as OpenGL, Qt or OpenInventor, while others involve a separate application, such as |
---|
74 | WIRED or DAWN. |
---|
75 | </para> |
---|
76 | |
---|
77 | <para> |
---|
78 | You need not use all visualization drivers. You can select those |
---|
79 | suitable to your purposes. In the following, for simplicity, we |
---|
80 | assume that the Geant4 libraries are built (installed) with the |
---|
81 | "OpenGL-Xlib driver" and the "DAWNFILE driver" incorporated. |
---|
82 | </para> |
---|
83 | |
---|
84 | <para> |
---|
85 | In order to use the DAWNFILE driver, you need Fukui Renderer |
---|
86 | DAWN, which is obtainable from the following Web site: |
---|
87 | <ulink url="http://geant4.kek.jp/GEANT4/vis"> |
---|
88 | http://geant4.kek.jp/GEANT4/vis</ulink>. |
---|
89 | </para> |
---|
90 | |
---|
91 | <para> |
---|
92 | In order to use the the OpenGL drivers, you need the OpenGL |
---|
93 | library, which is installed in many platforms by default. You also |
---|
94 | need to set an environmental variable |
---|
95 | <literal>G4VIS_BUILD_OPENGLX_DRIVER</literal> to <literal>1</literal> in |
---|
96 | building (installing) Genat4 libraries, and also set another environmental |
---|
97 | variable <literal>G4VIS_USE_OPENGLX</literal> to <literal>1</literal> |
---|
98 | in compiling your Geant4 executable. You may also have to set an |
---|
99 | environmental variable <literal>OGLHOME</literal> to the OpenGL root |
---|
100 | directory. For example, |
---|
101 | |
---|
102 | <informalexample> |
---|
103 | <programlisting> |
---|
104 | setenv G4VIS_BUILD_OPENGLX_DRIVER 1 |
---|
105 | setenv G4VIS_USE_OPENGLX 1 |
---|
106 | setenv OGLHOME /usr/X11R6 |
---|
107 | </programlisting> |
---|
108 | </informalexample> |
---|
109 | </para> |
---|
110 | |
---|
111 | <para> |
---|
112 | Some other visualization drivers depending on external libraries |
---|
113 | are also required to set the similar environmental variables, |
---|
114 | <literal>G4VIS_BUILD_DRIVERNAME_DRIVER</literal> and |
---|
115 | <literal>G4VIS_USE_DRIVERNAME</literal>, to <literal>1</literal>. All |
---|
116 | visualization drivers independent of external libraries, e.g. DAWNFILE and |
---|
117 | VRMLFILE drivers, need not such setting. (But you must prepare a |
---|
118 | proper visualization manager class and a proper <literal>main()</literal> |
---|
119 | function, anyway. See below.) |
---|
120 | </para> |
---|
121 | |
---|
122 | <para> |
---|
123 | For all visualization drivers available in your Geant4 |
---|
124 | executable, the C-pre-processor flags <literal>G4VIS_USE_DRIVERNAME</literal> |
---|
125 | are automatically set by <literal>config/G4VIS_USE.gmk</literal> in |
---|
126 | compilation. Similarly, for all visualization drivers incorporated |
---|
127 | into the Geant4 libraries, the C-pre-processor flags |
---|
128 | <literal>G4VIS_BUILD_DRIVERNAME_DRIVER</literal> are automatically set by |
---|
129 | <literal>config/G4VIS_BUILD.gmk</literal> in installation. |
---|
130 | </para> |
---|
131 | |
---|
132 | </sect2> |
---|
133 | |
---|
134 | |
---|
135 | <!-- ******************* Section (Level#2) ****************** --> |
---|
136 | <sect2 id="sect.HowToVis.IncorpVisDrivers"> |
---|
137 | <title> |
---|
138 | How to Incorporate Visualization Drivers into an Executable |
---|
139 | </title> |
---|
140 | |
---|
141 | <para> |
---|
142 | You can realize (use) visualization driver(s) you want in your |
---|
143 | Geant4 executable. These can only be from the set installed in the |
---|
144 | Geant4 libraries. You will be warned if the one you request is not |
---|
145 | available. |
---|
146 | </para> |
---|
147 | |
---|
148 | <para> |
---|
149 | In order to realize visualization drivers, you must instantiate |
---|
150 | and initialize a subclass of <literal>G4VisManager</literal> that implements |
---|
151 | the pure virtual function <literal>RegisterGraphicsSystems()</literal>. This |
---|
152 | subclass must be compiled in the user's domain to force the loading |
---|
153 | of appropriate libraries in the right order. The easiest way to do |
---|
154 | this is to use <literal>G4VisExecutive</literal>, a provided class with |
---|
155 | included implementation. <literal>G4VisExecutive</literal> is sensitive to |
---|
156 | the <literal>G4VIS_USE...</literal> variables mentioned above. |
---|
157 | </para> |
---|
158 | |
---|
159 | <para> |
---|
160 | If you do wish to write your own subclass, you may do so. You |
---|
161 | will see how to do this by looking at <literal>G4VisExecutive.icc</literal>. |
---|
162 | A typical extract is: |
---|
163 | |
---|
164 | <informalexample> |
---|
165 | <programlisting> |
---|
166 | ... |
---|
167 | RegisterGraphicsSystem (new G4DAWNFILE); |
---|
168 | ... |
---|
169 | #ifdef G4VIS_USE_OPENGLX |
---|
170 | RegisterGraphicsSystem (new G4OpenGLImmediateX); |
---|
171 | RegisterGraphicsSystem (new G4OpenGLStoredX); |
---|
172 | #endif |
---|
173 | ... |
---|
174 | </programlisting> |
---|
175 | </informalexample> |
---|
176 | </para> |
---|
177 | |
---|
178 | <para> |
---|
179 | If you wish to use <literal>G4VisExecutive</literal> but register an |
---|
180 | additional graphics system, <literal>XXX</literal> say, you may do so either |
---|
181 | before or after initializing: |
---|
182 | |
---|
183 | <informalexample> |
---|
184 | <programlisting> |
---|
185 | visManager->RegisterGraphicsSytem(new XXX); |
---|
186 | visManager->Initialize(); |
---|
187 | </programlisting> |
---|
188 | </informalexample> |
---|
189 | </para> |
---|
190 | |
---|
191 | <para> |
---|
192 | An example of a typical <literal>main()</literal> function is given |
---|
193 | below. |
---|
194 | </para> |
---|
195 | |
---|
196 | </sect2> |
---|
197 | |
---|
198 | |
---|
199 | <!-- ******************* Section (Level#2) ****************** --> |
---|
200 | <sect2 id="sect.HowToVis.WritingMain"> |
---|
201 | <title> |
---|
202 | Writing the <literal>main()</literal> Method to Include Visualization |
---|
203 | </title> |
---|
204 | |
---|
205 | <para> |
---|
206 | Now we explain how to write a visualization manager and the |
---|
207 | <literal>main()</literal> function for Geant4 visualization. In order that |
---|
208 | your Geant4 executable is able to perform visualization, you must |
---|
209 | instantiate and initialize <emphasis>your</emphasis> Visualization Manager |
---|
210 | in the <literal>main()</literal> function. The typical |
---|
211 | <literal>main()</literal> |
---|
212 | function available for visualization is written in the following style: |
---|
213 | |
---|
214 | <example id="programlist_HowToVis_1"> |
---|
215 | <title> |
---|
216 | The typical <literal>main()</literal> routine available for visualization. |
---|
217 | </title> |
---|
218 | <programlisting> |
---|
219 | //----- C++ source codes: main() function for visualization |
---|
220 | #ifdef G4VIS_USE |
---|
221 | #include "G4VisExecutive.hh" |
---|
222 | #endif |
---|
223 | |
---|
224 | ..... |
---|
225 | |
---|
226 | int main(int argc,char** argv) { |
---|
227 | |
---|
228 | ..... |
---|
229 | |
---|
230 | // Instantiation and initialization of the Visualization Manager |
---|
231 | #ifdef G4VIS_USE |
---|
232 | // visualization manager |
---|
233 | G4VisManager* visManager = new G4VisExecutive; |
---|
234 | visManager->Initialize(); |
---|
235 | #endif |
---|
236 | |
---|
237 | ..... |
---|
238 | |
---|
239 | // Job termination |
---|
240 | #ifdef G4VIS_USE |
---|
241 | delete visManager; |
---|
242 | #endif |
---|
243 | |
---|
244 | ..... |
---|
245 | |
---|
246 | return 0; |
---|
247 | } |
---|
248 | |
---|
249 | //----- end of C++ |
---|
250 | </programlisting> |
---|
251 | </example> |
---|
252 | </para> |
---|
253 | |
---|
254 | <para> |
---|
255 | In the instantiation, initialization, and deletion of the |
---|
256 | Visualization Manager, the use of the macro <literal>G4VIS_USE</literal> is |
---|
257 | recommended. This is set unless the environment variable |
---|
258 | <literal>G4VIS_NONE</literal> is set. This allows one easily to build an |
---|
259 | executable without visualization, if required, without changing the |
---|
260 | code (but remember you have to force recompilation whenever you |
---|
261 | change the environment). Note that it is your responsibility to |
---|
262 | delete the instantiated Visualization Manager by yourself. A |
---|
263 | complete description of a sample <literal>main()</literal> function is |
---|
264 | described in <literal>examples/novice/N03/exampleN03.cc</literal>. |
---|
265 | </para> |
---|
266 | |
---|
267 | </sect2> |
---|
268 | |
---|
269 | |
---|
270 | <!-- ******************* Section (Level#2) ****************** --> |
---|
271 | <sect2 id="sect.HowToVis.SampleVis"> |
---|
272 | <title> |
---|
273 | Sample Visualization Sessions |
---|
274 | </title> |
---|
275 | |
---|
276 | <para> |
---|
277 | In this section we present typical sessions of Geant4 |
---|
278 | visualization. You can test them with the sample program |
---|
279 | geant4/examples/novice/N03. Run a binary executable "exampleN03" |
---|
280 | without an argument, and then execute the commands below in the |
---|
281 | "Idle>" state. Explanation of each command will be described |
---|
282 | later. (Note that the OpenGL-Xlib driver, Qt driver and the DAWNFILE driver |
---|
283 | are incorporated into the executable, and that Fukui Renderer DAWN |
---|
284 | is installed in your machine. ) |
---|
285 | </para> |
---|
286 | |
---|
287 | <!-- ******************* Section (Level#3) ****************** --> |
---|
288 | <sect3 id="sect.HowToVis.SampleVis.VisDetector"> |
---|
289 | <title> |
---|
290 | Visualization of detector components |
---|
291 | </title> |
---|
292 | |
---|
293 | <para> |
---|
294 | The following session visualizes detector components with the |
---|
295 | OpenGL-Xlib driver and then with the DAWNFILE driver. The former |
---|
296 | exhibits minimal visualization commands to visualize detector |
---|
297 | geometry, while the latter exhibits customized visualization |
---|
298 | (visualization of a selected physical volume, coordinate axes, |
---|
299 | texts, etc). |
---|
300 | |
---|
301 | <informalexample> |
---|
302 | <programlisting> |
---|
303 | ################################################### |
---|
304 | # vis1.mac: |
---|
305 | # A Sample macro to demonstrate visualization |
---|
306 | # of detector geometry. |
---|
307 | # |
---|
308 | # USAGE: |
---|
309 | # Save the commands below as a macro file, say, |
---|
310 | # "vis1.mac", and execute it as follows: |
---|
311 | # |
---|
312 | # % $(G4BINDIR)/exampleN03 |
---|
313 | # Idle> /control/execute vis1.mac |
---|
314 | ############################################# |
---|
315 | |
---|
316 | ############################################# |
---|
317 | # Visualization of detector geometry |
---|
318 | # with the OGLIX (OpenGL Immediate X) driver |
---|
319 | ############################################# |
---|
320 | |
---|
321 | # Invoke the OGLIX driver: |
---|
322 | # Create a scene handler and a viewer for the OGLIX driver |
---|
323 | /vis/open OGLIX |
---|
324 | |
---|
325 | # Visualize the whole detector geometry |
---|
326 | # with the default camera parameters. |
---|
327 | # Command "/vis/drawVolume" visualizes the detector geometry, |
---|
328 | # and command "/vis/viewer/flush" declares the end of visualization. |
---|
329 | # (The command /vis/viewer/flush can be omitted for the OGLIX |
---|
330 | # and OGLSX drivers.) |
---|
331 | # The default argument of "/vis/drawVolume" is "world". |
---|
332 | /vis/drawVolume |
---|
333 | /vis/viewer/flush |
---|
334 | |
---|
335 | ######################################### |
---|
336 | # Visualization with the DAWNFILE driver |
---|
337 | ######################################### |
---|
338 | |
---|
339 | # Invoke the DAWNFILE driver |
---|
340 | # Create a scene handler and a viewer for the DAWNFILE driver |
---|
341 | /vis/open DAWNFILE |
---|
342 | |
---|
343 | # Bird's-eye view of a detector component (Absorber) |
---|
344 | # drawing style: hidden-surface removal |
---|
345 | # viewpoint : (theta,phi) = (35*deg, 45*deg), |
---|
346 | # zoom factor: 1.1 of the full screen size |
---|
347 | # coordinate axes: |
---|
348 | # x-axis:red, y-axis:green, z-axis:blue |
---|
349 | # origin: (0,0,0), length: 500 mm |
---|
350 | # |
---|
351 | /vis/viewer/reset |
---|
352 | /vis/viewer/set/style surface |
---|
353 | /vis/viewer/zoom 1.1 |
---|
354 | /vis/viewer/set/viewpointThetaPhi 35 45 |
---|
355 | /vis/drawVolume Absorber |
---|
356 | /vis/scene/add/axes 0 0 0 500 mm |
---|
357 | /vis/scene/add/text 0 0 0 mm 40 -100 -140 Absorber |
---|
358 | /vis/viewer/flush |
---|
359 | |
---|
360 | # Bird's-eye view of the whole detector components |
---|
361 | # * "/vis/viewer/set/culling global false" makes the invisible |
---|
362 | # world volume visible. |
---|
363 | # (The invisibility of the world volume is set |
---|
364 | # in ExN03DetectorConstruction.cc.) |
---|
365 | /vis/viewer/set/style wireframe |
---|
366 | /vis/viewer/set/culling global false |
---|
367 | /vis/drawVolume |
---|
368 | /vis/scene/add/axes 0 0 0 500 mm |
---|
369 | /vis/scene/add/text 0 0 0 mm 50 -50 -200 world |
---|
370 | /vis/viewer/flush |
---|
371 | ################### END of vis1.mac ################### |
---|
372 | </programlisting> |
---|
373 | </informalexample> |
---|
374 | </para> |
---|
375 | |
---|
376 | </sect3> |
---|
377 | |
---|
378 | <!-- ******************* Section (Level#3) ****************** --> |
---|
379 | <sect3 id="sect.HowToVis.SampleVis.VisEvents"> |
---|
380 | <title> |
---|
381 | Visualization of events |
---|
382 | </title> |
---|
383 | |
---|
384 | <para> |
---|
385 | The following session visualizes events (tajectories) with the |
---|
386 | OpenGL-Xlib driver and then with the DAWNFILE driver. The former |
---|
387 | exhibits minimal visualization commands to visualize events, while |
---|
388 | the latter exhibits customized visualization. Note that the run |
---|
389 | action and event action classes should be described properly. (See, |
---|
390 | for example, the following classes: |
---|
391 | "examples/novice/N03/src/ExN03RunAction.cc", |
---|
392 | |
---|
393 | <informalexample> |
---|
394 | <programlisting> |
---|
395 | ################################################### |
---|
396 | # vis2.mac: |
---|
397 | # A Sample macro to demonstrate visualization |
---|
398 | # of events (trajectories). |
---|
399 | # |
---|
400 | # USAGE: |
---|
401 | # Save the commands below as a macro file, say, |
---|
402 | # "vis2.mac", and execute it as follows: |
---|
403 | # |
---|
404 | # % $(G4BINDIR)/exampleN03 |
---|
405 | # Idle> /control/execute vis1.mac |
---|
406 | ############################################# |
---|
407 | |
---|
408 | ##################################################### |
---|
409 | # Store particle trajectories for visualization |
---|
410 | /tracking/storeTrajectory 1 |
---|
411 | ##################################################### |
---|
412 | |
---|
413 | ######################################################## |
---|
414 | # Visualization with the OGLSX (OpenGL Stored X) driver |
---|
415 | ######################################################## |
---|
416 | |
---|
417 | # Invoke the OGLSX driver |
---|
418 | # Create a scene handler and a viewer for the OGLSX driver |
---|
419 | /vis/open OGLSX |
---|
420 | |
---|
421 | # Create an empty scene and add detector components to it |
---|
422 | /vis/drawVolume |
---|
423 | |
---|
424 | # Add trajectories to the current scene |
---|
425 | # Note: This command is not necessary in, e.g., |
---|
426 | # examples/novice/N03, since the C++ method DrawTrajectory() |
---|
427 | # is described in the event action. |
---|
428 | #/vis/scene/add/trajectories |
---|
429 | |
---|
430 | # Set viewing parameters |
---|
431 | /vis/viewer/reset |
---|
432 | /vis/viewer/set/viewpointThetaPhi 10 20 |
---|
433 | |
---|
434 | # Visualize one it. |
---|
435 | /run/beamOn 1 |
---|
436 | |
---|
437 | ########################################################## |
---|
438 | # Visualization with the DAWNFILE driver |
---|
439 | ########################################################## |
---|
440 | |
---|
441 | # Invoke the DAWNFILE driver |
---|
442 | # Create a scene handler and a viewer for the DAWNFILE driver |
---|
443 | /vis/open DAWNFILE |
---|
444 | |
---|
445 | # Create an empty scene and add detector components to it |
---|
446 | /vis/drawVolume |
---|
447 | |
---|
448 | # Add trajectories to the current scene |
---|
449 | # Note: This command is not necessary in exampleN03, |
---|
450 | # since the C++ method DrawTrajectory() is |
---|
451 | # described in the event action. |
---|
452 | #/vis/scene/add/trajectories |
---|
453 | |
---|
454 | # Visualize plural events (bird's eye view) |
---|
455 | # drawing style: wireframe |
---|
456 | # viewpoint : (theta,phi) = (45*deg, 45*deg) |
---|
457 | # zoom factor: 1.5 x (full screen size) |
---|
458 | /vis/viewer/reset |
---|
459 | /vis/viewer/set/style wireframe |
---|
460 | /vis/viewer/set/viewpointThetaPhi 45 45 |
---|
461 | /vis/viewer/zoom 1.5 |
---|
462 | /run/beamOn 2 |
---|
463 | |
---|
464 | # Set the drawing style to "surface" |
---|
465 | # Candidates: wireframe, surface |
---|
466 | /vis/viewer/set/style surface |
---|
467 | |
---|
468 | # Visualize plural events (bird's eye view) again |
---|
469 | # with another drawing style (surface) |
---|
470 | /run/beamOn 2 |
---|
471 | |
---|
472 | ################### END of vis2.mac ################### |
---|
473 | </programlisting> |
---|
474 | </informalexample> |
---|
475 | </para> |
---|
476 | |
---|
477 | </sect3> |
---|
478 | </sect2> |
---|
479 | |
---|
480 | |
---|
481 | <!-- ******************* Section (Level#2) ****************** --> |
---|
482 | <sect2 id="sect.HowToVis.MoreInfo"> |
---|
483 | <title> |
---|
484 | For More Information on Geant4 Visualization |
---|
485 | </title> |
---|
486 | |
---|
487 | <para> |
---|
488 | See the <xref linkend="chap.Visualization" /> "Visualization" |
---|
489 | part of this user guide. |
---|
490 | </para> |
---|
491 | |
---|
492 | |
---|
493 | </sect2> |
---|
494 | </sect1> |
---|