Search in sources :

Example 31 with HalfEdge

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

the class FemMeshComp method createFineSurface.

protected void createFineSurface(int resolution, ElementFilter efilter) {
    // build from nodes/element filter
    createSurface(efilter);
    if (resolution < 2) {
        // if resolution < 2, just return regular surface
        return;
    }
    // Note: can no longer rely on the surface mesh consisting of only
    // FemMeshVertex
    // PolygonalMesh baseMesh = myFem.getSurfaceMesh();
    // since previously built
    PolygonalMesh baseMesh = (PolygonalMesh) getMesh();
    ArrayList<Face> baseFaces = baseMesh.getFaces();
    ArrayList<Vertex3d> baseVertices = baseMesh.getVertices();
    ArrayList<PointAttachment> baseAttachments = myVertexAttachments;
    // num vertices along the edge of each sub face
    int numv = resolution + 1;
    initializeSurfaceBuild();
    HashMap<EdgeDesc, Vertex3d[]> edgeVtxMap = new HashMap<EdgeDesc, Vertex3d[]>();
    // get newly empty mesh
    PolygonalMesh surfMesh = (PolygonalMesh) getMesh();
    for (Vertex3d vtx : baseVertices) {
        FemNode3d node = getNodeForVertex(baseAttachments.get(vtx.getIndex()));
        createVertex(node, vtx);
    // myNodeVertexMap.put (node, newVtx);
    }
    System.out.println("num base faces: " + baseFaces.size());
    for (int k = 0; k < baseFaces.size(); k++) {
        Face face = baseFaces.get(k);
        // store sub vertices for the face in the upper triangular half of
        // subv.
        MeshFactory.VertexSet subv = new MeshFactory.VertexSet(numv);
        FemElement3d elem = getFaceElement(face);
        if (elem == null) {
            continue;
        }
        HalfEdge he = face.firstHalfEdge();
        Vertex3d v0 = (Vertex3d) he.getHead();
        FemNode3d n0 = getNodeForVertex(baseAttachments.get(v0.getIndex()));
        he = he.getNext();
        Vertex3d v1 = (Vertex3d) he.getHead();
        FemNode3d n1 = getNodeForVertex(baseAttachments.get(v1.getIndex()));
        he = he.getNext();
        Vertex3d v2 = (Vertex3d) he.getHead();
        FemNode3d n2 = getNodeForVertex(baseAttachments.get(v2.getIndex()));
        subv.set(0, 0, getVertex(v0.getIndex()));
        subv.set(0, numv - 1, getVertex(v2.getIndex()));
        subv.set(numv - 1, numv - 1, getVertex(v1.getIndex()));
        Vertex3d[] vtxs01 = collectEdgeVertices(edgeVtxMap, v0, v1, n0, n1, elem, resolution);
        for (int i = 1; i < numv - 1; i++) {
            subv.set(i, i, vtxs01[i]);
        }
        Vertex3d[] vtxs02 = collectEdgeVertices(edgeVtxMap, v0, v2, n0, n2, elem, resolution);
        for (int j = 1; j < numv - 1; j++) {
            subv.set(0, j, vtxs02[j]);
        }
        Vertex3d[] vtxs21 = collectEdgeVertices(edgeVtxMap, v2, v1, n2, n1, elem, resolution);
        for (int i = 1; i < numv - 1; i++) {
            subv.set(i, numv - 1, vtxs21[i]);
        }
        for (int i = 1; i < numv - 1; i++) {
            for (int j = i + 1; j < numv - 1; j++) {
                double s1 = i / (double) resolution;
                double s0 = 1 - j / (double) resolution;
                Vertex3d vtx = createVertex(s0, s1, 1 - s0 - s1, elem, n0, n1, n2);
                subv.set(i, j, vtx);
            }
        }
        subv.check();
        for (int i = 0; i < resolution; i++) {
            for (int j = i; j < resolution; j++) {
                surfMesh.addFace(subv.get(i, j), subv.get(i + 1, j + 1), subv.get(i, j + 1));
                if (i != j) {
                    surfMesh.addFace(subv.get(i, j), subv.get(i + 1, j), subv.get(i + 1, j + 1));
                }
            }
        }
    }
    finalizeSurfaceBuild();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) MeshFactory(maspack.geometry.MeshFactory) HashMap(java.util.HashMap) HalfEdge(maspack.geometry.HalfEdge) PointAttachment(artisynth.core.mechmodels.PointAttachment) PolygonalMesh(maspack.geometry.PolygonalMesh) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Face(maspack.geometry.Face)

Example 32 with HalfEdge

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

the class MFreeMeshComp method getFaceElement.

public MFreeElement3d 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<MFreeNode3d> nodes = new HashSet<MFreeNode3d>();
    HalfEdge he0 = face.firstHalfEdge();
    HalfEdge he = he0;
    do {
        addVertexNodes(nodes, he.getHead());
        he = he.getNext();
    } while (he != he0);
    HashSet<FemElement3d> elems = null;
    for (MFreeNode3d node : nodes) {
        if (elems == null) {
            elems = new HashSet<>(node.getElementDependencies());
        } else {
            elems.retainAll(node.getElementDependencies());
        }
    }
    if (elems.size() != 1) {
        MFreeElement3d[] elemArray = elems.toArray(new MFreeElement3d[0]);
        int[] idxs = face.getVertexIndices();
        System.out.print("Error: couldn't get 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 (MFreeElement3d) elems.toArray()[0];
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) HalfEdge(maspack.geometry.HalfEdge) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) HashSet(java.util.HashSet)

Example 33 with HalfEdge

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

the class MFreeMeshComp 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);
                MFreeNode3d node = (MFreeNode3d) 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)

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