Search in sources :

Example 1 with InsideQuery

use of maspack.geometry.BVFeatureQuery.InsideQuery in project artisynth_core by artisynth.

the class BVFeatureQueryTest method pointInsideCheck.

private boolean pointInsideCheck(Point3d pnt, double tol, PolygonalMesh mesh, BVTree bvh, BVFeatureQuery query, TriangleIntersector intersector) {
    boolean isInside = query.isInsideOrientedMesh(bvh, pnt, tol);
    boolean isInsideCheck;
    // boolean isInsideCheck = obbTree.isInside (pnt, intersector, tol);
    // if (isInside != isInsideCheck) {
    // throw new TestException (
    // "query.isInsideMesh returned "+isInside+
    // ", OBBTree.isInside returned "+isInsideCheck);
    // }
    InsideQuery status = query.isInsideMesh(mesh, bvh, pnt, tol);
    // }
    if (status == InsideQuery.UNSURE) {
        System.out.println("isInsideMesh() did not converge");
        return false;
    } else {
        isInsideCheck = (status == InsideQuery.INSIDE);
        if (isInside != isInsideCheck) {
            System.out.println("pnt=" + pnt);
            System.out.println("last case: " + query.lastCase);
            throw new TestException("query.isInsideMesh returned  " + isInside + ", OBB.isInsideRayTest returned " + isInsideCheck);
        }
    }
    return isInside;
}
Also used : TestException(maspack.util.TestException) InsideQuery(maspack.geometry.BVFeatureQuery.InsideQuery)

Example 2 with InsideQuery

use of maspack.geometry.BVFeatureQuery.InsideQuery in project artisynth_core by artisynth.

the class BVFeatureQueryTest method pointInsideTiming.

private void pointInsideTiming(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 = 1;
    Point3d pnt = new Point3d();
    FunctionTimer obbOrientedTimer = new FunctionTimer();
    FunctionTimer aabbOrientedTimer = new FunctionTimer();
    FunctionTimer obbInsideTimer = new FunctionTimer();
    FunctionTimer aabbInsideTimer = new FunctionTimer();
    for (int i = 0; i < numcases; i++) {
        Random rand = RandomGenerator.get();
        int vidx = rand.nextInt(mesh.numVertices());
        pnt.setRandom();
        pnt.scale(0.001 * diameter);
        pnt.add(mesh.getVertex(vidx).pnt);
        pnt.transform(X, pnt);
        boolean inside;
        obbOrientedTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            inside = query.isInsideOrientedMesh(obbTree, pnt, 0);
        }
        obbOrientedTimer.stop();
        aabbOrientedTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            query.isInsideOrientedMesh(aabbTree, pnt, 0);
        }
        aabbOrientedTimer.stop();
        obbInsideTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            InsideQuery res;
            res = query.isInsideMesh(mesh, obbTree, pnt, 0);
        }
        obbInsideTimer.stop();
        aabbInsideTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            query.isInsideMesh(mesh, aabbTree, pnt, 0);
        }
        aabbInsideTimer.stop();
    }
    int cnt = numcases * timingcnt;
    System.out.println("isInsideOriented with OBB: " + obbOrientedTimer.result(cnt));
    System.out.println("isInsideOriented with AABB: " + aabbOrientedTimer.result(cnt));
    System.out.println("isInside with OBB: " + obbInsideTimer.result(cnt));
    System.out.println("isInside with AABB: " + aabbInsideTimer.result(cnt));
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Random(java.util.Random) Point3d(maspack.matrix.Point3d) FunctionTimer(maspack.util.FunctionTimer) InsideQuery(maspack.geometry.BVFeatureQuery.InsideQuery)

Aggregations

InsideQuery (maspack.geometry.BVFeatureQuery.InsideQuery)2 Random (java.util.Random)1 Point3d (maspack.matrix.Point3d)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 FunctionTimer (maspack.util.FunctionTimer)1 TestException (maspack.util.TestException)1