Making a Movie

These ideas are illustrated in examples/extended/visualization/movies.

These instructions are suggestive only. The following procedures have not been tested on all platforms. There are clearly some instructions that apply only to Unix-like systems with an X-Windows based windowing system. However, it should not be difficult to take the ideas presented here and extend them to other platforms and systems.

The procedures described here need graphics drivers that can produce picture files that can be converted to a form suitable for an MPEG encoder. There may be other ways of capturing the screen images and we would be happy to hear about them. Graphics drivers currently capable of producing picture files are:

Driver

File type

DAWNFILE

prim then eps using dawn

HepRepFile

HepRep1

OGLX

jpeg, eps, pdf, ppm, …

Qt

jpeg, eps, pdf, ppm, …

RayTracer

jpeg

VRML2FILE

vrml

So far, only DAWNFILE, OGLX, OGLQt and RayTracer have been “road tested”.

Once you have a set of files in a standard format, such as pdf or eps, they can be made into a movie.

  • iMovie (Apple Mac only):

  • Import the created files (PDF recommended).

  • Reduce the cliplength to 0.1 s (that seems to be the minimum).

  • Export to file.

  • Play at x2.

Using /vis/viewer/interpolate

  • Save a sequence of views with /vis/viewer/save (see How to save a view.).

  • “Fly through” them with /vis/viewer/interpolate (OpenGL and Qt only).

  • When you are happy, add the export parameter /vis/viewer/interpolate ! ! ! ! export.

The procedure is: choose a view, save, choose another view, save, and so on until you have, say, 10 saved views. Then /vis/viewer/interpolate ! ! ! ! export will produce hundreds of picture files.

From Geant4 10.5, you can interpolate time windows, and make particles appear to move:

# See guidance on /vis/viewer/set/timeWindow/ commands.
/vis/scene/add/trajectories rich
/vis/modeling/trajectories/drawByCharge-0/default/setTimeSliceInterval 0.01 ns
/run/beamOn # or several until you get a good event or events
# Then typically
/vis/viewer/set/timeWindow/displayLightFront true 0 0 -50 cm -0.5 ns
/vis/viewer/set/timeWindow/displayHeadTime true
/vis/viewer/set/timeWindow/fadeFactor 1
/vis/viewer/set/timeWindow/startTime 0 ns 1 ns
/vis/viewer/save
/vis/viewer/set/timeWindow/startTime 1 ns 1 ns
# Then zoom, pan etc to a view of interest and
/vis/viewer/save
# Then repeat with next start time, another view and a save, then try
/vis/viewer/interpolate
# Finally
/vis/viewer/interpolate ! ! ! ! export

See examples/extended/visualization/movies.

With a macro loop

Make a macro movie.mac with something like this:

/control/verbose 2
#/run/initialize
/vis/open OGL 600x600-0+0
/vis/drawVolume
/vis/viewer/set/style surface
/vis/viewer/set/projection perspective 50 deg
/control/alias phi 30
/control/loop movie.loop theta 0 360 1

which invokes movie.loop, which is something like:

/vis/viewer/set/viewpointThetaPhi {theta} {phi}
/vis/ogl/export

Then on the command line:

/control/execute movie.mac

It may work better in “batch mode”. Assuming your main program is similar to that in example B1, from your terminal:

./your-app-name movie.mac

Processing picture files with mpeg2encode

Say you have produced lots of eps files. Then…

make_mpeg2encode_parfile.sh G4OpenGL_*eps

Then edit mpeg2encode.par to specify file type and size, etc.:

$ diff mpeg2encode.par~ mpeg2encode.par
7c7
< 1         /* input picture file format: 0=*.Y,*.U,*.V, 1=*.yuv, 2=*.ppm */
---
> 2         /* input picture file format: 0=*.Y,*.U,*.V, 1=*.yuv, 2=*.ppm */
15,17c15,17
<    /* horizontal_size */
<   /* vertical_size */
< 8         /* aspect_ratio_information 1=square pel, 2=4:3, 3=16:9, 4=2.11:1 */
---
> 600   /* horizontal_size */
> 600  /* vertical_size */
> 1         /* aspect_ratio_information 1=square pel, 2=4:3, 3=16:9, 4=2.11:1 */

Then convert to ppm:

for i in G4OpenGL*eps;
  do j=`basename $i .eps`; command="convert $i $j.ppm"; echo $command; $command; done

Then

mpeg2encode mpeg2encode.par G4OpenGL.mpg

Then, on Mac, for example:

open G4OpenGL.mpg

opens a movie player.

Qt

The Qt driver provides one of the easiest ways to make a movie. Of course, you first need to add the Qt libraries and link with Qt, but once you have that, Qt provides a ready-made function to store all updates of the OpenGL frame into the movie format. You then use loops (as defined in OGLX section above) or even move/rotate/zoom you scene by mouse actions to form your movie.

The Qt driver automatically handles all of the movie-making steps described in the OGLX section of this document - storing the files, converting them and assembling the finished movie. You just have to take care of installing an mpeg_encoder.

To make a movie :

  • Right click to display a context menu, “Action”-<”Movie parameters”.

  • Select MPEG encoder path if it was not found.

  • Select the name of the output movie.

  • Let go! Hit SPACE to Start/Pause recording, RETURN to STOP

Then, open your movie (on Mac, for example):

open G4OpenGL.mpg

opens a QuickTime player.

DAWNFILE

You need to invoke dawn in “direct” mode, which picks up parameters from .DAWN_1.history, and suppress the GUI:

alias dawn='dawn -d'
export DAWN_BATCH=1

Change OGL to DAWNFILE in the above set of Geant4 commands and run. Then convert to ppm files as above:

for i in g4_*.eps;
  do j=`basename $i .eps`; command="convert $i $j.ppm"; echo $command; $command; done

Then make a .par file:

make_mpeg2encode_parfile.sh g4_*ppm

and edit mpeg2encode.par:

$ diff mpeg2encode.par~ mpeg2encode.par
7c7
< 1         /* input picture file format: 0=*.Y,*.U,*.V, 1=*.yuv, 2=*.ppm */
---
> 2         /* input picture file format: 0=*.Y,*.U,*.V, 1=*.yuv, 2=*.ppm */
9c9
< 1         /* number of first frame */
---
> 0         /* number of first frame */
15,16c15,16
<    /* horizontal_size */
<   /* vertical_size */
---
> 482   /* horizontal_size */
> 730  /* vertical_size */

Then encode and play:

mpeg2encode mpeg2encode.par DAWN.mpg
open DAWN.mpg

RayTracerX

/control/verbose 2
/vis/open RayTracerX 600x600-0+0
# (Raytracer doesn't need a scene; smoother not to /vis/drawVolume.)
/vis/viewer/reset
/vis/viewer/set/style surface
/vis/viewer/set/projection perspective 50 deg
/control/alias phi 30
/control/loop movie.loop theta 0 360 1

where movie.loop is as above. This produces lots of jpeg files (but takes 3 days!!!). Then…

make_mpeg2encode_parfile.sh g4RayTracer*jpeg

Then edit mpeg2encode.par to specify file type and size, etc.:

$ diff mpeg2encode.par.orig mpeg2encode.par
7c7
< 1         /* input picture file format: 0=*.Y,*.U,*.V, 1=*.yuv, 2=*.ppm */
---
> 2         /* input picture file format: 0=*.Y,*.U,*.V, 1=*.yuv, 2=*.ppm */
15,17c15,17
<    /* horizontal_size */
<   /* vertical_size */
< 8         /* aspect_ratio_information 1=square pel, 2=4:3, 3=16:9, 4=2.11:1 */
---
> 600   /* horizontal_size */
> 600  /* vertical_size */
> 1         /* aspect_ratio_information 1=square pel, 2=4:3, 3=16:9, 4=2.11:1 */

Then convert to ppm, encode and play:

for i in g4*jpeg;
  do j=`basename $i .jpeg`; command="convert $i $j.ppm"; echo $command; $command; done
mpeg2encode mpeg2encode.par g4RayTracer.mpg
open g4RayTracer.mpg