Search in sources :

Example 1 with FunctionTimer

use of maspack.util.FunctionTimer 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 2 with FunctionTimer

use of maspack.util.FunctionTimer in project artisynth_core by artisynth.

the class BVIntersectorTest method timeMeshIntersection.

public void timeMeshIntersection(PolygonalMesh mesh1) {
    Point3d center = new Point3d();
    double radius = RenderableUtils.getRadiusAndCenter(center, mesh1);
    PolygonalMesh mesh2 = new PolygonalMesh(mesh1);
    BVIntersector intersector = new BVIntersector();
    TriangleIntersector ti = new TriangleIntersector();
    ArrayList<TriTriIntersection> intersections = new ArrayList<TriTriIntersection>();
    OBBTree obbTree1 = new OBBTree(mesh1);
    OBBTree obbTree2 = new OBBTree(mesh2);
    AABBTree aabbTree1 = new AABBTree(mesh1);
    AABBTree aabbTree2 = new AABBTree(mesh2);
    FunctionTimer obbTimer = new FunctionTimer();
    FunctionTimer aabbTimer = new FunctionTimer();
    // FunctionTimer oldTimer = new FunctionTimer();
    RigidTransform3d X2W = new RigidTransform3d();
    RigidTransform3d X1W = new RigidTransform3d();
    int numcases = 50;
    int timingcnt = 500;
    for (int i = 0; i < numcases; i++) {
        X2W.R.setRandom();
        X2W.p.setRandom();
        X2W.p.scale(radius);
        X1W.R.setRandom();
        X1W.p.setRandom();
        X1W.p.scale(radius);
        obbTree1.setBvhToWorld(X1W);
        aabbTree1.setBvhToWorld(X1W);
        obbTree2.setBvhToWorld(X2W);
        aabbTree2.setBvhToWorld(X2W);
        mesh1.setMeshToWorld(X1W);
        mesh2.setMeshToWorld(X2W);
        obbTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            intersections.clear();
            intersector.intersectMeshMesh(intersections, obbTree1, obbTree2);
        }
        obbTimer.stop();
        aabbTimer.restart();
        for (int j = 0; j < timingcnt; j++) {
            intersections.clear();
            intersector.intersectMeshMesh(intersections, aabbTree1, aabbTree2);
        }
        aabbTimer.stop();
    // oldTimer.restart();
    // for (int j=0; j<timingcnt; j++) {
    // intersections.clear();
    // obbTree1.intersectFully (obbTree2, intersections, ti);
    // }
    // oldTimer.stop();
    }
    int cnt = numcases * timingcnt;
    System.out.println("mesh intersection with OBB: " + obbTimer.result(cnt));
    System.out.println("mesh intersection with AABB: " + aabbTimer.result(cnt));
// System.out.println (
// "mesh intersection with old OBB: " + oldTimer.result(cnt));
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) ArrayList(java.util.ArrayList) FunctionTimer(maspack.util.FunctionTimer) Point3d(maspack.matrix.Point3d)

Example 3 with FunctionTimer

use of maspack.util.FunctionTimer in project artisynth_core by artisynth.

the class CholeskyDecompositionTest method timingTests.

private void timingTests() {
    int numTrials = 10;
    int timingCnt = 1;
    int[] matsizes = new int[] { 32, 16, 32, 64, 128, 256 };
    NumberFormat ifmt = new NumberFormat("%3d");
    NumberFormat ffmt = new NumberFormat("%8.2f");
    System.out.println("\ntimes are in usec\n");
    System.out.println("matsize      factor   add row/col  del row/col");
    // XXX XXXXX.XX XXXXX.XX XXXXX.XX
    FunctionTimer timer = new FunctionTimer();
    for (int k = 0; k < matsizes.length; k++) {
        int n = matsizes[k];
        MatrixNd M = new MatrixNd(n, n);
        VectorNd col = new VectorNd(n);
        CholeskyDecomposition chol = new CholeskyDecomposition(n);
        double factorTime = 0;
        double addTime = 0;
        double delTime = 0;
        for (int cnt = 0; cnt < numTrials; cnt++) {
            M.setRandom();
            M.mulTranspose(M);
            M.getColumn(0, col);
            double x0 = col.get(0);
            for (int i = 0; i < n - 1; i++) {
                col.set(i, col.get(i + 1));
            }
            col.set(n - 1, x0);
            timer.start();
            for (int i = 0; i < timingCnt; i++) {
                chol.factor(M);
            }
            timer.stop();
            factorTime += timer.getTimeUsec() / timingCnt;
            timer.start();
            for (int i = 0; i < timingCnt; i++) {
                chol.deleteRowAndColumn(0);
            }
            timer.stop();
            delTime += timer.getTimeUsec() / timingCnt;
            timer.start();
            for (int i = 0; i < timingCnt; i++) {
                chol.addRowAndColumn(col);
            }
            timer.stop();
            addTime += timer.getTimeUsec() / timingCnt;
        }
        factorTime /= numTrials;
        addTime /= numTrials;
        delTime /= numTrials;
        if (k > 0) {
            System.out.println("  " + ifmt.format(n) + "      " + ffmt.format(factorTime) + "    " + ffmt.format(addTime) + "    " + ffmt.format(delTime));
        }
    }
}
Also used : FunctionTimer(maspack.util.FunctionTimer) NumberFormat(maspack.util.NumberFormat)

Example 4 with FunctionTimer

use of maspack.util.FunctionTimer in project artisynth_core by artisynth.

the class Matrix3d method main.

public static void main(String[] args) {
    Matrix3d MX = new Matrix3d(new double[] { 1, 2, 3, 4, 2, 4, 6, 5, 4 });
    Matrix3d M = new Matrix3d();
    LUDecomposition lu = new LUDecomposition();
    M.set(MX);
    M.invert();
    System.out.println("inv=\n" + M.toString("%9.4f"));
    lu.factor(MX);
    lu.inverse(M);
    System.out.println("lu inv=\n" + M.toString("%9.4f"));
    FunctionTimer timer = new FunctionTimer();
    int cnt = 10000000;
    timer.start();
    for (int i = 0; i < cnt; i++) {
        M.set(MX);
        M.invert();
    }
    timer.stop();
    System.out.println("inv time: " + timer.result(cnt));
    timer.start();
    for (int i = 0; i < cnt; i++) {
        lu.factor(MX);
        lu.inverse(M);
    }
    timer.stop();
    System.out.println("lu time: " + timer.result(cnt));
    timer.start();
    for (int i = 0; i < cnt; i++) {
        M.mul(MX, MX);
    }
    timer.stop();
    System.out.println("mul time: " + timer.result(cnt));
    timer.start();
    for (int i = 0; i < cnt; i++) {
        M.set(MX);
    }
    timer.stop();
    System.out.println("set time: " + timer.result(cnt));
}
Also used : FunctionTimer(maspack.util.FunctionTimer)

Example 5 with FunctionTimer

use of maspack.util.FunctionTimer in project artisynth_core by artisynth.

the class Matrix3dBase method main.

public static void main(String[] args) {
    FunctionTimer timer = new FunctionTimer();
    Matrix3d M = new Matrix3d();
    M.setRandom();
    int cnt = 1000000;
    Matrix3d R = new Matrix3d();
    for (int i = 0; i < cnt; i++) {
        R.fastInvert(M);
        R.invert(M);
    }
    timer.start();
    for (int i = 0; i < cnt; i++) {
        R.fastInvert(M);
    }
    timer.stop();
    System.out.println("fast invert=" + timer.result(cnt));
    timer.start();
    for (int i = 0; i < cnt; i++) {
        R.invert(M);
    }
    timer.stop();
    System.out.println("invert=" + timer.result(cnt));
}
Also used : FunctionTimer(maspack.util.FunctionTimer)

Aggregations

FunctionTimer (maspack.util.FunctionTimer)19 RigidTransform3d (maspack.matrix.RigidTransform3d)4 Point3d (maspack.matrix.Point3d)3 NumberFormat (maspack.util.NumberFormat)3 Point (artisynth.core.mechmodels.Point)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 NamedThreadFactory (maspack.concurrency.NamedThreadFactory)1 AABBTree (maspack.geometry.AABBTree)1 InsideQuery (maspack.geometry.BVFeatureQuery.InsideQuery)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 Vertex3d (maspack.geometry.Vertex3d)1 Vector2d (maspack.matrix.Vector2d)1