GraphStream Users

Archives de la liste Aide


Re: How to use GraphicGraph


Chronologique Discussions 
  • From: Stefan Balev <stefan.balev AT gmail.com>
  • To: graphstream-users AT litislab.fr
  • Subject: Re: How to use GraphicGraph
  • Date: Tue, 2 Aug 2011 14:50:36 +0200

Thank you very much, this was really helpful.

Now I can thread-safely drag my nodes as much as I want :)

--
Stefan



2011/8/2 Antoine Dutot
<antoine.dutot AT gmail.com>:
> Hi,
>
> Indeed, you will get the xyz values back from the viewer by putting
> the graph as sink of the viewer's graphic graph, however, as they are
> not in the same thread, you can get a lot of weird problems. To avoid
> this, you can use a special pipe dedicated to the inter-thread
> communication (this way, with your many CPU cores, the display runs
> aside of your aglorithm :-)).
>
> The viewer already uses such a pipe in the direction graph -> viewer,
> all you have to do is to close the loop in the direction viewer ->
> graph. However there is one problem : it will be necessary to look if
> some events occurred in the viewer "actively" by "pumping" events from
> the pipe. If your algorithm runs in a loop, you can do this in this
> loop, else before using the graph, you can ask to "pump" all events
> and apply them to the graph. The system used is a simple "mailbox" of
> events, one thread (the viewer) sends the events in the mailbox, and
> your thread will read the events when it can.
>
> Something like this should work:
>
> Viewer viewer = graph.display();  // As usual.
> ViewerPipe pipe = viewer.newViewerPipe(); // Create a special pipe
> that acts as a mailbox for events from the viewer.
>
> pipe.addSink(graph);  // Indeed addAttributeSink(graph) could be
> enough, since you are only interested in "xyz" attributes
>
> while( in your aglorithm ) {
>   ...
>   pipe.pumpEvents(); // Apply all buffered events coming from the
> viewer to the graph, by emptying the mail box in a thread safe way.
>   ...
>   // You can use the the "xyz" attributes.
> }
>
> In fact the ViewerPipe is a special ThreadProxyPipe that will allow
> more features, the ThreadProxyPipe is the real mailbox mechanism used
> to cross the thread boundary.
>
> Hope this helps,
>
> Cheers,
>
> Antoine
>
> 2011/8/2 Stefan Balev
> <stefan.balev AT gmail.com>:
>> Hello,
>>
>> I have an application that dynamically recomputes the coordinates of the
>> nodes of a graph :
>>
>> Graph g = ...
>> g.display(false);
>> new Steiner(g).compute();
>>
>> At the beginning I naively thought that when the user drags a node in the
>> viewer, this will change the "xyz" attribute of the node in g. Then I
>> realized that dragging a node actually changes the "xyz" attribute of the
>> node in the GraphicGraph associated to the viewer. In order to have the
>> coordinate changes back to g I tried something like this:
>>
>> Graph g = ...
>> g.display(false).getGraphicGraph().addSink(g);
>> new Steiner(g).compute();
>>
>> Now almost everything works fine, but sometimes I have random exceptions
>> like this:
>>
>> Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException
>> at java.util.LinkedList.remove(LinkedList.java:788)
>> at java.util.LinkedList.removeFirst(LinkedList.java:134)
>> at java.util.LinkedList.remove(LinkedList.java:481)
>> at org.graphstream.stream.SourceBase.manageEvents(SourceBase.java:837)
>> [ ... stack trace too long to paste it entirely ... ]
>> at
>> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
>> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
>>
>> Is it because of the "Caution : Use the returned graph only in the Swing
>> thread !!" warning that we can read in Javadoc of getGraphicGraph()? If
>> yes,
>> what is the easiest proper way to do what I am trying to? Thanks for your
>> help.
>>
>> Btw, everything works great when I use FileSinkImages. Here is a small
>> video
>> showing this.
>>
>> Best,
>>
>> --
>> Stefan
>>
>>
>



Archives gérées par MHonArc 2.6.16.

Top of page