Search in sources :

Example 1 with NURBSCurve2d

use of maspack.geometry.NURBSCurve2d in project artisynth_core by artisynth.

the class MeshThicken method drawToolEnd.

public void drawToolEnd(DrawToolEvent e) {
    System.out.println("Entered");
    Dragger3d tool = e.getSource();
    if (tool instanceof SplineTool) {
        SplineTool splineTool = (SplineTool) tool;
        NURBSCurve2d curve = splineTool.getCurve();
        if (curve != null) {
            if (myEditingRegion != null) {
                myEditingRegion.setCurve(new NURBSCurve2d(curve));
                myEditingRegion = null;
            } else {
                RigidTransform3d X = new RigidTransform3d();
                splineTool.getToolToWorld(X);
                X.mulXyz(0, 0, -myDefaultRegionHeight);
                Region region = new Region(curve, X, myDefaultRegionHeight);
                region.myMargin = myDefaultRegionMargin;
                region.myThickening = myDefaultRegionThickening;
                region.myUnthickening = myDefaultRegionUnthickening;
                addRegion(region);
            }
        }
        splineTool.clear();
        viewer.rerender();
    }
}
Also used : SplineTool(maspack.widgets.SplineTool) RigidTransform3d(maspack.matrix.RigidTransform3d) NURBSCurve2d(maspack.geometry.NURBSCurve2d) Dragger3d(maspack.render.Dragger3d)

Example 2 with NURBSCurve2d

use of maspack.geometry.NURBSCurve2d in project artisynth_core by artisynth.

the class NURBSCurve2dTest method addTestCurves.

public void addTestCurves() {
    Vector4d[] q4 = new Vector4d[] { new Vector4d(300, 100, 0, 1), new Vector4d(300, 300, 0, 1), new Vector4d(100, 300, 0, 1), new Vector4d(100, 100, 0, 1) };
    double[] k4 = new double[] { -2, -1, 0, 1, 2, 3, 4, 5, 6 };
    Vector4d[] qclosed = new Vector4d[] { new Vector4d(150, 50, 0, 1), new Vector4d(250, 50, 0, 1), new Vector4d(300, 100, 0, 1), new Vector4d(350, 150, 0, 1), new Vector4d(350, 250, 0, 1), new Vector4d(300, 300, 0, 1), new Vector4d(250, 350, 0, 1), new Vector4d(150, 350, 0, 1), new Vector4d(100, 300, 0, 1), new Vector4d(50, 250, 0, 1), new Vector4d(50, 150, 0, 1), new Vector4d(100, 100, 0, 1) };
    double[] kclosed = new double[] { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5 };
    Vector4d[] qopen = new Vector4d[] { new Vector4d(100, 100, 0, 1), new Vector4d(150, 50, 0, 1), new Vector4d(250, 50, 0, 1), new Vector4d(300, 100, 0, 1), new Vector4d(350, 150, 0, 1), new Vector4d(350, 250, 0, 1), new Vector4d(300, 300, 0, 1), new Vector4d(250, 350, 0, 1), new Vector4d(150, 350, 0, 1), new Vector4d(100, 300, 0, 1), new Vector4d(50, 250, 0, 1), new Vector4d(50, 150, 0, 1), new Vector4d(100, 100, 0, 1) };
    double[] kopen = new double[] { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11 };
    Vector4d[] qsimple = new Vector4d[] { new Vector4d(100, 100, 0, 1), new Vector4d(200, 100, 0, 1), new Vector4d(200, 200, 0, 1), new Vector4d(200, 300, 0, 1), new Vector4d(100, 300, 0, 1), new Vector4d(50, 200, 0, 1) };
    double[] ksimple = new double[] { 0, 0, 1, 1 };
    // NURBSCurve2d curve = new NURBSCurve2d (2, NURBSCurve2d.CLOSED, q4, null);
    NURBSCurve2d curve = new NURBSCurve2d(2, NURBSCurve2d.CLOSED, qsimple, null);
    curve.convertToBezier();
    writeCurve("curve.txt", curve);
    NURBSCurve2d curve2 = readCurve("curve.txt");
    NURBSCurve2d check = new NURBSCurve2d(3, NURBSCurve2d.CLOSED, q4, null);
    check.transform(new RigidTransform3d(300, 0, 0));
    DistanceGrid grid = new DistanceGrid(150, 200, 500, 500, 51, 51);
    grid.update(curve2, 50);
    QuadBezierDistance2d dist = new QuadBezierDistance2d(curve2);
    Vector2d pnt = new Vector2d(250, 200);
    Vector2d near = new Vector2d();
    double d = dist.computeDistance(near, pnt, 1e10);
    System.out.println("max curvature=" + dist.computeMaxCurvature());
    myFrame.addRenderable(curve2);
    myFrame.addRenderable(grid);
}
Also used : Vector4d(maspack.matrix.Vector4d) RigidTransform3d(maspack.matrix.RigidTransform3d) QuadBezierDistance2d(maspack.geometry.QuadBezierDistance2d) Vector2d(maspack.matrix.Vector2d) NURBSCurve2d(maspack.geometry.NURBSCurve2d)

Example 3 with NURBSCurve2d

use of maspack.geometry.NURBSCurve2d in project artisynth_core by artisynth.

the class NURBSCurve2dTest method readCurve.

public NURBSCurve2d readCurve(String fileName) {
    try {
        ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new FileReader(fileName)));
        NURBSCurve2d curve = new NURBSCurve2d();
        curve.read(rtok);
        return curve;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : NURBSCurve2d(maspack.geometry.NURBSCurve2d) ReaderTokenizer(maspack.util.ReaderTokenizer) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

NURBSCurve2d (maspack.geometry.NURBSCurve2d)3 RigidTransform3d (maspack.matrix.RigidTransform3d)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 QuadBezierDistance2d (maspack.geometry.QuadBezierDistance2d)1 Vector2d (maspack.matrix.Vector2d)1 Vector4d (maspack.matrix.Vector4d)1 Dragger3d (maspack.render.Dragger3d)1 ReaderTokenizer (maspack.util.ReaderTokenizer)1 SplineTool (maspack.widgets.SplineTool)1