Advertisement
Guest User

Untitled

a guest
Nov 25th, 2011
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import org.graphstream.algorithm.generator.BarabasiAlbertGenerator;
  2. import org.graphstream.graph.Node;
  3. import org.graphstream.graph.implementations.DefaultGraph;
  4. import org.graphstream.stream.thread.ThreadProxyPipe;
  5. import org.graphstream.ui.layout.springbox.SpringBox;
  6. import org.graphstream.ui.swingViewer.Viewer;
  7. import org.graphstream.ui.geom.Point3;
  8.  
  9. public class Test {
  10.  
  11.     public static void main(String[] args) throws Exception {
  12.         BarabasiAlbertGenerator gen = new BarabasiAlbertGenerator();
  13.         DefaultGraph g = new DefaultGraph("g");
  14.  
  15.         gen.addSink(g);
  16.  
  17.         gen.begin();
  18.         for (int i = 0; i < 10; i++)
  19.             gen.nextEvents();
  20.         gen.end();
  21.  
  22.         SpringBox box = new SpringBox();
  23.         ThreadProxyPipe pipe = new ThreadProxyPipe(box);
  24.         pipe.addAttributeSink(g);
  25.         Viewer v = g.display(false);
  26.         v.enableAutoLayout(box);
  27.        
  28.         Thread.sleep(5000);
  29.         pipe.pump();
  30.        
  31.         for (Node n : g) {
  32.             Object[] xy = n.getArray("xyz");
  33.             double x = (Double) xy[0];
  34.             double y = (Double) xy[1];
  35.             Point3 pixels = v.getDefaultView().getCamera().transformGuToPx(x, y, 0);
  36.             System.out.printf("'%s': (%.3f;%.3f)\t--> (%.0f;%.0f)\n", n.getId(), x, y, pixels.x, pixels.y);
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement