Search in sources :

Example 26 with HalfEdge

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));
    }
}
Also used : HalfEdge(maspack.geometry.HalfEdge)

Example 27 with HalfEdge

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;
}
Also used : HalfEdge(maspack.geometry.HalfEdge)

Example 28 with HalfEdge

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];
}
Also used : HalfEdge(maspack.geometry.HalfEdge) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) HashSet(java.util.HashSet)

Example 29 with HalfEdge

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) NumberFormat(maspack.util.NumberFormat)

Example 30 with HalfEdge

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];
}
Also used : HalfEdge(maspack.geometry.HalfEdge) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) HashSet(java.util.HashSet)

Aggregations

HalfEdge (maspack.geometry.HalfEdge)33 Face (maspack.geometry.Face)16 Vertex3d (maspack.geometry.Vertex3d)13 Point3d (maspack.matrix.Point3d)8 ArrayList (java.util.ArrayList)7 ContactPoint (artisynth.core.mechmodels.ContactPoint)6 Point (artisynth.core.mechmodels.Point)6 IntersectionPoint (maspack.collision.IntersectionPoint)6 Vector3d (maspack.matrix.Vector3d)6 PolygonalMesh (maspack.geometry.PolygonalMesh)5 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3 PenetratingPoint (maspack.collision.PenetratingPoint)3 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 BufferedWriter (java.io.BufferedWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2 NumberFormat (maspack.util.NumberFormat)2 FemElement3d (artisynth.core.femmodels.FemElement3d)1 PointAttachment (artisynth.core.mechmodels.PointAttachment)1