Search in sources :

Example 16 with Point3

use of org.graphstream.ui.geom.Point3 in project gs-ui-javafx by graphstream.

the class MovingNodeSprite method run.

private void run() {
    MultiGraph graph = new MultiGraph("TestSprites");
    Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
    ViewerPipe pipeIn = viewer.newViewerPipe();
    FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
    DefaultApplication.init(view, graph);
    new Thread(() -> Application.launch(DefaultApplication.class)).start();
    pipeIn.addAttributeSink(graph);
    pipeIn.addViewerListener(this);
    pipeIn.pump();
    graph.setAttribute("ui.stylesheet", styleSheet);
    graph.setAttribute("ui.antialias");
    graph.setAttribute("ui.quality");
    Node A = graph.addNode("A");
    Node B = graph.addNode("B");
    Node C = graph.addNode("C");
    Node D = graph.addNode("D");
    Node E = graph.addNode("E");
    C.setAttribute("ui.points", new Point3(-0.05f, -0.05f, 0f), new Point3(0f, -0.02f, 0f), new Point3(0.05f, -0.05f, 0f), new Point3(0f, 0.05f, 0f));
    graph.addEdge("AB1", "A", "B", true);
    graph.addEdge("AB2", "B", "A", true);
    graph.addEdge("BC", "B", "C");
    graph.addEdge("CD", "C", "D", true);
    graph.addEdge("DA", "D", "A");
    graph.addEdge("DE", "D", "E", true);
    graph.addEdge("EB", "E", "B", true);
    graph.addEdge("BB", "B", "B", true);
    graph.getEdge("CD").setAttribute("ui.points", new Point3(1, 0, 0), new Point3(0.6f, 0.1f, 0f), new Point3(0.3f, -0.1f, 0f), new Point3(0, 0, 0));
    A.setAttribute("xyz", new double[] { 0, 1, 0 });
    B.setAttribute("xyz", new double[] { 1.5, 1, 0 });
    C.setAttribute("xyz", new double[] { 1, 0, 0 });
    D.setAttribute("xyz", new double[] { 0, 0, 0 });
    E.setAttribute("xyz", new double[] { 0.4, 0.6, 0 });
    A.setAttribute("label", "A");
    B.setAttribute("label", "B");
    C.setAttribute("label", "C");
    D.setAttribute("label", "D");
    E.setAttribute("label", "E");
    SpriteManager sman = new SpriteManager(graph);
    MovingEdgeSprite s1 = sman.addSprite("S1", MovingEdgeSprite.class);
    MovingEdgeSprite s2 = sman.addSprite("S2", MovingEdgeSprite.class);
    MovingEdgeSprite s3 = sman.addSprite("S3", MovingEdgeSprite.class);
    MovingEdgeSprite s4 = sman.addSprite("S4", MovingEdgeSprite.class);
    DataSprite s5 = sman.addSprite("S5", DataSprite.class);
    MovingEdgeSprite s6 = sman.addSprite("S6", MovingEdgeSprite.class);
    MovingEdgeSprite s7 = sman.addSprite("S7", MovingEdgeSprite.class);
    MovingEdgeSprite s8 = sman.addSprite("S8", MovingEdgeSprite.class);
    s1.attachToEdge("AB1");
    s2.attachToEdge("CD");
    s3.attachToEdge("DA");
    s4.attachToEdge("EB");
    s5.attachToNode("A");
    s6.attachToNode("D");
    s7.attachToEdge("AB2");
    s8.attachToEdge("EB");
    s2.setOffsetPx(20);
    s3.setOffsetPx(15);
    s4.setOffsetPx(4);
    s5.setPosition(Units.PX, 0, 30, 0);
    s5.setData(new float[] { 0.3f, 0.5f, 0.2f });
    // s6.setOffsetPx(20);
    s8.setPosition(0.5f, 0.5f, 0f);
    s1.setAttribute("ui.label", "FooBar1");
    s2.setAttribute("ui.label", "FooBar2");
    s4.setAttribute("ui.label", "FooBar4");
    s7.setAttribute("ui.label", "FooBar7");
    s8.setAttribute("ui.points", new Point3(-0.02f, -0.02f, 0f), new Point3(0f, -0.01f, 0f), new Point3(0.02f, -0.02f, 0f), new Point3(0f, 0.02f, 0f));
    E.setAttribute("ui.pie-values", 0.2f, 0.3f, 0.4f, 0.1f);
    while (loop) {
        pipeIn.pump();
        s1.move();
        s2.move();
        s3.move();
        s4.move();
        s6.move();
        s7.move();
        s8.move();
        sleep(4);
    }
    System.out.println("bye bye");
    System.exit(0);
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Point3(org.graphstream.ui.geom.Point3) FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) Node(org.graphstream.graph.Node) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Viewer(org.graphstream.ui.view.Viewer) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) SpriteManager(org.graphstream.ui.spriteManager.SpriteManager) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 17 with Point3

use of org.graphstream.ui.geom.Point3 in project gs-ui-javafx by graphstream.

the class TestStars2 method start.

public void start(Stage primaryStage) throws Exception {
    SingleGraph graph = new SingleGraph("Stars !");
    double x0 = 0.0;
    double x1 = 0.0;
    double width = 100.0;
    double height = 20.0;
    int n = 500;
    Random random = new Random();
    double minDis = 4.0;
    double sizeMx = 10.0;
    graph.setAttribute("ui.stylesheet", styleSheet);
    graph.setAttribute("ui.quality");
    graph.setAttribute("ui.antialias");
    Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
    ViewerPipe pipeIn = viewer.newViewerPipe();
    FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
    view.resize(1000, (int) (1200 * (height / width)));
    Scene scene = new Scene(view, 1000, 1200 * (height / width), true, SceneAntialiasing.BALANCED);
    primaryStage.setScene(scene);
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent t) {
            Platform.exit();
            System.exit(0);
        }
    });
    primaryStage.setTitle("Stars 2");
    primaryStage.show();
    for (int i = 0; i < n; i++) {
        Node node = graph.addNode(i + "");
        node.setAttribute("xyz", (random.nextDouble() * width), (random.nextDouble() * height), 0);
        node.setAttribute("ui.size", (random.nextDouble() * sizeMx));
    }
    graph.nodes().forEach(node -> {
        Point3 pos = new Point3(GraphPosLengthUtils.nodePosition(node));
        graph.nodes().forEach(otherNode -> {
            if (otherNode != node) {
                Point3 otherPos = new Point3(GraphPosLengthUtils.nodePosition(otherNode));
                double dist = otherPos.distance(pos);
                if (dist < minDis) {
                    if (!node.hasEdgeBetween(otherNode.getId())) {
                        try {
                            graph.addEdge(node.getId() + "--" + otherNode.getId(), node.getId(), otherNode.getId());
                        } catch (IdAlreadyInUseException e) {
                            graph.addEdge(node.getId() + "--" + otherNode.getId() + "-2", node.getId(), otherNode.getId());
                        }
                    }
                }
            }
        });
    });
}
Also used : FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) Node(org.graphstream.graph.Node) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Viewer(org.graphstream.ui.view.Viewer) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) Scene(javafx.scene.Scene) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Point3(org.graphstream.ui.geom.Point3) IdAlreadyInUseException(org.graphstream.graph.IdAlreadyInUseException) Random(java.util.Random) WindowEvent(javafx.stage.WindowEvent) SingleGraph(org.graphstream.graph.implementations.SingleGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 18 with Point3

use of org.graphstream.ui.geom.Point3 in project gs-ui-javafx by graphstream.

the class BackendJ2D method inverseTransform.

@Override
public Point3 inverseTransform(double x, double y, double z) {
    dummyPoint = new Point2D(x, y);
    dummyPoint = xT.transform(dummyPoint.getX(), dummyPoint.getY());
    return new Point3(dummyPoint.getX(), dummyPoint.getY(), 0);
}
Also used : Point3(org.graphstream.ui.geom.Point3) Point2D(javafx.geometry.Point2D)

Example 19 with Point3

use of org.graphstream.ui.geom.Point3 in project gs-ui-javafx by graphstream.

the class BackendJ2D method transform.

@Override
public Point3 transform(double x, double y, double z) {
    dummyPoint = new Point2D(x, y);
    dummyPoint = Tx.transform(dummyPoint.getX(), dummyPoint.getY());
    return new Point3(dummyPoint.getX(), dummyPoint.getY(), 0);
}
Also used : Point3(org.graphstream.ui.geom.Point3) Point2D(javafx.geometry.Point2D)

Example 20 with Point3

use of org.graphstream.ui.geom.Point3 in project gs-ui-javafx by graphstream.

the class ConnectorSkeleton method setCurve.

public void setCurve(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3) {
    kind = EdgeShapeKind.CURVE;
    if (points.size() != 4)
        points = new EdgePoints(4);
    points.update(0, new Point3(x0, y0, z0));
    points.update(1, new Point3(x1, y1, z1));
    points.update(2, new Point3(x2, y2, z2));
    points.update(3, new Point3(x3, y3, z3));
}
Also used : Point3(org.graphstream.ui.geom.Point3) EdgePoints(org.graphstream.ui.javafx.util.EdgePoints)

Aggregations

Point3 (org.graphstream.ui.geom.Point3)28 Vector2 (org.graphstream.ui.geom.Vector2)6 Path2D (org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)4 EdgePoints (org.graphstream.ui.javafx.util.EdgePoints)4 Point2 (org.graphstream.ui.geom.Point2)3 Style (org.graphstream.ui.graphicGraph.stylesheet.Style)3 AreaSkeleton (org.graphstream.ui.javafx.renderer.AreaSkeleton)3 Point2D (javafx.geometry.Point2D)2 Node (org.graphstream.graph.Node)2 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)2 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)2 GraphicNode (org.graphstream.ui.graphicGraph.GraphicNode)2 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)2 Tuple (org.graphstream.ui.javafx.util.AttributeUtils.Tuple)2 Viewer (org.graphstream.ui.view.Viewer)2 ViewerPipe (org.graphstream.ui.view.ViewerPipe)2 Random (java.util.Random)1 Scene (javafx.scene.Scene)1 GraphicsContext (javafx.scene.canvas.GraphicsContext)1 Paint (javafx.scene.paint.Paint)1