source: trunk/documents/UserDoc/DocBookUsersGuides/ForApplicationDeveloper/xml/Visualization/visexecutable.xml @ 1150

Last change on this file since 1150 was 921, checked in by garnier, 16 years ago

en test de gl2ps. Problemes de libraries

File size: 14.6 KB
Line 
1<!-- ******************************************************** -->
2<!--                                                          -->
3<!--  [History]                                               -->
4<!--    Converted to DocBook: Katsuya Amako, Aug-2006         -->
5<!--    Updates for Qt: Laurent Garnier, Dec-2008             -->
6<!--                                                          -->
7<!-- ******************************************************** -->
8
9
10<!-- ******************* Section (Level#1) ****************** -->
11<sect1 id="sect.VisAddExe">
12<title>
13Adding Visualization to Your Executable
14</title>
15
16<para>
17This section explains how to incorporate your selected
18visualization drivers into the <literal>main()</literal> function and create
19an executable for it. In order to perform visualization with your
20Geant4 executable, you must compile it with realized visualization
21driver(s). You may be dazzled by the number of choices of
22visualization driver, but you need not use all of them at one time.
23</para>
24
25<!-- ******************* Section (Level#2) ****************** -->
26<sect2 id="sect.VisAddExe.InstDrv">
27<title>
28Installing Visualization Drivers
29</title>
30
31<para>
32Depending on what has been installed on your system, several kinds
33of visualization driver are available. One or many drivers may be
34chosen for realization in compilation, depending on your
35visualization requirements. Features and notes on each driver are
36briefly described in <xref linkend="sect.VisDrv" />
37"<emphasis role="bold">Visualization Drivers</emphasis>",
38along with links to detailed web pages for the various drivers.
39</para>
40
41<para>
42Note that not all drivers can be installed on all systems;
43<xref linkend="table.VisDrv_1" /> in
44<xref linkend="sect.VisDrv" /> lists all the available drivers
45and the platforms on which they can be installed.
46For any of the visualization drivers to work, the corresponding
47graphics system must be installed beforehand.
48</para>
49
50<para>
51Unless the environment variable <literal>G4VIS_NONE</literal> is set to
52"1", visualization drivers that do not depend on external libraries
53are automatically incorporated into Geant4 libraries during their
54installation. (Here "installation of Geant4 libraries" means the
55generation of Geant4 libraries by compilation.) The automatically
56incorporated visualization drivers are: DAWNFILE, HepRepFile,
57HepRepXML, RayTracer, VRML1FILE, VRML2FILE and ATree and
58GAGTree.
59</para>
60
61<para>
62The OpenGL, Qt, OpenInventor and RayTracerX drivers are not
63incorporated by default. Nor are the DAWN-Network and VRML-Network
64drivers, because they require the network setting of the installed
65machine. In order to incorporate them, the environment variables
66"<literal>G4VIS_BUILD_DRIVERNAME_DRIVER</literal>" should be set to
67"<literal>1</literal>" before installing the Geant4 libraries:
68
69<informalexample>
70<programlisting>
71     setenv G4VIS_BUILD_OPENGLX_DRIVER      1  # OpenGL-Xlib driver
72     setenv G4VIS_BUILD_OPENGLXM_DRIVER     1  # OpenGL-Motif driver
73     setenv G4VIS_BUILD_OPENGLQT_DRIVER     1  # Qt driver
74     setenv G4VIS_BUILD_OIX_DRIVER          1  # OpenInventor-Xlib driver
75     setenv G4VIS_BUILD_RAYTRACERX_DRIVER   1  # RayTracer-XLib driver
76     setenv G4VIS_BUILD_DAWN_DRIVER         1  # DAWN-Network driver
77     setenv G4VIS_BUILD_VRML_DRIVER         1  # VRML-Network
78</programlisting>
79</informalexample>
80</para>
81
82<para>
83Unless the environment variable <literal>G4VIS_NONE</literal> is set to "1",
84setting any of the above variables sets a C-pre-processor flag of
85the same name. Also the C-pre-processor flag <literal>G4VIS_BUILD</literal>
86is set (see config/G4VIS_BUILD.gmk), which incorparates the
87selected driver into the Geant4 libraries.
88</para>
89
90</sect2>
91
92<!-- ******************* Section (Level#2) ****************** -->
93<sect2 id="sect.VisAddExe.RealVisDrv">
94<title>
95How to Realize Visualization Drivers in an Executable
96</title>
97
98<para>
99You can realize and use any of the visualization driver(s) you want
100in your Geant4 executable, provided they are among the set
101installed beforehand into the Geant4 libraries. A warning will
102appear if this is not the case.
103</para>
104
105<para>
106In order to realize visualization drivers, you must instantiate
107and initialize a subclass of <literal>G4VisManager</literal> that implements
108the pure virtual function <literal>RegisterGraphicsSystems()</literal>. This
109subclass must be compiled in the user's domain to force the loading
110of appropriate libraries in the right order. The easiest way to do
111this is to use <literal>G4VisExecutive</literal>, a provided class with
112included implementation. <literal>G4VisExecutive</literal> is sensitive to
113the <literal>G4VIS_USE...</literal> variables mentioned below.
114</para>
115
116<para>
117If you do wish to write your own subclass, you may do so. You
118will see how to do this by looking at <literal>G4VisExecutive.icc</literal>.
119A typical extract is:
120
121<informalexample>
122<programlisting>
123     ...
124       RegisterGraphicsSystem (new G4DAWNFILE);
125     ...
126     #ifdef G4VIS_USE_OPENGLX
127       RegisterGraphicsSystem (new G4OpenGLImmediateX);
128       RegisterGraphicsSystem (new G4OpenGLStoredX);
129     #endif
130     ...
131</programlisting>
132</informalexample>
133</para>
134
135<para>
136If you wish to use <literal>G4VisExecutive</literal> but register an
137additional graphics system, <literal>XXX</literal> say, you may do so either
138before or after initializing:
139
140<informalexample>
141<programlisting>
142     visManager-&gt;RegisterGraphicsSytem(new XXX);
143     visManager-&gt;Initialize();
144</programlisting>
145</informalexample>
146</para>
147
148<para>
149By default, you get the DAWNFILE, HepRepFile, RayTracer,
150VRML1FILE, VRML2FILE, ATree and GAGTree drivers. Additionally, you
151may choose from the OpenGL-Xlib, OpenGL-Motif, Qt, OpenInventor,
152RayTracerX, DAWN-Network and VRML-Network drivers, each of which
153can be selected by setting the proper environment variable:
154
155<informalexample>
156<programlisting>
157     setenv G4VIS_USE_OPENGLX      1
158     setenv G4VIS_USE_OPENGLXM     1
159     setenv G4VIS_USE_OPENGLQT     1
160     setenv G4VIS_USE_OIX          1
161     setenv G4VIS_USE_RAYTRACERX   1
162     setenv G4VIS_USE_DAWN         1
163     setenv G4VIS_USE_VRML         1
164</programlisting>
165</informalexample>
166</para>
167
168<para>
169(Of course, this has to be chosen from the set incorporated into
170the Geant4 libraries during their compilation.) Unless the
171environment variable <literal>G4VIS_NONE</literal> is set, these set
172C-pre-processor flags of the same name.
173</para>
174
175<para>
176Also, unless the environment variable <literal>G4VIS_NONE</literal> is
177set, the C-pre-processor flag <literal>G4VIS_USE</literal> is always set by
178default. This flag is available in describing the <literal>main()</literal>
179function.
180</para>
181
182<para>
183You may have to set additional environment variables for your
184selected visualization drivers and graphics systems. For example,
185the OpenGL driver may require the setting of <literal>OGLHOME</literal> which
186points to the location of the OpenGL libraries. For more details,
187see <xref linkend="sect.VisDrv" /> 
188"<emphasis role="bold">Visualization Drivers</emphasis>" and
189pages linked from there.
190</para>
191
192</sect2>
193
194
195<!-- ******************* Section (Level#2) ****************** -->
196<sect2 id="sect.VisAddExe.SampSetup">
197<title>
198A Sample Set-up File
199</title>
200
201<para>
202The following can be part of the user's <literal>.cshrc</literal> or
203<literal>.tcshrc</literal> file on a Linux platform to configure the
204environment for creating Geant4 executables available for Geant4
205visualization. This sample is shown only as an example; it may NOT
206correspond to a specific platform configuration and does NOT apply
207in general for any specific setup !
208
209<example id="programlist_VisAddExe_1">
210<title>
211Part of a sample <literal>.cshrc</literal> setup file for the Linux platform.
212</title>
213
214<programlisting>
215 ############################################################
216 # Main Environment Variables for GEANT4 with Visualization #
217 ############################################################
218
219 ### Platform
220 setenv G4SYSTEM Linux-g++
221
222 ### CLHEP base directory
223 setenv CLHEP_BASE_DIR /opt/local
224
225 ### OpenGL base directory
226 setenv OGLHOME /usr/X11R6
227 
228 ### G4VIS_BUILD
229 ###   Incorporation of OpenGL-Xlib and OpenGL-Motif drivers
230 ###   into Geant4 libraries.
231 setenv G4VIS_BUILD_OPENGLX_DRIVER 1
232 setenv G4VIS_BUILD_OPENGLXM_DRIVER 1
233
234 ### G4VIS_USE
235 ###   Incorporation of OpenGL-Xlib and OpenGL-Motif drivers
236 ###   into Geant4 executables.
237 setenv G4VIS_USE_OPENGLX       1
238 setenv G4VIS_USE_OPENGLXM      1
239
240 ### Viewer for DAWNFILE driver
241 ### Default value is "dawn".  You can change it to, say,
242 ### "david" for volume overlapping tests
243 # setenv G4DAWNFILE_VIEWER david
244
245 ### Viewer for VRMLFILE drivers
246 setenv G4VRMLFILE_VIEWER vrmlview
247
248 ########## end
249</programlisting>
250</example>
251</para>
252
253</sect2>
254
255
256<!-- ******************* Section (Level#2) ****************** -->
257<sect2 id="sect.VisAddExe.VisMan">
258<title>
259Visualization Manager
260</title>
261
262<para>
263Visualization procedures are controlled by the "Visualization
264Manager", a class which must inherit from <emphasis>G4VisManager</emphasis>
265defined in the visualization category. Most users will find that
266they can just use the default visualization manager,
267<emphasis>G4VisExecutive</emphasis>. The Visualization Manager accepts users'
268requests for visualization, processes them, and passes the
269processed requirements to the abstract interface, i.e., to the
270currently selected visualization driver.
271</para>
272
273</sect2>
274
275
276<!-- ******************* Section (Level#2) ****************** -->
277<sect2 id="sect.VisAddExe.WrtMain">
278<title>
279How to Write the <literal>main()</literal> Function
280</title>
281
282<para>
283In order for your Geant4 executable to perform visualization, you
284must instantiate and initialize "your" Visualization Manager in the
285<literal>main()</literal> function. The core of the Visualization Manager is
286the class <literal>G4VisManager</literal>, defined in the visualization
287category. This class requires that one pure virtual function be
288implemented, namely, <literal>void RegisterGraphicsSystems()</literal>. The
289easiest way to do this is to use <literal>G4VisExecutive</literal>, as
290described above (but you may write your own class - see above).
291</para>
292
293<para>
294<xref linkend="programlist_VisAddExe_2" /> shows the form of the
295<literal>main()</literal> function.
296
297<example id="programlist_VisAddExe_2">
298<title>
299The form of the <literal>main()</literal> function.
300</title>
301
302<programlisting>
303 //----- C++ source codes: Instantiation and initialization of G4VisManager
304
305 .....
306 // Your Visualization Manager
307 #include "G4VisExecutive.hh"
308 .....
309
310 // Instantiation and initialization of the Visualization Manager
311 #ifdef G4VIS_USE
312 G4VisManager* visManager = new G4VisExecutive;
313 visManager -&gt; initialize ();
314 #endif
315
316 .....
317 #ifdef G4VIS_USE
318 delete visManager;
319 #endif
320
321 //----- end of C++
322</programlisting>
323</example>
324</para>
325
326<para>
327Alternatively, you can implement an empty
328<literal>RegisterGraphicsSystems()</literal> function, and register
329visualization drivers you want directly in your <literal>main()</literal>
330function. See <xref linkend="programlist_VisAddExe_3" />.
331
332<example id="programlist_VisAddExe_3">
333<title>
334An alternative style for the <literal>main()</literal> function.
335</title>
336
337<programlisting>
338 //----- C++ source codes: How to register a visualization driver directly
339 //                        in main() function
340
341 .....
342 G4VisManager* visManager = new G4VisExecutive;
343 visManager -&gt; RegisterGraphicsSystem (new MyGraphicsSystem);
344 .....
345 delete visManager
346
347 //----- end of C++
348</programlisting>
349</example>
350</para>
351
352<para>
353<emphasis>Do not forget</emphasis> to delete the instantiated Visualization
354Manager by yourself. Note that a graphics system for Geant4 Visualization
355may run as a different process. In that case, the destructor of
356<literal>G4VisManager</literal> might have to terminate the graphics system
357and/or close the connection.
358</para>
359
360<para>
361We recommend that the instantiation, initialization, and
362deletion of the Visualization Manager be protected by
363C-pre-processor commands, as in the novice examples. The
364C-pre-processor macro <literal>G4VIS_USE</literal> is automatically defined
365unless the environment variable <literal>G4VIS_NONE</literal> is set. This
366assumes that you are compiling your Geant4 executable with the
367standard version of GNUmakefile found in the <literal>config</literal>
368directory.
369</para>
370
371<para>
372<xref linkend="programlist_VisAddExe_4" /> shows an example of the
373<literal>main()</literal> function available for Geant4 Visualization.
374
375<example id="programlist_VisAddExe_4">
376<title>
377An example of the <literal>main()</literal> function available for
378Geant4 Visualization.
379</title>
380
381<programlisting>
382 //----- C++ source codes: An example of main() for visualization
383 .....
384 #include "G4VisExecutive.hh"
385 .....
386
387 int main()
388 {
389      // Run Manager
390      G4RunManager * runManager = new G4RunManager;
391
392      // Detector components
393      runManager-&gt;set_userInitialization(new MyDetectorConstruction);
394      runManager-&gt;set_userInitialization(new MyPhysicsList);
395
396      // UserAction classes.
397      runManager-&gt;set_userAction(new MyRunAction);
398      runManager-&gt;set_userAction(new MyPrimaryGeneratorAction);
399      runManager-&gt;set_userAction(new MyEventAction);
400      runManager-&gt;set_userAction(new MySteppingAction);
401
402 #ifdef G4VIS_USE
403      G4VisManager* visManager = new G4VisExecutive;
404      visManager -&gt; initialize ();
405 #endif
406
407      // Event loop
408      // Define (G)UI terminal
409      G4UIsession * session = new G4UIterminal
410      session-&gt;sessionStart();
411
412      delete session;
413      delete runManager;
414
415 #ifdef G4VIS_USE
416      delete visManager;
417 #endif
418
419      return 0;
420 }
421
422 //----- end of C++
423</programlisting>
424</example>
425</para>
426
427<para>
428Useful information on incorporated visualization drivers can be
429displayed in initializing the Visualization Manager. This is done
430by setting the verbosity flag to an appropriate string:
431
432<informalexample>
433<programlisting>
434   Simple graded message scheme - give first letter or a digit:
435    0) quiet,         // Nothing is printed.
436    1) startup,       // Startup and endup messages are printed...
437    2) errors,        // ...and errors...
438    3) warnings,      // ...and warnings...
439    4) confirmations, // ...and confirming messages...
440    5) parameters,    // ...and parameters of scenes and views...
441    6) all            // ...and everything available.
442</programlisting>
443</informalexample>
444</para>
445
446<para>
447For example, in your <literal>main()</literal> function, write the following
448code:
449
450<informalexample>
451<programlisting>
452  ...
453  G4VisManager* visManager = new G4VisExecutive ();
454  visManager -&gt; SetVerboseLevel (1);
455  visManager -&gt; Initialize ();
456  ...
457</programlisting>
458</informalexample>
459</para>
460
461<para>
462(This can also be set with the <literal>/vis/verbose</literal> command.)
463</para>
464
465
466</sect2>
467</sect1>
Note: See TracBrowser for help on using the repository browser.