Search in sources :

Example 1 with Edge

use of maspack.geometry.io.GtsReader.Edge in project artisynth_core by artisynth.

the class GtsWriter method writeMesh.

public void writeMesh(PolygonalMesh mesh) throws IOException {
    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
    int[] oldIdxs = new int[mesh.numVertices()];
    int vidx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        // protect vertex indices numbers
        oldIdxs[vidx] = vtx.getIndex();
        vtx.setIndex(vidx);
        vidx++;
    }
    LinkedHashMap<Edge, Integer> edgeList = new LinkedHashMap<Edge, Integer>();
    for (Face f : mesh.getFaces()) {
        HalfEdge he0 = f.firstHalfEdge();
        HalfEdge he = he0;
        do {
            HalfEdge next = he.getNext();
            Edge edge = new Edge(he.head, next.head);
            if (edgeList.get(edge) == null) {
                edgeList.put(edge, edgeList.size());
            }
            he = next;
        } while (he != he0);
    }
    pw.println(mesh.numVertices() + " " + edgeList.size() + " " + mesh.numFaces());
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.pnt.write(pw, myFmt);
        pw.println("");
    }
    for (Edge edge : edgeList.keySet()) {
        pw.println((edge.myVtx1.getIndex() + 1) + " " + (edge.myVtx2.getIndex() + 1));
    }
    for (Face f : mesh.getFaces()) {
        HalfEdge he0 = f.firstHalfEdge();
        HalfEdge he = he0;
        do {
            HalfEdge next = he.getNext();
            Edge edge = new Edge(he.head, next.head);
            Integer idx = edgeList.get(edge);
            pw.print((idx + 1) + " ");
            he = next;
        } while (he != he0);
        pw.println("");
    }
    // restore vertex indices
    vidx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.setIndex(oldIdxs[vidx]);
        vidx++;
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) OutputStreamWriter(java.io.OutputStreamWriter) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) Edge(maspack.geometry.io.GtsReader.Edge) HalfEdge(maspack.geometry.HalfEdge) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 Face (maspack.geometry.Face)1 HalfEdge (maspack.geometry.HalfEdge)1 Vertex3d (maspack.geometry.Vertex3d)1 Edge (maspack.geometry.io.GtsReader.Edge)1