Skip to content

Commit

Permalink
improve read_polygon_mesh_for_cdt_3
Browse files Browse the repository at this point in the history
I have added comments on the block of code that triangulates the polygon on-the-fly
  • Loading branch information
lrineau committed Dec 6, 2024
1 parent c1efeec commit e1a07a2
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,27 @@ namespace CGAL {
// check if the polygon soup is pure triangles, and create a triangulated copy otherwise
bool is_pure_triangles = std::all_of(faces.begin(), faces.end(), [](const Face &f) { return f.size() == 3; });

// create a non-deleting pointer to `faces` (with a null deleter)
using Deleter_function = void(Faces*);
using Deleter = Deleter_function*;
using Ptr = std::unique_ptr<Faces, Deleter>;
Ptr triangle_faces_ptr{&faces, +[](Faces *) {}};
if (!is_pure_triangles)
{
triangle_faces_ptr = Ptr(new Faces(faces), +[](Faces* vector){ delete vector; }); // copy `faces`
PMP::triangulate_polygons(points, *triangle_faces_ptr, np);
{ // Now, call does_triangle_soup_self_intersect.
// ... but that function requires a triangulated soup (triangle soup)
// So, if needed, create a copy of the range of faces, and triangulate it on the fly.

// create a non-deleting pointer to `faces` (with a null deleter)
using Deleter_function = void(Faces*);
using Deleter = Deleter_function*; // function pointer type
using Ptr = std::unique_ptr<Faces, Deleter>;
auto null_deleter = +[](Faces *) {};
Ptr triangle_faces_ptr{&faces, null_deleter};
if (!is_pure_triangles)
{
auto faces_copy_ptr = new Faces(faces); // copy `faces`
auto delete_function_ptr = +[](Faces* vector){ delete vector; };
triangle_faces_ptr = Ptr(faces_copy_ptr, delete_function_ptr);
PMP::triangulate_polygons(points, *triangle_faces_ptr, np);
}

result.polygon_soup_self_intersects = PMP::does_triangle_soup_self_intersect(points, *triangle_faces_ptr, np);
}

result.polygon_soup_self_intersects = PMP::does_triangle_soup_self_intersect(points, *triangle_faces_ptr, np);

if (!PMP::orient_polygon_soup(points, faces))
{
result.polygon_mesh_is_manifold = false;
Expand Down

0 comments on commit e1a07a2

Please sign in to comment.