diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h b/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h index f3ddf24b7f5..7ec2cb8f6bc 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h @@ -27,7 +27,7 @@ void read_surf(std::istream& input, std::vector& output, std::vector points; std::string line; std::istringstream iss; - int nb_vertices(0); + std::size_t nb_vertices(0); std::vector materials; //ignore header while(std::getline(input, line)) @@ -92,7 +92,6 @@ void read_surf(std::istream& input, std::vector& output, std::vector& output, std::vector::null_vertex(); + std::vector vertices(nb_vertices, null_vertex); + for(int i=0; i < nb_patches; /* i is incremented in the body */) { - std::map vertices; - Mesh mesh; + Mesh& mesh = output[i]; //get metada while(std::getline(input, line)) if(line.compare(0, 11, "InnerRegion") != 0) @@ -158,20 +159,23 @@ void read_surf(std::istream& input, std::vector& output, std::vector> index[0] >> index[1] >> index[2]; + CGAL::cpp11::array face; for(int id=0; id<3; ++id) { - if(vertices.find(index[id]) == vertices.end()) + if(vertices[index[id]] == null_vertex) { - vertices.insert(std::make_pair(index[id], add_vertex(points[index[id]-1], mesh))); + vertices[index[id]] = add_vertex(points[index[id]-1], mesh); } + face[id] = vertices[index[id]]; } - std::vector face; - for(int id=0; id<3; ++id) - face.push_back(vertices[index[id]]); CGAL::Euler::add_face(face, mesh); } - output.push_back(mesh); - } + // reset the `vertices` vector, unless that was the last iteration of + // the loop + if(++i < nb_patches) std::fill(vertices.begin(), + vertices.end(), + null_vertex); + } // end loop on patches } template