Search in sources :

Example 46 with Point3d

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

the class BVFeatureQueryTest method nearestFaceTiming.

private void nearestFaceTiming(PolygonalMesh mesh) {
    RigidTransform3d X = new RigidTransform3d();
    OBBTree obbTree = new OBBTree(mesh, 2);
    AABBTree aabbTree = new AABBTree(mesh);
    Point3d center = new Point3d();
    double diameter = 2 * aabbTree.getRadius();
    aabbTree.getCenter(center);
    X.setRandom();
    BVFeatureQuery query = new BVFeatureQuery();
    mesh.setMeshToWorld(X);
    obbTree.setBvhToWorld(X);
    aabbTree.setBvhToWorld(X);
    int numcases = 100;
    int timingcnt = 1000;
    Point3d pnt = new Point3d();
    Vector3d dir = new Vector3d();
    Point3d near = new Point3d();
    Vector2d coords = new Vector2d();
    Vector3d duv = new Vector3d();
    FunctionTimer obbFaceTimer = new FunctionTimer();
    FunctionTimer aabbFaceTimer = new FunctionTimer();
    // FunctionTimer oldFaceTimer = new FunctionTimer();
    FunctionTimer obbRayTimer = new FunctionTimer();
    FunctionTimer aabbRayTimer = new FunctionTimer();
    // FunctionTimer oldRayTimer = new FunctionTimer();
    TriangleIntersector ti = new TriangleIntersector();
    for (int i = 0; i < numcases; i++) {
        pnt.setRandom();
        pnt.scale(2 * diameter);
        pnt.add(center);
        pnt.transform(X, pnt);
        dir.setRandom();
        dir.normalize();
        obbFaceTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            query.nearestFaceToPoint(near, coords, obbTree, pnt);
        }
        obbFaceTimer.stop();
        aabbFaceTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            query.nearestFaceToPoint(near, coords, aabbTree, pnt);
        }
        aabbFaceTimer.stop();
        // oldFaceTimer.restart();
        // for (int j=0; j<timingcnt; j++) {
        // obbTree.nearestFace (pnt, null, near, coords, ti);
        // }
        // oldFaceTimer.stop();
        obbRayTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            query.nearestFaceAlongRay(near, duv, obbTree, center, dir);
        }
        obbRayTimer.stop();
        aabbRayTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            query.nearestFaceAlongRay(near, duv, aabbTree, center, dir);
        }
        aabbRayTimer.stop();
    // oldRayTimer.restart();
    // for (int j=0; j<timingcnt; j++) {
    // obbTree.intersect (center, dir, duv, ti);
    // }
    // oldRayTimer.stop();
    }
    int cnt = numcases * timingcnt;
    System.out.println("nearestFace with OBB: " + obbFaceTimer.result(cnt));
    System.out.println("nearestFace with AABB: " + aabbFaceTimer.result(cnt));
    // System.out.println (
    // "nearestFace with old OBB: " + oldFaceTimer.result(cnt));
    System.out.println("nearestRay with OBB: " + obbRayTimer.result(cnt));
    System.out.println("nearestRay with AABB: " + aabbRayTimer.result(cnt));
// System.out.println (
// "nearestRay with old OBB: " + oldRayTimer.result(cnt));
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) FunctionTimer(maspack.util.FunctionTimer)

Example 47 with Point3d

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

the class BVFeatureQueryTest method getNearestVerticesToPoint.

private ArrayList<Vertex3d> getNearestVerticesToPoint(MeshBase mesh, Point3d pnt) {
    Point3d loc = new Point3d();
    loc.inverseTransform(mesh.getMeshToWorld(), pnt);
    ArrayList<Vertex3d> verts = mesh.getVertices();
    double mind = Double.POSITIVE_INFINITY;
    for (int i = 0; i < verts.size(); i++) {
        double d = verts.get(i).pnt.distance(loc);
        if (d < mind) {
            mind = d;
        }
    }
    ArrayList<Vertex3d> nearestVerts = new ArrayList<Vertex3d>();
    for (int i = 0; i < verts.size(); i++) {
        double d = verts.get(i).pnt.distance(loc);
        if (d == mind) {
            nearestVerts.add(verts.get(i));
        }
    }
    return nearestVerts;
}
Also used : Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList)

Example 48 with Point3d

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

the class BVFeatureQueryTest method pointInsideTest.

private void pointInsideTest(PolygonalMesh mesh, BVTree bvh, RigidTransform3d X, double radius, Point3d center) {
    int numtrials = 10000;
    Point3d pnt = new Point3d();
    double tol = EPS * (center.norm() + radius);
    TriangleIntersector intersector = new TriangleIntersector();
    BVFeatureQuery query = new BVFeatureQuery();
    mesh.setMeshToWorld(X);
    bvh.setBvhToWorld(X);
    tol = 0;
    int numInside = 0;
    for (int i = 0; i < numtrials; i++) {
        pnt.setRandom();
        pnt.scale(2 * radius);
        pnt.add(center);
        pnt.transform(X, pnt);
        if (pointInsideCheck(pnt, tol, mesh, bvh, query, intersector)) {
            numInside++;
        }
    }
    double avgEdgeLength = mesh.computeAverageEdgeLength();
    int numv = mesh.numVertices();
    for (int i = 0; i < numtrials / numv; i++) {
        for (int j = 0; j < numv; j++) {
            pnt.setRandom();
            pnt.scale(avgEdgeLength / 10);
            pnt.add(mesh.getVertex(j).pnt);
            pnt.transform(X, pnt);
            if (pointInsideCheck(pnt, tol, mesh, bvh, query, intersector)) {
                numInside++;
            }
        }
    }
    if (printInsideOutsideCounts) {
        System.out.println("numInside=" + numInside);
        System.out.println("numOutside=" + (numtrials - numInside));
        System.out.println("cases: V=" + query.numVertexCases + " E=" + query.numEdgeCases + " F=" + query.numFaceCases);
    }
}
Also used : Point3d(maspack.matrix.Point3d)

Example 49 with Point3d

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

the class BVFeatureQueryTest method getNearestFacesToRay.

private ArrayList<NearestFaceInfo> getNearestFacesToRay(PolygonalMesh mesh, Point3d pnt, Vector3d dir, double tol) {
    Point3d lpnt = new Point3d();
    Vector3d ldir = new Vector3d();
    lpnt.inverseTransform(mesh.getMeshToWorld(), pnt);
    ldir.inverseTransform(mesh.getMeshToWorld(), dir);
    ArrayList<Face> faces = mesh.getFaces();
    NearestFaceInfo[] faceInfo = new NearestFaceInfo[faces.size()];
    TriangleIntersector intersector = new TriangleIntersector();
    double mind = Double.POSITIVE_INFINITY;
    for (int i = 0; i < faces.size(); i++) {
        NearestFaceInfo ninfo = new NearestFaceInfo();
        faceInfo[i] = ninfo;
        double d = ninfo.computeDistanceToRay(faces.get(i), lpnt, ldir, intersector);
        ninfo.myNear.transform(mesh.getMeshToWorld());
        if (d >= 0 && d < Double.POSITIVE_INFINITY) {
            if (d < mind) {
                mind = d;
            }
        }
    }
    ArrayList<NearestFaceInfo> nearestFaces = new ArrayList<NearestFaceInfo>();
    if (mind < Double.POSITIVE_INFINITY) {
        for (int i = 0; i < faces.size(); i++) {
            double d = faceInfo[i].myDist;
            if (d >= 0 && d < Double.POSITIVE_INFINITY) {
                if (Math.abs(d - mind) < tol) {
                    nearestFaces.add(faceInfo[i]);
                }
            }
        }
    }
    return nearestFaces;
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList)

Example 50 with Point3d

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

the class BVFeatureQueryTest method getNearestFacesToPoint.

private ArrayList<NearestFaceInfo> getNearestFacesToPoint(PolygonalMesh mesh, Point3d pnt, double tol) {
    Point3d loc = new Point3d();
    loc.inverseTransform(mesh.getMeshToWorld(), pnt);
    ArrayList<Face> faces = mesh.getFaces();
    NearestFaceInfo[] faceInfo = new NearestFaceInfo[faces.size()];
    TriangleIntersector intersector = new TriangleIntersector();
    double mind = Double.POSITIVE_INFINITY;
    for (int i = 0; i < faces.size(); i++) {
        NearestFaceInfo ninfo = new NearestFaceInfo();
        faceInfo[i] = ninfo;
        double d = ninfo.computeDistanceToPoint(faces.get(i), loc, intersector);
        ninfo.myNear.transform(mesh.getMeshToWorld());
        if (d < mind) {
            mind = d;
        }
    }
    ArrayList<NearestFaceInfo> nearestFaces = new ArrayList<NearestFaceInfo>();
    for (int i = 0; i < faces.size(); i++) {
        if (Math.abs(faceInfo[i].myDist - mind) < tol) {
            nearestFaces.add(faceInfo[i]);
        }
    }
    return nearestFaces;
}
Also used : Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList)

Aggregations

Point3d (maspack.matrix.Point3d)464 Vector3d (maspack.matrix.Vector3d)128 ArrayList (java.util.ArrayList)59 RigidTransform3d (maspack.matrix.RigidTransform3d)48 Vertex3d (maspack.geometry.Vertex3d)35 Point (artisynth.core.mechmodels.Point)30 PolygonalMesh (maspack.geometry.PolygonalMesh)30 Face (maspack.geometry.Face)25 ReaderTokenizer (maspack.util.ReaderTokenizer)19 IOException (java.io.IOException)18 RotationMatrix3d (maspack.matrix.RotationMatrix3d)17 Vector2d (maspack.matrix.Vector2d)16 VectorNd (maspack.matrix.VectorNd)16 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)15 HashMap (java.util.HashMap)14 Muscle (artisynth.core.mechmodels.Muscle)13 FemNode3d (artisynth.core.femmodels.FemNode3d)12 Particle (artisynth.core.mechmodels.Particle)12 BufferedReader (java.io.BufferedReader)11 Plane (maspack.matrix.Plane)11