Search in sources :

Example 11 with Point3

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

the class HorizontalSquareEdgeShape method makeSingle.

private void makeSingle(DefaultCamera2D camera, double sox, double soy, double swx, double swy) {
    Point3 from = new Point3(skel.from().x + sox, skel.from().y + soy, 0);
    Point3 to = new Point3(skel.to().x + sox, skel.to().y + soy, 0);
    double size = (theSourceSize.x + theTargetSize.x);
    Point3 inter1 = null;
    Point3 inter2 = null;
    Point3 inter3 = null;
    Point3 inter4 = null;
    if (to.x > from.x) {
        double len = to.x - from.x;
        if (len < size) {
            inter1 = new Point3(from.x + theSourceSize.x, from.y, 0);
            inter2 = new Point3(to.x - theTargetSize.x, to.y, 0);
            inter3 = new Point3(inter1.x, inter1.y + (to.y - from.y) / 2, 0);
            inter4 = new Point3(inter2.x, inter3.y, 0);
            if (sox == 0 && soy == 0) {
                Point3[] pts = { from, inter1, inter3, inter4, inter2, to };
                skel.setPoly(pts);
            }
        } else {
            double middle = (to.x - from.x) / 2;
            inter1 = new Point3(from.x + middle, from.y, 0);
            inter2 = new Point3(to.x - middle, to.y, 0);
            if (sox == 0 && soy == 0) {
                Point3[] pts = { from, inter1, inter2, to };
                skel.setPoly(pts);
            }
        }
    } else {
        double len = from.x - to.x;
        if (len < size) {
            inter1 = new Point3(from.x - theSourceSize.x, from.y, 0);
            inter2 = new Point3(to.x + theTargetSize.x, to.y, 0);
            inter3 = new Point3(inter1.x, inter1.y + (to.y - from.y) / 2, 0);
            inter4 = new Point3(inter2.x, inter3.y, 0);
            if (sox == 0 && soy == 0) {
                Point3[] pts = { from, inter1, inter3, inter4, inter2, to };
                skel.setPoly(pts);
            }
        } else {
            double middle = (to.x - from.x) / 2;
            inter1 = new Point3(from.x + middle, from.y, 0);
            inter2 = new Point3(to.x - middle, to.y, 0);
            if (sox == 0 && soy == 0) {
                Point3[] pts = { from, inter1, inter2, to };
                skel.setPoly(pts);
            }
        }
    }
    theShape = new Path2D(10, true);
    theShape.moveTo(from.x, from.y);
    theShape.lineTo(inter1.x, inter1.y);
    if ((inter3 != null) && (inter4 != null)) {
        theShape.lineTo(inter3.x, inter3.y);
        theShape.lineTo(inter4.x, inter4.y);
    }
    theShape.lineTo(inter2.x, inter2.y);
    theShape.lineTo(to.x, to.y);
}
Also used : Point3(org.graphstream.ui.geom.Point3) Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

Example 12 with Point3

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

the class CircleOnEdge method makeOnCurve.

private void makeOnCurve(boolean forShadow, DefaultCamera2D camera) {
    Tuple<Point2, Double> tuple = CubicCurve.approxIntersectionPointOnCurve(theEdge, theConnector, camera);
    Point2 p1 = tuple.x;
    double t = tuple.y;
    Style style = theEdge.getStyle();
    Point3 p2 = CubicCurve.eval(theConnector.fromPos(), theConnector.byPos1(), theConnector.byPos2(), theConnector.toPos(), t - 0.1f);
    Vector2 dir = new Vector2(p1.x - p2.x, p1.y - p2.y);
    dir.normalize();
    dir.scalarMult(theSize.x / 2);
    // Create a polygon.
    theShape.setFrame((p1.x - dir.x()) - (theSize.x / 2), (p1.y - dir.y()) - (theSize.y / 2), theSize.x, theSize.y);
}
Also used : Point3(org.graphstream.ui.geom.Point3) Point2(org.graphstream.ui.geom.Point2) Vector2(org.graphstream.ui.geom.Vector2) Style(org.graphstream.ui.graphicGraph.stylesheet.Style)

Example 13 with Point3

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

the class PolygonShape method configureForElement.

@Override
public void configureForElement(Backend bck, GraphicElement element, Skeleton skel, DefaultCamera2D camera) {
    super.configureForElement(bck, element, skel, camera);
    if (element.hasAttribute("ui.points")) {
        Object oldRef = valuesRef;
        valuesRef = element.getAttribute("ui.points");
        // recreating the values array for nothing.
        if ((theValues == null) || (oldRef != valuesRef)) {
            theValues = getPoints(valuesRef);
            if (skel instanceof AreaSkeleton) {
                Tuple<Point3, Point3> tuple = boundingBoxOfPoints(theValues);
                minPoint = tuple.x;
                maxPoint = tuple.y;
            }
        }
        AreaSkeleton ninfo = (AreaSkeleton) skel;
        ninfo.theSize.set(maxPoint.x - minPoint.x, maxPoint.y - minPoint.y);
        area.theSize.copy(ninfo.theSize);
    }
}
Also used : Point3(org.graphstream.ui.geom.Point3) AreaSkeleton(org.graphstream.ui.javafx.renderer.AreaSkeleton)

Example 14 with Point3

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

the class AttributeUtils method getPoints.

default Point3[] getPoints(Object values) {
    if (values instanceof Point3[]) {
        if (((Point3[]) values).length == 0) {
            Logger.getLogger(this.getClass().getSimpleName()).info("0 ui.points");
        }
        return (Point3[]) values;
    } else if (values instanceof Object[]) {
        Object[] tabValues = (Object[]) values;
        if (tabValues.length > 0) {
            if (tabValues[0] instanceof Point3) {
                Point3[] res = new Point3[tabValues.length];
                for (int i = 0; i < tabValues.length; i++) {
                    res[i] = (Point3) tabValues[i];
                }
                return res;
            } else if (tabValues[0] instanceof Number) {
                int size = tabValues.length / 3;
                Point3[] res = new Point3[size];
                for (int i = 0; i < size; i++) {
                    res[i] = new Point3(((Number) tabValues[i * 3]).doubleValue(), ((Number) tabValues[i * 3 + 1]).doubleValue(), ((Number) tabValues[i * 3 + 2]).doubleValue());
                }
                return res;
            } else {
                Logger.getLogger(this.getClass().getSimpleName()).warning("Cannot interpret ui.points elements type " + ((Object[]) values)[0].getClass().getName());
                return new Point3[0];
            }
        } else {
            Logger.getLogger(this.getClass().getSimpleName()).warning("ui.points array size is zero !");
            return new Point3[0];
        }
    } else if (values instanceof double[]) {
        double[] tabValues = ((double[]) values);
        if (tabValues.length > 0) {
            int size = tabValues.length / 3;
            Point3[] res = new Point3[size];
            for (int i = 0; i < size; i++) {
                res[i] = new Point3(tabValues[i * 3], tabValues[i * 3 + 1], tabValues[i * 3 + 2]);
            }
            return res;
        } else {
            Logger.getLogger(this.getClass().getSimpleName()).warning("ui.points array size is zero !");
            return new Point3[0];
        }
    } else if (values instanceof float[] || values instanceof Float[]) {
        float[] tabValues = ((float[]) values);
        if (tabValues.length > 0) {
            int size = tabValues.length / 3;
            Point3[] res = new Point3[size];
            for (int i = 0; i < size; i++) {
                res[i] = new Point3(tabValues[i * 3], tabValues[i * 3 + 1], tabValues[i * 3 + 2]);
            }
            return res;
        } else {
            Logger.getLogger(this.getClass().getSimpleName()).warning("ui.points array size is zero !");
            return new Point3[0];
        }
    } else {
        Logger.getLogger(this.getClass().getSimpleName()).warning("Cannot interpret ui.points contents " + values.getClass().getName());
        return new Point3[0];
    }
}
Also used : Point3(org.graphstream.ui.geom.Point3)

Example 15 with Point3

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

the class SpriteFlowShape method make.

private void make(GraphicsContext graphics2d, DefaultCamera2D camera, double shx, double shy) {
    // we only need to compute the perpendicular vector once, hence this code.
    if (connectorSkel != null) {
        if (connectorSkel.isCurve()) {
            Point3 P0 = connectorSkel.apply(0);
            if (reverse)
                P0 = connectorSkel.apply(3);
            Point3 P1 = connectorSkel.apply(1);
            if (reverse)
                P1 = connectorSkel.apply(2);
            Point3 P2 = connectorSkel.apply(2);
            if (reverse)
                P2 = connectorSkel.apply(1);
            Point3 P3 = connectorSkel.apply(3);
            if (reverse)
                P3 = connectorSkel.apply(0);
            double inc = 0.01;
            double t = 0.0;
            Vector2 dir = new Vector2(P3.x - P0.x, P3.y - P0.y);
            Vector2 per = new Vector2(dir.y() + shx, -dir.x() + shy);
            per.normalize();
            per.scalarMult(offset);
            theShape = new Path2D((int) (along / inc) + 3, false);
            theShape.moveTo(P0.x + per.x(), P0.y + per.y());
            while (t <= along) {
                theShape.lineTo(CubicCurve.eval(P0.x + per.x(), P1.x + per.x(), P2.x + per.x(), P3.x + per.x(), t), CubicCurve.eval(P0.y + per.y(), P1.y + per.y(), P2.y + per.y(), P3.y + per.y(), t));
                t += inc;
            }
        } else if (connectorSkel.isPoly()) {
            Point3 P0 = connectorSkel.from();
            if (reverse)
                P0 = connectorSkel.to();
            Point3 P1 = connectorSkel.to();
            if (reverse)
                P1 = connectorSkel.from();
            double a = along;
            if (reverse)
                a = 1 - along;
            Triplet<Integer, Double, Double> triplet = connectorSkel.wichSegment(a);
            int i = triplet.i;
            double sum = triplet.sum;
            double ps = triplet.ps;
            Vector2 dir = new Vector2(P1.x - P0.x, P1.y - P0.y);
            Vector2 per = new Vector2(dir.y() + shx, -dir.x() + shy);
            per.normalize();
            per.scalarMult(offset);
            theShape = new Path2D(i + 3, false);
            if (reverse) {
                int n = connectorSkel.size();
                sum = connectorSkel.length() - sum;
                ps = 1 - ps;
                theShape.moveTo(P1.x + per.x(), P1.y + per.y());
                for (int j = n - 2; j < i; j--) {
                    theShape.lineTo(connectorSkel.apply(j).x + per.x(), connectorSkel.apply(j).y + per.y());
                }
                Point3 PX = connectorSkel.pointOnShape(along);
                theShape.lineTo(PX.x + per.x(), PX.y + per.y());
            } else {
                theShape.moveTo(P0.x + per.x(), P0.y + per.y());
                for (int j = 1; j <= i; j++) {
                    theShape.lineTo(connectorSkel.apply(j).x + per.x(), connectorSkel.apply(j).y + per.y());
                }
                Point3 PX = connectorSkel.pointOnShape(along);
                theShape.lineTo(PX.x + per.x(), PX.y + per.y());
            }
        } else {
            Point3 P0 = connectorSkel.from();
            if (reverse)
                P0 = connectorSkel.to();
            Point3 P1 = connectorSkel.to();
            if (reverse)
                P1 = connectorSkel.from();
            Vector2 dir = new Vector2(P1.x - P0.x, P1.y - P0.y);
            Vector2 per = new Vector2(dir.y() + shx, -dir.x() + shy);
            per.normalize();
            per.scalarMult(offset);
            dir.scalarMult(along);
            theShape = new Path2D(5, false);
            theShape.moveTo(P0.x + per.x(), P0.y + per.y());
            theShape.lineTo(P0.x + dir.x() + per.x(), P0.y + dir.y() + per.y());
        }
    }
// if( connectorSkel != null ) {
// var P0  = if( reverse ) connectorSkel.to else connectorSkel.from
// var P3  = if( reverse ) connectorSkel.from else connectorSkel.to
// val dir = Vector2( P3.x-P0.x, P3.y-P0.y )
// val per = Vector2( dir.y + shx, -dir.x + shy )
// 
// per.normalize
// per.scalarMult( offset )
// theShape.reset
// theShape.moveTo( P0.x + per.x, P0.y + per.y  )
// 
// if( connectorSkel.isCurve ) {
// val P1  = if( reverse ) connectorSkel(2) else connectorSkel(1)
// val P2  = if( reverse ) connectorSkel(1) else connectorSkel(2)
// val inc = 0.01f
// var t   = 0f
// 
// while( t <= along ) {
// theShape.lineTo(
// CubicCurve.eval( P0.x + per.x, P1.x + per.x, P2.x + per.x, P3.x + per.x, t ),
// CubicCurve.eval( P0.y + per.y, P1.y + per.y, P2.y + per.y, P3.y + per.y, t )
// )
// 
// t += inc
// }
// } else {
// val dir = Vector2( P3.x-P0.x, P3.y-P0.y )
// dir.scalarMult( along )
// theShape.lineTo( P0.x + dir.x + per.x, P0.y + dir.y + per.y )
// }
// }
}
Also used : Point3(org.graphstream.ui.geom.Point3) Vector2(org.graphstream.ui.geom.Vector2) Triplet(org.graphstream.ui.javafx.renderer.Skeleton.Triplet) Path2D(org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)

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