Search in sources :

Example 1 with ValueVector

use of com.graphbuilder.curve.ValueVector in project poi by apache.

the class SplineCollector method addToPath.

public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
    // ok, we have the start, and all knots... do something with this
    Point2D last = path.getCurrentPoint();
    // create a control path and knots
    ControlPath controlPath = new ControlPath();
    ValueVector knots = new ValueVector(_knots.size() + 3);
    double firstKnot = _start.getB();
    double lastKnot = _start.getC();
    int degree = _start.getD();
    // first/second knot
    knots.add(firstKnot);
    knots.add(_start.getA());
    // first/second control point
    controlPath.addPoint(PointFactory.create(last.getX(), last.getY()));
    controlPath.addPoint(PointFactory.create(_start.getX(), _start.getY()));
    // middle knots/control points
    for (SplineKnot knot : _knots) {
        knots.add(knot.getA());
        controlPath.addPoint(PointFactory.create(knot.getX(), knot.getY()));
    }
    // last knot
    knots.add(lastKnot);
    ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath, knots, null, degree);
    path.append(shape, true);
}
Also used : ValueVector(com.graphbuilder.curve.ValueVector) Point2D(java.awt.geom.Point2D) ShapeMultiPath(com.graphbuilder.curve.ShapeMultiPath) ControlPath(com.graphbuilder.curve.ControlPath) SplineKnot(org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot)

Example 2 with ValueVector

use of com.graphbuilder.curve.ValueVector in project poi by apache.

the class NURBSTo method addToPath.

@Override
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
    if (getDel())
        return;
    Point2D last = path.getCurrentPoint();
    // A NURBS formula: knotLast, degree, xType, yType, x1, y1, knot1,
    // weight1, ..
    String formula = getE().trim();
    if (!formula.startsWith("NURBS(") || !formula.endsWith(")"))
        throw new POIXMLException("Invalid NURBS formula: " + formula);
    String[] components = formula.substring(6, formula.length() - 1).split(",");
    if (components.length < 8)
        throw new POIXMLException("Invalid NURBS formula (not enough arguments)");
    if ((components.length - 4) % 4 != 0)
        throw new POIXMLException("Invalid NURBS formula -- need 4 + n*4 arguments, got " + components.length);
    double lastControlX = getX();
    double lastControlY = getY();
    double secondToLastKnot = getA();
    double lastWeight = getB();
    double firstKnot = getC();
    double firstWeight = getD();
    double lastKnot = Double.parseDouble(components[0].trim());
    int degree = Integer.parseInt(components[1].trim());
    int xType = Integer.parseInt(components[2].trim());
    int yType = Integer.parseInt(components[3].trim());
    double xScale = 1;
    double yScale = 1;
    if (xType == 0)
        xScale = parent.getWidth();
    if (yType == 0)
        yScale = parent.getHeight();
    // setup first knots/weights/control point
    ControlPath controlPath = new ControlPath();
    ValueVector knots = new ValueVector();
    ValueVector weights = new ValueVector();
    knots.add(firstKnot);
    weights.add(firstWeight);
    controlPath.addPoint(PointFactory.create(last.getX(), last.getY()));
    // iterate get knots/weights
    int sets = (components.length - 4) / 4;
    for (int i = 0; i < sets; i++) {
        double x1 = Double.parseDouble(components[4 + i * 4 + 0].trim());
        double y1 = Double.parseDouble(components[4 + i * 4 + 1].trim());
        double k = Double.parseDouble(components[4 + i * 4 + 2].trim());
        double w = Double.parseDouble(components[4 + i * 4 + 3].trim());
        controlPath.addPoint(PointFactory.create(x1 * xScale, y1 * yScale));
        knots.add(k);
        weights.add(w);
    }
    // last knots/weights/control point
    knots.add(secondToLastKnot);
    knots.add(lastKnot);
    weights.add(lastWeight);
    controlPath.addPoint(PointFactory.create(lastControlX, lastControlY));
    ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath, knots, weights, degree);
    path.append(shape, true);
}
Also used : ValueVector(com.graphbuilder.curve.ValueVector) Point2D(java.awt.geom.Point2D) ShapeMultiPath(com.graphbuilder.curve.ShapeMultiPath) ControlPath(com.graphbuilder.curve.ControlPath) POIXMLException(org.apache.poi.POIXMLException)

Aggregations

ControlPath (com.graphbuilder.curve.ControlPath)2 ShapeMultiPath (com.graphbuilder.curve.ShapeMultiPath)2 ValueVector (com.graphbuilder.curve.ValueVector)2 Point2D (java.awt.geom.Point2D)2 POIXMLException (org.apache.poi.POIXMLException)1 SplineKnot (org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot)1