use of maspack.graph.DirectedGraph 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;
}
Aggregations