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