Creating a movie with FileSinkImages
We often have to take screenshot of a graph to show it in a presentation or at a moment where it is hard to run the program. Problem is that when we are rendering a dynamic graph, the dynamicity is not rendered in a single screenshot. Movies could be the dynamic screenshot of such graphs.
This tutorial explains how to produce a sequence of images rendering a graph, and how to compil these images to produce a movie.
Choosing when images are produced
The sink needs to know when images have to be outputted. For example, images can be outputted in the following cases:
- reception of any event ;
- reception of a node/edge/graph event ;
- a node/edge is added/removed ;
- reception of a step event ;
FileSinkImages.OutputPolicy defines all theses cases.
The corresponding code is:
Choosing the format
Three things have to be defined:
- prefix of image filenames ;
- type of images ;
- resolution of images.
Type of images can be png or jpeg. Types are contained if the enum
FileSinkImages.Resolutions contains classic resolution:
WVGA 5/3, 800x480
WVGA 16/9, 854x480
WXGA 5/3, 1280x768
WXGA 8/5, 1280x800
but it is possible to define a custom resolution with
The corresponding code is:
This is easily done with the following code :
Choosing a source
FileSinkImages is a sink and need a source of events. This source could
be a graph for example, but it could be a generator, a dgs source, etc…
Using a dgs file allows to avoid the creation of a graph object. This can be usefull when the graph to render is really big and has a high memory cost.
For example :
Set style of graph/nodes/edges
The definition of a style for graph, nodes or edges is allowed by providing a css stylesheet. Syntax is the same that in the GraphStream viewer.
Optionally, enable layout
It is possible to run a layout algorithm. If enabled, the layout can computed
LayoutRunner or before each image outputted. Layout modes are defined
in the enum
NoLayout, layout is disable ;
ComputedInLayoutRunner, layout is computed in a
ComputedAtNewImage, layout is computed when a new image is outputted.
Layout policy can changed with the following code :
Optionally, enable high quality rendering
Like in the GraphStream viewer, it is possible to enable an high quality rendering.
This is done by calling
setHighQuality() method :
Optionally, add a logo
Sometimes, it could be usefull to add a logo on your movie. The sink provides an easy way to add a logo-image on outputted images. Only pathname of the logo and coordinate on outputted images are needed :
Create a movie with outputted images
A way to create the movie is using
mencoder from the
MPlayer Movie Player <http://www.mplayerhq.hu>_
The following bash script compils all images prefix by
$PREFIX and ended by
$EXT to create an high quality movie
Make a single screenshot
writeAll(String) method of the sink can be used to make single screenshot
of the graph: