Search in sources :

Example 11 with FunctionTimer

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

the class MFreeFactory method createModel.

public static MFreeModel3d createModel(MFreeModel3d model, MFreeNode3d[] nodes, PolygonalMesh surface, CubaturePoint3d[] cpnts) {
    MFreeShapeFunction func = new MLSShapeFunction();
    FunctionTimer timer = new FunctionTimer();
    // timer.start();
    // boolean[][] iChart = buildIntersectionChart(nodeArray);
    // timer.stop();
    // System.out.println("Intersection chart: " + timer.getTimeUsec()/1000 +
    // " ms");
    AABBTree nodeTree = new AABBTree();
    RestNode[] rnodes = new RestNode[nodes.length];
    for (int i = 0; i < nodes.length; ++i) {
        rnodes[i] = new RestNode(nodes[i], nodes[i].getInfluenceRadius());
    }
    timer.start();
    nodeTree.build(rnodes, nodes.length);
    timer.stop();
    System.out.println("Node BVTree: " + timer.getTimeUsec() / 1000 + " ms");
    // compute node dependencies and coordinates
    timer.start();
    for (MFreeNode3d node : nodes) {
        MFreeNode3d[] deps = findNodesContaining(node.getRestPosition(), nodeTree, 0);
        VectorNd coords = new VectorNd();
        getShapeCoords(func, coords, node.getRestPosition(), deps);
        node.setDependentNodes(deps, coords);
    }
    timer.stop();
    System.out.println("Node coordinates: " + timer.getTimeUsec() / 1000 + " ms");
    // timer.start();
    // DirectedGraph<int[], Integer> connectivityGraph =
    // IntersectionFactory.buildConnectivityGraph(iChart);
    // timer.stop();
    // System.out.println("Connectivity graph: " + timer.getTimeUsec()/1000 +
    // " ms");
    // timer.start();
    // ArrayList<MFreeElement3d> elemList = createPartitionedElements(nodes,
    // connectivityGraph);
    // timer.stop();
    // System.out.println("Partitioned elements: " + timer.getTimeUsec()/1000
    // + " ms");
    timer.start();
    MFreeIntegrationPoint3d[] ipnts = createIntegrationPoints(func, cpnts, nodeTree);
    timer.stop();
    System.out.println("Integration points: " + timer.getTimeUsec() / 1000 + " ms");
    HashMap<MFreeIntegrationPoint3d, MFreeElement3d> pntMap = new HashMap<MFreeIntegrationPoint3d, MFreeElement3d>(ipnts.length);
    timer.start();
    ArrayList<MFreeElement3d> elemList = createPartitionedElementsFromPoints(ipnts, pntMap);
    timer.stop();
    System.out.println("Building elements from points: " + timer.getTimeUsec() / 1000 + " ms");
    timer.start();
    distributeIPointsFromMap(pntMap);
    timer.stop();
    System.out.println("Distributing integration Points: " + timer.getTimeUsec() / 1000 + " ms");
    // trimEmptyElements(elemList);
    addWarpingPoints(elemList, nodeTree);
    if (model == null) {
        model = new MFreeModel3d();
    }
    model.addNodes(Arrays.asList(nodes));
    model.addElements(elemList);
    model.setSurfaceMesh(surface);
    model.updateNodeMasses(-1, null);
    return model;
}
Also used : HashMap(java.util.HashMap) FunctionTimer(maspack.util.FunctionTimer) AABBTree(maspack.geometry.AABBTree) VectorNd(maspack.matrix.VectorNd)

Example 12 with FunctionTimer

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

the class IntersectionTester method prerender.

@Override
public void prerender(RenderList list) {
    super.prerender(list);
    if (myZPerturb0 != null) {
        for (Vertex3d v : myMesh0.getVertices()) {
            if (isInterior(v)) {
                v.pnt.z = RandomGenerator.nextDouble(myZPerturb0.getLowerBound(), myZPerturb0.getUpperBound());
            }
        }
        myMesh0.notifyVertexPositionsModified();
        myMesh0.updateFaceNormals();
    }
    if (myZPerturb1 != null) {
        for (Vertex3d v : myMesh1.getVertices()) {
            if (isInterior(v)) {
                v.pnt.z = RandomGenerator.nextDouble(myZPerturb1.getLowerBound(), myZPerturb1.getUpperBound());
            }
        }
        myMesh1.notifyVertexPositionsModified();
        myMesh1.updateFaceNormals();
    }
    PolygonalMesh csgMesh = null;
    FunctionTimer timer = new FunctionTimer();
    if (myContoursOnly) {
        timer.start();
        System.out.println("finding contours");
        myContours = myIntersector.findContours(myMesh0, myMesh1);
        System.out.println("num contours=" + myContours.size());
        timer.stop();
        if (myContours.size() == 0) {
            return;
        }
    } else {
        timer.start();
        if (myCSGOperation == SurfaceMeshIntersector.CSG.INTERSECTION) {
            myContactInfo = myIntersector.findContoursAndRegions(myMesh0, RegionType.INSIDE, myMesh1, RegionType.INSIDE);
            csgMesh = myIntersector.createCSGMesh(myContactInfo);
        } else if (myCSGOperation == SurfaceMeshIntersector.CSG.UNION) {
            myContactInfo = myIntersector.findContoursAndRegions(myMesh0, RegionType.OUTSIDE, myMesh1, RegionType.OUTSIDE);
            csgMesh = myIntersector.createCSGMesh(myContactInfo);
        } else if (myCSGOperation == SurfaceMeshIntersector.CSG.DIFFERENCE01) {
            myContactInfo = myIntersector.findContoursAndRegions(myMesh0, RegionType.OUTSIDE, myMesh1, RegionType.INSIDE);
            csgMesh = myIntersector.createCSGMesh(myContactInfo);
        } else if (myCSGOperation == SurfaceMeshIntersector.CSG.DIFFERENCE10) {
            myContactInfo = myIntersector.findContoursAndRegions(myMesh0, RegionType.INSIDE, myMesh1, RegionType.OUTSIDE);
            csgMesh = myIntersector.createCSGMesh(myContactInfo);
        } else {
            myContactInfo = myIntersector.findContoursAndRegions(myMesh0, RegionType.INSIDE, myMesh1, RegionType.INSIDE);
        }
        timer.stop();
        if (myContactInfo == null) {
            myContours = null;
            return;
        }
        myContours = myContactInfo.getContours();
        ArrayList<PenetratingPoint> points0 = myContactInfo.getPenetratingPoints(0);
        // if (points0 != null) {
        // System.out.println ("num verts0= " + points0.size());
        // }
        // else {
        // System.out.println ("num verts0= null");
        // }
        ArrayList<PenetratingPoint> points1 = myContactInfo.getPenetratingPoints(1);
        // if (points1 != null) {
        // System.out.println ("num verts1= " + points1.size());
        // }
        // else {
        // System.out.println ("num verts1= null");
        // }
        ArrayList<PenetrationRegion> regions;
        if (false) {
            System.out.println("Regions 0:");
            regions = myContactInfo.getRegions(0);
            for (int i = 0; i < regions.size(); i++) {
                PenetrationRegion r = regions.get(i);
                int[] faceIdxs = SurfaceMeshIntersectorTest.getFaceIndices(r.getFaces());
                ArraySort.sort(faceIdxs);
                int[] vtxIdxs = SurfaceMeshIntersectorTest.getVertexIndices(r);
                ArraySort.sort(vtxIdxs);
                System.out.println(" " + i + " area=" + r.getArea() + " faces=[ " + ArraySupport.toString(faceIdxs) + " vtxs=[ " + ArraySupport.toString(vtxIdxs) + "]");
            }
            System.out.println("Regions 1:");
            regions = myContactInfo.getRegions(1);
            for (int i = 0; i < regions.size(); i++) {
                PenetrationRegion r = regions.get(i);
                int[] faceIdxs = SurfaceMeshIntersectorTest.getFaceIndices(r.getFaces());
                ArraySort.sort(faceIdxs);
                int[] vtxIdxs = SurfaceMeshIntersectorTest.getVertexIndices(r);
                ArraySort.sort(vtxIdxs);
                System.out.println(" " + i + " area=" + r.getArea() + " faces=[ " + ArraySupport.toString(faceIdxs) + " vtxs=[ " + ArraySupport.toString(vtxIdxs) + "]");
            }
            System.out.println("contours:");
            RigidTransform3d T = new RigidTransform3d();
            ArrayList<IntersectionContour> contours = myContactInfo.getContours();
            for (int k = 0; k < contours.size(); k++) {
                IntersectionContour c = contours.get(k);
                c.printCornerPoints("contour " + k + " closed=" + c.isClosed(), "%20.16f", T);
            }
        }
        if (false) {
            String pfx = "         ";
            System.out.print(pfx + "new int[] {");
            int k = 0;
            Collections.sort(points0, new CPPVertexComparator());
            for (PenetratingPoint cpp : points0) {
                System.out.print((k++ > 0 ? ", " : " ") + cpp.vertex.getIndex());
            }
            System.out.println(" },");
            System.out.print(pfx + "new int[] {");
            k = 0;
            Collections.sort(points1, new CPPVertexComparator());
            for (PenetratingPoint cpp : points1) {
                System.out.print((k++ > 0 ? ", " : " ") + cpp.vertex.getIndex());
            }
            System.out.println(" },");
        }
        if (myRenderCSGMesh && csgMesh != null) {
            csgMesh.prerender(myRenderProps);
            myCSGMesh = csgMesh;
        } else {
            myCSGMesh = null;
        }
    }
// System.out.println ("time=" + timer.result(1));
}
Also used : Vertex3d(maspack.geometry.Vertex3d) RigidTransform3d(maspack.matrix.RigidTransform3d) FunctionTimer(maspack.util.FunctionTimer) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 13 with FunctionTimer

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

the class Test method main.

public static void main(String[] args) {
    FunctionTimer timer = new FunctionTimer();
    long l = 0;
    long d = 0;
    double v = 0;
    int cnt = 10000000;
    timer.start();
    for (int i = 0; i < cnt; i++) {
        l = 0;
        for (int k = 0; k < 10; k++) {
            l = l * 10 + k;
        }
    }
    timer.stop();
    System.out.println("long: " + timer.result(cnt));
    timer.start();
    for (int i = 0; i < cnt; i++) {
        v = 0;
        for (int k = 0; k < 10; k++) {
            v = v * 10 + k;
        }
    }
    timer.stop();
    System.out.println("double: " + timer.result(cnt));
    timer.start();
    for (int i = 0; i < cnt; i++) {
        d = 0;
        for (int k = 0; k < 10; k++) {
            d = d * 10 + k;
        }
    }
    timer.stop();
    System.out.println("int: " + timer.result(cnt));
}
Also used : FunctionTimer(maspack.util.FunctionTimer)

Example 14 with FunctionTimer

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

the class FemModel method copy.

public FemModel copy(int flags, Map<ModelComponent, ModelComponent> copyMap) {
    FemModel fem = (FemModel) super.copy(flags, copyMap);
    for (int i = 0; i < fem.numComponents(); i++) {
        System.out.println(" child " + fem.get(i).getName());
    }
    fem.initializeChildComponents();
    // need to set markers and attachments in the subclass
    fem.setSurfaceRenderingMode(mySurfaceRenderingMode);
    if (mySurfaceRenderingMode == PropertyMode.Explicit) {
        fem.setSurfaceRendering(mySurfaceRendering);
    }
    fem.setStressPlotRangingMode(myStressPlotRangingMode);
    if (myStressPlotRangingMode == PropertyMode.Explicit) {
        fem.setStressPlotRanging(myStressPlotRanging);
    }
    fem.setStressPlotRangeMode(myStressPlotRangeMode);
    if (myStressPlotRangeMode == PropertyMode.Explicit) {
        fem.setStressPlotRange(myStressPlotRange);
    }
    fem.setGravityMode(myGravityMode);
    if (myGravityMode == PropertyMode.Explicit) {
        fem.setGravity(myGravity);
    }
    fem.setDensityMode(myDensityMode);
    if (myDensityMode == PropertyMode.Explicit) {
        fem.setDensity(myDensity);
    }
    fem.setParticleDamping(myMassDamping);
    fem.setStiffnessDamping(myStiffnessDamping);
    fem.setIntegrator(myIntegrator);
    fem.setMatrixSolver(myMatrixSolver);
    fem.myMinBound = null;
    fem.myMaxBound = null;
    fem.setMaterial(myMaterial);
    fem.mySolveMatrix = null;
    fem.myStressesValidP = false;
    fem.myStiffnessesValidP = false;
    fem.steptime = new FunctionTimer();
    fem.myVolume = myVolume;
    fem.myVolumeValid = myVolumeValid;
    fem.myCharacteristicSize = myCharacteristicSize;
    fem.myForcesNeedUpdating = true;
    fem.myMaxTranslationalVel = myMaxTranslationalVel;
    return fem;
}
Also used : FunctionTimer(maspack.util.FunctionTimer) Point(artisynth.core.mechmodels.Point)

Example 15 with FunctionTimer

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

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