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;
}
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);
}
}
}
}
Aggregations