Documentation / Tutorials
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 ;
- …
The enum FileSinkImages.OutputPolicy
defines all theses cases.
ByEventOutput
ByElementEventOutput
ByAttributeEventOutput
ByNodeEventOutput
ByEdgeEventOutput
ByGraphEventOutput
ByStepOutput
ByNodeAddedRemovedOutput
ByEdgeAddedRemovedOutput
ByNodeAttributeOutput
ByEdgeAttributeOutput
ByGraphAttributeOutput
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.OutputType
.
The enum FileSinkImages.Resolutions
contains classic resolution:
QVGA, 320x240
CGA, 320x200
VGA, 640x480
NTSC, 720x480
PAL, 768x576
WVGA 5/3, 800x480
SVGA, 800x600
WVGA 16/9, 854x480
WSVGA, 1024x600
XGA, 1024x768
HD720, 1280x720
WXGA 5/3, 1280x768
WXGA 8/5, 1280x800
SXGA; 1280x1024
SXGAp, 1400x1050
WSXGAp, 1680x1050
UXGA, 1600x1200
HD1080, 1920x1080
WUXGA, 1920x1200
TwoK, 2048x1080
QXGA, 2048x1536
WQXGA, 2560x1600
QSXGA, 2560x2048
but it is possible to define a custom resolution with
FileSinkImages.CustomResolution
.
The corresponding code is:
Create the FileSinkImages
object
This is easily done with the following code :
Choosing a source
The 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
in a LayoutRunner
or before each image outputted. Layout modes are defined
in the enum FileSinkImages.LayoutPolicy
:
NoLayout
, layout is disable ;ComputedInLayoutRunner
, layout is computed in aLayoutRunner
;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 :
Complete example
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 $OUPUT
:
Make a single screenshot
The writeAll(String)
method of the sink can be used to make single screenshot
of the graph: