Search in sources :

Example 1 with AABBTree

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

the class FemModel3d method updateBVHierarchies.

private void updateBVHierarchies() {
    if (myAABBTree == null) {
        myAABBTree = new AABBTree();
        Boundable[] elements = new Boundable[numElements()];
        for (int i = 0; i < elements.length; i++) {
            elements[i] = myElements.get(i);
        }
        myAABBTree.build(elements, numElements());
    } else {
        myAABBTree.update();
    }
    myBVTreeValid = true;
}
Also used : AABBTree(maspack.geometry.AABBTree) Boundable(maspack.geometry.Boundable) Point(artisynth.core.mechmodels.Point)

Example 2 with AABBTree

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

the class FemIntersector method intersectPlane.

/**
 * Intersects a FEM 3d model with a plane, returning a Polygonal mesh
 * on the plane corresponding to inside the FEM
 * @param fem model to intersect with the plane
 * @param plane plane to intersect with
 * @return intersection mesh
 */
public PolygonalMesh intersectPlane(FemModel3d fem, Plane plane) {
    AABBTree aabb = new AABBTree();
    FemElement3d[] elements = fem.getElements().toArray(new FemElement3d[fem.numElements()]);
    aabb.build(elements, fem.numElements());
    ArrayList<BVNode> nodes = new ArrayList<BVNode>();
    aabb.intersectPlane(nodes, plane);
    DirectedGraph<Point3d, Vector3d> nodeGraph = new DirectedGraph<Point3d, Vector3d>();
    TriangleIntersector ti = new TriangleIntersector();
    ti.setEpsilon(epsilon);
    for (BVNode node : nodes) {
        Boundable[] elems = node.getElements();
        for (int i = 0; i < node.getNumElements(); i++) {
            FemElement3d elem = (FemElement3d) elems[i];
            FaceNodes3d[] faceNodes = elem.getFaces();
            for (FaceNodes3d fn : faceNodes) {
                FemNode3d[][] faces = fn.triangulate();
                for (FemNode3d[] face : faces) {
                    addIfUnique(ti.intersectTrianglePlane(face[0].getPosition(), face[1].getPosition(), face[2].getPosition(), plane), nodeGraph, epsilon);
                }
            // end loop through faces
            }
        // end loop through "face nodes"
        }
    // end looping through elements
    }
    // end looping through BVNodes
    // reduceGraph(nodeGraph, tol);
    fixOverlaps(nodeGraph, epsilon);
    PolygonalMesh mesh = buildMesh(nodeGraph, plane.normal);
    removeBackFaces(mesh, plane.normal);
    nonConvexTriangulate(mesh, plane.normal, epsilon);
    return mesh;
}
Also used : ArrayList(java.util.ArrayList) TriangleIntersector(maspack.geometry.TriangleIntersector) PolygonalMesh(maspack.geometry.PolygonalMesh) DirectedGraph(maspack.graph.DirectedGraph) AABBTree(maspack.geometry.AABBTree) Vector3d(maspack.matrix.Vector3d) BVNode(maspack.geometry.BVNode) Point3d(maspack.matrix.Point3d) Boundable(maspack.geometry.Boundable)

Example 3 with AABBTree

use of maspack.geometry.AABBTree 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 4 with AABBTree

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

the class MFreeModel3d method buildRestNodeTree.

private static AABBTree buildRestNodeTree(Collection<FemNode3d> nodes) {
    AABBTree nodeTree = new AABBTree();
    RestNode[] rnodes = new RestNode[nodes.size()];
    int idx = 0;
    for (FemNode3d node : nodes) {
        rnodes[idx] = new RestNode(node, ((MFreeNode3d) node).getInfluenceRadius());
        ++idx;
    }
    nodeTree.build(rnodes, rnodes.length);
    return nodeTree;
}
Also used : AABBTree(maspack.geometry.AABBTree) FemNode3d(artisynth.core.femmodels.FemNode3d) Point(artisynth.core.mechmodels.Point)

Example 5 with AABBTree

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

the class MFreeModel3d method updateBVHierarchies.

private void updateBVHierarchies() {
    if (myElementTree == null) {
        myElementTree = new AABBTree();
        Boundable[] elements = new Boundable[numElements()];
        for (int i = 0; i < elements.length; i++) {
            elements[i] = myElements.get(i);
        }
        myElementTree.build(elements, numElements());
    } else {
        myElementTree.update();
    }
    if (myNodeTree == null) {
        myNodeTree = new AABBTree();
        Boundable[] nodes = new Boundable[numNodes()];
        for (int i = 0; i < nodes.length; i++) {
            nodes[i] = (MFreeNode3d) myNodes.get(i);
        }
        myNodeTree.build(nodes, numNodes());
    } else {
        myNodeTree.update();
    }
    myBVTreeValid = true;
}
Also used : AABBTree(maspack.geometry.AABBTree) Boundable(maspack.geometry.Boundable) Point(artisynth.core.mechmodels.Point)

Aggregations

AABBTree (maspack.geometry.AABBTree)6 Point (artisynth.core.mechmodels.Point)4 Boundable (maspack.geometry.Boundable)4 FemNode3d (artisynth.core.femmodels.FemNode3d)2 ArrayList (java.util.ArrayList)2 BVNode (maspack.geometry.BVNode)2 HashMap (java.util.HashMap)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 TriangleIntersector (maspack.geometry.TriangleIntersector)1 DirectedGraph (maspack.graph.DirectedGraph)1 Point3d (maspack.matrix.Point3d)1 Vector3d (maspack.matrix.Vector3d)1 VectorNd (maspack.matrix.VectorNd)1 FunctionTimer (maspack.util.FunctionTimer)1