Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.graphstream.algorithm.generator.BarabasiAlbertGenerator;
- import org.graphstream.graph.Node;
- import org.graphstream.graph.implementations.DefaultGraph;
- import org.graphstream.stream.thread.ThreadProxyPipe;
- import org.graphstream.ui.layout.springbox.SpringBox;
- import org.graphstream.ui.swingViewer.Viewer;
- import org.graphstream.ui.geom.Point3;
- public class Test {
- public static void main(String[] args) throws Exception {
- BarabasiAlbertGenerator gen = new BarabasiAlbertGenerator();
- DefaultGraph g = new DefaultGraph("g");
- gen.addSink(g);
- gen.begin();
- for (int i = 0; i < 10; i++)
- gen.nextEvents();
- gen.end();
- SpringBox box = new SpringBox();
- ThreadProxyPipe pipe = new ThreadProxyPipe(box);
- pipe.addAttributeSink(g);
- Viewer v = g.display(false);
- v.enableAutoLayout(box);
- Thread.sleep(5000);
- pipe.pump();
- for (Node n : g) {
- Object[] xy = n.getArray("xyz");
- double x = (Double) xy[0];
- double y = (Double) xy[1];
- Point3 pixels = v.getDefaultView().getCamera().transformGuToPx(x, y, 0);
- System.out.printf("'%s': (%.3f;%.3f)\t--> (%.0f;%.0f)\n", n.getId(), x, y, pixels.x, pixels.y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement