Search in sources :

Example 1 with Vector4d

use of maspack.matrix.Vector4d in project artisynth_core by artisynth.

the class NURBSViewer method addNURBS.

public void addNURBS(File file) throws IOException {
    WavefrontReader wfr = new WavefrontReader(file);
    wfr.parse();
    Vector4d[] allControlPnts = wfr.getHomogeneousPoints();
    for (WavefrontReader.Curve curve : wfr.getCurveList()) {
        NURBSCurve3d curveCopy = new NURBSCurve3d();
        try {
            curveCopy.set(curve, allControlPnts);
        } catch (IllegalArgumentException e) {
            throw new IOException(e.getMessage());
        }
        addNURBS(curveCopy);
    }
    for (WavefrontReader.Surface surf : wfr.getSurfaceList()) {
        NURBSSurface surfCopy = new NURBSSurface();
        try {
            surfCopy.set(surf, allControlPnts);
        } catch (IllegalArgumentException e) {
            throw new IOException(e.getMessage());
        }
        addNURBS(surfCopy);
    }
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) Vector4d(maspack.matrix.Vector4d) NURBSCurve3d(maspack.geometry.NURBSCurve3d) IOException(java.io.IOException) NURBSSurface(maspack.geometry.NURBSSurface)

Example 2 with Vector4d

use of maspack.matrix.Vector4d in project artisynth_core by artisynth.

the class NURBSCurve2d method eval.

/**
 * {@inheritDoc}
 */
public void eval(Point3d pnt, double u) {
    int numc = numControlPoints();
    if (numc == 0) {
        throw new IllegalStateException("curve does not contain control points");
    }
    int k = getKnotIndex(u);
    double[] bvals = new double[this.myDegree + 1];
    basisValues(bvals, k, u);
    pnt.setZero();
    double w = 0;
    for (int i = 0; i <= myDegree; i++) {
        Vector4d cpnt = myCtrlPnts.get(getCtrlIndex(k, i, numc));
        double wb = cpnt.w * bvals[i];
        pnt.x += wb * cpnt.x;
        pnt.y += wb * cpnt.y;
        w += wb;
    }
    pnt.z = 0;
    pnt.scale(1 / w);
}
Also used : Vector4d(maspack.matrix.Vector4d)

Example 3 with Vector4d

use of maspack.matrix.Vector4d in project artisynth_core by artisynth.

the class NURBSCurveBase method setCircle.

/**
 * Sets this curve to an eight-point circle formed using rational cubics.
 *
 * @param x
 * center x coordinate
 * @param y
 * center y coordinate
 * @param radius
 * circle radius
 * @throws IllegalArgumentException
 * if radius is non-positive
 */
public void setCircle(double x, double y, double radius) {
    if (radius <= 0) {
        throw new IllegalArgumentException("radius must be positive");
    }
    Vector4d[] cpnts = new Vector4d[8];
    double w = Math.sqrt(2) / 4;
    cpnts[0] = new Vector4d(1, 0, 0, 1);
    cpnts[1] = new Vector4d(1, 1, 0, w);
    cpnts[2] = new Vector4d(0, 1, 0, 1);
    cpnts[3] = new Vector4d(-1, 1, 0, w);
    cpnts[4] = new Vector4d(-1, 0, 0, 1);
    cpnts[5] = new Vector4d(-1, -1, 0, w);
    cpnts[6] = new Vector4d(0, -1, 0, 1);
    cpnts[7] = new Vector4d(1, -1, 0, w);
    for (int i = 0; i < cpnts.length; i++) {
        cpnts[i].x = radius * cpnts[i].x + x;
        cpnts[i].y = radius * cpnts[i].y + y;
    }
    set(3, CLOSED, cpnts, null);
}
Also used : Vector4d(maspack.matrix.Vector4d)

Example 4 with Vector4d

use of maspack.matrix.Vector4d in project artisynth_core by artisynth.

the class NURBSCurveBase method render.

/**
 * {@inheritDoc}
 */
public void render(Renderer renderer, RenderProps props, int flags) {
    boolean selecting = renderer.isSelecting();
    int numc = numControlPoints();
    if (numc == 0) {
        return;
    }
    renderer.pushModelMatrix();
    if (myXObjToWorld != RigidTransform3d.IDENTITY) {
        RigidTransform3d XOW = new RigidTransform3d(myXObjToWorld);
        renderer.mulModelMatrix(XOW);
    }
    renderer.setShading(Shading.NONE);
    if (myDrawControlShapeP) {
        // draw the control polygon
        if (props.getDrawEdges()) {
            renderer.setLineWidth(props.getEdgeWidth());
            if (!selecting) {
                renderer.setColor(props.getEdgeOrLineColorF());
            }
            if (myClosedP) {
                renderer.beginDraw(DrawMode.LINE_LOOP);
            } else {
                renderer.beginDraw(DrawMode.LINE_STRIP);
            }
            for (int i = 0; i < numc; i++) {
                Vector4d cpnt = myCtrlPnts.get(i);
                renderer.addVertex(cpnt.x, cpnt.y, cpnt.z);
            }
            renderer.endDraw();
        }
        // draw the control points
        drawControlPoints(renderer, props, flags);
    }
    // draw the curve itself
    if (!selecting) {
        renderer.setColor(props.getLineColorF());
    }
    double len = computeControlPolygonLength();
    double res = myResolution * renderer.distancePerPixel(myXObjToWorld.p);
    int nsegs = (int) Math.max(10, len / res);
    Point3d pnt = new Point3d();
    renderer.setLineWidth(props.getLineWidth());
    renderer.beginDraw(DrawMode.LINE_LOOP);
    double[] urange = new double[2];
    getRange(urange);
    for (int i = 0; i < nsegs + 1; i++) {
        eval(pnt, urange[0] + (urange[1] - urange[0]) * i / nsegs);
        renderer.addVertex(pnt);
    }
    renderer.endDraw();
    renderer.setLineWidth(1);
    renderer.setShading(Shading.FLAT);
    renderer.popModelMatrix();
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector4d(maspack.matrix.Vector4d) Point3d(maspack.matrix.Point3d)

Example 5 with Vector4d

use of maspack.matrix.Vector4d in project artisynth_core by artisynth.

the class NURBSObject method set.

protected void set(NURBSObject nobj) {
    myCtrlPnts.clear();
    for (Vector4d cpnt : nobj.myCtrlPnts) {
        myCtrlPnts.add(new Vector4d(cpnt));
    }
    myCtrlPntSelected = (ArrayList<Boolean>) nobj.myCtrlPntSelected.clone();
    if (nobj.myXObjToWorld.isIdentity()) {
        myXObjToWorld = RigidTransform3d.IDENTITY;
    } else {
        myXObjToWorld = new RigidTransform3d(nobj.myXObjToWorld);
    }
    myRenderProps = nobj.myRenderProps.clone();
}
Also used : Vector4d(maspack.matrix.Vector4d) RigidTransform3d(maspack.matrix.RigidTransform3d)

Aggregations

Vector4d (maspack.matrix.Vector4d)20 IOException (java.io.IOException)4 Point3d (maspack.matrix.Point3d)4 RigidTransform3d (maspack.matrix.RigidTransform3d)3 Vector3d (maspack.matrix.Vector3d)3 NURBSCurve2d (maspack.geometry.NURBSCurve2d)1 NURBSCurve3d (maspack.geometry.NURBSCurve3d)1 NURBSSurface (maspack.geometry.NURBSSurface)1 QuadBezierDistance2d (maspack.geometry.QuadBezierDistance2d)1 WavefrontReader (maspack.geometry.io.WavefrontReader)1 Vector2d (maspack.matrix.Vector2d)1 RenderProps (maspack.render.RenderProps)1 TestException (maspack.util.TestException)1