diff --git a/BGL/examples/BGL_OpenMesh/TriMesh.cpp b/BGL/examples/BGL_OpenMesh/TriMesh.cpp index c28e11f7886..d9ca1648505 100644 --- a/BGL/examples/BGL_OpenMesh/TriMesh.cpp +++ b/BGL/examples/BGL_OpenMesh/TriMesh.cpp @@ -36,13 +36,13 @@ int main(int argc, char** argv ) V.push_back(add_vertex(mesh)); add_face(V.begin(), V.end(), mesh); - // OpenMesh::IO::read_mesh(mesh, (argc>1)?argv[1]:"in.off"); + CGAL::read_off(std::ifstream((argc>1)?argv[1]:"in.off"), mesh); BOOST_FOREACH(vertex_descriptor vd, vertices(mesh)){ BOOST_FOREACH(halfedge_descriptor hd, CGAL::halfedges_around_target(vd,mesh)){ if(! CGAL::is_border(edge(hd,mesh),mesh)){ CGAL::Euler::flip_edge(hd,mesh); - OpenMesh::IO::write_mesh(mesh, (argc>2)?argv[2]:"out.off"); + CGAL::write_off((argc>2)?argv[2]:"out.off", mesh); return 0; } } diff --git a/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h b/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h index a5d8517940d..91ef36d20b5 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -691,6 +692,20 @@ void clear(OpenMesh::PolyMesh_ArrayKernelT& sm) CGAL_postcondition(num_faces(sm) == 0); } + +template +bool read_off(std::istream& is, OpenMesh::PolyMesh_ArrayKernelT& sm) +{ + return OpenMesh::IO::read_mesh(sm, is, ".OFF"); +} + + +template +bool write_off(std::ostream& os, OpenMesh::PolyMesh_ArrayKernelT& sm) +{ + return OpenMesh::IO::write_mesh(sm, os, ".OFF"); +} + } #ifndef CGAL_NO_DEPRECATED_CODE #include diff --git a/BGL/include/CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h b/BGL/include/CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h index 22de500ffc2..0ada26c60a1 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -610,7 +611,40 @@ bool is_valid(OpenMesh::TriMesh_ArrayKernelT& sm, bool /* verbose */ = false) } // namespace OpenMesh +namespace CGAL { +// Overload CGAL::clear function. TriMesh_ArrayKernel behaves +// differently from other meshes. Calling clear does not affect the +// number of vertices, edges, or faces in the mesh. To get actual +// numbers it is necessary to first collect garbage. We add an +// overlaod to get consistent behavior. +template +void clear(OpenMesh::TriMesh_ArrayKernelT& sm) +{ + sm.clear(); + sm.garbage_collection(true, true, true); + CGAL_postcondition(num_edges(sm) == 0); + CGAL_postcondition(num_vertices(sm) == 0); + CGAL_postcondition(num_faces(sm) == 0); +} + + +template +bool read_off(std::istream& is, OpenMesh::TriMesh_ArrayKernelT& sm) +{ + OpenMesh::IO::Options ropt; + return OpenMesh::IO::read_mesh(sm, is, ".OFF", ropt, false); +} + + +template +bool write_off(std::ostream& os, OpenMesh::TriMesh_ArrayKernelT& sm) +{ + OpenMesh::IO::Options ropt; + return OpenMesh::IO::write_mesh(sm, os, ".OFF", ropt); +} + +} #ifndef CGAL_NO_DEPRECATED_CODE #include diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 08e470f829e..4ca01efe28e 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -75,7 +75,7 @@ bool write_off(std::ostream& os, */ template -void write_off(const char* fname, +bool write_off(const char* fname, const FaceGraph& g) { std::ofstream out(fname);