Search in sources :

Example 1 with GraphicNode

use of org.graphstream.ui.graphicGraph.GraphicNode in project gs-ui-javafx by graphstream.

the class DefaultCamera method getSpritePositionNode.

/**
 * Compute the position of a sprite if attached to a node.
 *
 * @param sprite
 *            The sprite.
 * @param pos
 *            Where to stored the computed position, if null, the position
 *            is created.
 * @param units
 *            The units the computed position must be given into.
 * @return The same instance as pos, or a new one if pos was null.
 */
protected Point2D getSpritePositionNode(GraphicSprite sprite, Point2D pos, Units units) {
    GraphicNode node = sprite.getNodeAttachment();
    double x = node.x + sprite.getX();
    double y = node.y + sprite.getY();
    pos = new Point2D(x, y);
    if (units == Units.PX)
        pos = Tx.transform(pos.getX(), pos.getY());
    return pos;
}
Also used : Point2D(javafx.geometry.Point2D) GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode)

Example 2 with GraphicNode

use of org.graphstream.ui.graphicGraph.GraphicNode in project gs-ui-javafx by graphstream.

the class DefaultCamera method isEdgeVisible.

/**
 * Check if an edge is visible in the current view port.
 *
 * @param edge
 *            The edge to check.
 * @return True if visible.
 */
protected boolean isEdgeVisible(GraphicEdge edge) {
    GraphicNode node0 = (GraphicNode) edge.getNode0();
    GraphicNode node1 = (GraphicNode) edge.getNode1();
    if (edge.hidden)
        return false;
    if ((!node1.positionned) || (!node0.positionned))
        return false;
    boolean node0Invis = nodeInvisible.contains(node0.getId());
    boolean node1Invis = nodeInvisible.contains(node1.getId());
    return !(node0Invis && node1Invis);
}
Also used : GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode)

Example 3 with GraphicNode

use of org.graphstream.ui.graphicGraph.GraphicNode in project gs-ui-javafx by graphstream.

the class DefaultCamera method checkVisibility.

/**
 * Process each node to check if it is in the actual view port, and mark
 * invisible nodes. This method allows for fast node, sprite and edge
 * visibility checking when drawing. This must be called before each
 * rendering (if the view port changed).
 */
public void checkVisibility(GraphicGraph graph) {
    double X = metrics.viewport[0];
    double Y = metrics.viewport[1];
    double W = metrics.viewport[2];
    double H = metrics.viewport[3];
    nodeInvisible.clear();
    for (Node node : graph) {
        boolean visible = isNodeIn((GraphicNode) node, X, Y, X + W, Y + H) && (!((GraphicNode) node).hidden) && ((GraphicNode) node).positionned;
        if (!visible)
            nodeInvisible.add(node.getId());
    }
}
Also used : GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode) Node(org.graphstream.graph.Node) GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode)

Example 4 with GraphicNode

use of org.graphstream.ui.graphicGraph.GraphicNode in project gs-ui-javafx by graphstream.

the class CubicCurve method approxVectorEnteringCurve.

/**
 * Return two points, one inside and the second outside of the shape of the destination node
 * of the given `edge`, the points can be used to deduce a vector along the Bézier curve entering
 * point in the shape.
 */
public static Tuple<Point2, Point2> approxVectorEnteringCurve(GraphicEdge edge, Connector c, DefaultCamera2D camera) {
    GraphicNode node = edge.to;
    AreaSkeleton info = (AreaSkeleton) node.getAttribute(Skeleton.attributeName);
    double w = 0.0;
    double h = 0.0;
    if (info != null) {
        w = info.theSize.x;
        h = info.theSize.y;
    } else {
        w = camera.getMetrics().lengthToGu(node.getStyle().getSize(), 0);
        h = w;
        if (node.getStyle().getSize().size() > 1)
            camera.getMetrics().lengthToGu(node.getStyle().getSize(), 1);
    }
    boolean searching = true;
    Point3 p0 = c.fromPos();
    Point3 p1 = c.toPos();
    double inc = 0.1f;
    double i = inc;
    while (searching) {
        p1 = CubicCurve.eval(c.fromPos(), c.byPos1(), c.byPos2(), c.toPos(), i);
        if (ShapeUtil.isPointIn(node, p1, w, h)) {
            searching = false;
        } else {
            p0 = p1;
        }
    }
    return new Tuple<Point2, Point2>(p0, p1);
}
Also used : Point3(org.graphstream.ui.geom.Point3) GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode) AreaSkeleton(org.graphstream.ui.javafx.renderer.AreaSkeleton) Tuple(org.graphstream.ui.javafx.util.AttributeUtils.Tuple)

Example 5 with GraphicNode

use of org.graphstream.ui.graphicGraph.GraphicNode in project gs-ui-javafx by graphstream.

the class CubicCurve method approxIntersectionPointOnCurve.

/**
 * Use a dichotomy method to evaluate the intersection between the `edge` destination node
 * shape and the Bézier curve of the connector `c`. The returned values are the point of
 * intersection as well as the parametric position of this point on the curve (a float).
 * The dichotomy can recurse at any level to increase precision, often 7 is sufficient, the
 * `maxDepth` parameter allows to set this depth.
 * @return A 2-tuple made of the point of intersection and the associated parametric position.
 */
public static Tuple<Point2, Double> approxIntersectionPointOnCurve(GraphicEdge edge, Connector c, DefaultCamera2D camera, int maxDepth) {
    GraphicNode node = edge.to;
    AreaSkeleton info = (AreaSkeleton) node.getAttribute(Skeleton.attributeName);
    double w = 0.0;
    double h = 0.0;
    if (info != null) {
        w = info.theSize.x;
        h = info.theSize.y;
    } else {
        w = camera.getMetrics().lengthToGu(node.getStyle().getSize(), 0);
        h = w;
        if (node.getStyle().getSize().size() > 1)
            camera.getMetrics().lengthToGu(node.getStyle().getSize(), 1);
    }
    boolean searching = true;
    // = CubicCurve.eval( c.fromPos, c.byPos1, c.byPos2, c.toPos, 0.5f )
    Point3 p = c.toPos();
    double tbeg = 0.0;
    double tend = 1.0;
    double t = 0.0;
    double depth = 0;
    while (depth < maxDepth) {
        t = tbeg + ((tend - tbeg) / 2);
        p = CubicCurve.eval(c.fromPos(), c.byPos1(), c.byPos2(), c.toPos(), t);
        if (ShapeUtil.isPointIn(node, p, w, h)) {
            tend = t;
        } else {
            tbeg = t;
        }
        depth += 1;
    }
    return new Tuple<Point2, Double>(p, t);
}
Also used : Point3(org.graphstream.ui.geom.Point3) GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode) AreaSkeleton(org.graphstream.ui.javafx.renderer.AreaSkeleton) Tuple(org.graphstream.ui.javafx.util.AttributeUtils.Tuple)

Aggregations

GraphicNode (org.graphstream.ui.graphicGraph.GraphicNode)7 Point2D (javafx.geometry.Point2D)3 Point3 (org.graphstream.ui.geom.Point3)3 Node (org.graphstream.graph.Node)2 Point2 (org.graphstream.ui.geom.Point2)2 Vector2 (org.graphstream.ui.geom.Vector2)2 GraphicEdge (org.graphstream.ui.graphicGraph.GraphicEdge)2 AreaSkeleton (org.graphstream.ui.javafx.renderer.AreaSkeleton)2 Tuple (org.graphstream.ui.javafx.util.AttributeUtils.Tuple)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1