diff --git a/BGL/include/CGAL/boost/graph/selection.h b/BGL/include/CGAL/boost/graph/selection.h index 668bc4707e0..890c0622e68 100644 --- a/BGL/include/CGAL/boost/graph/selection.h +++ b/BGL/include/CGAL/boost/graph/selection.h @@ -1137,8 +1137,8 @@ void expand_face_selection_for_removal(const FaceRange& faces_to_be_deleted, //todo: take non-manifold vertices into account. template -bool is_selection_a_topological_disk(const FaceRange& face_selection, - PolygonMesh& pm) +int euler_characteristic_of_selection(const FaceRange& face_selection, + PolygonMesh& pm) { typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::face_descriptor face_descriptor; @@ -1154,8 +1154,18 @@ bool is_selection_a_topological_disk(const FaceRange& face_selection, sel_edges.insert(edge(h,pm)); } } - return (sel_vertices.size() - sel_edges.size() + face_selection.size() == 1); + return static_cast(sel_vertices.size()) + - static_cast(sel_edges.size()) + + static_cast(face_selection.size()); } + +template +bool is_selection_a_topological_disk(const FaceRange& face_selection, + PolygonMesh& pm) +{ + return euler_characteristic_of_selection(face_selection, pm) == 1; +} + } //end of namespace CGAL #endif //CGAL_BOOST_GRAPH_SELECTION_H diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_self_intersections.h index 7663a49a419..ca8cc0c7897 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_self_intersections.h @@ -1764,21 +1764,43 @@ remove_self_intersections_one_step(std::set mesh_non_border_hedges; std::set mesh_border_hedge; for(halfedge_descriptor h : cc_border_hedges) { if(!is_border(opposite(h, tmesh), tmesh)) - only_border_edges = false; + mesh_non_border_hedges.push_back(h); else mesh_border_hedge.insert(opposite(h, tmesh)); } - int nb_cycles = 0; + if (mesh_border_hedge.empty()) + { +#ifdef CGAL_PMP_REMOVE_SELF_INTERSECTION_DEBUG + std::cout << " DEBUG: CC not handled, selection is not a topological disk (preserve_genus=false)\n"; + ++unsolved_self_intersections; +#endif + topology_issue = true; + continue; + } + + // we look for cycles of border halfedges and update selection_chi while(!mesh_border_hedge.empty()) { // we must count the number of cycle of boundary edges @@ -1790,14 +1812,14 @@ remove_self_intersections_one_step(std::set::iterator it = mesh_border_hedge.find(h); if(it == mesh_border_hedge.end()) - break; // not a cycle + break; // not a cycle does not count mesh_border_hedge.erase(it); } @@ -1805,29 +1827,19 @@ remove_self_intersections_one_step(std::set (only_border_edges ? 1 : 0)) + if(selection_chi!=1) { #ifdef CGAL_PMP_REMOVE_SELF_INTERSECTION_DEBUG - std::cout << " DEBUG: CC not handled due to the presence of " - << nb_cycles << " of boundary edges\n"; - ++unsolved_self_intersections; + std::cout << " DEBUG: CC not handled, selection is not a topological disk even if" + << " boundary cycles are removed: chi=" << selection_chi << "\n"; + ++unsolved_self_intersections; #endif - topology_issue = true; continue; } else { - if(preserve_genus) - { -#ifdef CGAL_PMP_REMOVE_SELF_INTERSECTION_DEBUG - std::cout << " DEBUG: CC not handled because it is not a topological disk (preserve_genus=true)\n"; - ++unsolved_self_intersections; -#endif - - all_fixed = false; - continue; - } + cc_border_hedges.swap(mesh_non_border_hedges); // count the number of cycles of halfedges of the boundary std::map bhs;