// // File: feature_mesh.cc // // (C) 2000-2006 Helmut Cantzler // // Licensed under the terms of the Lesser General Public License. // #include "feature_mesh.h" int Feature_Mesh::read(FILE *f, int (*update_progress)(int pos), void (*set_total)(int size)) { list *shape_vertices; list *shape_edges; Vertex *v1, *v2; Edge *e; char type; float x, y, z; fseek(f, 0, SEEK_END); (*set_total)(ftell(f)); fseek(f, 0, SEEK_SET); shape_vertices = new list; shape_edges = new list; while ((type=fgetc(f)) != EOF) if (type == '#') do // Reads till end of the line { type=fgetc(f); } while (type != EOF && type != '\n'); else if ((type=fgetc(f)) != EOF) { switch (type) { case 'v': case 'V': if (fscanf(f," %f %f %f\n",&x,&y,&z) != 3) { FILE_ERROR(f, "File format error: v"); return 3; } v1 = new Vertex(x,y,z); add_vertex(v1); shape_vertices->push_back(v1); break; case 'e': case 'E': if (fscanf(f," %f %f %f",&x,&y,&z) != 3) { FILE_ERROR(f, "File format error: e1"); return 4; } v1 = new Vertex(x,y,z); add_vertex(v1); shape_vertices->push_back(v1); if (fscanf(f," %f %f %f\n",&x,&y,&z) != 3) { FILE_ERROR(f, "File format error: e2"); return 5; } v2 = new Vertex(x,y,z); add_vertex(v2); shape_vertices->push_back(v2); e = new Edge(v1, v2); add_edge(e); shape_edges->push_back(e); break; } if ((*update_progress)(ftell(f))) return 90; } shapes->push_back(new Shape(shape_edges, shape_vertices)); return 0; } void Feature_Mesh::write(FILE *f, const char *comment) { list::iterator ie; list::iterator iv; Vertex v; fprintf(f, "#Features\n"); fprintf(f, "# %s\n", comment); if (edge_nr > 0) for (ie=edges->begin(); ie != edges->end(); ie++) { calc_original_coordinates((*ie)->vertices[0], &v); fprintf(f, "fe %f %f %f ", v.x(), v.y(), v.z()); calc_original_coordinates((*ie)->vertices[1], &v); fprintf(f, "%f %f %f\n", v.x(), v.y(), v.z()); } else for (iv=vertices->begin(); iv != vertices->end(); iv++) { calc_original_coordinates(*iv, &v); fprintf(f, "fv %f %f %f\n", v.x(), v.y(), v.z()); } }