Search in sources :

Example 1 with TriangleIntersector

use of maspack.geometry.TriangleIntersector 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 2 with TriangleIntersector

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

the class FemDisplayProbe method updateVertexIndicators.

/**
 *  determines which vertices are inside the supplied mesh
 */
protected void updateVertexIndicators() {
    vtxIndicatorMap = new HashMap<Vertex3d, Boolean>(myPlaneSurface.numVertices());
    TriangleIntersector ti = new TriangleIntersector();
    BVFeatureQuery query = new BVFeatureQuery();
    ti.setEpsilon(myIntersectionTolerance);
    if (myFem != null) {
        PolygonalMesh mesh = myFem.getSurfaceMesh();
        for (Vertex3d vtx : myPlaneSurface.getVertices()) {
            Point3d pnt = vtx.getWorldPoint();
            if (query.isInsideOrientedMesh(mesh, pnt, myIntersectionTolerance)) {
                vtxIndicatorMap.put(vtx, true);
            } else {
                vtxIndicatorMap.put(vtx, false);
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point3d(maspack.matrix.Point3d) TriangleIntersector(maspack.geometry.TriangleIntersector) BVFeatureQuery(maspack.geometry.BVFeatureQuery) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

PolygonalMesh (maspack.geometry.PolygonalMesh)2 TriangleIntersector (maspack.geometry.TriangleIntersector)2 Point3d (maspack.matrix.Point3d)2 ArrayList (java.util.ArrayList)1 AABBTree (maspack.geometry.AABBTree)1 BVFeatureQuery (maspack.geometry.BVFeatureQuery)1 BVNode (maspack.geometry.BVNode)1 Boundable (maspack.geometry.Boundable)1 Vertex3d (maspack.geometry.Vertex3d)1 DirectedGraph (maspack.graph.DirectedGraph)1 Vector3d (maspack.matrix.Vector3d)1