diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 3c97bfe987f..ef627ff6def 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -2019,8 +2019,16 @@ private: //------------------------------------------------------- private data +/// @endcond + + /// \relates Surface_mesh + /// Extracts the surface mesh from an input stream in Ascii OFF, COFF, NOFF, CNOFF format. + /// The operator reads the point property as well as "v:normal", "v:color", and "f:color". + /// Vertex texture coordinates are ignored. + /// \pre `operator>>(std::istream&,const P&)` must be defined. + template - bool read_off_clear(std::istream& is, Surface_mesh

& sm) + bool read_off(std::istream& is, Surface_mesh

& sm) { typedef Surface_mesh

Mesh; typedef typename Kernel_traits

::Kernel K; @@ -2028,7 +2036,6 @@ private: //------------------------------------------------------- private data typedef typename Mesh::Face_index Face_index; typedef typename Mesh::Vertex_index Vertex_index; typedef typename Mesh::size_type size_type; - sm.clear(); int n, f, e; std::string off; is >> sm_skip_comments; @@ -2037,7 +2044,8 @@ private: //------------------------------------------------------- private data is >> n >> f >> e; - sm.reserve(n,2*f,e); + sm.reserve(sm.num_vertices()+n, sm.num_faces()+2*f, sm.num_edges()+e); + std::vector vertexmap(n); P p; Vector_3 v; typename Mesh::template Property_map vcolor; @@ -2055,6 +2063,7 @@ private: //------------------------------------------------------- private data is >> sm_skip_comments; is >> p; Vertex_index vi= sm.add_vertex(p); + vertexmap[i] = vi; if(v_has_normals){ is >> v; vnormal[vi] = v; @@ -2079,9 +2088,8 @@ private: //------------------------------------------------------- private data } } } - std::vector vr; - std::size_t d; - + std::vector vr; + size_type d, vi; bool fcolored = false; typename Mesh::template Property_map fcolor; @@ -2090,7 +2098,8 @@ private: //------------------------------------------------------- private data is >> d; vr.resize(d); for(std::size_t j=0; j> vr[j]; + is >> vi; + vr[j] = vertexmap[vi]; } Face_index fi = sm.add_face(vr); if(fi == sm.null_face()) @@ -2121,27 +2130,7 @@ private: //------------------------------------------------------- private data } return is.good(); } -/// @endcond - /// \relates Surface_mesh - /// Extracts the surface mesh from an input stream in Ascii OFF, COFF, NOFF, CNOFF format. - /// The operator reads the point property as well as "v:normal", "v:color", and "f:color". - /// Vertex texture coordinates are ignored. - /// \pre `operator>>(std::istream&,const P&)` must be defined. - - template - bool read_off(std::istream& is, Surface_mesh

& sm) - { - if( (sm.num_vertices() == 0) && (sm.num_halfedges() == 0)&& (sm.num_faces() == 0) ){ - return read_off_clear(is,sm); - } - Surface_mesh

other; - if(read_off_clear(is,other)){ - copy_face_graph(other,sm); - return true; - } - return false; - } /// \relates Surface_mesh