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