From f5a6ff424e7ebd1245e343f1adf8fc4a91f33f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 19 Mar 2021 14:43:20 +0100 Subject: [PATCH] collect face incident to edges too --- .../Corefinement/intersection_callbacks.h | 34 ++++++++++++++----- .../internal/Corefinement/intersection_impl.h | 16 ++++++--- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h index bd6e1b23bbb..d764b106181 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h @@ -324,23 +324,41 @@ class Callback_with_self_intersection_report : public Base { typedef typename Base::face_descriptor face_descriptor; + typedef typename Base::halfedge_descriptor halfedge_descriptor; typedef typename Base::Box Box; - boost::shared_ptr< std::set > faces_with_bbox_involved_in_intersections; + std::set* tmf_collected_faces_ptr; + std::set* tme_collected_faces_ptr; public: - Callback_with_self_intersection_report(const Base& base) - : Base(base), faces_with_bbox_involved_in_intersections(new std::set()) + Callback_with_self_intersection_report(const Base& base, + std::set& tmf_collected_faces, + std::set& tme_collected_faces) + : Base(base), + tmf_collected_faces_ptr(&tmf_collected_faces), + tme_collected_faces_ptr(&tme_collected_faces) {} void operator()( const Box* fb, const Box* eb) { - faces_with_bbox_involved_in_intersections->insert( face(fb->info(), this->tm_faces) ); + halfedge_descriptor h = eb->info(); + if (!is_border(h, this->tm_edges)) + tme_collected_faces_ptr->insert( face(h, this->tm_edges) ); + h = opposite(h, this->tm_edges); + if (!is_border(h, this->tm_edges)) + tme_collected_faces_ptr->insert( face(h, this->tm_edges) ); + tmf_collected_faces_ptr->insert( face(fb->info(), this->tm_faces) ); Base::operator()(fb, eb); } bool self_intersections_found() { - return Polygon_mesh_processing::does_self_intersect( - *faces_with_bbox_involved_in_intersections, - this->tm_faces, - Polygon_mesh_processing::parameters::vertex_point_map(this->vpmap_tmf)); + return + Polygon_mesh_processing::does_self_intersect( + *tmf_collected_faces_ptr, + this->tm_faces, + Polygon_mesh_processing::parameters::vertex_point_map(this->vpmap_tmf)) + || + Polygon_mesh_processing::does_self_intersect( + *tme_collected_faces_ptr, + this->tm_edges, + Polygon_mesh_processing::parameters::vertex_point_map(this->vpmap_tme)); } }; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 60aecbe0f23..c8330039809 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -195,7 +195,10 @@ class Intersection_of_triangle_meshes const TriangleMesh& tm_e, const VPMF& vpm_f, const VPME& vpm_e, - bool throw_on_self_intersection) + bool throw_on_self_intersection, + std::set& tm_f_faces, + std::set& tm_e_faces, + bool run_check) { std::vector face_boxes, edge_boxes; std::vector face_boxes_ptr, edge_boxes_ptr; @@ -245,11 +248,11 @@ class Intersection_of_triangle_meshes #endif //using pointers in box_intersection_d is about 10% faster if (throw_on_self_intersection){ - Callback_with_self_intersection_report callback_si(callback); + Callback_with_self_intersection_report callback_si(callback, tm_f_faces, tm_e_faces); CGAL::box_intersection_d( face_boxes_ptr.begin(), face_boxes_ptr.end(), edge_boxes_ptr.begin(), edge_boxes_ptr.end(), callback_si, cutoff ); - if (callback_si.self_intersections_found()) + if (run_check && callback_si.self_intersections_found()) throw Self_intersection_exception(); } else { @@ -1302,8 +1305,11 @@ public: const VertexPointMap1& vpm1=nodes.vpm1; const VertexPointMap2& vpm2=nodes.vpm2; - filter_intersections(tm1, tm2, vpm1, vpm2, throw_on_self_intersection); - filter_intersections(tm2, tm1, vpm2, vpm1, throw_on_self_intersection); + // used only if throw_on_self_intersection == true + std::set tm1_faces; + std::set tm2_faces; + filter_intersections(tm1, tm2, vpm1, vpm2, throw_on_self_intersection, tm1_faces, tm2_faces, false); + filter_intersections(tm2, tm1, vpm2, vpm1, throw_on_self_intersection, tm2_faces, tm1_faces, true); Node_id current_node((std::numeric_limits::max)()); CGAL_assertion(current_node+1==0);