GraphStream Users

Archives de la liste Aide

Re: Tracking Example - Need some help

Chronologique Discussions 
  • From: guilhelm savin <guilhelm.savin AT>
  • To: Carina Oliveira <carinacapelao AT>, "graphstream-users AT" <graphstream-users AT>
  • Subject: Re: Tracking Example - Need some help
  • Date: Sat, 6 Aug 2016 11:01:53 +0200

Hi Carina,

When using the viewer pipe, you have to call the `pump()` or `blockingPump()` method in order to flush events from the GUI thread into the main thread. You can find explanations here . If you are using the viewer just to get the coordinates of nodes, consider using the `Toolkit.computeLayout()` method.

Hope if helps...

2016-08-01 16:15 GMT+02:00 Carina Oliveira <carinacapelao AT>:


My graph is created without coordinates at all, but before using it for making the video I set the coordinates of the nodes (I will explain it better later).

After creating the graph, it is displayed on the screen, basically on the following way:

//I get the instance of the created graph, that is a class on the Singleton pattern that extends the MultiGraph class

GraphSingleton graph = GraphSingleton.getInstance();

Viewer viewer = new Viewer(graph,Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);

SpringBox layout = new SpringBox(false, new Random(newDate().getTime()));


DefaultView view = (DefaultView) viewer.addDefaultView(false);


final ViewerPipe pipe = viewer.newViewerPipe();


After that, I get the GraphicGraph of my graph and after I get the positions of all nodes of GraphicGraph, saving it into a Array List. I also created an Array List with all nodes’ positions that have to be in the way to go. Thus, I can set the nodes’ coordinates of my original graph. The coordinates are on graph units.

GraphicGraph copyGraphInstance = viewer.getGraphicGraph();

Iterable<? extends Node> eachNode = copyGraphInstance.getEachNode();

List<Position> positionsAllNodes = new ArrayList<Position>();

for(Node node: eachNode){

double[] xyz = GraphPosLengthUtils.nodePosition(node);

//Postion is a class that has three attributes x,y and z

Position position = new Position(xyz[0], xyz[1], xyz[2]);

//Setting the nodes’ positions on the original graph

String id = node.getId();

Node node2 = myInstance.getNode(id);

node2.setAttribute("xyz", xyz[0], xyz[1], xyz[2]);



Thus, now that my graph has coordinates, I use the LeHavreClass, using the FileSinkImages on the following way:

String prefix = "tracking/images/prefix_";

OutputType type = OutputType.PNG;

Resolution resolution = Resolutions.HD720;

OutputPolicy outputPolicy = OutputPolicy.NONE;

FileSinkImages images = new FileSinkImages(prefix, type, resolution, outputPolicy);




SpriteManager manager = new SpriteManager(GraphSingleton.getInstance());

RandomWalk rwalk = new LHRandomWalk(manager);


try {


} catch (IOException e1) {



double step = 0;

The rest of the code is on the same way of your LeHavreClass.

A important diference is that on your dgs file, each edge has some attributes: name, speedMax, time, lanes, length e maxCap, while the edges of my graph have only an id.

In that way, on the “step” function of “VehicleEntity” class, that you use the speedMax and Lenght attributes, for example, I needed to do an adaptation and I entered some random numbers, so I don’t know if it could be the problem.

public void step() {

if (position >= 1 || crossing == null)


if (crossing != null) {

//double speed = crossing.getNumber("speedMax") / 90.0;

double speed = 100 / 90.0;

double trafic = 1 - 0.3 * Math.min(50, crossing.getNumber(context.getPassesAttribute())) / 50.0;

crossedLength += speed * trafic * 25;

//crossedLength = Math.min(crossedLength, crossing.getNumber("length"));

crossedLength = Math.min(crossedLength, 400);

position = crossedLength / 400;

addPass(crossing, current);


} else

System.out.printf("%s nowhere\n", sprite.getId());



Would you have any idea about what could be happening to my images? They are being created empty.



2016-07-19 23:21 GMT-03:00 guilhelm savin <guilhelm.savin AT>:
Hi Carina,

Please note that this code is a quick & dirty made creature which has only been used to generate the video. We made sources available "just in case" someone could find something interesting in it.

I can not say why you images are empty. It could be a lack of coordinates. But I need more informations about how you are using the FileSinkImages.

About magic numbers : it represents the count of produced images. The video has been generated at 25 fps. Since the output policy of the FileSinkImages is set to STEP_POLICY, images are produced at each call to graph.stepBegins(...). When passing such number to DynamicAttribute, we are telling it how many steps there will be for the animation. It is a bit too far to remember but I guess that 925 (ie. 37 seconds) is the length of the sequence.

Hope it helps.


2016-07-19 15:47 GMT+02:00 Carina Oliveira <carinacapelao AT>:

Hi all,

First of all, congratulations for your API ! This is great and it helps so much !

My name is Carina, I'm studying Information Systems on Federal University of Minas Gerais (UFMG) in Brazil and I’m a Research Assistant on Compilers Laboratory, UFMG. I'm currently in a project that involves the design and implementation of an information flow system, which involves the creation of graphs and involves some interactions on this graphs. I'm using your API.

At this moment, what I need to do is: given a graph, and a set of connected nodes, that are considered tainted and that form a path, I need to do how you did in the "tracking example" (( I want to zoom the first tainted node and walk through the graph, showing the tainted nodes that are on this path, and, in the end, create a video with this animation.

I saw the LeHavre class, that you provided, and I adapted my code to use this class. Nevertheless, my graph doesn’t work. The generated images are empty. So, I thought that maybe you could help me. I didn't understand very well some particularities of the LeHavre class.

->For example, at this part of the code:

MoveCenterView move = new MoveCenterView(images, g.getNode("LH.9921_0"), 75, true);

DynamicCenterViewZoom zoom = new DynamicCenterViewZoom(images, 0.1, 75, true);

I didn't understand the meaning, the role, of the value 75.

->At this slices:

for (int i = 0; i < 20; i++)



for (int i = 0; i < 75; i++) {


updateGraph(g, rwalk);



I didn't understand the meaning, the role, of the values 20 and 75, as well as the other bounds of the 'for' (20, 75, 100).

->At this part:

double byStepLength = fullLength / 925.0;

I didn't understand what the value 925 represents.

I would like to understand what the values means so that I can adapt this functionalities to create a video on my graph, which is a MultiGraph, that isn't in a DGS file.

Thanks in advance and  I await your reply.



Guilhelm Savin
PhD of Computer Science

Guilhelm Savin
PhD of Computer Science

  • Re: Tracking Example - Need some help, guilhelm savin, 06/08/2016

Archives gérées par MHonArc 2.6.16.

Top of page