Skip to content

Commit

Permalink
Merge pull request CGAL#7655 from soesau/Polygonal_surface_reconstruc…
Browse files Browse the repository at this point in the history
…tion-Unoriented_soup_to_mesh-GF

Converting unoriented polygon soup to polygon mesh
  • Loading branch information
lrineau committed Oct 19, 2023
2 parents 1ae1d21 + 33e88b2 commit d5c8582
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <CGAL/Polygonal_surface_reconstruction/internal/hypothesis.h>
#include <CGAL/Polygonal_surface_reconstruction/internal/compute_confidences.h>
#include <CGAL/Polygonal_surface_reconstruction/internal/point_set_with_planes.h>
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Polygon_mesh_processing/polygon_mesh_to_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>

#include <unordered_map>

Expand Down Expand Up @@ -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<Point> points;
std::vector<std::vector<std::size_t> > 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5c8582

Please sign in to comment.