Search in sources :

Example 26 with Point3

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

the class AttributeUtils method boundingBoxOfPoints.

default Tuple<Point3, Point3> boundingBoxOfPoints(Point3[] points) {
    Double minx = Double.MAX_VALUE;
    Double miny = Double.MAX_VALUE;
    Double minz = Double.MAX_VALUE;
    Double maxx = Double.MIN_VALUE;
    Double maxy = Double.MIN_VALUE;
    Double maxz = Double.MIN_VALUE;
    for (int i = 0; i < points.length; i++) {
        if (points[i].x < minx)
            minx = points[i].x;
        if (points[i].y < miny)
            miny = points[i].y;
        if (points[i].z < minz)
            minz = points[i].z;
        if (points[i].x > maxx)
            maxx = points[i].x;
        if (points[i].y > maxy)
            maxy = points[i].y;
        if (points[i].z > maxz)
            maxz = points[i].z;
    }
    return new Tuple<Point3, Point3>(new Point3(minx, miny, minz), new Point3(maxx, maxy, maxz));
}
Also used : Point3(org.graphstream.ui.geom.Point3)

Example 27 with Point3

use of org.graphstream.ui.geom.Point3 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)

Example 28 with Point3

use of org.graphstream.ui.geom.Point3 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)

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