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