From a3ede642cd4348dbf19ed29ce9b458f45e29722e Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 21 Apr 2017 11:19:37 +0200 Subject: [PATCH 1/4] number materials from 0 (exterior) to n-1, whatever is written in the file it happens that Exterior does not have the label 0 in the file, which causes trouble to Mesh_3 --- .../demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 58d4f370cd5..1e5b96deaac 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h @@ -36,6 +36,7 @@ bool get_material_metadata(std::istream& input, iss >> _material.second;//name + static int material_id = 0; while (std::getline(input, line)) { std::string prop; //property @@ -45,7 +46,9 @@ bool get_material_metadata(std::istream& input, if (prop.compare("Id") == 0) { - iss >> _material.first; + int tmp_id; + iss >> tmp_id; + _material.first = material_id++; if ((0 == to_lower_case(_material.second).compare("exterior")) && _material.first != 0) From 9f4eb7c8870e3021c8ccb6a26d6b39231ae07c52 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 21 Apr 2017 11:21:16 +0200 Subject: [PATCH 2/4] use array instead of vector to avoid allocations, save memory and time --- .../demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 1e5b96deaac..b4c784f2fd0 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h @@ -233,7 +233,8 @@ bool read_surf(std::istream& input, std::vector& output, } //connect triangles - std::vector > polygons; + typedef CGAL::cpp11::array Triangle_ind; + std::vector polygons; polygons.reserve(nb_triangles); while(std::getline(input, line)) { @@ -249,7 +250,7 @@ bool read_surf(std::istream& input, std::vector& output, iss.str(line); iss >> index[0] >> index[1] >> index[2]; - std::vector polygon(3); + Triangle_ind polygon; polygon[0] = index[0] - 1; polygon[1] = index[1] - 1; polygon[2] = index[2] - 1; From 2b16193db4c33961d79da7effe93fc60deba071f Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 21 Apr 2017 14:40:08 +0200 Subject: [PATCH 3/4] deal with non-manifold surfaces because a CGAL::Polyhedron cannot be non-manifold along an edge, we need to build the polyhedral surface using PMP::orient_polygon_soup, and PMP::polygon_soup_to_polygon_mesh. These functions introduce duplicated points, that are dealt with in this commit when reading a .surf file, isolated vertices are ignored --- .../polygon_soup_to_polygon_mesh.h | 21 +++++++++++- .../Polyhedron/Plugins/IO/Surf_io_plugin.cpp | 9 +++++- .../Plugins/IO/Surf_to_sm_io_plugin.cpp | 12 +++++-- .../include/CGAL/IO/read_surf_trianglemesh.h | 32 +++++++++++++------ 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h index f5f24d096b6..64cecfb5ea0 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -67,13 +68,29 @@ public: _polygons(polygons) { } - void operator()(PM& pmesh) + void operator()(PM& pmesh, const bool insert_isolated_vertices = true) { Vpmap vpmap = get(CGAL::vertex_point, pmesh); + boost::dynamic_bitset<> not_isolated; + if (!insert_isolated_vertices) + { + not_isolated.resize(_points.size()); + for (std::size_t i = 0, end = _polygons.size(); i < end; ++i) + { + const Polygon& polygon = _polygons[i]; + const std::size_t size = polygon.size(); + for (std::size_t j = 0; j < size; ++j) + not_isolated.set(polygon[j], true); + } + } + std::vector vertices(_points.size()); for (std::size_t i = 0, end = _points.size(); i < end; ++i) { + if (!insert_isolated_vertices && !not_isolated.test(i)) + continue; + Point_3 pi(_points[i][0], _points[i][1], _points[i][2]); vertices[i] = add_vertex(pmesh); put(vpmap, vertices[i], pi); @@ -162,6 +179,8 @@ public: typename Orienter::Marked_edges marked_edges; Orienter::fill_edge_map(edges, marked_edges, polygons); //returns false if duplication is necessary + if (!marked_edges.empty()) + return false; return Orienter::has_singular_vertices(static_cast(max_id+1),polygons,edges,marked_edges); } diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_io_plugin.cpp index 7574bdb077f..0f274e8f610 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_io_plugin.cpp @@ -15,6 +15,7 @@ #include "Color_map.h" #include +#include using namespace CGAL::Three; class Surf_io_plugin: @@ -62,13 +63,19 @@ CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo) std::vector material_data; CGAL::Bbox_3 grid_box; CGAL::cpp11::array grid_size = {{1, 1, 1}}; - read_surf(in, patches, material_data, grid_box, grid_size); + boost::container::flat_set duplicated_points; + read_surf(in, patches, material_data, grid_box, grid_size + , std::inserter(duplicated_points, duplicated_points.end())); + for(std::size_t i=0; i colors_; compute_color_map(QColor(100, 100, 255), static_cast(patches.size()), std::back_inserter(colors_)); diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_to_sm_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_to_sm_io_plugin.cpp index bca3516e5b1..3dcc124a932 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_to_sm_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/Surf_to_sm_io_plugin.cpp @@ -14,6 +14,7 @@ #include "Color_map.h" #include +#include using namespace CGAL::Three; class Surf_io_plugin: @@ -51,6 +52,7 @@ public: CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo) { typedef Scene_surface_mesh_item::SMesh SMesh; + typedef Scene_surface_mesh_item::Point Point; // Open file std::ifstream in(fileinfo.filePath().toUtf8()); if(!in) { @@ -62,13 +64,19 @@ CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo) std::vector material_data; CGAL::Bbox_3 grid_box; CGAL::cpp11::array grid_size = {{1, 1, 1}}; - read_surf(in, patches, material_data, grid_box, grid_size); - for(std::size_t i=0; i duplicated_points; + read_surf(in, patches, material_data, grid_box, grid_size + , std::inserter(duplicated_points, duplicated_points.end())); + + for (std::size_t i = 0; i colors_; compute_color_map(QColor(100, 100, 255), static_cast(patches.size()), std::back_inserter(colors_)); 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 b4c784f2fd0..48895652521 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h @@ -77,16 +77,18 @@ bool line_starts_with(const std::string& line, const char* cstr) * read_surf reads a file which extension is .surf and fills `output` with one `Mesh` per patch. * Mesh is a model of FaceListGraph. */ -template +template bool read_surf(std::istream& input, std::vector& output, std::vector& metadata, CGAL::Bbox_3& grid_box, CGAL::cpp11::array& grid_size, + DuplicatedPointsOutIterator out, const NamedParameters&) { typedef typename CGAL::GetGeomTraits::type Kernel; typedef typename Kernel::Point_3 Point_3; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; std::vector points; std::string line; std::istringstream iss; @@ -264,33 +266,45 @@ bool read_surf(std::istream& input, std::vector& output, { std::cout << "Orientation of patch #" << (i + 1) << "..."; std::cout.flush(); + + const std::size_t nbp_init = points.size(); bool no_duplicates = PMP::orient_polygon_soup(points, polygons);//returns false if some points //were duplicated + std::cout << "\rOrientation of patch #" << (i + 1) << " done"; - if (!no_duplicates) - std::cout << " (non manifold -> duplicated vertices)"; + + if(!no_duplicates) //collect duplicates + { + for (std::size_t i = nbp_init; i < points.size(); ++i) + *out++ = points[i]; + std::cout << " (non manifold -> " + << (points.size() - nbp_init) << " duplicated vertices)"; + } std::cout << "." << std::endl; } + Mesh& mesh = output[i]; - CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh( - points, polygons, mesh); - CGAL::Polygon_mesh_processing::remove_isolated_vertices(mesh); + PMP::internal::Polygon_soup_to_polygon_mesh + converter(points, polygons); + converter(mesh, false/*insert_isolated_vertices*/); + CGAL_assertion(PMP::remove_isolated_vertices(mesh) == 0); CGAL_assertion(is_valid(mesh)); } // end loop on patches return true; } -template +template bool read_surf(std::istream& input, std::vector& output, std::vector& metadata, CGAL::Bbox_3& grid_box, - CGAL::cpp11::array& grid_size) + CGAL::cpp11::array& grid_size, + DuplicatedPointsOutIterator out) { - return read_surf(input, output, metadata, grid_box, grid_size, + return read_surf(input, output, metadata, grid_box, grid_size, out, CGAL::Polygon_mesh_processing::parameters::all_default()); } From 37f27b8381e3f8cb1320efbfd3f6aa8fb3e25027 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 16 May 2017 08:07:42 +0200 Subject: [PATCH 4/4] Remove unused typedef --- .../demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h | 1 - 1 file changed, 1 deletion(-) 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 48895652521..e0e3b906b11 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/IO/read_surf_trianglemesh.h @@ -88,7 +88,6 @@ bool read_surf(std::istream& input, std::vector& output, typedef typename CGAL::GetGeomTraits::type Kernel; typedef typename Kernel::Point_3 Point_3; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; std::vector points; std::string line; std::istringstream iss;