Partenaires

CNRS Centre National de la recherche scientifique IN2P3 CNRS

Search

On this website

On the whole CNRS Web


HomeVisualization & Qt

Geant4.9.4 (december 2010) Visualization Tutorial using the OpenGL Event Display with Qt Toolkit


New Geant4 logo contest !

We are setting an open competition for the creation of the new Geant4 logo !
The competition is open until 12th November 2016 midnight (GMT).
One winner will receive the prize consisting of 150€.

Competition is open for :

  • A square logo, ratio 1:1 (for Youtube, Facebook, ...)
  • A horizontal banner, aspect ratio between 3:1 and 5:1 (for web-pages and publications)

Competition web site : https://g4logo-contest.github.io
 

If you have Geant4.9.6 version (december 2012), Please follow this link Tutorial for Geant4.9.6 users

Introduction

This tutorial is designed for anyone who wants to learn OpenGL Visualization for Geant4.9.4 with Qt powerful toolkit.

This tutorial can be used on its own, but gives the most comprehensive introduction to Geant4.9.4 visualization when used as part of the following full set of documents:
- Geant4 Installation Guides
- Introduction to Geant4 Visualization (ppt, pdf)
- Geant4 Visualization Tutorial using the HepRApp HepRep Browser
- Geant4 Visualization Tutorial using the DAWN Event Display
- Geant4 Visualization Tutorial using the OpenGL Event Display
- Geant4 Visualization Tutorial using the OpenGL Event Display with Qt toolkit
- Geant4 Visualization Commands (ppt, pdf)
- Geant4 Advanced Visualization (ppt, pdf)

While some Geant4 visualization drivers are always included by default in your Geant4 build (because they require no external libraries), Qt is not part of the default set. You have to specifically ask to include Qt.

If you followed the Geant4 Installation Guides referenced above, you used the Geant4 Configuration script and said "yes" to including Qt. Qt version should be Qt3 are above (Qt 4.4 is current version)

If you are following some other set of build instructions, refer to them for how to include Qt driver. This may involve explicitly setting environment variables.

Movies...

In this page, you will find some movies to illustrate Qt Driver. All are resume here :

MPEG - 30 Mb
Viewer Demo

QuickTime - 3.7 Mb
Cout Demo

QuickTime - 15.6 Mb
Geant4 with 3 Viewers

QuickTime - 5.3 Mb
Help Tree Demo

QuickTime - 8.4 Mb
’Google like’ rotation
Geant4 Qt Driver with ’google like’ rotation way

QuickTime - 5.5 Mb
’Theta-Phi’ rotation
Geant4 Qt Driver with ’theta-phi’ rotation way

QuickTime - 6.5 Mb
Qt_Movie_PrintEPS
Export file in vectored EPS

QuickTime - 7.2 Mb
Qt_Movie_EPS_Zoom
Zoom into a 8192x8192 EPS file


Main features

Multi platforms thanks to Qt
- Windows
- Mac OS X
- Linux / X11
- Hight level and fast visualization thanks to OpenGL
- Interactive move/rotate scene
- Photorealistic image
- Export in many formats (pixel graphics, SVG graphics, ps, eps, pdf)
- Full screen mode
- Easy to make movies !
- Only ONE window, User Interface and viewers are integrate into the same window


How to install Geant4 with Qt driver

How to install Qt ?

Really easy everywhere Ask your package manager on Linux Or go on the Nokia web site

How to compile G4 with Qt Driver ?

At configuration step, answer Yes(y) on the two questions :


Enable building of the Qt UI module? [n] y
Enable building of the Qt OpenGL visualization driver? [n] y

Building User interface and visualization driver

If you do not want to reconfigure all geant4, set the following variables according to your shell, then recompile sources/interfaces, sources/visualization.


G4UI_BUILD_QT_SESSION 1
G4UI_USE_QT 1
G4VIS_BUILD_OPENGLQT_DRIVER 1
G4VIS_USE_OPENGLQT 1

Notes :
- Remember to do the appropriate setup commands before you start Geant4 from a new windows (see the installation guides for details).
- You can build and set a lot of visualization drivers, but only ONE session (User Interface). If you want Qt viewer, you NEED to have a Qt User Interface.
- Don’t forget to unset your previous G4UI_USE flags before building your example.
- Start a fresh Geant4 session.
- Open the visualization driver /vis/open OGLIQt or /vis/open OGLSQt. An empty graphics windows should appear
- Issue the first command to draw something: /vis/drawVolume


Running Geant4 with Qt driver

Since OpenGL runs directly from Geant4, you just start Geant4 and then issue a few visualization commands. The Installation Guides listed above already showed you how to start Geant4 with OpenGL Qt driver included. They then showed you how to use a few simple commands to do the most minimal visualization of some detector geometry and some event data.


...
 runManager->Initialize();
 
#ifdef G4VIS_USE
 // Initialize visualization
 //
 G4VisManager* visManager = new G4VisExecutive;
 visManager->Initialize();
#endif
 
 // Get the pointer to the User Interface manager
 //
 G4UImanager* UImanager = G4UImanager::GetUIpointer();
 
#ifdef G4UI_USE
   G4UIExecutive* ui = new G4UIExecutive(argc, argv);
#ifdef G4VIS_USE
   UImanager->ApplyCommand("/control/execute your_macro_file.mac");    
#endif
   if (ui->IsGUI())
     UImanager->ApplyCommand("/control/execute your_gui_macro_file.mac");    
// Start
   ui->SessionStart();
   delete ui;
#endif
...  
#ifdef G4VIS_USE
 delete visManager;
#endif                
 delete runManager;

User Interface and Visualization

As others Graphic User Interfaces (Xm,Win32), Qt User Interface have the same look & feel. A output area, history area, command area, menu are available. But, in addition, we have as many tab viewers as you want on the right side.

PNG - 85.3 kb
Qt_Vis_InterfaceSmall
Qt Visualization Interface and viewers

Demo :

QuickTime - 15.6 Mb
Geant4 with 3 Viewers

Building the menu is available by executing set of commands defined in a macro file or entering theses commands in the User Interface (as other Graphics User Interfaces). For example :


/gui/addMenu run Run
/gui/addButton run "beamOn 1" "/run/beamOn 1"

Theses command will build a new menu "Run" with a sub-menu "beamOn 1" calling /run/beamOn command

PNG - 23.5 kb
Qt_addMenu
Adding menu

Help container

This container is the first on the left part. Open it will display the help tree widget. All commands already loaded from Geant4 and all your personnels commands if Geant4 already knows them. Adding a new command will refresh the Help Tree widget

PNG - 150.6 kb
Qt_HelpWidget
Help Widget

Very useful to find quicky a command in the geant4 set of commands. Moreover, you could double-click on the command you have find to set it in User Interface command area.

This help widget is composed of :
- A search area: Look in command definition the string you look for
- A command tree browser
- A command definition outpup zone

Demo :

QuickTime - 5.3 Mb
Help Tree Demo

Cout Container

As other viewers, Cout is there, but with some minor enhancements:
- A filter
- All error messages are print in red

PNG - 130.8 kb
Qt_CoutWidget
Cout Widget

Demo :

QuickTime - 3.7 Mb
Cout Demo

History Container

No new feature here, except when you click on a history command, it will be set in the Session box.

PNG - 29.5 kb
Qt_HistoryWidget
History Widget

Visualization driver

As OpenInventor driver, Qt driver is a real-time display. There is three control modes availables thanks to context-menu (right mouse button) :
- Rotate : rotate scene when left mouse click.
- Move : move scence when left mouse click
- Pick : Display picking information when click on volume As default, control is set to rotate mode.

If you release mouse press when moving mouse press (in rotate/move mode), you will set the scene in an auto rotate/move mode. Press mouse will stop this auto move/rotate mode. The speed of this auto rotation/move is control by the speed of your mouse move when releasing mouse press.

Rotations

Two rotation mode are available : Theta/Phi rotation and ’google earth’ like rotation (see below for shortcuts) Theta/Phi rotation : The default mode
- Ensure the ’up’ vector to be vertical direction
- Impossible to reach some points of view
- ’Not intuitive’ behaviour on some angles ’google earth like’ rotation
- ’Up’ vector is NOT vertical
- Could reach all volume point of view
- More ’intuitive’ rotation mode

Demo :

QuickTime - 8.4 Mb
’Google like’ rotation
Geant4 Qt Driver with ’google like’ rotation way
QuickTime - 5.5 Mb
’Theta-Phi’ rotation
Geant4 Qt Driver with ’theta-phi’ rotation way

Shortcuts

All vis commands are available with Keyboard shortcuts. Ex :
- ALT + Click and move mouse : rotate volume (google like)
- Click and move mouse : rotate volume (theta/phi)
- CTRL + Click and mouse move : zoom in/out
- SHIFT + Click and mouse move : move camera point of view
- Arrow : move volume
- ’+’/’-’ : move volume toward/forward
- SHIFT + Arrows : rotate volume in phi/theta
- SHIFT + Arrows : rotate volume in vertical/horizontal
- CTRL + ’+’/’-’ : zoom into volume
- H : reset view to initial position
- SPACE : Start/Pause video recording
- RETURN : Stop video recording

Context menu

A context menu is available on right mouse button, it is a quick mean to set somes geant4 main options :
- Orthographic, Perspective, Polyhedron, NURBS, ...

And some Qt specific ones :
- Save as... (see below)
- Movies parameters... (see below)

Save as..

Thanks to Qt, we could export graphics in a lot of formats :
- bmp, jpeg, jpg, png, ppm, tif, tiff, xbm, xpm, eps (Vectorial and non-vectorial), ps, pdf

Making Posters (available for ALL openGL drivers!

It could be very interesting to export bigger file in order to print, exchange screenshots, publish, or make poster. Thanks to gl2ps library we could now export up to maximum graphic card capacity size (Ex: Up to 8192 x 8192 on MacBook Pro). How do we do that ?

Set the print mode to vectored (best quality)


/vis/ogl/set/printMode (vectored or pixmap)

Set the filename (optional)


/vis/ogl/set/printFilename (default G4OpenGL_XX)

Set the print size


/vis/ogl/set/printSize (up to maximum graphic card capacity)

Then...print !


/vis/ogl/printEPS

Demo :

QuickTime - 6.5 Mb
Qt_Movie_PrintEPS
Export file in vectored EPS
QuickTime - 7.2 Mb
Qt_Movie_EPS_Zoom
Zoom into a 8192x8192 EPS file

Making Movies

A important feature of Qt driver is avaibility to make movies. To do this Qt driver rely on an free external software call ppmtompeg. It is available here. Qt driver record each frame on OpenGL scene, ppmtompeg will merge all picture in one movie file

Caution : This is not a time based saving, but a frame based !

An example is available here : (30Mo video)

MPEG - 30 Mb
Viewer Demo

To record a movie, open the "Movie parameter" dialog in Action context menu. Fill parameters :
- First of all, you have to set where is install mpeg_encoder
- Then, set the temp folder (by default Qt should find the good one)
- Set the name of the movie file that will be created

PNG - 51.8 kb
Qt_Movie
Qt movie parameters

Then press Start/Pause/Stop to record/pause/stop movie When press Save, the movie will be created, it could take a while depending of frame number.

Further Resources

- On-line documentation on Geant4 visualization
- List of visualization commands

Questions, comments about Geant4 Visualization -Contact us through the Geant4 Visualization online forum

 

 

To read, in the same section...