diff --git a/Polygonal_surface_reconstruction/include/CGAL/Polygonal_surface_reconstruction.h b/Polygonal_surface_reconstruction/include/CGAL/Polygonal_surface_reconstruction.h index e78c2d390a65..9ca8016600b6 100644 --- a/Polygonal_surface_reconstruction/include/CGAL/Polygonal_surface_reconstruction.h +++ b/Polygonal_surface_reconstruction/include/CGAL/Polygonal_surface_reconstruction.h @@ -18,6 +18,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -455,7 +459,12 @@ namespace CGAL { // Converts from internal data structure to the required `PolygonMesh`. output_mesh.clear(); // make sure it is empty. - CGAL::copy_face_graph(target_mesh, output_mesh); + std::vector points; + std::vector > polygons; + CGAL::Polygon_mesh_processing::polygon_mesh_to_polygon_soup(target_mesh, points, polygons); + CGAL::Polygon_mesh_processing::merge_duplicate_points_in_polygon_soup(points, polygons); + CGAL::Polygon_mesh_processing::orient_polygon_soup(points, polygons); + CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, polygons, output_mesh); } else { error_message_ = "solving the binary program failed"; diff --git a/Polygonal_surface_reconstruction/include/CGAL/Polygonal_surface_reconstruction/internal/point_set_with_planes.h b/Polygonal_surface_reconstruction/include/CGAL/Polygonal_surface_reconstruction/internal/point_set_with_planes.h index 09d628e7f4e0..02e68d733ce6 100644 --- a/Polygonal_surface_reconstruction/include/CGAL/Polygonal_surface_reconstruction/internal/point_set_with_planes.h +++ b/Polygonal_surface_reconstruction/include/CGAL/Polygonal_surface_reconstruction/internal/point_set_with_planes.h @@ -67,6 +67,18 @@ namespace CGAL { delete supporting_plane_; supporting_plane_ = new Plane; CGAL::linear_least_squares_fitting_3(pts.begin(), pts.end(), *supporting_plane_, CGAL::Dimension_tag<0>()); + + // Check orientation + int vote_for_opposite = 0; + for (std::size_t i = 0; i < size(); i++) + if (supporting_plane_->orthogonal_vector() * point_set_->normal_map()[at(i)] < 0) + vote_for_opposite++; + else + vote_for_opposite--; + + if (vote_for_opposite > 0) + *supporting_plane_ = supporting_plane_->opposite(); + return supporting_plane_; } diff --git a/Polygonal_surface_reconstruction/package_info/Polygonal_surface_reconstruction/dependencies b/Polygonal_surface_reconstruction/package_info/Polygonal_surface_reconstruction/dependencies index cf61d44e4ba4..650e4a65343e 100644 --- a/Polygonal_surface_reconstruction/package_info/Polygonal_surface_reconstruction/dependencies +++ b/Polygonal_surface_reconstruction/package_info/Polygonal_surface_reconstruction/dependencies @@ -22,6 +22,7 @@ Point_set_3 Point_set_processing_3 Polygon Polygonal_surface_reconstruction +Polygon_mesh_processing Principal_component_analysis Principal_component_analysis_LGPL Profiling_tools