From 6d0cca9a2997f4203e59db1fe5970ec1c508c6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 29 Jun 2018 08:46:21 +0200 Subject: [PATCH] convenience function write_off uses documented one --- Surface_mesh/include/CGAL/Surface_mesh/IO.h | 41 +++------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO.h b/Surface_mesh/include/CGAL/Surface_mesh/IO.h index f497336951a..7ffc0bed21f 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO.h @@ -327,45 +327,14 @@ bool read_off(Surface_mesh& mesh, const std::string& filename) template bool write_off(const Surface_mesh& mesh, const std::string& filename) { - typedef Surface_mesh Mesh; - typedef typename Mesh::Point Point_3; - - FILE* out = fopen(filename.c_str(), "w"); - if (!out) + std::ofstream out(filename.c_str()); + if (out.fail()) return false; + out << std::setprecision(17); + write_off(out, mesh); - // header - fprintf(out, "OFF\n%d %d 0\n", mesh.num_vertices(), mesh.num_faces()); - - - // vertices - typename Mesh::template Property_map points - = mesh.template property_map("v:point").first; - for (typename Mesh::Vertex_iterator vit=mesh.vertices_begin(); vit!=mesh.vertices_end(); ++vit) - { - const Point_3& p = points[*vit]; - fprintf(out, "%.10f %.10f %.10f\n", p[0], p[1], p[2]); - } - - - // faces - for (typename Surface_mesh::Face_iterator fit=mesh.faces_begin(); fit!=mesh.faces_end(); ++fit) - { - int nV = mesh.degree(*fit); - fprintf(out, "%d", nV); - typename Surface_mesh::Vertex_around_face_circulator fvit(mesh.halfedge(*fit),mesh), fvend=fvit; - do - { - typename Surface_mesh::size_type idx = *fvit; - fprintf(out, " %d", idx); - } - while (++fvit != fvend); - fprintf(out, "\n"); - } - - fclose(out); - return true; + return !out.fail(); } #if 0