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