use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class IntersectionContour method dividesMesh.
/**
* Returns <code>true</code> if this contour divides the specified mesh
* into "inside" and "outside" regions. This will be true if
*
* <ul>
* <li>the contour is closed;
* <li>both end points of the contour lie on boundary edges of the mesh
* </ul>
*
* @return <code>true</code> if this contour divides the mesh
*/
public boolean dividesMesh(PolygonalMesh mesh) {
if (isClosed()) {
return true;
} else {
HalfEdge he0 = getFirst().edge;
HalfEdge heL = getLast().edge;
return (he0.opposite == null && edgeOnMesh(he0, mesh) && heL.opposite == null && edgeOnMesh(heL, mesh));
}
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class IntersectionPoint method onTriangleEdge.
/**
* Queries whether this intersection point is degenerate such that
* it lies on the specified triangle edge. This includes both the edge
* itself as well as its end-point vertices. The edge may be specified
* using either the actual triangle edge or its opposite.
*
* @param edge face edge which the point must lie on.
* @return <code>true</code> if the point lies on the edge.
*/
public boolean onTriangleEdge(HalfEdge edge) {
HalfEdge he = face.firstHalfEdge();
if (he == edge || he.getPrimary() == edge) {
return (intersectionCode & RobustPreds.E01_ON_SEGMENT) != 0;
}
he = he.getNext();
if (he == edge || he.getPrimary() == edge) {
return (intersectionCode & RobustPreds.E12_ON_SEGMENT) != 0;
}
he = he.getNext();
if (he == edge || he.getPrimary() == edge) {
return (intersectionCode & RobustPreds.E20_ON_SEGMENT) != 0;
}
return false;
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class FemMeshComp method getFaceElementOld.
/**
* Find the FEM element corresponding to a surface face.
*/
FemElement3d getFaceElementOld(Face face) {
// Form the intersection of all the element dependencies of all three
// nodes associated with the face. If the face is on the surface,
// there should be only one element left.
HalfEdge he0 = face.firstHalfEdge();
HalfEdge he1 = he0.getNext();
HalfEdge he2 = he1.getNext();
HashSet<FemElement3d> elems = new HashSet<FemElement3d>(getEdgeNode(he0).getElementDependencies());
elems.retainAll(getEdgeNode(he1).getElementDependencies());
elems.retainAll(getEdgeNode(he2).getElementDependencies());
if (elems.size() != 1) {
FemElement3d[] elemArray = elems.toArray(new FemElement3d[0]);
System.out.println("face is " + getEdgeNode(he0).getNumber() + " " + getEdgeNode(he1).getNumber() + " " + getEdgeNode(he2).getNumber());
for (int i = 0; i < elemArray.length; i++) {
System.out.println(" element " + elemArray[i].getNumber());
}
return null;
// ignore for now ...
// throw new InternalErrorException (
// "Face "+face+" associated with "+elems.size()+" elements");
}
return (FemElement3d) elems.toArray()[0];
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class FemMeshComp method writeMesh.
public boolean writeMesh(PrintWriter pw, boolean nodeFormat) {
PolygonalMesh mesh = null;
if (!(getMesh() instanceof PolygonalMesh)) {
return false;
}
mesh = (PolygonalMesh) getMesh();
pw.print("[ ");
NumberFormat fmt = new NumberFormat("%.8g");
IndentingPrintWriter.addIndentation(pw, 2);
if (!nodeFormat) {
for (Vertex3d vtx : mesh.getVertices()) {
writeVertexInfo(pw, vtx, fmt);
}
}
ArrayList<Integer> nodeNums = new ArrayList<Integer>();
for (Face face : mesh.getFaces()) {
HalfEdge he0 = face.firstHalfEdge();
HalfEdge he = he0;
pw.print("f");
do {
int vidx = he.head.getIndex();
if (nodeFormat) {
PointParticleAttachment ppa = (PointParticleAttachment) getAttachment(vidx);
FemNode3d node = (FemNode3d) ppa.getParticle();
pw.print(" " + node.getNumber());
} else {
pw.print(" " + (vidx + 1));
}
he = he.getNext();
} while (he != he0);
pw.println("");
}
IndentingPrintWriter.addIndentation(pw, -2);
pw.println("]");
return true;
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class FemMeshComp method getFaceElement.
public FemElement3d getFaceElement(Face face) {
// Form the intersection of all the element dependencies of all three
// nodes associated with the face. If the face is on the surface,
// there should be only one element left.
HashSet<FemNode3d> nodes = new HashSet<FemNode3d>();
HalfEdge he0 = face.firstHalfEdge();
HalfEdge he = he0;
do {
addVertexNodes(nodes, he.getHead());
he = he.getNext();
} while (he != he0);
HashSet<FemElement3d> elems = null;
for (FemNode3d node : nodes) {
if (elems == null) {
elems = new HashSet<FemElement3d>(node.getElementDependencies());
} else {
elems.retainAll(node.getElementDependencies());
}
}
if (elems.size() != 1) {
FemElement3d[] elemArray = elems.toArray(new FemElement3d[0]);
int[] idxs = face.getVertexIndices();
System.out.print("Error in FemMeshComp.getFaceElement(): " + " couldn't isolate element for face [ ");
for (int i = 0; i < idxs.length; i++) {
System.out.print("" + idxs[i] + " ");
}
System.out.println("]");
System.out.println("Candidate elements are:");
for (int i = 0; i < elemArray.length; i++) {
System.out.println(" element " + elemArray[i].getNumber());
}
return null;
// ignore for now ...
// throw new InternalErrorException (
// "Face "+face+" associated with "+elems.size()+" elements");
}
return (FemElement3d) elems.toArray()[0];
}
Aggregations