diff --git a/Surface_mesh/examples/Surface_mesh/sm_properties.cpp b/Surface_mesh/examples/Surface_mesh/sm_properties.cpp index 1e4c1a8a36a..1779dee5a33 100644 --- a/Surface_mesh/examples/Surface_mesh/sm_properties.cpp +++ b/Surface_mesh/examples/Surface_mesh/sm_properties.cpp @@ -14,6 +14,10 @@ int main() { Mesh m; + std::cin >> m; + std::cout << m << std::endl; + + m.clear(); vertex_descriptor v0 = m.add_vertex(K::Point_3(0,2,0)); vertex_descriptor v1 = m.add_vertex(K::Point_3(2,2,0)); vertex_descriptor v2 = m.add_vertex(K::Point_3(0,0,0)); @@ -25,7 +29,6 @@ int main() m.add_face(v2, v3, v4); - // give each vertex a name, the default is empty Mesh::Property_map name; bool created; @@ -59,6 +62,8 @@ int main() // delete the string property again m.remove_property_map(name); + std::cout << m <& mesh, Point_3 p; Vector_3 n, c; Vector_2 t; - typename Mesh::Vertex_descriptor v; + typename Mesh::Vertex_index v; // properties - Property_map normals; - Property_map texcoords; - if (has_normals) normals = mesh.template get_property_map("v:normal"); - if (has_texcoords) texcoords = mesh.template get_property_map("v:texcoord"); + Mesh::Property_map normals; + Mesh::Property_map texcoords; + if (has_normals) normals = mesh.template get_or_add_property_map("v:normal"); + if (has_texcoords) texcoords = mesh.template get_or_add_property_map("v:texcoord"); // #Vertice, #Faces, #Edges @@ -107,7 +107,7 @@ bool read_off_binary(Surface_mesh& mesh, // read faces: #N v[1] v[2] ... v[n-1] - std::vector vertices; + std::vector vertices; for (i=0; i& mesh, for (j=0; j& mesh, char line[100], *lp; unsigned int i, j, items, idx, nc; unsigned int nV, nF, nE; - typename Mesh::Vertex_descriptor v; + typename Mesh::Vertex_index v; // properties - Property_map normals; - Property_map texcoords; + Mesh::Property_map normals; + Mesh::Property_map texcoords; - if (has_normals) normals = mesh.template get_property_map("v:normal"); - if (has_texcoords) texcoords = mesh.template get_property_map("v:texcoord"); + if (has_normals) normals = mesh.template get_or_add_property_map("v:normal"); + if (has_texcoords) texcoords = mesh.template get_or_add_property_map("v:texcoord"); int c; do { @@ -206,7 +206,7 @@ bool read_off_ascii(Surface_mesh& mesh, } // read faces: #N v[1] v[2] ... v[n-1] - std::vector vertices; + std::vector vertices; for (i=0; i& mesh, { items = sscanf(lp, "%d%n", (int*)&idx, &nc); CGAL_assertion(items == 1); - vertices[j] = typename Mesh::Vertex_descriptor(idx); + vertices[j] = typename Mesh::Vertex_index(idx); lp += nc; } @@ -343,8 +343,8 @@ bool write_off(const Surface_mesh& mesh, const std::string& filename) // vertices - Property_map points - = mesh.template get_property_map("v:point"); + Mesh::Property_map points + = mesh.template property_map("v:point"); for (typename Mesh::Vertex_iterator vit=mesh.vertices_begin(); vit!=mesh.vertices_end(); ++vit) { const Point_3& p = points[*vit]; diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 1178f8ae52f..26874dddf2f 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -1955,8 +1955,6 @@ private: //--------------------------------------------------- property handling } - - /// @cond CGAL_DOCUMENT_INTERNALS /// returns a property map with key `I` and value type `T` with /// `name`. If no such property exists one is added with the default /// value `t`. @@ -1966,7 +1964,7 @@ private: //--------------------------------------------------- property handling { return (this->*boost::fusion::at_key(pmap_)).template get_or_add(name, t); } - /// @endcond + /// removes property map `p`. The memory allocated for that property map is /// freed. @@ -2091,8 +2089,28 @@ private: //------------------------------------------------------- private data template std::ostream& operator<<(std::ostream& os, const Surface_mesh

& sm) { + typedef Surface_mesh

Mesh; + typedef typename Mesh::Vertex_index Vertex_index; + typedef typename Mesh::Face_index Face_index; + + os << "OFF\n" << sm.num_vertices() << " " << sm.num_faces() << " 0\n"; + std::vector reindex; + reindex.resize(sm.num_vertices()); + int n = 0; + BOOST_FOREACH(Vertex_index v, sm.vertices()){ + os << sm.point(v) << std::endl; + reindex[v]=n++; + } + + BOOST_FOREACH(Face_index f, sm.faces()){ + os << sm.degree(f); + BOOST_FOREACH(Vertex_index v, CGAL::vertices_around_face(sm.halfedge(f),sm)){ + os << " " << reindex[v]; + } + os << "\n"; + } return os; - } + } /// \relates Surface_mesh /// Extracts the surface mesh from an input stream in Ascii OFF format. /// If the vertices have the property "v:normal" it is also extracted from the stream. @@ -2100,6 +2118,32 @@ private: //------------------------------------------------------- private data template std::istream& operator>>(std::istream& is, Surface_mesh

& sm) { + typedef Surface_mesh

Mesh; + typedef typename Mesh::Vertex_index Vertex_index; + typedef typename Mesh::Face_index Face_index; + typedef typename Mesh::size_type size_type; + sm.clear(); + int n, f, e; + std::string off; + is >> off; + assert(off == "OFF"); + is >> n >> f >> e; + sm.reserve(n,2*f,e); + P p; + for(int i=0; i < n; i++){ + is >> p; + sm.add_vertex(p); + } + std::vector vr; + std::size_t d; + for(std::size_t i=0; i < f; i++){ + is >> d; + vr.resize(d); + for(std::size_t j=0; j> vr[j]; + } + sm.add_face(vr); + } return is; } @@ -2363,12 +2407,11 @@ Surface_mesh

::add_face(const Range& r) // test for topological errors for (i=0, ii=1; i