From ff86d694146fb740c7648dcf38206bcee4d98bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 27 Aug 2026 11:40:00 +0200 Subject: [PATCH 001/136] Replace box_intersection per AABB_tree in self_intersection.h and optimize AABB_tree for interseciton with itself --- .../internal/AABB_traversal_traits.h | 41 -- .../internal/AABB_two_trees_traversal.h | 80 ++- .../AABB_two_trees_traversal_traits.h | 55 +- .../include/CGAL/AABB_trees/intersection.h | 4 +- .../internal/Corefinement/face_graph_utils.h | 98 ++++ .../self_intersections.h | 471 ++++++++++++------ 6 files changed, 494 insertions(+), 255 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h index f00bc1340090..db7a804cc6d1 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h @@ -239,47 +239,6 @@ class Listing_primitive_traits_with_transformation bool m_has_rotation; }; -/** - * @class Listing_distinct_primitive_traits - * used by `all_pairs_of_intersecting_primitives()` to avoid reporting `(i, i)` and twice `(i, j)`. - */ -template -class Listing_distinct_primitive_traits -{ - typedef typename AABBTraits::FT FT; - typedef typename AABBTraits::Point Point; - typedef typename AABBTraits::Primitive Primitive; - typedef typename AABBTraits::Bounding_box Bounding_box; - typedef typename AABBTraits::Primitive::Id Primitive_id; - typedef typename AABBTraits::Point_and_primitive_id Point_and_primitive_id; - typedef typename AABBTraits::Object_and_primitive_id Object_and_primitive_id; - typedef ::CGAL::AABB_node Node; - -public: - Listing_distinct_primitive_traits(OutputIterator out_it, const AABBTraits& traits) - : m_out_it(out_it), m_traits(traits) {} - - constexpr bool go_further() const { return true; } - - void intersection(const Primitive& query, const Primitive& primitive) - { - if( query.id()::get_datum(query, m_traits), primitive) ) - { - *m_out_it++ = primitive.id(); - } - } - - bool do_intersect(const Primitive& query, const Node& node) const - { - return m_traits.do_intersect_object()(internal::Primitive_helper::get_datum(query, m_traits), node.bbox()); - } - -private: - OutputIterator m_out_it; - const AABBTraits& m_traits; -}; - - /** * @class First_primitive_traits */ diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h index b024e15fa766..7aaa626c1d71 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h @@ -34,7 +34,7 @@ void two_trees_traversal(const ::CGAL::AABB_node& node_A, TwoTreeTraversalTraits& traversal_traits) { #if CGAL_LINKED_WITH_TBB - const std::size_t cutoff_parallel_call = 100000; + const std::size_t cutoff_parallel_call = 3000; #endif auto recursive_call = [](const auto &node_A, const auto &node_B, const std::size_t nb_primitives_A, const std::size_t nb_primitives_B, auto &traversal_traits){ if(traversal_traits.prefer_A_for_next_step(node_A, node_B, nb_primitives_A, nb_primitives_B)) @@ -117,13 +117,85 @@ template void two_trees_traversal(const Tree_A& tree_A, - const Tree_B& tree_B, - TwoTreeTraversalTraits &traits) + const Tree_B& tree_B, + TwoTreeTraversalTraits &traits) { CGAL_precondition(tree_A.size() != 0 && tree_B.size() != 0); two_trees_traversal(*tree_A.root_node(), *tree_B.root_node(), tree_A.size(), tree_B.size(), traits); } +// An optimization to traverse a tree with itself +template +void one_tree_traversal(const ::CGAL::AABB_node& node, + const std::size_t nb_primitives, + TwoTreeTraversalTraits& traversal_traits) +{ +#if CGAL_LINKED_WITH_TBB + const std::size_t cutoff_parallel_call = 3000; +#endif + switch(nb_primitives) + { + case 2: + { + traversal_traits.intersection(node.left_data(), node.right_data()); + break; + } + case 3: + { + traversal_traits.intersection(node.left_data(), node.right_child(), 2); + one_tree_traversal(node.right_child(), 2, traversal_traits); + break; + } + default: + { +#if CGAL_LINKED_WITH_TBB + if constexpr(ConcurrencyTag::is_parallel) + { + if(nb_primitives > cutoff_parallel_call) + { + oneapi::tbb::task_group tg; + if(traversal_traits.do_intersect(node.left_child(), node.right_child())){ + tg.run([&]{ + two_trees_traversal(node.left_child(), node.right_child(), nb_primitives/2, nb_primitives - nb_primitives/2, traversal_traits);} + ); + } + tg.run([&]{ + one_tree_traversal(node.left_child(), nb_primitives/2, traversal_traits);} + ); + one_tree_traversal(node.right_child(), nb_primitives - nb_primitives/2, traversal_traits); + tg.wait(); + } + else + { + if(traversal_traits.do_intersect(node.left_child(), node.right_child())) + two_trees_traversal(node.left_child(), node.right_child(), nb_primitives/2, nb_primitives - nb_primitives/2, traversal_traits); + one_tree_traversal(node.left_child(), nb_primitives/2, traversal_traits); + one_tree_traversal(node.right_child(), nb_primitives - nb_primitives/2, traversal_traits); + } + } + else +#endif + { + if(traversal_traits.do_intersect(node.left_child(), node.right_child())) + two_trees_traversal(node.left_child(), node.right_child(), nb_primitives/2, nb_primitives - nb_primitives/2, traversal_traits); + one_tree_traversal(node.left_child(), nb_primitives/2, traversal_traits); + one_tree_traversal(node.right_child(), nb_primitives - nb_primitives/2, traversal_traits); + } + }} // switch end +} + +template +void one_tree_traversal(const Tree& tree, + TwoTreeTraversalTraits &traits) +{ + CGAL_precondition(tree.size() != 0); + one_tree_traversal(*tree.root_node(), tree.size(), traits); +} + namespace experimental{ template & node_A, TwoTreeTraversalTraits& traversal_traits) { #if CGAL_LINKED_WITH_TBB - const std::size_t cutoff_parallel_call = 100000; + const std::size_t cutoff_parallel_call = 3000; #endif auto recursive_call = [&](const auto &node_A, const auto &node_B, const std::size_t nb_primitives_A, const std::size_t nb_primitives_B, auto &traversal_traits){ if(traversal_traits.prefer_A_for_next_step(node_A, node_B, nb_primitives_A, nb_primitives_B)) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 9751387c39e3..f17b3c8a8499 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -69,6 +69,14 @@ class Two_trees_listing_intersecting_primitives_traits return node_a.bbox().squared_diagonal_length() > node_b.bbox().squared_diagonal_length(); } + void intersection(const Primitive1& primitive1, const Primitive2& primitive2) + { + using Wrap_iterator = Wrap_output_iterator; + Wrap_iterator wrap_out(primitive1.id(), out); + Listing_primitive_traits traits(wrap_out, m_traits2); + traits.intersection(primitive1, primitive2); + } + void intersection(const Primitive1& primitive1, const Node2& node2, std::size_t nb_primitives_2) { using Wrap_iterator = Wrap_output_iterator; @@ -191,53 +199,6 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation bool m_tr1_has_rotation, m_tr2_has_rotation; }; -template -class Listing_self_intersecting_primitives_traits -{ - typedef typename AABBTraits::Primitive Primitive; - typedef ::CGAL::AABB_node Node; - -public: - Listing_self_intersecting_primitives_traits(const AABBTraits& traits, OutputIterator out_) - : m_traits(traits), out(out_) - {} - - bool go_further() const { - return true; - } - - // If true, the next step of traversal continue on A, if false, the next step of traversal is on B - template - bool prefer_A_for_next_step(const Node_A& node_a, const Node_B& node_b, const std::size_t&, const std::size_t&) const { - return node_a.bbox().squared_diagonal_length() > node_b.bbox().squared_diagonal_length(); - } - - void intersection(const Primitive& primitive1, const Node& node2, std::size_t nb_primitives_2) - { - using Wrap_iterator = Wrap_output_iterator; - Wrap_iterator wrap_out(primitive1.id(), out); - Listing_distinct_primitive_traits traits(wrap_out, m_traits); - node2.traversal( primitive1, traits, nb_primitives_2); - } - - void intersection(const Node& node1, std::size_t nb_primitives_1, const Primitive& primitive2) - { - using Wrap_iterator= Wrap_output_iterator; - Wrap_iterator wrap_out(primitive2.id(), out); - Listing_distinct_primitive_traits traits(wrap_out, m_traits); - node1.traversal( primitive2, traits, nb_primitives_1); - } - - bool do_intersect(const Node& node1, const Node& node2) const - { - return do_overlap(node1.bbox(), node2.bbox()); - } - -private: - const AABBTraits& m_traits; - OutputIterator out; -}; - template class Two_trees_do_intersect_traits { diff --git a/AABB_tree/include/CGAL/AABB_trees/intersection.h b/AABB_tree/include/CGAL/AABB_trees/intersection.h index 3a0f4aa0a99b..bb0e346caa27 100644 --- a/AABB_tree/include/CGAL/AABB_trees/intersection.h +++ b/AABB_tree/include/CGAL/AABB_trees/intersection.h @@ -207,8 +207,8 @@ namespace AABB_trees { void all_pairs_of_intersecting_primitives(const AABBTree &tree, OutputIterator out) { - CGAL::internal::AABB_tree::Listing_self_intersecting_primitives_traits traversal_traits(tree.traits(), out); - CGAL::internal::AABB_tree::two_trees_traversal(tree, tree, traversal_traits); + CGAL::internal::AABB_tree::Two_trees_listing_intersecting_primitives_traits traversal_traits(tree.traits(), tree.traits(), out); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); } }} // end namespace CGAL::AABB_trees diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 4276641ce7c7..3729bfadc2e0 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -15,6 +15,9 @@ #include +#include +#include +#include #include #include @@ -244,6 +247,101 @@ struct Compute_bbox { BPM bpm; }; +template +struct AABB_tree_build_helper +{ + using Primitive = AABB_face_graph_triangle_primitive; + using Traits = AABB_traits_3; + using Tree = AABB_tree; + + using Graph_traits = boost::graph_traits; + using vertex_descriptor = typename Graph_traits::vertex_descriptor; + using face_descriptor = typename Graph_traits::face_descriptor; + + template + struct Split_primitives + { + Split_primitives(const RPM &rpm): rpm(rpm){} + + template + void operator()(PrimitiveIterator first, + PrimitiveIterator beyond, + const CGAL::Bbox_3& bbox) const + { + auto longest_axis=[](const CGAL::Bbox_3& bbox){ + const double dx = bbox.x_span(); + const double dy = bbox.y_span(); + const double dz = bbox.z_span(); + return (dx>=dy) ? ((dx>=dz) ? 0 : 2) : ((dy>=dz) ? 1 : 2); + }; + + PrimitiveIterator middle = first + (beyond - first)/2; + const int crd=longest_axis(bbox); + std::nth_element(first, middle, beyond, [this, crd](const Primitive& p1, const Primitive& p2){ return get(rpm, p1.id())[crd] < get(rpm, p2.id())[crd];}); + } + const RPM &rpm; + }; + + // For exact side_of_triangle_mesh + template + struct Compute_bbox { + Compute_bbox(const BPM& bpm): bpm(bpm){} + + template + CGAL::Bbox_3 operator()(ConstPrimitiveIterator first, + ConstPrimitiveIterator beyond) const + { + CGAL::Bbox_3 bbox = get(bpm, first->id()); + for(++first; first != beyond; ++first) + bbox += get(bpm, first->id()); + return bbox; + } + BPM bpm; + }; + + template + void build(const FaceRange &face_range, Tree& tree, const TriangleMesh& tm, VertexPointMap& vpm){ + using Face_bbox_tag = typename CGAL::dynamic_face_property_t; + using Face_ref_point_tag = typename CGAL::dynamic_face_property_t; + using Bbox_map = typename boost::property_map::const_type; + using Ref_point_map = typename boost::property_map::const_type; + + using VPM_kernel = typename Kernel_traits::value_type>::Kernel; + CGAL::Cartesian_converter to_input; + + Bbox_map bb_map = get(Face_bbox_tag(), tm); + Ref_point_map rp_map = get(Face_ref_point_tag(), tm); + +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(std::is_same_v) + { + tbb::parallel_for(std::size_t(0), faces(tm).size(), [&](std::size_t i){ + face_descriptor f(i); + put(bb_map, f, face_bbox(f, tm)); + put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); + }); + } + else +#endif + { + for(face_descriptor f : faces(tm)){ + put(bb_map, f, face_bbox(f, tm)); + put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); + } + } + tree.insert(face_range.begin(), face_range.end(), tm, vpm); + + Compute_bbox compute_bbox(bb_map); + Split_primitives split_primitives(rp_map); + tree.template custom_build(compute_bbox, split_primitives); + } + + template + void build(Tree& tree, const TriangleMesh& tm, VertexPointMap& vpm){ + build(faces(tm), tree, tm, vpm); + } +}; + // For exact side_of_triangle_mesh template #include #include -#include #include #include #include @@ -51,16 +50,64 @@ #include #include +#include + +#include +#include +#include +#include + namespace CGAL { namespace Polygon_mesh_processing { namespace internal { -template +#ifndef DOXYGEN_RUNNING +template +struct Property_map_for_soup +{ + using VPM_base = VPM; + using key_type = std::size_t; + using value_type = typename boost::property_traits::value_type; + using category = boost::readable_property_map_tag; + using reference = typename boost::property_traits::reference; + + const PointRange& points; + VPM vpm; + + Property_map_for_soup(const PointRange& points, VPM vpm) + : points(points) + , vpm(vpm) + {} + + inline friend + reference get(const Property_map_for_soup& map, key_type k) + { + return get(map.vpm, map.points[k]); + } +}; +#endif + +template struct Triangle_mesh_and_triangle_soup_wrapper { - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; // private + using face_descriptor = typename boost::graph_traits::face_descriptor; + using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; + using halfedge_descriptor = typename boost::graph_traits::halfedge_descriptor; // private + + using Tree_helper = Corefinement::AABB_tree_build_helper; + using Tree = typename Tree_helper::Tree; + + template + static void build_tree(const FaceRange& faces, Tree& tree, const TM &tm, VPM vpm) + { + Tree_helper().template build(faces, tree, tm, vpm); + } + + template + static void build_tree(Tree& tree, const TM &tm, VPM vpm) + { + Tree_helper().template build(tree, tm, vpm); + } static void get_face_vertices(face_descriptor fd, std::array& vh, const TM& tm) { @@ -103,15 +150,99 @@ struct Triangle_mesh_and_triangle_soup_wrapper } }; -template -struct Triangle_mesh_and_triangle_soup_wrapper< - std::pair> +template +struct Triangle_mesh_and_triangle_soup_wrapper< std::pair, GT, VPM> { - typedef std::size_t face_descriptor; - typedef std::size_t vertex_descriptor; + using face_descriptor = std::size_t; + using vertex_descriptor = std::size_t; + + using Soup = std::pair; + + using Primitive = AABB_indexed_triangle_primitive_3; + using Tree = AABB_tree>; + + template + struct Split_primitives + { + Split_primitives(const RPM &rpm): rpm(rpm){} - typedef std::pair Soup; + template + void operator()(PrimitiveIterator first, + PrimitiveIterator beyond, + const CGAL::Bbox_3& bbox) const + { + PrimitiveIterator middle = first + (beyond - first)/2; + const int crd = bbox.largest_span_index(); + std::nth_element(first, middle, beyond, [this, crd](const auto& p1, const auto& p2){ return get(rpm, p1.id())[crd] < get(rpm, p2.id())[crd];}); + } + const RPM &rpm; + }; + + // For exact side_of_triangle_mesh + template + struct Compute_bbox { + Compute_bbox(const BPM& bpm): bpm(bpm){} + + template + CGAL::Bbox_3 operator()(ConstPrimitiveIterator first, + ConstPrimitiveIterator beyond) const + { + CGAL::Bbox_3 bbox = get(bpm, first->id()); + for(++first; first != beyond; ++first) + bbox += get(bpm, first->id()); + return bbox; + } + BPM bpm; + }; + + template + static void build_tree(const FaceRange &face_range, Tree& tree, const Soup& soup, VPM vpm){ + using PM_kernel = typename Kernel_traits::value_type>::Kernel; + using Bbox_map = Pointer_property_map::type; + using Ref_point_map = Pointer_property_map::type; + + CGAL::Cartesian_converter to_input; + + const auto& points = soup.first; + const auto& triangles = soup.second; + + tree.insert(face_range.begin(), face_range.end(), points, triangles, vpm.vpm); + + std::vector bb_vector(triangles.size(), Bbox_3()); + std::vector rp_vector(triangles.size(), Epick::Point_3()); + Bbox_map bb_map = make_property_map(bb_vector); + Ref_point_map rp_map = make_property_map(rp_vector); + +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(std::is_same_v) + { + tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ + i = face_range[i]; + put(bb_map, i, get(vpm, triangles[i][0]).bbox() + + get(vpm, triangles[i][1]).bbox() + + get(vpm, triangles[i][2]).bbox()); + put(rp_map, i, to_input(get(vpm, triangles[i][0])) ); + }); + } + else +#endif + { + for(std::size_t i: face_range){ + put(bb_map, i, get(vpm, triangles[i][0]).bbox() + + get(vpm, triangles[i][1]).bbox() + + get(vpm, triangles[i][2]).bbox()); + put(rp_map, i, to_input(get(vpm, triangles[i][0])) ); + } + } + Compute_bbox compute_bbox(bb_map); + Split_primitives split_primitives(rp_map); + tree.template custom_build(compute_bbox, split_primitives); + } + + template + static void build_tree(Tree& tree, const Soup& soup, VPM vpm){ + build_tree(soup.second, tree, soup, vpm); + } static void get_face_vertices(face_descriptor fd, std::array& vh, const Soup& soup) { @@ -186,48 +317,51 @@ struct Triangle_mesh_and_triangle_soup_wrapper< } }; -template -struct Throw_at_count_reached_functor { - - std::atomic& counter; - const unsigned int& maxval; - - Output_iterator out; - - Throw_at_count_reached_functor(std::atomic& counter, - const unsigned int& maxval, - Output_iterator out) +template +struct Throw_at_count_reached_output_iterator +{ + using Self = Throw_at_count_reached_output_iterator; + std::atomic &counter; + const unsigned int &maxval; + OutputIterator out; + + using iterator_category = std::output_iterator_tag; + Throw_at_count_reached_output_iterator(std::atomic &counter, + const unsigned int &maxval, + OutputIterator out) : counter(counter), maxval(maxval), out(out) {} template - void operator()(const T& t ) + Self& operator=(const T& t) { *out++ = t; ++counter; if(counter >= maxval) - { throw CGAL::internal::Throw_at_output_exception(); - } + return *this; } + + Self& operator*(){ return *this; } + Self& operator++(){ return *this; } + Self& operator++(int){ return *this; } }; // Checks for 'real' intersections, i.e. not simply a shared vertex or edge template -bool do_faces_intersect(typename Triangle_mesh_and_triangle_soup_wrapper::face_descriptor fh, - typename Triangle_mesh_and_triangle_soup_wrapper::face_descriptor fg, +bool do_faces_intersect(typename Triangle_mesh_and_triangle_soup_wrapper::face_descriptor fh, + typename Triangle_mesh_and_triangle_soup_wrapper::face_descriptor fg, const TM& tmesh, const VPM vpmap, const typename GT::Construct_segment_3& construct_segment, const typename GT::Construct_triangle_3& construct_triangle, const typename GT::Do_intersect_3& do_intersect) { - typedef Triangle_mesh_and_triangle_soup_wrapper Wrapper; - typedef typename Wrapper::vertex_descriptor vertex_descriptor; - - typedef typename GT::Segment_3 Segment; - typedef typename GT::Triangle_3 Triangle; + using Wrapper = Triangle_mesh_and_triangle_soup_wrapper; + using vertex_descriptor = typename Wrapper::vertex_descriptor; + using Segment = typename GT::Segment_3; + using Triangle = typename GT::Triangle_3; std::array hv, gv; Wrapper::get_face_vertices(fh, hv, tmesh); @@ -306,32 +440,103 @@ bool do_faces_intersect(typename Triangle_mesh_and_triangle_soup_wrapper::fa return false; } -template -struct Strict_intersect_faces // "strict" as in "not sharing a subface" +template +class Listing_distinct_intersecting_faces_traits { - mutable OutputIterator m_iterator; - const TM& m_tmesh; - const VPM m_vpmap; - typename GT::Construct_segment_3 m_construct_segment; - typename GT::Construct_triangle_3 m_construct_triangle; - typename GT::Do_intersect_3 m_do_intersect; - - Strict_intersect_faces(const TM& tmesh, VPM vpmap, const GT& gt, OutputIterator it) - : - m_iterator(it), - m_tmesh(tmesh), - m_vpmap(vpmap), - m_construct_segment(gt.construct_segment_3_object()), - m_construct_triangle(gt.construct_triangle_3_object()), - m_do_intersect(gt.do_intersect_3_object()) - {} + using FT = typename AABBTraits::FT; + using Point = typename AABBTraits::Point; + using Primitive = typename AABBTraits::Primitive; + using Bounding_box = typename AABBTraits::Bounding_box; + using Primitive_id = typename AABBTraits::Primitive::Id; + using Point_and_primitive_id = typename AABBTraits::Point_and_primitive_id; + using Object_and_primitive_id = typename AABBTraits::Object_and_primitive_id; + using Node = ::CGAL::AABB_node; + +public: + Listing_distinct_intersecting_faces_traits(OutputIterator out_it, const GT& gt, const AABBTraits& traits, const TriangleMesh &tm, const VertexPointMap &vpm) + : m_out_it(out_it), m_gt(gt), m_traits(traits), m_tm(tm), m_vpm(vpm) {} + + constexpr bool go_further() const { return true; } + void intersection(const Primitive& query, const Primitive& primitive) + { + if(do_faces_intersect(query.id(), primitive.id(), m_tm, m_vpm, + m_gt.construct_segment_3_object(), + m_gt.construct_triangle_3_object(), + m_gt.do_intersect_3_object())) + { + *m_out_it++ = std::make_pair(query.id(), primitive.id()); + } + } + + bool do_intersect(const Primitive& query, const Node& node) const + { + return m_traits.do_intersect_object()(CGAL::internal::Primitive_helper::get_datum(query, m_traits).bbox(), node.bbox()); + } + +private: + OutputIterator m_out_it; + const GT& m_gt; + const AABBTraits& m_traits; + const TriangleMesh& m_tm; + const VertexPointMap& m_vpm; +}; + +template +class Listing_intersecting_faces_two_trees_traits +{ + using Primitive = typename AABBTraits::Primitive; + using Node = ::CGAL::AABB_node; + +public: + Listing_intersecting_faces_two_trees_traits(const AABBTraits& traits, + const GT& gt, + OutputIterator out_, + const TriangleMesh& tm, + const VertexPointMap& vpm) + : m_traits(traits), m_gt(gt), out(out_), m_tm(tm), m_vpm(vpm) {} + + constexpr bool go_further() const { return true; } + + // node coming from the same tree, always alternate is a good choice + template + bool prefer_A_for_next_step(const Node_A&, const Node_B&, const std::size_t&, const std::size_t&) const { + return false; + } + + void intersection(const Primitive& primitive1, const Primitive& primitive2) + { + if(do_faces_intersect(primitive1.id(), primitive2.id(), m_tm, m_vpm, + m_gt.construct_segment_3_object(), + m_gt.construct_triangle_3_object(), + m_gt.do_intersect_3_object())) + { + *out++ = std::make_pair(primitive1.id(), primitive2.id()); + } + } + + void intersection(const Primitive& primitive1, const Node& node2, std::size_t nb_primitives_2) + { + Listing_distinct_intersecting_faces_traits traits(out, m_gt, m_traits, m_tm, m_vpm); + node2.traversal( primitive1, traits, nb_primitives_2); + } + + void intersection(const Node& node1, std::size_t nb_primitives_1, const Primitive& primitive2) + { + Listing_distinct_intersecting_faces_traits traits(out, m_gt, m_traits, m_tm, m_vpm); + node1.traversal( primitive2, traits, nb_primitives_1); + } - void operator()(const Box* b, const Box* c) const + bool do_intersect(const Node& node1, const Node& node2) const { - if(do_faces_intersect(b->info(), c->info(), m_tmesh, m_vpmap, m_construct_segment, m_construct_triangle, m_do_intersect)) - *m_iterator++ = std::make_pair(b->info(), c->info()); + return do_overlap(node1.bbox(), node2.bbox()); } + +private: + const AABBTraits& m_traits; + const GT& m_gt; + OutputIterator out; + const TriangleMesh& m_tm; + const VertexPointMap& m_vpm; }; template Wrapper; - - CGAL_precondition(Wrapper::is_pure_triangle(tmesh)); - using CGAL::parameters::choose_parameter; using CGAL::parameters::get_parameter; using CGAL::parameters::is_default_parameter; - typedef typename Wrapper::face_descriptor face_descriptor; - typedef typename Wrapper::vertex_descriptor vertex_descriptor; - - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Box; - - typedef typename GetGeomTraits::type GT; + using TM = TriangleMesh; + using GT = typename GetGeomTraits::type; GT gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); - typedef GetVertexPointMap VPM_helper; - typedef typename VPM_helper::const_type VPM; + CGAL_precondition(Wrapper::is_pure_triangle(tmesh)); + + using VPM_helper = GetVertexPointMap; + using VPM = typename VPM_helper::const_type; VPM vpmap = VPM_helper::get_const_map(np, tmesh); const bool do_limit = !(is_default_parameter::value); @@ -375,16 +572,17 @@ self_intersections_impl(const FaceRange& face_range, return out; } unsigned int counter = 0; - const unsigned int seed = choose_parameter(get_parameter(np, internal_np::random_seed), 0); - CGAL_USE(seed); // used in the random shuffle of the range, which is only done to balance tasks in parallel - const std::ptrdiff_t cutoff = 2000; + using Wrapper = Triangle_mesh_and_triangle_soup_wrapper; + using face_descriptor = typename Wrapper::face_descriptor; + using vertex_descriptor = typename Wrapper::vertex_descriptor; - // make one box per face - std::vector boxes; - boxes.reserve(std::distance(std::begin(face_range), std::end(face_range))); + using AABB_tree = typename Wrapper::Tree; + using AABB_traits = typename AABB_tree::AABB_traits; // This loop is very cheap, so there is hardly anything to gain from parallelizing it + std::vector faces_not_degenerated; + faces_not_degenerated.reserve(face_range.size()); for(face_descriptor f : face_range) { std::array vh; @@ -397,8 +595,7 @@ self_intersections_impl(const FaceRange& face_range, // tiny fixme: if f is degenerate, we might still have a real intersection between f // and another face f', but right now we are not creating a box for f and thus not returning those - if(collinear(p, q, r)) - { + if(collinear(p, q, r)){ if(throw_on_SI) throw CGAL::internal::Throw_at_output_exception(); else @@ -406,97 +603,79 @@ self_intersections_impl(const FaceRange& face_range, *out++= std::make_pair(f, f); ++counter; if(do_limit && counter == maximum_number) - { return out; - } } - } - else - { - boxes.push_back(Box(p.bbox() + q.bbox() + r.bbox(), f)); + } else { + faces_not_degenerated.push_back(f); } } - // generate box pointers - std::vector box_ptr; - box_ptr.reserve(boxes.size()); - - for(Box& b : boxes) - box_ptr.push_back(&b); - // In case we are throwing, like in `does_self_intersect()`, we keep the geometric test to throw ASAP. // This is obviously not optimal if there are no or few self-intersections: it would be a greater speed-up // to do the same as for `self_intersections()`. However, doing like `self_intersections()` would // be a major slow-down over sequential code if there are a lot of self-intersections... - typedef boost::function_output_iterator Throwing_output_iterator; - typedef internal::Strict_intersect_faces Throwing_filter; - Throwing_filter throwing_filter(tmesh, vpmap, gt, Throwing_output_iterator()); + using Throwing_output_iterator = boost::function_output_iterator; + Throwing_output_iterator throwing_filter; + + AABB_tree tree; + Wrapper::template build_tree(faces_not_degenerated, tree, tmesh, vpmap); #if !defined(CGAL_LINKED_WITH_TBB) static_assert (!(std::is_convertible::value), "Parallel_tag is enabled but TBB is unavailable."); #else + const auto all_pairs_of_intersecting_faces = [&](const AABB_tree& tree, auto out){ + Listing_intersecting_faces_two_trees_traits + traversal_traits(tree.traits(), gt, out, tmesh, vpmap); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); + }; + if(std::is_convertible::value) { - // We are going to split the range into a number of smaller ranges. To handle - // smaller trees of roughly the same size, we first apply a random shuffle to the range - CGAL::Random rng(seed); - CGAL::cpp98::random_shuffle(box_ptr.begin(), box_ptr.end(), rng); - // Write in a concurrent vector all pairs that intersect - typedef tbb::concurrent_vector > Face_pairs; - typedef std::back_insert_iterator Face_pairs_back_inserter; - typedef internal::Strict_intersect_faces Intersecting_faces_filter; + using Face_pairs = tbb::concurrent_vector >; + using Face_pairs_inserter = std::back_insert_iterator; //for maximum_number - typedef internal::Throw_at_count_reached_functor Throw_functor; - typedef boost::function_output_iterator Throwing_after_count_output_iterator; - typedef internal::Strict_intersect_faces Filtered_intersecting_faces_filter; + using Throw_iterator = internal::Throw_at_count_reached_output_iterator; Face_pairs face_pairs; if(throw_on_SI) - CGAL::box_self_intersection_d(box_ptr.begin(), box_ptr.end(), throwing_filter, cutoff); + all_pairs_of_intersecting_faces(tree, throwing_filter); else if(do_limit) { try { std::atomic atomic_counter(counter); - Throw_functor throwing_count_functor(atomic_counter, maximum_number, std::back_inserter(face_pairs)); - Throwing_after_count_output_iterator count_filter(throwing_count_functor); - Filtered_intersecting_faces_filter limited_callback(tmesh, vpmap, gt, count_filter); - CGAL::box_self_intersection_d(box_ptr.begin(), box_ptr.end(), limited_callback, cutoff); + Throw_iterator throwing_count(atomic_counter, maximum_number, std::back_inserter(face_pairs)); + Throw_at_count_reached_output_iterator count_filter(throwing_count); + all_pairs_of_intersecting_faces(tree, count_filter); } catch(const CGAL::internal::Throw_at_output_exception&) { // Sequentially write into the output iterator - std::copy(face_pairs.begin(), face_pairs.end(), out); - return out; + for(std::size_t i=0; i(box_ptr.begin(), box_ptr.end(), callback, cutoff); + all_pairs_of_intersecting_faces(tree, std::back_inserter(face_pairs)); } // Sequentially write into the output iterator for(std::size_t i=0; i Intersecting_faces_filter; - Intersecting_faces_filter intersect_faces(tmesh, vpmap, gt, out); - if(throw_on_SI) - CGAL::box_self_intersection_d(box_ptr.begin(), box_ptr.end(), throwing_filter, cutoff); + all_pairs_of_intersecting_faces(tree, throwing_filter); else if(do_limit) { - typedef std::function&) > Count_and_throw_filter; + using Count_and_throw_filter = std::function&) >; std::size_t nbi=0; Count_and_throw_filter max_inter_counter = [&nbi, maximum_number, &out](const std::pair& f_pair) { @@ -504,12 +683,10 @@ self_intersections_impl(const FaceRange& face_range, if (++nbi == maximum_number) throw CGAL::internal::Throw_at_output_exception(); }; - typedef internal::Strict_intersect_faces > Intersecting_faces_limited_filter; - Intersecting_faces_limited_filter limited_intersect_faces(tmesh, vpmap, gt, - boost::make_function_output_iterator(max_inter_counter)); + try { - CGAL::box_self_intersection_d(box_ptr.begin(), box_ptr.end(), limited_intersect_faces, cutoff); + all_pairs_of_intersecting_faces(tree, boost::make_function_output_iterator(max_inter_counter)); } catch (const CGAL::internal::Throw_at_output_exception&) { @@ -517,9 +694,8 @@ self_intersections_impl(const FaceRange& face_range, } } else - CGAL::box_self_intersection_d(box_ptr.begin(), box_ptr.end(), intersect_faces, cutoff); - - return intersect_faces.m_iterator; + all_pairs_of_intersecting_faces(tree, out); + return out; } } // namespace internal @@ -777,33 +953,6 @@ bool does_self_intersect(const TriangleMesh& tmesh, return does_self_intersect(faces(tmesh), tmesh, np); } - -#ifndef DOXYGEN_RUNNING -template -struct Property_map_for_soup -{ - typedef std::size_t key_type; - typedef typename boost::property_traits::value_type value_type; - //typedef typename boost::property_traits::category category; - typedef boost::readable_property_map_tag category; - typedef typename boost::property_traits::reference reference; - - const PointRange& points; - VPM vpm; - - Property_map_for_soup(const PointRange& points, VPM vpm) - : points(points) - , vpm(vpm) - {} - - inline friend - reference get(const Property_map_for_soup& map, key_type k) - { - return get(map.vpm, map.points[k]); - } -}; -#endif - /** * \ingroup PMP_intersection_grp * @@ -877,10 +1026,10 @@ triangle_soup_self_intersections(const PointRange& points, using parameters::get_parameter; using parameters::is_default_parameter; - typedef typename CGAL::GetPointMap::const_type Point_map_base; + using Point_map_base = typename CGAL::GetPointMap::const_type; Point_map_base pm_base = choose_parameter(get_parameter(np, internal_np::point_map)); - typedef Property_map_for_soup Point_map; - typedef typename GetPolygonSoupGeomTraits::type GT; + using Point_map = internal::Property_map_for_soup; + using GT = typename GetPolygonSoupGeomTraits::type; GT gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); const bool do_limit = !(is_default_parameter::value); @@ -960,10 +1109,10 @@ bool does_triangle_soup_self_intersect(const PointRange& points, using parameters::get_parameter; CGAL::Emptyset_iterator unused_out; - typedef typename CGAL::GetPointMap::const_type Point_map_base; + using Point_map_base = typename CGAL::GetPointMap::const_type; Point_map_base pm_base = choose_parameter(get_parameter(np, internal_np::point_map)); - typedef Property_map_for_soup Point_map; - typedef typename GetPolygonSoupGeomTraits::type GT; + using Point_map = internal::Property_map_for_soup; + using GT = typename GetPolygonSoupGeomTraits::type; GT gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); internal::self_intersections_impl(boost::irange(0, triangles.size()), From 0c035ca77b67a006b2ae50d99f6248625a0f362b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 27 Aug 2026 15:23:56 +0200 Subject: [PATCH 002/136] Solved compile error in debug --- .../include/CGAL/Polygon_mesh_processing/self_intersections.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index ea14396a8e54..b686167373d9 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -559,8 +559,6 @@ self_intersections_impl(const FaceRange& face_range, using GT = typename GetGeomTraits::type; GT gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); - CGAL_precondition(Wrapper::is_pure_triangle(tmesh)); - using VPM_helper = GetVertexPointMap; using VPM = typename VPM_helper::const_type; VPM vpmap = VPM_helper::get_const_map(np, tmesh); @@ -580,6 +578,8 @@ self_intersections_impl(const FaceRange& face_range, using AABB_tree = typename Wrapper::Tree; using AABB_traits = typename AABB_tree::AABB_traits; + CGAL_precondition(Wrapper::is_pure_triangle(tmesh)); + // This loop is very cheap, so there is hardly anything to gain from parallelizing it std::vector faces_not_degenerated; faces_not_degenerated.reserve(face_range.size()); From 348e9c159ff98ec8c2c03e0085be9de1d1c15cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 27 Aug 2026 20:39:04 +0200 Subject: [PATCH 003/136] Parallellisation of fukter intersection of corefinement --- .../PMP_Boolean_operations/CMakeLists.txt | 1 + .../corefinement_mesh_union_progress.cpp | 7 +- .../Polygon_mesh_processing/corefinement.h | 44 +- .../Corefinement/Face_graph_output_builder.h | 1 + .../internal/Corefinement/face_graph_utils.h | 98 +---- .../Corefinement/intersection_callbacks.h | 4 +- .../internal/Corefinement/intersection_impl.h | 406 +++++++++--------- .../soup_and_face_graph_tree_helper.h | 130 ++++++ .../self_intersections.h | 4 +- 9 files changed, 381 insertions(+), 314 deletions(-) create mode 100644 PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h diff --git a/PMP_Boolean_operations/examples/PMP_Boolean_operations/CMakeLists.txt b/PMP_Boolean_operations/examples/PMP_Boolean_operations/CMakeLists.txt index ae035b0858de..9fe4b45685af 100644 --- a/PMP_Boolean_operations/examples/PMP_Boolean_operations/CMakeLists.txt +++ b/PMP_Boolean_operations/examples/PMP_Boolean_operations/CMakeLists.txt @@ -50,6 +50,7 @@ include(CGAL_TBB_support) if(TARGET CGAL::TBB_support) target_link_libraries(soup_autorefinement PRIVATE CGAL::TBB_support) target_link_libraries(snap_polygon_soup PRIVATE CGAL::TBB_support) + target_link_libraries(corefinement_mesh_union_progress PRIVATE CGAL::TBB_support) create_single_source_cgal_program("corefinement_parallel_union_meshes.cpp") target_link_libraries(corefinement_parallel_union_meshes PRIVATE CGAL::TBB_support) diff --git a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp index 67c2c3615fe5..381ccf7047b4 100644 --- a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp +++ b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -97,7 +98,7 @@ struct Visitor_rep{ std::size_t bound_intersection = 0; std::size_t tintersection = 0; std::size_t count_intersection = 0; - CGAL::Timer t; + CGAL::Real_timer t; }; @@ -196,12 +197,12 @@ int main(int argc, char* argv[]) return 1; } - CGAL::Timer t; + CGAL::Real_timer t; t.start(); Mesh out; Visitor visitor; - bool valid_union = PMP::corefine_and_compute_union (mesh1,mesh2, out, CGAL::parameters::visitor(visitor)); + bool valid_union = PMP::corefine_and_compute_union (mesh1,mesh2, out, CGAL::parameters::visitor(visitor).concurrency_tag(CGAL::Parallel_if_available_tag())); std::cout << "Global timer = " << t.time() << " sec." << std::endl; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h index 4176b99fbe4e..27441dc2b5b9 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h @@ -190,6 +190,12 @@ enum Boolean_operation_type {UNION = 0, INTERSECTION=1, * @param np2 an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm1` (`tm2`)} * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -284,6 +290,12 @@ corefine_and_compute_boolean_operations( using parameters::choose_parameter; using parameters::get_parameter; + using ConcurrencyTag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NPIn1, + Sequential_tag + > ::type; + const bool throw_on_self_intersection = choose_parameter(get_parameter(np1, internal_np::throw_on_self_intersection), false); @@ -489,7 +501,7 @@ corefine_and_compute_boolean_operations( ob.setup_for_clipping_a_surface(use_compact_clipper); } - Corefinement::Intersection_of_triangle_meshes + Corefinement::Intersection_of_triangle_meshes functor(tm1, tm2, vpm1, vpm2, Algo_visitor(uv,ob,ecm_in)); functor(CGAL::Emptyset_iterator(), throw_on_self_intersection, true); @@ -530,6 +542,12 @@ corefine_and_compute_boolean_operations( * @param np2 an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm1` (`tm2`)} * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -762,6 +780,12 @@ corefine( TriangleMesh& tm1, using parameters::choose_parameter; using parameters::get_parameter; + using ConcurrencyTag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters1, + Sequential_tag + > ::type; + TriangleMesh* const_mesh_ptr=nullptr; if (choose_parameter(get_parameter(np1, internal_np::do_not_modify), false)) { @@ -835,7 +859,7 @@ corefine( TriangleMesh& tm1, Ob ob; Ecm ecm(tm1,tm2,ecm1,ecm2); - Corefinement::Intersection_of_triangle_meshes + Corefinement::Intersection_of_triangle_meshes functor(tm1, tm2, vpm1, vpm2, Algo_visitor(uv,ob,ecm,const_mesh_ptr), const_mesh_ptr); // Fill non-manifold feature maps if provided @@ -903,6 +927,12 @@ autorefine( TriangleMesh& tm, using parameters::choose_parameter; using parameters::get_parameter; + using ConcurrencyTag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + > ::type; + // Vertex point maps typedef typename GetVertexPointMap::type VPM; @@ -932,7 +962,7 @@ autorefine( TriangleMesh& tm, TriangleMesh, VPM, VPM, Ob, Ecm, User_visitor,true> Algo_visitor; Ob ob; - Corefinement::Intersection_of_triangle_meshes + Corefinement::Intersection_of_triangle_meshes functor(tm, vpm, Algo_visitor(uv,ob,ecm) ); functor(CGAL::Emptyset_iterator(), true); @@ -997,6 +1027,12 @@ autorefine_and_remove_self_intersections( TriangleMesh& tm, using parameters::choose_parameter; using parameters::get_parameter; + using ConcurrencyTag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + > ::type; + // Vertex point maps typedef typename GetVertexPointMap::type VPM; VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), @@ -1034,7 +1070,7 @@ autorefine_and_remove_self_intersections( TriangleMesh& tm, TriangleMesh, VPM, VPM, Ob, Ecm, User_visitor,true> Algo_visitor; Ob ob(tm, vpm, fid_map, ecm); - Corefinement::Intersection_of_triangle_meshes + Corefinement::Intersection_of_triangle_meshes functor(tm, vpm, Algo_visitor(uv,ob,ecm) ); functor(CGAL::Emptyset_iterator(), true); diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index 85a73ae8628b..b2f52abd152e 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -17,6 +17,7 @@ #include +#include #include #include diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 3729bfadc2e0..e8860b8c6d35 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -247,101 +247,6 @@ struct Compute_bbox { BPM bpm; }; -template -struct AABB_tree_build_helper -{ - using Primitive = AABB_face_graph_triangle_primitive; - using Traits = AABB_traits_3; - using Tree = AABB_tree; - - using Graph_traits = boost::graph_traits; - using vertex_descriptor = typename Graph_traits::vertex_descriptor; - using face_descriptor = typename Graph_traits::face_descriptor; - - template - struct Split_primitives - { - Split_primitives(const RPM &rpm): rpm(rpm){} - - template - void operator()(PrimitiveIterator first, - PrimitiveIterator beyond, - const CGAL::Bbox_3& bbox) const - { - auto longest_axis=[](const CGAL::Bbox_3& bbox){ - const double dx = bbox.x_span(); - const double dy = bbox.y_span(); - const double dz = bbox.z_span(); - return (dx>=dy) ? ((dx>=dz) ? 0 : 2) : ((dy>=dz) ? 1 : 2); - }; - - PrimitiveIterator middle = first + (beyond - first)/2; - const int crd=longest_axis(bbox); - std::nth_element(first, middle, beyond, [this, crd](const Primitive& p1, const Primitive& p2){ return get(rpm, p1.id())[crd] < get(rpm, p2.id())[crd];}); - } - const RPM &rpm; - }; - - // For exact side_of_triangle_mesh - template - struct Compute_bbox { - Compute_bbox(const BPM& bpm): bpm(bpm){} - - template - CGAL::Bbox_3 operator()(ConstPrimitiveIterator first, - ConstPrimitiveIterator beyond) const - { - CGAL::Bbox_3 bbox = get(bpm, first->id()); - for(++first; first != beyond; ++first) - bbox += get(bpm, first->id()); - return bbox; - } - BPM bpm; - }; - - template - void build(const FaceRange &face_range, Tree& tree, const TriangleMesh& tm, VertexPointMap& vpm){ - using Face_bbox_tag = typename CGAL::dynamic_face_property_t; - using Face_ref_point_tag = typename CGAL::dynamic_face_property_t; - using Bbox_map = typename boost::property_map::const_type; - using Ref_point_map = typename boost::property_map::const_type; - - using VPM_kernel = typename Kernel_traits::value_type>::Kernel; - CGAL::Cartesian_converter to_input; - - Bbox_map bb_map = get(Face_bbox_tag(), tm); - Ref_point_map rp_map = get(Face_ref_point_tag(), tm); - -#ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) - { - tbb::parallel_for(std::size_t(0), faces(tm).size(), [&](std::size_t i){ - face_descriptor f(i); - put(bb_map, f, face_bbox(f, tm)); - put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); - }); - } - else -#endif - { - for(face_descriptor f : faces(tm)){ - put(bb_map, f, face_bbox(f, tm)); - put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); - } - } - tree.insert(face_range.begin(), face_range.end(), tm, vpm); - - Compute_bbox compute_bbox(bb_map); - Split_primitives split_primitives(rp_map); - tree.template custom_build(compute_bbox, split_primitives); - } - - template - void build(Tree& tree, const TriangleMesh& tm, VertexPointMap& vpm){ - build(faces(tm), tree, tm, vpm); - } -}; - // For exact side_of_triangle_mesh template (tm1, edge_mark_map_in1, edge_mark_map_out1); if (reverse_patch_orientation_tm1){ - Polygon_mesh_processing:: - reverse_face_orientations_of_mesh_with_polylines(tm1); + Polygon_mesh_processing::reverse_face_orientations_of_mesh_with_polylines(tm1); // here we need to update the mapping to use the correct border // halfedges while appending the patches from tm2 for(typename EdgeMap::value_type& v : tm2_edge_to_tm1_edge) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h index 6e0a2f38f9ce..5a57b5297389 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h @@ -109,9 +109,7 @@ class Collect_face_bbox_per_edge_bbox_with_coplanar_handling { , visitor(visitor) {} - void operator()( const Box& face_box, const Box& edge_box) const { - halfedge_descriptor fh = face_box.info(); - halfedge_descriptor eh = edge_box.info(); + void operator()(halfedge_descriptor fh, halfedge_descriptor eh) const { if(is_border(eh,tm_edges)) eh = opposite(eh, tm_edges); //check if the segment intersects the plane of the facet or if it is included in the plane diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 2ad06651e85b..b0cba2146004 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -15,16 +15,16 @@ #include - #include -#include #include #include #include #include #include +#include #include #include +#include #include #include @@ -51,8 +51,7 @@ struct Triple_intersection_exception : // The algorithm works as follow: // From each triangle mesh, we extract a set of segments from the edges and a // set of triangles from the faces. -// We use Box_intersection_d to filter intersection between the segments from -// one mesh with the triangles from the other one. +// We use AABB_trees to filter pairs of candidates intersecting faces and extract the intersection of between an edge and a face. // From this filtered set, for each pair (segment,triangle), we look at the // intersection type. If not empty, we can have three different cases // 1)the segment intersect the interior of the triangle: @@ -195,7 +194,8 @@ struct Node_id_set { template< class TriangleMesh, class VertexPointMap1, class VertexPointMap2, - class Node_visitor=Default_surface_intersection_visitor + class Node_visitor=Default_surface_intersection_visitor, + class ConcurrencyTag=Sequential_tag > class Intersection_of_triangle_meshes { @@ -205,9 +205,6 @@ class Intersection_of_triangle_meshes typedef typename graph_traits::halfedge_descriptor halfedge_descriptor; typedef typename graph_traits::vertex_descriptor vertex_descriptor; - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Box; - typedef std::unordered_set Face_set; typedef std::unordered_map Edge_to_faces; @@ -243,164 +240,154 @@ class Intersection_of_triangle_meshes CGAL_assertion_code(bool doing_autorefinement;) // member functions - template - void filter_intersections(const TriangleMesh& tm_f, - const TriangleMesh& tm_e, - const VPMF& vpm_f, - const VPME& vpm_e, - const Non_manifold_feature_map& non_manifold_feature_map, + template + void filter_intersections(const TriangleMesh& tm1, + const TriangleMesh& tm2, + const VPM1& vpm1, + const VPM2& vpm2, + const Non_manifold_feature_map& non_manifold_feature_map_1, + const Non_manifold_feature_map& non_manifold_feature_map_2, bool throw_on_self_intersection, - std::set& tm_f_faces, - std::set& tm_e_faces, - Bbox_3 g_bb, - IFSM is_shared_map_f, - IESM is_shared_map_e, - bool run_check) + std::set& tm1_faces, + std::set& tm2_faces, + Bbox_3 bb, + ISM1 is_shared_map_1, + ISM2 is_shared_map_2) { - std::vector face_boxes, edge_boxes; - std::vector face_boxes_ptr, edge_boxes_ptr; + using GT = typename GetGeomTraits::type; + using AABB_tree_helper = internal::AABB_tree_build_helper; + using Tree = typename AABB_tree_helper::Tree; + AABB_tree_helper helper; + + Tree tree1(faces(tm1).begin(), faces(tm1).end(), tm1); + Tree tree2(faces(tm2).begin(), faces(tm2).end(), tm2); + + auto wrap_callback = [&](){ +#ifdef DO_NOT_HANDLE_COPLANAR_FACES + using Callback = Collect_face_bbox_per_edge_bbox; + Callback callback12(tm1, tm2, ltm_edge_to_stm_faces); + Callback callback21(tm2, tm1, stm_edge_to_ltm_faces); +#else + using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling< + TriangleMesh, VPM1, VPM2, Edge_to_faces, Coplanar_face_set, Node_visitor>; + Callback callback12(tm1, tm2, vpm1, vpm2, ltm_edge_to_stm_faces, coplanar_faces, visitor); + Callback callback21(tm2, tm1, vpm2, vpm1, stm_edge_to_ltm_faces, coplanar_faces, visitor); +#endif - face_boxes.reserve(num_faces(tm_f)); - face_boxes_ptr.reserve(num_faces(tm_f)); - for(face_descriptor fd : faces(tm_f)) + // if (throw_on_self_intersection){ + // Callback_with_self_intersection_report callback_si_12(callback12, tm1_faces, tm2_faces); + // Callback_with_self_intersection_report callback_si_21(callback21, tm2_faces, tm1_faces); + // return std::make_pair(callback_si_12, callback_si_21); + // } + // else { + // if (const_mesh_ptr==&tm1) + // { + // auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + // if(!callback12.is_face_degenerated(h1)); + // callback12(h1, h2); + // }; + // auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + // if(!callback21.is_face_degenerated(h1)) + // callback21(h2, h1); + // }; + // return std::make_pair(filtered_callback_12, filtered_callback_21); + // } + // else + // { + // if (const_mesh_ptr==&tm2) + // { + // auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + // if(!callback12.is_face_degenerated(h2)); + // callback12(h1, h2); + // }; + // auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + // if(!callback21.is_face_degenerated(h2)) + // callback21(h2, h1); + // }; + // return std::make_pair(filtered_callback_12, filtered_callback_21); + // } + // else + // { + return std::make_pair(callback12, callback21); + // } + // } + // } + }; + auto [callback12, callback21] = wrap_callback(); + +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(std::is_same_v) { - if (get(is_shared_map_f,fd)) continue; - halfedge_descriptor h=halfedge(fd,tm_f); - Bbox_3 bb = get(vpm_f,source(h,tm_f)).bbox() + - get(vpm_f,target(h,tm_f)).bbox() + - get(vpm_f,target(next(h,tm_f),tm_f)).bbox(); - if (do_overlap(bb, g_bb)) - { - face_boxes.emplace_back(bb, h); - face_boxes_ptr.push_back( &face_boxes.back() ); + oneapi::tbb::task_group tg; + tg.run([&]{ helper.template build(tree1, tm1, vpm1); }); + helper.template build(tree2, tm2, vpm2); + tg.wait(); + + tbb::concurrent_vector> inter; + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter), parameters::concurrency_tag(ConcurrencyTag())); + + // tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ + for(std::size_t i=0; i - Callback; - Callback callback(tm_f, tm_e, edge_to_faces); - #else - typedef Collect_face_bbox_per_edge_bbox_with_coplanar_handling< - TriangleMesh, VPMF, VPME, Edge_to_faces, Coplanar_face_set, Node_visitor> - Callback; - Callback callback(tm_f, tm_e, vpm_f, vpm_e, edge_to_faces, coplanar_faces, visitor); - #endif - //using pointers in box_intersection_d is about 10% faster - if (throw_on_self_intersection){ - 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 (run_check && callback_si.self_intersections_found()) - throw Self_intersection_exception(); - } - else { - if (const_mesh_ptr==&tm_e) - { - // tm_f might feature degenerate faces - auto filtered_callback = [&callback](const Box* fb, const Box* eb) - { - if (!callback.is_face_degenerated(fb->info())) - callback(fb, eb); - }; - CGAL::box_intersection_d( face_boxes_ptr.begin(), face_boxes_ptr.end(), - edge_boxes_ptr.begin(), edge_boxes_ptr.end(), - filtered_callback, cutoff ); - } - else - { - if (const_mesh_ptr==&tm_f) - { - // tm_e might feature degenerate edges - auto filtered_callback = [&,this](const Box* fb, const Box* eb) - { - if (get(vpm_e, source(eb->info(), tm_e)) != get(vpm_e, target(eb->info(), tm_e))) - callback(fb, eb); - else - { - halfedge_descriptor hf = fb->info(); - halfedge_descriptor he = eb->info(); - for (int i=0; i<2; ++i) - { - if (!is_border(he, tm_e)) - { - if ( get(vpm_e, target(next(he, tm_e), tm_e))==get(vpm_e, target(he, tm_e)) && - coplanar(get(vpm_f, source(hf, tm_f)), - get(vpm_f, target(hf, tm_f)), - get(vpm_f, target(next(hf, tm_f), tm_f)), - get(vpm_e, target(he, tm_e))) ) - { - coplanar_faces.insert( - &tm_e < &tm_f - ? std::make_pair(face(he, tm_e), face(hf, tm_f)) - : std::make_pair(face(hf, tm_f), face(he, tm_e)) - ); - } - } - he=opposite(he, tm_e); - } - } - }; - CGAL::box_intersection_d( face_boxes_ptr.begin(), face_boxes_ptr.end(), - edge_boxes_ptr.begin(), edge_boxes_ptr.end(), - filtered_callback, cutoff ); - } - else - CGAL::box_intersection_d( face_boxes_ptr.begin(), face_boxes_ptr.end(), - edge_boxes_ptr.begin(), edge_boxes_ptr.end(), - callback, cutoff ); +#endif + { + helper.template build(tree1, tm1, vpm1); + helper.template build(tree2, tm2, vpm2); + + std::vector> inter; + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter)); + + for(const auto& [f_1, f_2]: inter){ + halfedge_descriptor hf1_0 = halfedge(f_1, tm1); + halfedge_descriptor hf1_1 = next(hf1_0, tm1); + halfedge_descriptor hf1_2 = next(hf1_1, tm1); + + halfedge_descriptor hf2_0 = halfedge(f_2, tm2); + halfedge_descriptor hf2_1 = next(hf2_0, tm2); + halfedge_descriptor hf2_2 = next(hf2_1, tm2); + + if (is_border(hf2_0, tm2) || hf2_0 < opposite(hf2_0, tm2)) + callback12(hf1_0, hf2_0); + if (is_border(hf2_1, tm2) || hf2_1 < opposite(hf2_1, tm2)) + callback12(hf1_0, hf2_1); + if (is_border(hf2_2, tm2) || hf2_2 < opposite(hf2_2, tm2)) + callback12(hf1_0, hf2_2); + + if (is_border(hf1_0, tm1) || hf1_0 < opposite(hf1_0, tm1)) + callback21(hf2_0, hf1_0); + if (is_border(hf1_1, tm1) || hf1_1 < opposite(hf1_1, tm1)) + callback21(hf2_0, hf1_1); + if (is_border(hf1_2, tm1) || hf1_2 < opposite(hf1_2, tm1)) + callback21(hf2_0, hf1_2); + + // if (throw_on_self_intersection && callback12.self_intersections_found()) + // throw Self_intersection_exception(); } } } @@ -410,49 +397,64 @@ class Intersection_of_triangle_meshes void filter_intersections(const TriangleMesh& tm, const VPM& vpm) { - std::vector face_boxes, edge_boxes; - std::vector face_boxes_ptr, edge_boxes_ptr; + using GT = typename GetGeomTraits::type; + using AABB_tree_helper = internal::AABB_tree_build_helper; + using Tree = typename AABB_tree_helper::Tree; + AABB_tree_helper helper; + + Tree tree(faces(tm).begin(), faces(tm).end(), tm); + helper.template build(tree, tm, vpm); + + using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh< + TriangleMesh, VPM, Edge_to_faces, Coplanar_face_set>; + Callback callback(tm, tm, stm_edge_to_ltm_faces, coplanar_faces); - face_boxes.reserve(num_faces(tm)); - face_boxes_ptr.reserve(num_faces(tm)); - for(face_descriptor fd : faces(tm)) + #ifdef CGAL_LINKED_WITH_TBB + if constexpr(std::is_same_v) { - halfedge_descriptor h=halfedge(fd,tm); - face_boxes.push_back( Box( - get(vpm,source(h,tm)).bbox() + - get(vpm,target(h,tm)).bbox() + - get(vpm,target(next(h,tm),tm)).bbox(), - h ) ); - face_boxes_ptr.push_back( &face_boxes.back() ); + tbb::concurrent_vector> inter; + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(inter)); + + // tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ + for(std::size_t i=0; i> inter; + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(inter)); + + for(const auto& [f_1, f_2]: inter){ + halfedge_descriptor h0 = halfedge(f_1, tm); + halfedge_descriptor h1 = next(h0, tm); + halfedge_descriptor h2 = next(h1, tm); + + halfedge_descriptor h_f2 = halfedge(f_1, tm); + + if (is_border(h0, tm) || h0 < opposite(h0, tm)) + callback(h0, h_f2); + if (is_border(h1, tm) || h1 < opposite(h1, tm)) + callback(h1, h_f2); + if (is_border(h2, tm) || h2 < opposite(h2, tm)) + callback(h2, h_f2); + } } - - /// \todo experiments different cutoff values - std::ptrdiff_t cutoff = 2 * std::ptrdiff_t( - std::sqrt(face_boxes.size()+edge_boxes.size()) ); - - Edge_to_faces& edge_to_faces = stm_edge_to_ltm_faces; - - typedef Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh< - TriangleMesh, VPM, Edge_to_faces, Coplanar_face_set> - Callback; - Callback callback(tm, vpm, edge_to_faces, coplanar_faces); - - //using pointers in box_intersection_d is about 10% faster - CGAL::box_intersection_d( face_boxes_ptr.begin(), face_boxes_ptr.end(), - edge_boxes_ptr.begin(), edge_boxes_ptr.end(), - callback, cutoff ); } template @@ -1887,10 +1889,7 @@ class Intersection_of_triangle_meshes if (!identical_meshes) { visitor.start_filtering_intersections(); - filter_intersections(tm1, tm2, vpm1, vpm2, non_manifold_feature_map_2, throw_on_self_intersection, tm1_faces, tm2_faces, bb12, - is_fshared_map1, is_eshared_map2, false); - filter_intersections(tm2, tm1, vpm2, vpm1, non_manifold_feature_map_1, throw_on_self_intersection, tm2_faces, tm1_faces, bb12, - is_fshared_map2, is_eshared_map1, true); + filter_intersections(tm1, tm2, vpm1, vpm2, non_manifold_feature_map_1, non_manifold_feature_map_2, throw_on_self_intersection, tm1_faces, tm2_faces, bb12, is_fshared_map1, is_eshared_map2); visitor.end_filtering_intersections(); // dumping shared edges in output @@ -1933,10 +1932,7 @@ class Intersection_of_triangle_meshes Static_boolean_property_map is_fshared_map; Static_boolean_property_map is_eshared_map; visitor.start_filtering_intersections(); - filter_intersections(tm1, tm2, vpm1, vpm2, non_manifold_feature_map_2, throw_on_self_intersection, tm1_faces, tm2_faces, bb12, - is_fshared_map, is_eshared_map, false); - filter_intersections(tm2, tm1, vpm2, vpm1, non_manifold_feature_map_1, throw_on_self_intersection, tm2_faces, tm1_faces, bb12, - is_fshared_map, is_eshared_map, true); + filter_intersections(tm1, tm2, vpm1, vpm2, non_manifold_feature_map_1, non_manifold_feature_map_2, throw_on_self_intersection, tm1_faces, tm2_faces, bb12, is_fshared_map, is_eshared_map); visitor.end_filtering_intersections(); } diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h new file mode 100644 index 000000000000..6f02526646db --- /dev/null +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -0,0 +1,130 @@ +// Copyright (c) 2016 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sebastien Loriot + +#ifndef CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SOUP_AND_TREE_HELPER_H +#define CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SOUP_AND_TREE_HELPER_H + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace Polygon_mesh_processing { +namespace internal { + +template +struct AABB_tree_build_helper +{ + using Primitive = AABB_face_graph_triangle_primitive; + using Traits = AABB_traits_3; + using Tree = AABB_tree; + + using Graph_traits = boost::graph_traits; + using vertex_descriptor = typename Graph_traits::vertex_descriptor; + using face_descriptor = typename Graph_traits::face_descriptor; + + template + struct Split_primitives + { + Split_primitives(const RPM &rpm): rpm(rpm){} + + template + void operator()(PrimitiveIterator first, + PrimitiveIterator beyond, + const CGAL::Bbox_3& bbox) const + { + auto longest_axis=[](const CGAL::Bbox_3& bbox){ + const double dx = bbox.x_span(); + const double dy = bbox.y_span(); + const double dz = bbox.z_span(); + return (dx>=dy) ? ((dx>=dz) ? 0 : 2) : ((dy>=dz) ? 1 : 2); + }; + + PrimitiveIterator middle = first + (beyond - first)/2; + const int crd=longest_axis(bbox); + std::nth_element(first, middle, beyond, [this, crd](const Primitive& p1, const Primitive& p2){ return get(rpm, p1.id())[crd] < get(rpm, p2.id())[crd];}); + } + const RPM &rpm; + }; + + // For exact side_of_triangle_mesh + template + struct Compute_bbox { + Compute_bbox(const BPM& bpm): bpm(bpm){} + + template + CGAL::Bbox_3 operator()(ConstPrimitiveIterator first, + ConstPrimitiveIterator beyond) const + { + CGAL::Bbox_3 bbox = get(bpm, first->id()); + for(++first; first != beyond; ++first) + bbox += get(bpm, first->id()); + return bbox; + } + BPM bpm; + }; + + template + void build(const FaceRange &face_range, Tree& tree, const TriangleMesh& tm, VertexPointMap& vpm){ + using Face_bbox_tag = typename CGAL::dynamic_face_property_t; + using Face_ref_point_tag = typename CGAL::dynamic_face_property_t; + using Bbox_map = typename boost::property_map::const_type; + using Ref_point_map = typename boost::property_map::const_type; + + using VPM_kernel = typename Kernel_traits::value_type>::Kernel; + CGAL::Cartesian_converter to_input; + + Bbox_map bb_map = get(Face_bbox_tag(), tm); + Ref_point_map rp_map = get(Face_ref_point_tag(), tm); + +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(std::is_same_v) + { + tbb::parallel_for(std::size_t(0), faces(tm).size(), [&](std::size_t i){ + face_descriptor f(i); + put(bb_map, f, face_bbox(f, tm)); + put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); + }); + } + else +#endif + { + for(face_descriptor f : faces(tm)){ + put(bb_map, f, face_bbox(f, tm)); + put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); + } + } + tree.insert(face_range.begin(), face_range.end(), tm, vpm); + + Compute_bbox compute_bbox(bb_map); + Split_primitives split_primitives(rp_map); + tree.template custom_build(compute_bbox, split_primitives); + } + + template + void build(Tree& tree, const TriangleMesh& tm, VertexPointMap& vpm){ + build(faces(tm), tree, tm, vpm); + } +}; + +} } } // CGAL::Polygon_mesh_processing::internal + +#endif // CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SOUP_AND_TREE_HELPER_H diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index b686167373d9..adfa2353b1bb 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include @@ -94,7 +94,7 @@ struct Triangle_mesh_and_triangle_soup_wrapper using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; using halfedge_descriptor = typename boost::graph_traits::halfedge_descriptor; // private - using Tree_helper = Corefinement::AABB_tree_build_helper; + using Tree_helper = AABB_tree_build_helper; using Tree = typename Tree_helper::Tree; template From a67586de26eb0355a347f926f47fc5e281a30b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 31 Aug 2026 12:19:10 +0200 Subject: [PATCH 004/136] Correct build error with CGALlab --- .../AABB_two_trees_traversal_traits.h | 2 +- .../internal/Corefinement/intersection_impl.h | 6 +- .../soup_and_face_graph_tree_helper.h | 132 ++++++++++++++++-- .../self_intersections.h | 128 ++--------------- 4 files changed, 140 insertions(+), 128 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index f17b3c8a8499..039617cb846e 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -74,7 +74,7 @@ class Two_trees_listing_intersecting_primitives_traits using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive1.id(), out); Listing_primitive_traits traits(wrap_out, m_traits2); - traits.intersection(primitive1, primitive2); + traits.intersection(internal::Primitive_helper::get_datum(primitive1, m_traits1), primitive2); } void intersection(const Primitive1& primitive1, const Node2& node2, std::size_t nb_primitives_2) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index b0cba2146004..0e8db0d47efd 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -255,7 +255,7 @@ class Intersection_of_triangle_meshes ISM2 is_shared_map_2) { using GT = typename GetGeomTraits::type; - using AABB_tree_helper = internal::AABB_tree_build_helper; + using AABB_tree_helper = internal::AABB_tree_graph_helper; using Tree = typename AABB_tree_helper::Tree; AABB_tree_helper helper; @@ -398,7 +398,7 @@ class Intersection_of_triangle_meshes const VPM& vpm) { using GT = typename GetGeomTraits::type; - using AABB_tree_helper = internal::AABB_tree_build_helper; + using AABB_tree_helper = internal::AABB_tree_graph_helper; using Tree = typename AABB_tree_helper::Tree; AABB_tree_helper helper; @@ -407,7 +407,7 @@ class Intersection_of_triangle_meshes using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh< TriangleMesh, VPM, Edge_to_faces, Coplanar_face_set>; - Callback callback(tm, tm, stm_edge_to_ltm_faces, coplanar_faces); + Callback callback(tm, vpm, stm_edge_to_ltm_faces, coplanar_faces); #ifdef CGAL_LINKED_WITH_TBB if constexpr(std::is_same_v) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 6f02526646db..7d4ba80a8929 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -15,11 +15,15 @@ #include +#include + #include #include #include +#include +#include -#include +#include #include #include #include @@ -31,7 +35,7 @@ namespace Polygon_mesh_processing { namespace internal { template -struct AABB_tree_build_helper +struct AABB_tree_graph_helper { using Primitive = AABB_face_graph_triangle_primitive; using Traits = AABB_traits_3; @@ -51,15 +55,8 @@ struct AABB_tree_build_helper PrimitiveIterator beyond, const CGAL::Bbox_3& bbox) const { - auto longest_axis=[](const CGAL::Bbox_3& bbox){ - const double dx = bbox.x_span(); - const double dy = bbox.y_span(); - const double dz = bbox.z_span(); - return (dx>=dy) ? ((dx>=dz) ? 0 : 2) : ((dy>=dz) ? 1 : 2); - }; - PrimitiveIterator middle = first + (beyond - first)/2; - const int crd=longest_axis(bbox); + const int crd = bbox.largest_span_index(); std::nth_element(first, middle, beyond, [this, crd](const Primitive& p1, const Primitive& p2){ return get(rpm, p1.id())[crd] < get(rpm, p2.id())[crd];}); } const RPM &rpm; @@ -125,6 +122,121 @@ struct AABB_tree_build_helper } }; +#ifndef DOXYGEN_RUNNING +template +struct Property_map_for_soup +{ + using VPM_base = VPM; + using key_type = std::size_t; + using value_type = typename boost::property_traits::value_type; + using category = boost::readable_property_map_tag; + using reference = typename boost::property_traits::reference; + + const PointRange& points; + VPM vpm; + + Property_map_for_soup(const PointRange& points, VPM vpm) + : points(points) + , vpm(vpm) + {} + + inline friend + reference get(const Property_map_for_soup& map, key_type k) + { + return get(map.vpm, map.points[k]); + } +}; + +template +struct AABB_tree_soup_helper +{ + using Primitive = AABB_indexed_triangle_primitive_3; + using Traits = AABB_traits_3; + using Tree = AABB_tree; + + template + struct Split_primitives + { + Split_primitives(const RPM &rpm): rpm(rpm){} + + template + void operator()(PrimitiveIterator first, + PrimitiveIterator beyond, + const CGAL::Bbox_3& bbox) const + { + PrimitiveIterator middle = first + (beyond - first)/2; + const int crd = bbox.largest_span_index(); + std::nth_element(first, middle, beyond, [this, crd](const auto& p1, const auto& p2){ return get(rpm, p1.id())[crd] < get(rpm, p2.id())[crd];}); + } + const RPM &rpm; + }; + + // For exact side_of_triangle_mesh + template + struct Compute_bbox { + Compute_bbox(const BPM& bpm): bpm(bpm){} + + template + CGAL::Bbox_3 operator()(ConstPrimitiveIterator first, + ConstPrimitiveIterator beyond) const + { + CGAL::Bbox_3 bbox = get(bpm, first->id()); + for(++first; first != beyond; ++first) + bbox += get(bpm, first->id()); + return bbox; + } + BPM bpm; + }; + + template + void build(const FaceRange &face_range, Tree& tree, const PointRange& pts, const TriangleRange& triangles, VPM vpm){ + using PM_kernel = typename Kernel_traits::value_type>::Kernel; + using Bbox_map = Pointer_property_map::type; + using Ref_point_map = Pointer_property_map::type; + + CGAL::Cartesian_converter to_input; + + tree.insert(face_range.begin(), face_range.end(), pts, triangles, vpm.vpm); + + std::vector bb_vector(triangles.size(), Bbox_3()); + std::vector rp_vector(triangles.size(), Epick::Point_3()); + Bbox_map bb_map = make_property_map(bb_vector); + Ref_point_map rp_map = make_property_map(rp_vector); + +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(std::is_same_v) + { + tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ + i = face_range[i]; + put(bb_map, i, get(vpm, triangles[i][0]).bbox() + + get(vpm, triangles[i][1]).bbox() + + get(vpm, triangles[i][2]).bbox()); + put(rp_map, i, to_input(get(vpm, triangles[i][0])) ); + }); + } + else +#endif + { + for(std::size_t i: face_range){ + put(bb_map, i, get(vpm, triangles[i][0]).bbox() + + get(vpm, triangles[i][1]).bbox() + + get(vpm, triangles[i][2]).bbox()); + put(rp_map, i, to_input(get(vpm, triangles[i][0])) ); + } + } + Compute_bbox compute_bbox(bb_map); + Split_primitives split_primitives(rp_map); + tree.template custom_build(compute_bbox, split_primitives); + } + + template + void build(Tree& tree, const PointRange& pts, const TriangleRange& triangles, VPM vpm){ + build(triangles, tree, pts, triangles, vpm); + } +}; + +#endif + } } } // CGAL::Polygon_mesh_processing::internal #endif // CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SOUP_AND_TREE_HELPER_H diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index adfa2353b1bb..055a8414083e 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -61,32 +61,6 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace internal { -#ifndef DOXYGEN_RUNNING -template -struct Property_map_for_soup -{ - using VPM_base = VPM; - using key_type = std::size_t; - using value_type = typename boost::property_traits::value_type; - using category = boost::readable_property_map_tag; - using reference = typename boost::property_traits::reference; - - const PointRange& points; - VPM vpm; - - Property_map_for_soup(const PointRange& points, VPM vpm) - : points(points) - , vpm(vpm) - {} - - inline friend - reference get(const Property_map_for_soup& map, key_type k) - { - return get(map.vpm, map.points[k]); - } -}; -#endif - template struct Triangle_mesh_and_triangle_soup_wrapper { @@ -94,7 +68,7 @@ struct Triangle_mesh_and_triangle_soup_wrapper using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; using halfedge_descriptor = typename boost::graph_traits::halfedge_descriptor; // private - using Tree_helper = AABB_tree_build_helper; + using Tree_helper = AABB_tree_graph_helper; using Tree = typename Tree_helper::Tree; template @@ -158,90 +132,17 @@ struct Triangle_mesh_and_triangle_soup_wrapper< std::pair; - using Primitive = AABB_indexed_triangle_primitive_3; - using Tree = AABB_tree>; - - template - struct Split_primitives - { - Split_primitives(const RPM &rpm): rpm(rpm){} - - template - void operator()(PrimitiveIterator first, - PrimitiveIterator beyond, - const CGAL::Bbox_3& bbox) const - { - PrimitiveIterator middle = first + (beyond - first)/2; - const int crd = bbox.largest_span_index(); - std::nth_element(first, middle, beyond, [this, crd](const auto& p1, const auto& p2){ return get(rpm, p1.id())[crd] < get(rpm, p2.id())[crd];}); - } - const RPM &rpm; - }; - - // For exact side_of_triangle_mesh - template - struct Compute_bbox { - Compute_bbox(const BPM& bpm): bpm(bpm){} - - template - CGAL::Bbox_3 operator()(ConstPrimitiveIterator first, - ConstPrimitiveIterator beyond) const - { - CGAL::Bbox_3 bbox = get(bpm, first->id()); - for(++first; first != beyond; ++first) - bbox += get(bpm, first->id()); - return bbox; - } - BPM bpm; - }; + using Tree_helper = AABB_tree_soup_helper; + using Tree = typename Tree_helper::Tree; template - static void build_tree(const FaceRange &face_range, Tree& tree, const Soup& soup, VPM vpm){ - using PM_kernel = typename Kernel_traits::value_type>::Kernel; - using Bbox_map = Pointer_property_map::type; - using Ref_point_map = Pointer_property_map::type; - - CGAL::Cartesian_converter to_input; - - const auto& points = soup.first; - const auto& triangles = soup.second; - - tree.insert(face_range.begin(), face_range.end(), points, triangles, vpm.vpm); - - std::vector bb_vector(triangles.size(), Bbox_3()); - std::vector rp_vector(triangles.size(), Epick::Point_3()); - Bbox_map bb_map = make_property_map(bb_vector); - Ref_point_map rp_map = make_property_map(rp_vector); - -#ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) - { - tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ - i = face_range[i]; - put(bb_map, i, get(vpm, triangles[i][0]).bbox() + - get(vpm, triangles[i][1]).bbox() + - get(vpm, triangles[i][2]).bbox()); - put(rp_map, i, to_input(get(vpm, triangles[i][0])) ); - }); - } - else -#endif - { - for(std::size_t i: face_range){ - put(bb_map, i, get(vpm, triangles[i][0]).bbox() + - get(vpm, triangles[i][1]).bbox() + - get(vpm, triangles[i][2]).bbox()); - put(rp_map, i, to_input(get(vpm, triangles[i][0])) ); - } - } - Compute_bbox compute_bbox(bb_map); - Split_primitives split_primitives(rp_map); - tree.template custom_build(compute_bbox, split_primitives); + static void build_tree(const FaceRange &faces, Tree& tree, const Soup& soup, VPM vpm){ + Tree_helper().template build(faces, tree, soup.first, soup.second, vpm); } template static void build_tree(Tree& tree, const Soup& soup, VPM vpm){ - build_tree(soup.second, tree, soup, vpm); + Tree_helper().template build( tree, soup.first, soup.second, vpm); } static void get_face_vertices(face_descriptor fd, std::array& vh, const Soup& soup) @@ -614,22 +515,21 @@ self_intersections_impl(const FaceRange& face_range, // This is obviously not optimal if there are no or few self-intersections: it would be a greater speed-up // to do the same as for `self_intersections()`. However, doing like `self_intersections()` would // be a major slow-down over sequential code if there are a lot of self-intersections... - using Throwing_output_iterator = boost::function_output_iterator; - Throwing_output_iterator throwing_filter; + using Throwing_output_iterator = boost::function_output_iterator; + Throwing_output_iterator throwing_filter; - AABB_tree tree; - Wrapper::template build_tree(faces_not_degenerated, tree, tmesh, vpmap); + AABB_tree tree; + Wrapper::template build_tree(faces_not_degenerated, tree, tmesh, vpmap); -#if !defined(CGAL_LINKED_WITH_TBB) - static_assert (!(std::is_convertible::value), - "Parallel_tag is enabled but TBB is unavailable."); -#else const auto all_pairs_of_intersecting_faces = [&](const AABB_tree& tree, auto out){ Listing_intersecting_faces_two_trees_traits traversal_traits(tree.traits(), gt, out, tmesh, vpmap); CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); }; - +#if !defined(CGAL_LINKED_WITH_TBB) + static_assert (!(std::is_convertible::value), + "Parallel_tag is enabled but TBB is unavailable."); +#else if(std::is_convertible::value) { // Write in a concurrent vector all pairs that intersect From b12ecda870ac580813f9b153677a4185ef1a22eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 31 Aug 2026 12:54:19 +0200 Subject: [PATCH 005/136] Use combine orientation computation to improve running time --- .../internal/Corefinement/intersection_callbacks.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h index 5a57b5297389..3694bed5ead4 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h @@ -118,8 +118,10 @@ class Collect_face_bbox_per_edge_bbox_with_coplanar_handling { Point c = get(vpmap_tmf, target(next(fh, tm_faces), tm_faces)); /// SHOULD_USE_TRAITS_TAG - const Orientation abcp = orientation(a,b,c, get(vpmap_tme, target(eh, tm_edges))); - const Orientation abcq = orientation(a,b,c, get(vpmap_tme, source(eh, tm_edges))); + using K = typename Kernel_traits>::Kernel; + auto orientation = K().orientation_3_object(); + const auto [abcp,abcq] = orientation(a,b,c, get(vpmap_tme, target(eh, tm_edges)), get(vpmap_tme, source(eh, tm_edges))); + if (abcp==abcq){ if (abcp!=COPLANAR){ return; //no intersection From 3afc0936904f4300986e8ae9b32203bb7c32c474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 31 Aug 2026 14:58:54 +0200 Subject: [PATCH 006/136] Simple parallellization of conncted components in corefinement --- .../Corefinement/Face_graph_output_builder.h | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index b2f52abd152e..a39f51f16506 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -1078,32 +1078,50 @@ class Face_graph_output_builder // (1) Assign a patch id to each facet indicating in which connected // component limited by intersection edges of the surface they are. - // ... for tm1 - std::vector tm1_patch_ids( num_faces(tm1),NID ); - Border_edge_map is_marked_1(intersection_edges1, tm1); - std::size_t nb_patches_tm1 = - connected_components(tm1, - make_compose_property_map(fids1,make_property_map(&tm1_patch_ids[0])), - parameters::edge_is_constrained_map(is_marked_1) - .face_index_map(fids1)); - - std::vector tm1_patch_sizes(nb_patches_tm1, 0); - for(std::size_t i : tm1_patch_ids) - if(i!=NID) - ++tm1_patch_sizes[i]; - // ... for tm2 - std::vector tm2_patch_ids( num_faces(tm2),NID ); - Border_edge_map is_marked_2(intersection_edges2, tm2); - std::size_t nb_patches_tm2 = - connected_components(tm2, - make_compose_property_map(fids2,make_property_map(&tm2_patch_ids[0])), - parameters::edge_is_constrained_map(is_marked_2) - .face_index_map(fids2)); - - std::vector tm2_patch_sizes(nb_patches_tm2, 0); - for(Node_id i : tm2_patch_ids) - if(i!=NID) - ++tm2_patch_sizes[i]; + std::vector tm1_patch_sizes, tm2_patch_sizes; + std::size_t nb_patches_tm1, nb_patches_tm2; + auto connected_components_1=[&]() + { + // ... for tm1 + std::vector tm1_patch_ids( num_faces(tm1),NID ); + Border_edge_map is_marked_1(intersection_edges1, tm1); + nb_patches_tm1 = connected_components(tm1, + make_compose_property_map(fids1,make_property_map(&tm1_patch_ids[0])), + parameters::edge_is_constrained_map(is_marked_1) + .face_index_map(fids1)); + + tm1_patch_sizes.resize(nb_patches_tm1, 0); + for(std::size_t i : tm1_patch_ids) + if(i!=NID) + ++tm1_patch_sizes[i]; + }; + + auto connected_components_2=[&]() + { + // ... for tm2 + std::vector tm2_patch_ids( num_faces(tm2),NID ); + Border_edge_map is_marked_2(intersection_edges2, tm2); + nb_patches_tm2 = connected_components(tm2, + make_compose_property_map(fids2,make_property_map(&tm2_patch_ids[0])), + parameters::edge_is_constrained_map(is_marked_2) + .face_index_map(fids2)); + + tm2_patch_sizes.resize(nb_patches_tm2, 0); + for(Node_id i : tm2_patch_ids) + if(i!=NID) + ++tm2_patch_sizes[i]; + }; +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(std::is_same_v) + { + tbb::parallel_invoke(connected_components_1, connected_components_2); + } + else +#endif + { + connected_components_1(); + connected_components_2(); + } #ifdef CGAL_COREFINEMENT_DEBUG std::cout << "nb_patches_tm1 = " << nb_patches_tm1 << "\n"; From 03e7749e0fb151067662532b37bcc220bb828d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 31 Aug 2026 15:33:59 +0200 Subject: [PATCH 007/136] add ConcurrencyTag to face_graph_output_builder --- .../include/CGAL/Polygon_mesh_processing/corefinement.h | 3 ++- .../internal/Corefinement/Face_graph_output_builder.h | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h index 27441dc2b5b9..d4dc7d7a8d8f 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h @@ -480,7 +480,8 @@ corefine_and_compute_boolean_operations( Default, Ecm_in, Edge_mark_map_tuple, - User_visitor> Ob; + User_visitor, + ConcurrencyTag> Ob; typedef Corefinement::Surface_intersection_visitor_for_corefinement< TriangleMesh, VPM1, VPM2, Ob, Ecm_in, User_visitor> Algo_visitor; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index a39f51f16506..3d00f58a1777 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -467,7 +467,8 @@ template + class UserVisitor_ = Default, + class ConcurrencyTag = Sequential_tag> class Face_graph_output_builder { //Default typedefs @@ -1078,12 +1079,13 @@ class Face_graph_output_builder // (1) Assign a patch id to each facet indicating in which connected // component limited by intersection edges of the surface they are. + std::vector tm1_patch_ids( num_faces(tm1),NID ); + std::vector tm2_patch_ids( num_faces(tm2),NID ); std::vector tm1_patch_sizes, tm2_patch_sizes; std::size_t nb_patches_tm1, nb_patches_tm2; auto connected_components_1=[&]() { // ... for tm1 - std::vector tm1_patch_ids( num_faces(tm1),NID ); Border_edge_map is_marked_1(intersection_edges1, tm1); nb_patches_tm1 = connected_components(tm1, make_compose_property_map(fids1,make_property_map(&tm1_patch_ids[0])), @@ -1099,7 +1101,6 @@ class Face_graph_output_builder auto connected_components_2=[&]() { // ... for tm2 - std::vector tm2_patch_ids( num_faces(tm2),NID ); Border_edge_map is_marked_2(intersection_edges2, tm2); nb_patches_tm2 = connected_components(tm2, make_compose_property_map(fids2,make_property_map(&tm2_patch_ids[0])), @@ -1111,6 +1112,7 @@ class Face_graph_output_builder if(i!=NID) ++tm2_patch_sizes[i]; }; + #ifdef CGAL_LINKED_WITH_TBB if constexpr(std::is_same_v) { From ae886f2dd41e25bab6f59df407551b2817f0a6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 31 Aug 2026 16:01:40 +0200 Subject: [PATCH 008/136] Clean import polyline and fill tm2_to_output_vertices --- .../internal/Corefinement/face_graph_utils.h | 61 ++++++++----------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index e8860b8c6d35..70ac815f3cd5 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -894,6 +894,15 @@ void import_polyline( output_shared_edges.push_back(add_edge(output)); halfedge_descriptor h_out = halfedge(output_shared_edges.back(),output); + auto set_output_vertex = [&](vertex_descriptor v, halfedge_descriptor h_out){ + user_visitor.before_vertex_copy(v, pm1, output); + vertex_descriptor new_v = add_vertex(output); + set_halfedge(new_v, opposite(h_out, output),output); + put(vpm_out, new_v, get(vpm1, v)); + user_visitor.after_vertex_copy(v, pm1, new_v, output); + return new_v; + }; + //make sure the first vertex does not already exist vertex_descriptor src = GT::null_vertex(); std::pair< typename VertexMap::iterator, bool > insert_res= @@ -901,12 +910,9 @@ void import_polyline( if( insert_res.second ) { - user_visitor.before_vertex_copy(source(h1,pm1), pm1, output); - src = add_vertex(output); - set_halfedge(src, opposite(h_out,output),output); - put(vpm_out, src, get(vpm1, source(h1,pm1))); - user_visitor.after_vertex_copy(source(h1,pm1), pm1, src, output); + src = set_output_vertex(source(h1, pm1), h_out); insert_res.first->second = src; + pm2_to_output_vertices.insert(std::make_pair(source(h2, pm2), src)); } else src = insert_res.first->second; @@ -915,26 +921,20 @@ void import_polyline( vertex_descriptor tgt=GT::null_vertex(); if ( nb_segments==1 ) { - insert_res = - pm1_to_output_vertices.insert( std::make_pair( target(h1,pm1), tgt ) ); + insert_res = pm1_to_output_vertices.insert( std::make_pair( target(h1,pm1), tgt ) ); if( insert_res.second ) { - user_visitor.before_vertex_copy(target(h1,pm1), pm1, output); - tgt = add_vertex(output); - set_halfedge(tgt, h_out, output); - put(vpm_out, tgt, get(vpm1, target(h1,pm1))); - user_visitor.after_vertex_copy(target(h1,pm1), pm1, tgt, output); + tgt = set_output_vertex(target(h1, pm1), h_out); insert_res.first->second = tgt; + pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); } else tgt = insert_res.first->second; } - else{ - user_visitor.before_vertex_copy(target(h1,pm1), pm1, output); - tgt = add_vertex(output); - set_halfedge(tgt, h_out, output); - put(vpm_out, tgt, get(vpm1, target(h1,pm1))); - user_visitor.after_vertex_copy(target(h1,pm1), pm1, tgt, output); + else + { + tgt = set_output_vertex(target(h1, pm1), h_out); + pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); } //update source and target vertex of the edge created @@ -946,10 +946,8 @@ void import_polyline( halfedge_descriptor prev2=h2; //set the correspondence - pm1_to_output_edges.insert( - std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); - pm2_to_output_edges.insert( - std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); + pm1_to_output_edges.insert( std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); + pm2_to_output_edges.insert( std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); user_visitor.intersection_edge_copy(prev1, pm1, prev2, pm2, h_out, output); @@ -968,23 +966,14 @@ void import_polyline( //if this is the final segment, only create a target vertex if it does not exist if (i+1!=nb_segments) { - user_visitor.before_vertex_copy(target(h1,pm1), pm1, output); - tgt=add_vertex(output); - set_halfedge(tgt, h_out, output); - put(vpm_out, tgt, get(vpm1, target(h1,pm1))); - user_visitor.after_vertex_copy(target(h1,pm1), pm1, tgt, output); + tgt = set_output_vertex(target(h1, pm1), h_out); } else{ std::pair< typename VertexMap::iterator, bool > insert_res = pm1_to_output_vertices.insert(std::make_pair(target(h1,pm1), tgt)); if (insert_res.second) { - user_visitor.before_vertex_copy(target(h1,pm1), pm1, output); - tgt=add_vertex(output); - set_halfedge(tgt, h_out, output); - put(vpm_out, tgt, get(vpm1, target(h1,pm1))); - insert_res.first->second = tgt; - user_visitor.after_vertex_copy(target(h1,pm1), pm1, tgt, output); + tgt = set_output_vertex(target(h1, pm1), h_out); } else tgt = insert_res.first->second; @@ -998,10 +987,8 @@ void import_polyline( prev2 = h2; src = tgt; - pm1_to_output_edges.insert( - std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); - pm2_to_output_edges.insert( - std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); + pm1_to_output_edges.insert( std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); + pm2_to_output_edges.insert( std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); } } From a87f92f9cb8b529ee569b1ad35355d81fe80ef6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 2 Sep 2026 16:26:13 +0200 Subject: [PATCH 009/136] Clean unused lines --- .../internal/Corefinement/face_graph_utils.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 70ac815f3cd5..818796d9120e 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -912,7 +912,6 @@ void import_polyline( { src = set_output_vertex(source(h1, pm1), h_out); insert_res.first->second = src; - pm2_to_output_vertices.insert(std::make_pair(source(h2, pm2), src)); } else src = insert_res.first->second; @@ -926,7 +925,6 @@ void import_polyline( { tgt = set_output_vertex(target(h1, pm1), h_out); insert_res.first->second = tgt; - pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); } else tgt = insert_res.first->second; @@ -934,7 +932,6 @@ void import_polyline( else { tgt = set_output_vertex(target(h1, pm1), h_out); - pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); } //update source and target vertex of the edge created From 94951c7165685dfd675786639749cc09e81a57d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 2 Sep 2026 18:18:27 +0200 Subject: [PATCH 010/136] interior_vertices of patch is now a vector (instead of a set) and all corresponding modifications to maintain a valid output --- .../corefinement_mesh_union_progress.cpp | 1 + .../Corefinement/Face_graph_output_builder.h | 23 +- .../internal/Corefinement/face_graph_utils.h | 286 +++++++++++------- 3 files changed, 190 insertions(+), 120 deletions(-) diff --git a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp index 381ccf7047b4..71707c1457d5 100644 --- a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp +++ b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp @@ -203,6 +203,7 @@ int main(int argc, char* argv[]) Visitor visitor; bool valid_union = PMP::corefine_and_compute_union (mesh1,mesh2, out, CGAL::parameters::visitor(visitor).concurrency_tag(CGAL::Parallel_if_available_tag())); + // bool valid_union = PMP::corefine_and_compute_union (mesh1,mesh2, out, CGAL::parameters::visitor(visitor)); std::cout << "Global timer = " << t.time() << " sec." << std::endl; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index 3d00f58a1777..f64907ee2b3e 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -516,6 +516,8 @@ class Face_graph_output_builder typedef std::unordered_map Node_id_map; typedef std::unordered_map Edge_map; + typedef std::unordered_map Vertex_map; //Data members TriangleMesh &tm1, &tm2; // property maps of input meshes @@ -2404,6 +2406,7 @@ class Face_graph_output_builder } Edge_map disconnected_patches_edge_to_tm2_edge; + Vertex_map disconnected_patches_vertex_to_tm2_vertex; /// handle the operations updating tm1 and/or tm2 if ( inplace_operation_tm1!=NONE ) @@ -2482,6 +2485,7 @@ class Face_graph_output_builder marks_on_input_edges.ecm2, \ std::get(out_edge_mark_maps), \ disconnected_patches_edge_to_tm2_edge, \ + disconnected_patches_vertex_to_tm2_vertex, \ user_visitor) CGAL_COREF_FUNCTION_CALL(inplace_operation_tm1) #undef CGAL_COREF_FUNCTION_CALL_DEF @@ -2501,6 +2505,7 @@ class Face_graph_output_builder marks_on_input_edges.ecm1, \ std::get(out_edge_mark_maps), \ disconnected_patches_edge_to_tm2_edge, \ + disconnected_patches_vertex_to_tm2_vertex, \ user_visitor) CGAL_COREF_FUNCTION_CALL(inplace_operation_tm2) #undef CGAL_COREF_FUNCTION_CALL_DEF @@ -2571,6 +2576,7 @@ class Face_graph_output_builder } if (!to_rm.empty()) { + // Here there are an assumption that edges in to_rm are necessarly the last of shared edges std::reverse(to_rm.begin(), to_rm.end()); for(Hedge_iterator it : to_rm) { @@ -2579,6 +2585,7 @@ class Face_graph_output_builder std::swap(patches_of_tm1[i].shared_edges.back(), *it); patches_of_tm1[i].shared_edges.pop_back(); } + //now update interior vertices std::set border_vertices; for(halfedge_descriptor h : patches_of_tm1[i].shared_edges) @@ -2587,13 +2594,15 @@ class Face_graph_output_builder border_vertices.insert( source(h,tm1) ); } + std::set vertices_to_add; for(halfedge_descriptor h : patches_of_tm1[i].interior_edges) { if ( !border_vertices.count( target(h,tm1) ) ) - patches_of_tm1[i].interior_vertices.insert( target(h,tm1) ); + vertices_to_add.insert(target(h, tm1)); if ( !border_vertices.count( source(h,tm1) ) ) - patches_of_tm1[i].interior_vertices.insert( source(h,tm1) ); + vertices_to_add.insert(source(h, tm1)); } + patches_of_tm1[i].interior_vertices.insert(patches_of_tm1[i].interior_vertices.end(), vertices_to_add.begin(), vertices_to_add.end() ); } } @@ -2618,8 +2627,14 @@ class Face_graph_output_builder if (all_removed) id_p_rm.erase(id_p_rm.begin()); // remove the vertex from the interior vertices of patches to be removed - for(std::size_t pid : id_p_rm) - patches_of_tm1[pid].interior_vertices.erase(vd); + for(std::size_t pid : id_p_rm){ + auto it = std::find( patches_of_tm1[pid].interior_vertices.begin(), + patches_of_tm1[pid].interior_vertices.end(), + vd); // Linear time, expensive + if (it!=std::prev(patches_of_tm1[pid].interior_vertices.end())) + std::swap(*it, patches_of_tm1[pid].interior_vertices.back()); + patches_of_tm1[pid].interior_vertices.pop_back(); + } // we now need to update the next/prev relationship induced by the future removal of patches // that will not be updated after patch removal diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 818796d9120e..c35fa1a31d38 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -670,9 +670,15 @@ struct Patch_description{ typedef typename GT::vertex_descriptor vertex_descriptor; std::vector faces; - std::set interior_vertices; + std::vector interior_vertices; std::vector interior_edges; std::vector shared_edges; + + // Three sets used only for patch with borders not shared, their are empty if not + std::set border_edges; + std::set border_with_shared_target; + std::set border_with_shared_source; + bool is_initialized; Patch_description(): is_initialized(false) {}; @@ -684,10 +690,7 @@ struct Patch_description{ template void extract_patch_simplices( PolygonMesh& pm, - std::vector::face_descriptor>& patch_faces, - std::set::vertex_descriptor>& interior_vertices, - std::vector::halfedge_descriptor>& interior_edges, - std::vector::halfedge_descriptor>& shared_edges, + Patch_description& patch, const IsIntersectionEdge& is_intersection_edge) { typedef boost::graph_traits GT; @@ -695,35 +698,49 @@ void extract_patch_simplices( typedef typename GT::vertex_descriptor vertex_descriptor; typedef typename GT::face_descriptor face_descriptor; - for(face_descriptor f : patch_faces) - { - for(halfedge_descriptor h : - halfedges_around_face(halfedge(f, pm),pm)) - { + for(face_descriptor f : patch.faces) { + for(halfedge_descriptor h : halfedges_around_face(halfedge(f, pm),pm)) { if ( !is_intersection_edge.count(edge(h, pm)) ) { - if ( h < opposite(h,pm) || is_border(opposite(h,pm),pm) ) - interior_edges.push_back( h ); + halfedge_descriptor h_opp = opposite(h, pm); + if(is_border(h_opp,pm)){ + patch.border_edges.insert(h_opp); + patch.interior_edges.push_back(h); + } + else if ( h < h_opp) + patch.interior_edges.push_back(h); } else - shared_edges.push_back(h); + patch.shared_edges.push_back(h); } } std::set border_vertices; - for(halfedge_descriptor h : shared_edges) - { + for(halfedge_descriptor h : patch.shared_edges){ border_vertices.insert( target(h,pm) ); // if the model is not closed i.e. patch_border_halfedge is not cycle-only - border_vertices.insert( source(h,pm) ); + if(!patch.interior_edges.empty()) + border_vertices.insert( source(h,pm) ); } - for(halfedge_descriptor h : interior_edges) - { - if ( !border_vertices.count( target(h,pm) ) ) - interior_vertices.insert( target(h,pm) ); - if ( !border_vertices.count( source(h,pm) ) ) - interior_vertices.insert( source(h,pm) ); + // a patch is a disk v = 2 + e - f + // v_in = v - v_border, e = e_in + e_shared, v_border = e_shared ( +1 if not closed) + // v_in = 2 + e_in - f (-1 if not closed) + patch.interior_vertices.reserve(2 + patch.interior_edges.size() - patch.faces.size() ); + for(halfedge_descriptor h : patch.interior_edges){ + if ( !border_vertices.count( target(h,pm) ) && + halfedge(target(h,pm),pm) == h ) // only add the vertex once + patch.interior_vertices.push_back( target(h,pm) ); + if ( !border_vertices.count( source(h,pm) ) && + halfedge(source(h,pm),pm) == opposite(h,pm) ) // only add the vertex once + patch.interior_vertices.push_back( source(h,pm) ); + } + + for(halfedge_descriptor h : patch.border_edges){ + if ( border_vertices.count( target(h,pm) ) ) + patch.border_with_shared_target.emplace(h); + if ( border_vertices.count( source(h,pm) ) ) + patch.border_with_shared_source.emplace(h); } } @@ -759,13 +776,7 @@ struct Patch_container{ Patch_description& operator[](std::size_t i) { if ( !patches[i].is_initialized ) { - extract_patch_simplices( - pm, - patches[i].faces, patches[i].interior_vertices, - patches[i].interior_edges, patches[i].shared_edges, - is_intersection_edge - ); - + extract_patch_simplices(pm, patches[i], is_intersection_edge); patches[i].is_initialized=true; } return patches[i]; @@ -878,6 +889,7 @@ void import_polyline( EdgeMap& pm1_to_output_edges, EdgeMap& pm2_to_output_edges, VertexMap& pm1_to_output_vertices, + VertexMap& pm2_to_output_vertices, const IntersectionEdgeMap& intersection_edges1, const IntersectionEdgeMap& intersection_edges2, const VertexPointMap1& vpm1, @@ -912,6 +924,7 @@ void import_polyline( { src = set_output_vertex(source(h1, pm1), h_out); insert_res.first->second = src; + pm2_to_output_vertices.insert( std::make_pair( source(h2,pm2), src ) ); } else src = insert_res.first->second; @@ -925,6 +938,7 @@ void import_polyline( { tgt = set_output_vertex(target(h1, pm1), h_out); insert_res.first->second = tgt; + pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); } else tgt = insert_res.first->second; @@ -932,6 +946,10 @@ void import_polyline( else { tgt = set_output_vertex(target(h1, pm1), h_out); + CGAL_assertion( pm1_to_output_vertices.count(target(h1,pm1))==0 ); + CGAL_assertion( pm2_to_output_vertices.count(target(h2,pm2))==0 ); + pm1_to_output_vertices.insert( std::make_pair( target(h1,pm1), tgt ) ); + pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); } //update source and target vertex of the edge created @@ -964,6 +982,8 @@ void import_polyline( if (i+1!=nb_segments) { tgt = set_output_vertex(target(h1, pm1), h_out); + pm1_to_output_vertices.insert( std::make_pair( target(h1,pm1), tgt ) ); + pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); } else{ std::pair< typename VertexMap::iterator, bool > insert_res = @@ -971,6 +991,7 @@ void import_polyline( if (insert_res.second) { tgt = set_output_vertex(target(h1, pm1), h_out); + pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); } else tgt = insert_res.first->second; @@ -987,6 +1008,8 @@ void import_polyline( pm1_to_output_edges.insert( std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); pm2_to_output_edges.insert( std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); } + CGAL_assertion( pm1_to_output_edges.size() == pm2_to_output_edges.size() ); + CGAL_assertion( pm1_to_output_vertices.size() == pm2_to_output_vertices.size() ); } template @@ -1095,6 +1118,10 @@ void append_patches_to_triangle_mesh( typename boost::graph_traits::edge_descriptor, typename boost::graph_traits::edge_descriptor >& tm_to_output_edges, + std::unordered_map< + typename boost::graph_traits::vertex_descriptor, + typename boost::graph_traits::vertex_descriptor + >& tm_to_output_vertices, UserVisitor& user_visitor) { typedef boost::graph_traits GT; @@ -1104,8 +1131,7 @@ void append_patches_to_triangle_mesh( typedef typename GT::face_descriptor face_descriptor; const TriangleMesh& tm = patches.pm; - Triangle_mesh_extension_helper - helper(tm_to_output_edges, tm, output); + Triangle_mesh_extension_helper helper(tm_to_output_edges, tm, output); std::vector ids_of_patches_to_append; ids_of_patches_to_append.reserve(patches_to_append.count()); @@ -1128,7 +1154,18 @@ void append_patches_to_triangle_mesh( Patch_description& patch = patches[i]; - //insert interior halfedges and create interior vertices + // copy the vertices in the output without connecting them + for(vertex_descriptor v: patch.interior_vertices) + { + vertex_descriptor new_v = add_vertex(output); + set_halfedge(new_v, GT::null_halfedge(), output); + + auto res = tm_to_output_vertices.insert( std::make_pair( v, new_v ) ); + CGAL_assertion(res.second); // should be inserted, not already present + put(vpm_out, new_v, get(vpm_tm, v)); + } + + // insert interior halfedges and connect vertices for(halfedge_descriptor h : patch.interior_edges) { user_visitor.before_edge_copy(h, tm, output); @@ -1149,28 +1186,32 @@ void append_patches_to_triangle_mesh( CGAL_assertion(is_border(opposite(new_h,output), output)); //create a copy of interior vertices only once - if ( halfedge(target(h,tm),tm)==h && - patch.interior_vertices.count(target(h, tm)) ) - { - user_visitor.before_vertex_copy(target(h,tm), tm, output); - vertex_descriptor v = add_vertex(output); - set_halfedge(v, new_h, output); - set_target(new_h, v, output); - put(vpm_out, v, get(vpm_tm, target(h, tm) ) ); - user_visitor.after_vertex_copy(target(h,tm), tm, v, output); + auto fill_vertex = [&](vertex_descriptor v, vertex_descriptor new_v, halfedge_descriptor new_h){ + user_visitor.before_vertex_copy(v, tm, output); + set_halfedge(new_v, new_h, output); + user_visitor.after_vertex_copy(v, tm, new_v, output); interior_vertex_halfedges.push_back( new_h ); + }; + + vertex_descriptor tgt = target(h, tm); + vertex_descriptor new_tgt = tm_to_output_vertices[tgt]; + CGAL_assertion( new_tgt != GT::null_vertex() ); + set_target(new_h, new_tgt, output); + if ( halfedge(tgt,tm)==h && + halfedge(new_tgt, output) == GT::null_halfedge()) + { + fill_vertex(tgt, new_tgt, new_h); } - if ( halfedge(source(h,tm),tm)==opposite(h,tm) && - patch.interior_vertices.count(source(h,tm)) ) + + vertex_descriptor src = source(h, tm); + vertex_descriptor new_src = tm_to_output_vertices[src]; + CGAL_assertion( new_src != GT::null_vertex() ); + halfedge_descriptor new_h_opp = opposite(new_h, output); + set_target(new_h_opp, new_src, output); + if ( halfedge(src,tm)==opposite(h, tm) && + halfedge(new_src, output) == GT::null_halfedge()) { - user_visitor.before_vertex_copy(source(h,tm), tm, output); - vertex_descriptor v = add_vertex(output); - halfedge_descriptor new_h_opp = opposite(new_h, output); - set_halfedge(v, new_h_opp, output); - set_target(new_h_opp, v, output); - put(vpm_out, v, get(vpm_tm, source(h, tm) ) ); - user_visitor.after_vertex_copy(source(h,tm), tm, v, output); - interior_vertex_halfedges.push_back( new_h_opp ); + fill_vertex(src, new_src, new_h_opp); } } } @@ -1214,32 +1255,32 @@ void append_patches_to_triangle_mesh( for (std::size_t i : ids_of_patches_to_append) { Patch_description& patch = patches[i]; - for(halfedge_descriptor h : patch.interior_edges) - if (is_border_edge(h,tm)) - { - if (!is_border(h, tm)) h=opposite(h, tm); - - vertex_descriptor src = source(h, tm); - vertex_descriptor tgt = target(h, tm); - if (reverse_patch_orientation) std::swap(src, tgt); - - if ( !patch.interior_vertices.count(src) ) - border_halfedges_source_to_link.push_back(helper.get_hedge(h)); - if ( !patch.interior_vertices.count(tgt) ){ - border_halfedges_target_to_link.push_back(helper.get_hedge(h)); - continue; // since the next halfedge should not be in the same patch - } - CGAL_assertion( is_border(h, tm) && - is_border(prev(h, tm),tm) && - is_border(next(h, tm),tm)); - // step (i) - halfedge_descriptor h_out=helper.get_hedge(h); - halfedge_descriptor h_out_next = reverse_patch_orientation - ? helper.get_hedge(prev(h,tm)) - : helper.get_hedge(next(h,tm)); - CGAL_assertion(is_border(h_out,output) && is_border(h_out_next,output)); - set_next(h_out, h_out_next, output); - } + for(halfedge_descriptor h : patch.border_edges){ + if( (!reverse_patch_orientation && patch.border_with_shared_target.count(h)) || + ( reverse_patch_orientation && patch.border_with_shared_source.count(h)) ) + continue; // since the next halfedge should not be in the same patch + halfedge_descriptor h_out=helper.get_hedge(h); + halfedge_descriptor h_out_next = reverse_patch_orientation + ? helper.get_hedge(prev(h,tm)) + : helper.get_hedge(next(h,tm)); + CGAL_assertion(is_border(h_out,output) && is_border(h_out_next,output)); + set_next(h_out, h_out_next, output); + } + if(reverse_patch_orientation){ + border_halfedges_target_to_link.insert(border_halfedges_target_to_link.begin(), + patch.border_with_shared_source.begin(), + patch.border_with_shared_source.end()); + border_halfedges_source_to_link.insert(border_halfedges_target_to_link.begin(), + patch.border_with_shared_target.begin(), + patch.border_with_shared_target.end()); + } else { + border_halfedges_target_to_link.insert(border_halfedges_target_to_link.begin(), + patch.border_with_shared_target.begin(), + patch.border_with_shared_target.end()); + border_halfedges_source_to_link.insert(border_halfedges_target_to_link.begin(), + patch.border_with_shared_source.begin(), + patch.border_with_shared_source.end()); + } } // now the step (ii) we look for the candidate halfedge by turning around @@ -1265,19 +1306,6 @@ void append_patches_to_triangle_mesh( set_next(candidate, h_out, output); } - // For all interior vertices, update the vertex pointer - // of all but the vertex halfedge - for(halfedge_descriptor h_out : interior_vertex_halfedges) - { - vertex_descriptor v = target(h_out, output); - halfedge_descriptor next_around_vertex=h_out; - do{ - CGAL_assertion(next(next_around_vertex, output) != GT::null_halfedge()); - next_around_vertex=opposite(next(next_around_vertex, output), output); - set_target(next_around_vertex, v, output); - }while(h_out != next_around_vertex); - } - for (std::size_t i : ids_of_patches_to_append) { Patch_description& patch = patches[i]; @@ -1355,9 +1383,10 @@ void fill_new_triangle_mesh( //add a polyline inside O for each intersection polyline std::size_t nb_polylines = polylines.lengths.size(); - std::unordered_map tm1_to_output_vertices; + std::unordered_map tm1_to_output_vertices, + tm2_to_output_vertices; std::unordered_map tm1_to_output_edges, - tm2_to_output_edges; + tm2_to_output_edges; for (std::size_t i=0; i < nb_polylines; ++i) if (!polylines.to_skip.test(i)) @@ -1367,7 +1396,7 @@ void fill_new_triangle_mesh( patches_of_tm2.pm, polylines.lengths[i], tm1_to_output_edges, tm2_to_output_edges, - tm1_to_output_vertices, + tm1_to_output_vertices, tm2_to_output_vertices, intersection_edges1, intersection_edges2, vpm1, vpm2, vpm_out, output_shared_edges, @@ -1383,6 +1412,7 @@ void fill_new_triangle_mesh( edge_mark_map_out, edge_mark_map1, tm1_to_output_edges, + tm1_to_output_vertices, user_visitor); else append_patches_to_triangle_mesh(output, @@ -1393,6 +1423,7 @@ void fill_new_triangle_mesh( edge_mark_map_out, edge_mark_map1, tm1_to_output_edges, + tm1_to_output_vertices, user_visitor); //import patches from tm2 @@ -1405,6 +1436,7 @@ void fill_new_triangle_mesh( edge_mark_map_out, edge_mark_map2, tm2_to_output_edges, + tm2_to_output_vertices, user_visitor); else append_patches_to_triangle_mesh(output, @@ -1415,6 +1447,7 @@ void fill_new_triangle_mesh( edge_mark_map_out, edge_mark_map2, tm2_to_output_edges, + tm2_to_output_vertices, user_visitor); } @@ -1576,6 +1609,7 @@ template GT; + typedef typename GT::vertex_descriptor vertex_descriptor; typedef typename GT::edge_descriptor edge_descriptor; typedef typename GT::halfedge_descriptor halfedge_descriptor; typedef std::unordered_map Edge_map; + typedef std::unordered_map Vertex_map; Edge_map tm2_edge_to_tm1_edge, tm1_edge_to_tm2_edge; + Vertex_map tm2_vertex_to_tm1_vertex; //maps intersection edges from tm2 to tm1 std::size_t nb_polylines = polylines.lengths.size(); for(std::size_t i=0; i(tm1, @@ -1658,6 +1699,7 @@ void compute_inplace_operation_delay_removal_and_insideout( edge_mark_map_out1, edge_mark_map2, tm2_edge_to_tm1_edge, + tm2_vertex_to_tm1_vertex, user_visitor); } @@ -1704,24 +1746,19 @@ remove_patches(TriangleMesh& tm, // prev pointer set correctly. To fix that, we consider all interior edges // and check for one that is on the border of the patch and that is incident // to a border vertex and use it to get the missing prev pointer. - for(halfedge_descriptor h : patch.interior_edges) - if(is_border_edge(h, tm)) - { - if (is_border(h, tm)) h=opposite(h, tm); - if ( !patch.interior_vertices.count(target(h, tm)) ) - { - // look for the halfedge belonging to shared_edges - // having the prev pointer not correctly set - halfedge_descriptor nxt=next(h, tm); - while(!is_border(nxt, tm)) - nxt=next(opposite(nxt, tm), tm); - CGAL_assertion( is_border(nxt, tm) );//we marked it above! - // now update the prev pointer - halfedge_descriptor prv=prev(opposite(h, tm), tm); - set_next(prv, nxt, tm); - set_halfedge(target(prv, tm), prv, tm); - } - } + for(halfedge_descriptor h : patch.border_with_shared_target) + { + // look for the halfedge belonging to shared_edges + // having the prev pointer not correctly set + halfedge_descriptor nxt=next(h, tm); + while(!is_border(nxt, tm)) + nxt=next(opposite(nxt, tm), tm); + CGAL_assertion( is_border(nxt, tm) );//we marked it above! + // now update the prev pointer + halfedge_descriptor prv=prev(opposite(h, tm), tm); + set_next(prv, nxt, tm); + set_halfedge(target(prv, tm), prv, tm); + } //now remove the simplices for(halfedge_descriptor h : patch.interior_edges) @@ -1760,11 +1797,18 @@ void compute_inplace_operation( typename boost::graph_traits::edge_descriptor, typename boost::graph_traits::edge_descriptor >& tm2_edge_to_tm1_edge, + std::unordered_map< + typename boost::graph_traits::vertex_descriptor, + typename boost::graph_traits::vertex_descriptor + >& tm2_vertex_to_tm1_vertex, UserVisitor& user_visitor) { typedef std::unordered_map< typename boost::graph_traits::edge_descriptor, typename boost::graph_traits::edge_descriptor> EdgeMap; + typedef std::unordered_map< + typename boost::graph_traits::vertex_descriptor, + typename boost::graph_traits::vertex_descriptor> VertexMap; //clean up patches not kept remove_patches(tm1, ~patches_of_tm1_to_keep, patches_of_tm1, edge_mark_map_in1); @@ -1789,6 +1833,7 @@ void compute_inplace_operation( edge_mark_map_out1, edge_mark_map_in2, tm2_edge_to_tm1_edge, + tm2_vertex_to_tm1_vertex, user_visitor); else append_patches_to_triangle_mesh(tm1, @@ -1799,6 +1844,7 @@ void compute_inplace_operation( edge_mark_map_out1, edge_mark_map_in2, tm2_edge_to_tm1_edge, + tm2_vertex_to_tm1_vertex, user_visitor); } @@ -1806,14 +1852,16 @@ template + class EdgeMap, + class VertexMap> void compute_border_edge_map( const TriangleMesh& tm1, const TriangleMesh& tm2, const IntersectionPolylines& polylines, PatchContainer1& patches_of_tm1, PatchContainer2& patches_of_tm2, - EdgeMap& tm2_edge_to_tm1_edge) + EdgeMap& tm2_edge_to_tm1_edge, + VertexMap& tm2_vertex_to_tm1_vertex) { typedef boost::graph_traits GT; typedef typename GT::halfedge_descriptor halfedge_descriptor; @@ -1829,6 +1877,8 @@ void compute_border_edge_map( for (std::size_t k=0;;) { tm2_edge_to_tm1_edge[edge(h2, tm2)]=edge(h1, tm1); + tm2_vertex_to_tm1_vertex[target(h2, tm2)]=target(h1, tm1); + tm2_vertex_to_tm1_vertex[source(h2, tm2)]=source(h1, tm1); if (++k==nb_segments) break; h2 = next_marked_halfedge_around_target_vertex( h2, tm2, patches_of_tm2.is_intersection_edge); @@ -1868,14 +1918,17 @@ void compute_inplace_operation( { typedef boost::graph_traits GT; typedef typename GT::edge_descriptor edge_descriptor; + typedef typename GT::vertex_descriptor vertex_descriptor; std::unordered_map tm2_edge_to_tm1_edge; + std::unordered_map tm2_vertex_to_tm1_vertex; //maps intersection edges from tm2 to the equivalent in tm1 compute_border_edge_map(tm1, tm2, polylines, patches_of_tm1, patches_of_tm2, - tm2_edge_to_tm1_edge); + tm2_edge_to_tm1_edge, + tm2_vertex_to_tm1_vertex); compute_inplace_operation(tm1, tm2, patches_of_tm1_to_keep, patches_of_tm2_to_import, @@ -1888,6 +1941,7 @@ void compute_inplace_operation( edge_mark_map_in2, edge_mark_map_out1, tm2_edge_to_tm1_edge, + tm2_vertex_to_tm1_vertex, user_visitor); } From 300e1995a3230f0a9d058392bb0917e705e915b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 4 Sep 2026 15:22:18 +0200 Subject: [PATCH 011/136] Replace unordered_map per property_map --- .../Corefinement/Face_graph_output_builder.h | 28 +- .../internal/Corefinement/face_graph_utils.h | 250 +++++++++--------- 2 files changed, 148 insertions(+), 130 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index f64907ee2b3e..c5f72745f495 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -494,12 +495,12 @@ class Face_graph_output_builder static constexpr bool has_soup_visitor = HSV::value; // graph_traits typedefs - typedef TriangleMesh TM; - typedef boost::graph_traits GT; - typedef typename GT::edge_descriptor edge_descriptor; - typedef typename GT::face_descriptor face_descriptor; - typedef typename GT::halfedge_descriptor halfedge_descriptor; - typedef typename GT::vertex_descriptor vertex_descriptor; + using TM = TriangleMesh; + using GT = boost::graph_traits; + using edge_descriptor = typename GT::edge_descriptor; + using face_descriptor = typename GT::face_descriptor; + using halfedge_descriptor = typename GT::halfedge_descriptor; + using vertex_descriptor = typename GT::vertex_descriptor; // Internal typedefs typedef std::size_t Node_id; typedef std::pair Node_id_pair; @@ -514,10 +515,7 @@ class Face_graph_output_builder An_edge_per_polyline_map; typedef std::unordered_map Node_id_map; - typedef std::unordered_map Edge_map; - typedef std::unordered_map Vertex_map; + //Data members TriangleMesh &tm1, &tm2; // property maps of input meshes @@ -2405,8 +2403,14 @@ class Face_graph_output_builder mark_edges(out_edge_mark_maps, shared_edges, operation); } - Edge_map disconnected_patches_edge_to_tm2_edge; - Vertex_map disconnected_patches_vertex_to_tm2_vertex; + using V2V_tag = typename CGAL::dynamic_vertex_property_t; + using Vertex_to_vertex_map = typename boost::property_map::type; + + using E2E_tag = typename CGAL::dynamic_edge_property_t; + using Edge_to_edge_map = typename boost::property_map::type; + + Vertex_to_vertex_map disconnected_patches_vertex_to_tm2_vertex = get(V2V_tag(), tm1, GT::null_vertex()); + Edge_to_edge_map disconnected_patches_edge_to_tm2_edge = get(E2E_tag(), tm1, edge(GT::null_halfedge(), tm2)); /// handle the operations updating tm1 and/or tm2 if ( inplace_operation_tm1!=NONE ) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index c35fa1a31d38..b5eb2fac2f67 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -30,6 +30,9 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { +template +struct is_surface_mesh : std::false_type {}; + enum Boolean_operation_type {UNION = 0, INTERSECTION, TM1_MINUS_TM2, TM2_MINUS_TM1, NONE }; @@ -909,7 +912,7 @@ void import_polyline( auto set_output_vertex = [&](vertex_descriptor v, halfedge_descriptor h_out){ user_visitor.before_vertex_copy(v, pm1, output); vertex_descriptor new_v = add_vertex(output); - set_halfedge(new_v, opposite(h_out, output),output); + set_halfedge(new_v, h_out, output); put(vpm_out, new_v, get(vpm1, v)); user_visitor.after_vertex_copy(v, pm1, new_v, output); return new_v; @@ -917,39 +920,33 @@ void import_polyline( //make sure the first vertex does not already exist vertex_descriptor src = GT::null_vertex(); - std::pair< typename VertexMap::iterator, bool > insert_res= - pm1_to_output_vertices.insert( std::make_pair( source(h1,pm1), src ) ); - - if( insert_res.second ) + if( get(pm1_to_output_vertices, source(h1,pm1)) == GT::null_vertex() ) { - src = set_output_vertex(source(h1, pm1), h_out); - insert_res.first->second = src; - pm2_to_output_vertices.insert( std::make_pair( source(h2,pm2), src ) ); + src = set_output_vertex(source(h1, pm1), opposite(h_out, output)); + put(pm1_to_output_vertices, source(h1,pm1), src); + put(pm2_to_output_vertices, source(h2,pm2), src); } else - src = insert_res.first->second; + src = get(pm1_to_output_vertices, source(h1,pm1)); //make sure the target vertex does not already exist if it is a polyline endpoint - vertex_descriptor tgt=GT::null_vertex(); + vertex_descriptor tgt = GT::null_vertex(); if ( nb_segments==1 ) { - insert_res = pm1_to_output_vertices.insert( std::make_pair( target(h1,pm1), tgt ) ); - if( insert_res.second ) + if( get(pm1_to_output_vertices, target(h1,pm1)) == GT::null_vertex() ) { tgt = set_output_vertex(target(h1, pm1), h_out); - insert_res.first->second = tgt; - pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); + put(pm1_to_output_vertices, target(h1,pm1), tgt); + put(pm2_to_output_vertices, target(h2,pm2), tgt); } else - tgt = insert_res.first->second; + tgt = get(pm1_to_output_vertices, target(h1,pm1)); } else { tgt = set_output_vertex(target(h1, pm1), h_out); - CGAL_assertion( pm1_to_output_vertices.count(target(h1,pm1))==0 ); - CGAL_assertion( pm2_to_output_vertices.count(target(h2,pm2))==0 ); - pm1_to_output_vertices.insert( std::make_pair( target(h1,pm1), tgt ) ); - pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); + put(pm1_to_output_vertices, target(h1,pm1), tgt); + put(pm2_to_output_vertices, target(h2,pm2), tgt); } //update source and target vertex of the edge created @@ -961,8 +958,8 @@ void import_polyline( halfedge_descriptor prev2=h2; //set the correspondence - pm1_to_output_edges.insert( std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); - pm2_to_output_edges.insert( std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); + put(pm1_to_output_edges, edge(prev1, pm1), edge(prev_out, output)); + put(pm2_to_output_edges, edge(prev2, pm2), edge(prev_out, output)); user_visitor.intersection_edge_copy(prev1, pm1, prev2, pm2, h_out, output); @@ -982,19 +979,18 @@ void import_polyline( if (i+1!=nb_segments) { tgt = set_output_vertex(target(h1, pm1), h_out); - pm1_to_output_vertices.insert( std::make_pair( target(h1,pm1), tgt ) ); - pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); + put( pm1_to_output_vertices, target(h1,pm1), tgt ); + put( pm2_to_output_vertices, target(h2,pm2), tgt ); } else{ - std::pair< typename VertexMap::iterator, bool > insert_res = - pm1_to_output_vertices.insert(std::make_pair(target(h1,pm1), tgt)); - if (insert_res.second) + if( get(pm1_to_output_vertices, target(h1,pm1)) == GT::null_vertex() ) { tgt = set_output_vertex(target(h1, pm1), h_out); - pm2_to_output_vertices.insert( std::make_pair( target(h2,pm2), tgt ) ); + put( pm1_to_output_vertices, target(h1,pm1), tgt ); + put( pm2_to_output_vertices, target(h2,pm2), tgt ); } else - tgt = insert_res.first->second; + tgt = get(pm1_to_output_vertices, target(h1,pm1)); } set_target(h_out, tgt, output); @@ -1005,30 +1001,29 @@ void import_polyline( prev2 = h2; src = tgt; - pm1_to_output_edges.insert( std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); - pm2_to_output_edges.insert( std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); + put(pm1_to_output_edges, edge(prev1, pm1), edge(prev_out, output)); + put(pm2_to_output_edges, edge(prev2, pm2), edge(prev_out, output)); } CGAL_assertion( pm1_to_output_edges.size() == pm2_to_output_edges.size() ); CGAL_assertion( pm1_to_output_vertices.size() == pm2_to_output_vertices.size() ); } -template +template struct Triangle_mesh_extension_helper; -template -struct Triangle_mesh_extension_helper +template +struct Triangle_mesh_extension_helper { typedef boost::graph_traits GT; typedef typename GT::halfedge_descriptor halfedge_descriptor; typedef typename GT::edge_descriptor edge_descriptor; typedef typename GT::face_descriptor face_descriptor; - typedef std::unordered_map< edge_descriptor, edge_descriptor> Edge_map; - Edge_map& tm_to_output_edges; + EdgeMap& tm_to_output_edges; const TriangleMesh& tm; TriangleMesh& output; - Triangle_mesh_extension_helper(Edge_map& tm_to_output_edges, + Triangle_mesh_extension_helper(EdgeMap& tm_to_output_edges, const TriangleMesh& tm, TriangleMesh& output) : tm_to_output_edges(tm_to_output_edges) @@ -1038,12 +1033,12 @@ struct Triangle_mesh_extension_helper halfedge_descriptor get_hedge(halfedge_descriptor h_tm) { - CGAL_assertion( tm_to_output_edges.count(edge(h_tm, tm))!=0 ); - const std::pair& key_and_value = - *tm_to_output_edges.find(edge(h_tm, tm)); - return halfedge(key_and_value.first,tm) != h_tm - ? halfedge(key_and_value.second, output) - : opposite(halfedge(key_and_value.second, output), output); + edge_descriptor key = edge(h_tm, tm); + edge_descriptor value = get(tm_to_output_edges, key); + CGAL_assertion( value != GT::null_halfedge() ); + return halfedge(key, tm) != h_tm + ? halfedge(value, output) + : opposite(halfedge(value, output), output); } std::array @@ -1056,20 +1051,19 @@ struct Triangle_mesh_extension_helper } }; -template -struct Triangle_mesh_extension_helper +template +struct Triangle_mesh_extension_helper { typedef boost::graph_traits GT; typedef typename GT::halfedge_descriptor halfedge_descriptor; typedef typename GT::edge_descriptor edge_descriptor; typedef typename GT::face_descriptor face_descriptor; - typedef std::unordered_map< edge_descriptor, edge_descriptor> Edge_map; - Edge_map& tm_to_output_edges; + EdgeMap& tm_to_output_edges; const TriangleMesh& tm; TriangleMesh& output; - Triangle_mesh_extension_helper(Edge_map& tm_to_output_edges, + Triangle_mesh_extension_helper(EdgeMap& tm_to_output_edges, const TriangleMesh& tm, TriangleMesh& output) : tm_to_output_edges(tm_to_output_edges) @@ -1079,12 +1073,12 @@ struct Triangle_mesh_extension_helper halfedge_descriptor get_hedge(halfedge_descriptor h_tm) { - CGAL_assertion( tm_to_output_edges.count(edge(h_tm, tm))!=0 ); - const std::pair& key_and_value = - *tm_to_output_edges.find(edge(h_tm, tm)); - return halfedge(key_and_value.first,tm) == h_tm - ? halfedge(key_and_value.second, output) - : opposite(halfedge(key_and_value.second, output), output); + edge_descriptor key = edge(h_tm, tm); + edge_descriptor value = get(tm_to_output_edges, key); + CGAL_assertion( value != GT::null_halfedge() ); + return halfedge(key, tm) != h_tm + ? halfedge(value, output) + : opposite(halfedge(value, output), output); } std::array @@ -1105,6 +1099,8 @@ template < bool reverse_patch_orientation, class VertexPointMapOut, class EdgeMarkMapOut, class EdgeMarkMapIn , + class EdgetoEdgeMap, + class VertextoVertexMap, class UserVisitor> void append_patches_to_triangle_mesh( TriangleMesh& output, @@ -1114,14 +1110,8 @@ void append_patches_to_triangle_mesh( const VertexPointMap& vpm_tm, EdgeMarkMapOut& edge_mark_map_out, const EdgeMarkMapIn& edge_mark_map_in, - std::unordered_map< - typename boost::graph_traits::edge_descriptor, - typename boost::graph_traits::edge_descriptor - >& tm_to_output_edges, - std::unordered_map< - typename boost::graph_traits::vertex_descriptor, - typename boost::graph_traits::vertex_descriptor - >& tm_to_output_vertices, + EdgetoEdgeMap& tm_to_output_edges, + VertextoVertexMap& tm_to_output_vertices, UserVisitor& user_visitor) { typedef boost::graph_traits GT; @@ -1131,7 +1121,7 @@ void append_patches_to_triangle_mesh( typedef typename GT::face_descriptor face_descriptor; const TriangleMesh& tm = patches.pm; - Triangle_mesh_extension_helper helper(tm_to_output_edges, tm, output); + Triangle_mesh_extension_helper helper(tm_to_output_edges, tm, output); std::vector ids_of_patches_to_append; ids_of_patches_to_append.reserve(patches_to_append.count()); @@ -1142,7 +1132,6 @@ void append_patches_to_triangle_mesh( ids_of_patches_to_append.push_back(i); } - std::vector interior_vertex_halfedges; for (std::size_t i : ids_of_patches_to_append) { #ifdef CGAL_COREFINEMENT_POLYHEDRA_DEBUG @@ -1160,8 +1149,7 @@ void append_patches_to_triangle_mesh( vertex_descriptor new_v = add_vertex(output); set_halfedge(new_v, GT::null_halfedge(), output); - auto res = tm_to_output_vertices.insert( std::make_pair( v, new_v ) ); - CGAL_assertion(res.second); // should be inserted, not already present + put(tm_to_output_vertices, v, new_v); put(vpm_out, new_v, get(vpm_tm, v)); } @@ -1177,7 +1165,7 @@ void append_patches_to_triangle_mesh( edge_mark_map_in, edge_mark_map_out); halfedge_descriptor new_h = halfedge(new_edge, output); - tm_to_output_edges[ed] = new_edge; + put(tm_to_output_edges, ed, new_edge); set_face(new_h, GT::null_face(), output); set_face(opposite(new_h, output), GT::null_face(), output); @@ -1190,11 +1178,10 @@ void append_patches_to_triangle_mesh( user_visitor.before_vertex_copy(v, tm, output); set_halfedge(new_v, new_h, output); user_visitor.after_vertex_copy(v, tm, new_v, output); - interior_vertex_halfedges.push_back( new_h ); }; vertex_descriptor tgt = target(h, tm); - vertex_descriptor new_tgt = tm_to_output_vertices[tgt]; + vertex_descriptor new_tgt = get(tm_to_output_vertices, tgt); CGAL_assertion( new_tgt != GT::null_vertex() ); set_target(new_h, new_tgt, output); if ( halfedge(tgt,tm)==h && @@ -1204,7 +1191,7 @@ void append_patches_to_triangle_mesh( } vertex_descriptor src = source(h, tm); - vertex_descriptor new_src = tm_to_output_vertices[src]; + vertex_descriptor new_src = get(tm_to_output_vertices, src); CGAL_assertion( new_src != GT::null_vertex() ); halfedge_descriptor new_h_opp = opposite(new_h, output); set_target(new_h_opp, new_src, output); @@ -1372,28 +1359,36 @@ void fill_new_triangle_mesh( output_shared_edges, UserVisitor& user_visitor) { - typedef boost::graph_traits GT; - typedef typename GT::vertex_descriptor vertex_descriptor; - typedef typename GT::edge_descriptor edge_descriptor; + using GT = boost::graph_traits; + using vertex_descriptor = typename GT::vertex_descriptor; + using edge_descriptor = typename GT::edge_descriptor; + + using V2V_tag = typename CGAL::dynamic_vertex_property_t; + using Vertex_to_vertex_map = typename boost::property_map::const_type; + + using E2E_tag = typename CGAL::dynamic_edge_property_t; + using Edge_to_edge_map = typename boost::property_map::const_type; + + const TriangleMesh& tm1 = patches_of_tm1.pm; + const TriangleMesh& tm2 = patches_of_tm2.pm; + + Vertex_to_vertex_map tm1_to_output_vertices = get(V2V_tag(), tm1, GT::null_vertex()), + tm2_to_output_vertices = get(V2V_tag(), tm2, GT::null_vertex()); + Edge_to_edge_map tm1_to_output_edges = get(E2E_tag(), tm1, edge(GT::null_halfedge(), tm1)), + tm2_to_output_edges = get(E2E_tag(), tm2, edge(GT::null_halfedge(), tm2)); // this is the minimal number of edges that will be marked (intersection edge). // We cannot easily have the total number since some patch interior edges might be marked - output_shared_edges.reserve( - std::accumulate(polylines.lengths.begin(),polylines.lengths.end(),std::size_t(0)) ); + output_shared_edges.reserve(std::accumulate(polylines.lengths.begin(),polylines.lengths.end(),std::size_t(0)) ); //add a polyline inside O for each intersection polyline std::size_t nb_polylines = polylines.lengths.size(); - std::unordered_map tm1_to_output_vertices, - tm2_to_output_vertices; - std::unordered_map tm1_to_output_edges, - tm2_to_output_edges; for (std::size_t i=0; i < nb_polylines; ++i) if (!polylines.to_skip.test(i)) import_polyline(output, polylines.tm1[i], polylines.tm2[i], - patches_of_tm1.pm, - patches_of_tm2.pm, + tm1, tm2, polylines.lengths[i], tm1_to_output_edges, tm2_to_output_edges, tm1_to_output_vertices, tm2_to_output_vertices, @@ -1454,6 +1449,7 @@ void fill_new_triangle_mesh( template void disconnect_patches( TriangleMesh& tm1, @@ -1461,6 +1457,8 @@ void disconnect_patches( PatchContainer& patches_of_tm1, const EdgeMap& tm1_edge_to_tm2_edge, //map intersection edges of tm1 to the equivalent in tm2 EdgeMap& new_tm1_edge_to_tm2_edge, //map the new intersection edges of tm1 to the equivalent in tm2 + VertexMap& tm1_vertex_to_tm2_vertex, //map intersection vertices of tm1 to the equivalent in tm2 + VertexMap& new_tm1_vertex_to_tm2_vertex, //map the new intersection vertices UserVisitor& user_visitor) { typedef boost::graph_traits GT; @@ -1590,14 +1588,23 @@ void disconnect_patches( CGAL_assertion( is_border(next(opposite(new_patch_border[k], tm1), tm1), tm1) ); CGAL_assertion( is_border(prev(opposite(new_patch_border[k], tm1), tm1), tm1) ); - typename EdgeMap::const_iterator it_res = - tm1_edge_to_tm2_edge.find( edge(patch.shared_edges[k], tm1) ); - CGAL_assertion( it_res != tm1_edge_to_tm2_edge.end() ); + auto e = get(tm1_edge_to_tm2_edge, edge(patch.shared_edges[k], tm1)); + auto src = get(tm1_vertex_to_tm2_vertex, source(patch.shared_edges[k], tm1)); + auto tgt = get(tm1_vertex_to_tm2_vertex, target(patch.shared_edges[k], tm1)); + CGAL_assertion( e != edge(GT::null_halfedge(), tm2) ); + CGAL_assertion( src != GT::null_vertex() ); + CGAL_assertion( tgt != GT::null_vertex() ); - new_tm1_edge_to_tm2_edge[ - patch.shared_edges[k]==halfedge(it_res->first, tm1) + /* halfedge(edge(h, g)) == h is a requirement of the concept and so the if is useless, TODO Sebastien can you confirm + put(new_tm1_edge_to_tm2_edge, + patch.shared_edges[k]==halfedge(edge(patch.shared_edges[k], tm1), tm1) ? edge(new_patch_border[k], tm1) - : edge(opposite(new_patch_border[k], tm1), tm1) ] = it_res->second; + : edge(opposite(new_patch_border[k], tm1), tm1), + e); + */ + put(new_tm1_edge_to_tm2_edge, edge(new_patch_border[k], tm1), e); + put(new_tm1_vertex_to_tm2_vertex, target(new_patch_border[k], tm1), tgt); + put(new_tm1_vertex_to_tm2_vertex, source(new_patch_border[k], tm1), src); } patch.shared_edges.swap(new_patch_border); @@ -1638,11 +1645,14 @@ void compute_inplace_operation_delay_removal_and_insideout( typedef typename GT::vertex_descriptor vertex_descriptor; typedef typename GT::edge_descriptor edge_descriptor; typedef typename GT::halfedge_descriptor halfedge_descriptor; - typedef std::unordered_map Edge_map; - typedef std::unordered_map Vertex_map; - Edge_map tm2_edge_to_tm1_edge, tm1_edge_to_tm2_edge; - Vertex_map tm2_vertex_to_tm1_vertex; + using V2V_tag = typename CGAL::dynamic_vertex_property_t; + using E2E_tag = typename CGAL::dynamic_edge_property_t; + + EdgeMap tm2_edge_to_tm1_edge = get(E2E_tag(), tm2, edge(GT::null_halfedge(), tm2)), + tm1_edge_to_tm2_edge = get(E2E_tag(), tm1, edge(GT::null_halfedge(), tm1)); + VertexMap tm2_vertex_to_tm1_vertex = get(V2V_tag(), tm2, GT::null_vertex()), + tm1_vertex_to_tm2_vertex = get(V2V_tag(), tm1, GT::null_vertex()); //maps intersection edges from tm2 to tm1 std::size_t nb_polylines = polylines.lengths.size(); for(std::size_t i=0; i void compute_inplace_operation( TriangleMesh& tm1, - const TriangleMesh& /*tm2*/, + const TriangleMesh& tm2, const boost::dynamic_bitset<>& patches_of_tm1_to_keep, const boost::dynamic_bitset<>& patches_of_tm2_to_import, PatchContainer1& patches_of_tm1, @@ -1793,22 +1809,11 @@ void compute_inplace_operation( EdgeMarkMapIn1& edge_mark_map_in1, const EdgeMarkMapIn2& edge_mark_map_in2, EdgeMarkMapOut1& edge_mark_map_out1, - std::unordered_map< - typename boost::graph_traits::edge_descriptor, - typename boost::graph_traits::edge_descriptor - >& tm2_edge_to_tm1_edge, - std::unordered_map< - typename boost::graph_traits::vertex_descriptor, - typename boost::graph_traits::vertex_descriptor - >& tm2_vertex_to_tm1_vertex, - UserVisitor& user_visitor) + EdgeToEdgeMap& tm2_edge_to_tm1_edge, + VertexToVertexMap& tm2_vertex_to_tm1_vertex, + UserVisitor& user_visitor) { - typedef std::unordered_map< - typename boost::graph_traits::edge_descriptor, - typename boost::graph_traits::edge_descriptor> EdgeMap; - typedef std::unordered_map< - typename boost::graph_traits::vertex_descriptor, - typename boost::graph_traits::vertex_descriptor> VertexMap; + using edge_descriptor = typename boost::graph_traits::edge_descriptor; //clean up patches not kept remove_patches(tm1, ~patches_of_tm1_to_keep, patches_of_tm1, edge_mark_map_in1); @@ -1819,8 +1824,11 @@ void compute_inplace_operation( Polygon_mesh_processing::reverse_face_orientations_of_mesh_with_polylines(tm1); // here we need to update the mapping to use the correct border // halfedges while appending the patches from tm2 - for(typename EdgeMap::value_type& v : tm2_edge_to_tm1_edge) - v.second=edge(opposite(halfedge(v.second, tm1), tm1), tm1); + for(edge_descriptor e2: edges(tm2)){ + edge_descriptor e1 = get(tm2_edge_to_tm1_edge, e2); + if (e1 != edge(boost::graph_traits::null_halfedge(), tm1)) + put(tm2_edge_to_tm1_edge, e2, edge(opposite(halfedge(e1, tm1), tm1), tm1)); + } } //we import patches from tm2 @@ -1876,9 +1884,9 @@ void compute_border_edge_map( for (std::size_t k=0;;) { - tm2_edge_to_tm1_edge[edge(h2, tm2)]=edge(h1, tm1); - tm2_vertex_to_tm1_vertex[target(h2, tm2)]=target(h1, tm1); - tm2_vertex_to_tm1_vertex[source(h2, tm2)]=source(h1, tm1); + put(tm2_edge_to_tm1_edge, edge(h2, tm2), edge(h1, tm1)); + put(tm2_vertex_to_tm1_vertex, target(h2, tm2), target(h1, tm1)); + put(tm2_vertex_to_tm1_vertex, source(h2, tm2), source(h1, tm1)); if (++k==nb_segments) break; h2 = next_marked_halfedge_around_target_vertex( h2, tm2, patches_of_tm2.is_intersection_edge); @@ -1920,8 +1928,14 @@ void compute_inplace_operation( typedef typename GT::edge_descriptor edge_descriptor; typedef typename GT::vertex_descriptor vertex_descriptor; - std::unordered_map tm2_edge_to_tm1_edge; - std::unordered_map tm2_vertex_to_tm1_vertex; + using V2V_tag = typename CGAL::dynamic_vertex_property_t; + using Vertex_to_vertex_map = typename boost::property_map::const_type; + + using E2E_tag = typename CGAL::dynamic_edge_property_t; + using Edge_to_edge_map = typename boost::property_map::const_type; + + Edge_to_edge_map tm2_edge_to_tm1_edge = get(E2E_tag(), tm2); + Vertex_to_vertex_map tm2_vertex_to_tm1_vertex = get(V2V_tag(), tm2, GT::null_vertex()); //maps intersection edges from tm2 to the equivalent in tm1 compute_border_edge_map(tm1, tm2, From 65e6338dd4469ab55f566010cbac82fd78e1f8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 7 Sep 2026 12:26:46 +0200 Subject: [PATCH 012/136] Solved a bug where shared edges are not correctly linked to their new neighbours --- .../corefinement_mesh_union_progress.cpp | 2 + .../internal/Corefinement/face_graph_utils.h | 83 ++++++------------- .../include/CGAL/Surface_mesh/Surface_mesh.h | 40 +++++++++ 3 files changed, 68 insertions(+), 57 deletions(-) diff --git a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp index 71707c1457d5..dbf05483c0a1 100644 --- a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp +++ b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index b5eb2fac2f67..e9599dd99144 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -1004,55 +1004,10 @@ void import_polyline( put(pm1_to_output_edges, edge(prev1, pm1), edge(prev_out, output)); put(pm2_to_output_edges, edge(prev2, pm2), edge(prev_out, output)); } - CGAL_assertion( pm1_to_output_edges.size() == pm2_to_output_edges.size() ); - CGAL_assertion( pm1_to_output_vertices.size() == pm2_to_output_vertices.size() ); } -template -struct Triangle_mesh_extension_helper; - -template -struct Triangle_mesh_extension_helper -{ - typedef boost::graph_traits GT; - typedef typename GT::halfedge_descriptor halfedge_descriptor; - typedef typename GT::edge_descriptor edge_descriptor; - typedef typename GT::face_descriptor face_descriptor; - - EdgeMap& tm_to_output_edges; - const TriangleMesh& tm; - TriangleMesh& output; - - Triangle_mesh_extension_helper(EdgeMap& tm_to_output_edges, - const TriangleMesh& tm, - TriangleMesh& output) - : tm_to_output_edges(tm_to_output_edges) - , tm(tm) - , output(output) - {} - - halfedge_descriptor get_hedge(halfedge_descriptor h_tm) - { - edge_descriptor key = edge(h_tm, tm); - edge_descriptor value = get(tm_to_output_edges, key); - CGAL_assertion( value != GT::null_halfedge() ); - return halfedge(key, tm) != h_tm - ? halfedge(value, output) - : opposite(halfedge(value, output), output); - } - - std::array - halfedges(face_descriptor f) - { - halfedge_descriptor h=halfedge(f,tm); - return make_array( get_hedge( h ), - get_hedge( prev(h,tm) ), - get_hedge( next(h,tm) ) ); - } -}; - -template -struct Triangle_mesh_extension_helper +template +struct Triangle_mesh_extension_helper { typedef boost::graph_traits GT; typedef typename GT::halfedge_descriptor halfedge_descriptor; @@ -1060,13 +1015,16 @@ struct Triangle_mesh_extension_helper typedef typename GT::face_descriptor face_descriptor; EdgeMap& tm_to_output_edges; + VertexMap& tm_to_output_vertices; const TriangleMesh& tm; TriangleMesh& output; Triangle_mesh_extension_helper(EdgeMap& tm_to_output_edges, + VertexMap& tm_to_output_vertices, const TriangleMesh& tm, TriangleMesh& output) : tm_to_output_edges(tm_to_output_edges) + , tm_to_output_vertices(tm_to_output_vertices) , tm(tm) , output(output) {} @@ -1075,23 +1033,32 @@ struct Triangle_mesh_extension_helper { edge_descriptor key = edge(h_tm, tm); edge_descriptor value = get(tm_to_output_edges, key); - CGAL_assertion( value != GT::null_halfedge() ); - return halfedge(key, tm) != h_tm - ? halfedge(value, output) - : opposite(halfedge(value, output), output); + CGAL_assertion( value != edge(GT::null_halfedge(), tm) ); + if constexpr(reverse_patch_orientation) + return target(halfedge(value, output), output) == get(tm_to_output_vertices, target(h_tm, tm)) + ? opposite(halfedge(value, output), output) + : halfedge(value, output); + else + return target(halfedge(value, output), output) == get(tm_to_output_vertices, target(h_tm, tm)) + ? halfedge(value, output) + : opposite(halfedge(value, output), output); } std::array halfedges(face_descriptor f) { halfedge_descriptor h=halfedge(f,tm); - return make_array( get_hedge( h ), - get_hedge( next(h,tm) ), - get_hedge( prev(h,tm) ) ); + if constexpr(reverse_patch_orientation) + return make_array( get_hedge( h ), + get_hedge( prev(h,tm) ), + get_hedge( next(h,tm) ) ); + else + return make_array( get_hedge( h ), + get_hedge( next(h,tm) ), + get_hedge( prev(h,tm) ) ); } }; - template < bool reverse_patch_orientation, class TriangleMesh, class PatchContainer, @@ -1120,8 +1087,11 @@ void append_patches_to_triangle_mesh( typedef typename GT::vertex_descriptor vertex_descriptor; typedef typename GT::face_descriptor face_descriptor; + CGAL::Real_timer t; + t.start(); + const TriangleMesh& tm = patches.pm; - Triangle_mesh_extension_helper helper(tm_to_output_edges, tm, output); + Triangle_mesh_extension_helper helper(tm_to_output_edges, tm_to_output_vertices, tm, output); std::vector ids_of_patches_to_append; ids_of_patches_to_append.reserve(patches_to_append.count()); @@ -1591,7 +1561,6 @@ void disconnect_patches( auto e = get(tm1_edge_to_tm2_edge, edge(patch.shared_edges[k], tm1)); auto src = get(tm1_vertex_to_tm2_vertex, source(patch.shared_edges[k], tm1)); auto tgt = get(tm1_vertex_to_tm2_vertex, target(patch.shared_edges[k], tm1)); - CGAL_assertion( e != edge(GT::null_halfedge(), tm2) ); CGAL_assertion( src != GT::null_vertex() ); CGAL_assertion( tgt != GT::null_vertex() ); diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 148785e4d90f..cbb430366a41 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -2891,6 +2891,46 @@ namespace boost { } // namespace boost +namespace CGAL { + +/// Print all mesh elements and their connectivity to an output stream. +template +void print_surface_mesh(const Surface_mesh

& mesh, + std::ostream& out = std::cout) +{ + typedef Surface_mesh

Mesh; + typedef typename Mesh::Vertex_index Vertex_index; + typedef typename Mesh::Halfedge_index Halfedge_index; + typedef typename Mesh::Edge_index Edge_index; + typedef typename Mesh::Face_index Face_index; + + out << "Points:\n"; + for (Vertex_index v : mesh.vertices()) + out << " " << v << ": point=" << mesh.point(v) << '\n'; + + out << "Vertices:\n"; + for (Vertex_index v : mesh.vertices()) + out << " " << v << ": halfedge=" << mesh.halfedge(v) << '\n'; + + out << "Halfedges:\n"; + for (Halfedge_index h : mesh.halfedges()) + { + out << " " << h << ": target=" << mesh.target(h) + << " face=" << mesh.face(h) + << " next=" << mesh.next(h) << '\n'; + } + + out << "Faces:\n"; + for (Face_index f : mesh.faces()) + { + out << " " << f << ": halfedge=" << mesh.halfedge(f) << '\n'; + } +} + +} // namespace CGAL + + + #endif // DOXYGEN_RUNNING #include From 1f9c17ed2b8b8ba1b6b0a11011f15eacaaf55b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 7 Sep 2026 12:26:46 +0200 Subject: [PATCH 013/136] Solved a bug where shared edges are not correctly linked to their new neighbours --- .../corefinement_mesh_union_progress.cpp | 2 + .../internal/Corefinement/face_graph_utils.h | 80 +--- .../include/CGAL/Surface_mesh/Surface_mesh.h | 40 ++ .../internal/boolean_operations_utils.h | 403 ++++++++++++++++++ 4 files changed, 468 insertions(+), 57 deletions(-) create mode 100644 Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h diff --git a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp index 71707c1457d5..dbf05483c0a1 100644 --- a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp +++ b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index b5eb2fac2f67..7313409a0727 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -1004,15 +1004,10 @@ void import_polyline( put(pm1_to_output_edges, edge(prev1, pm1), edge(prev_out, output)); put(pm2_to_output_edges, edge(prev2, pm2), edge(prev_out, output)); } - CGAL_assertion( pm1_to_output_edges.size() == pm2_to_output_edges.size() ); - CGAL_assertion( pm1_to_output_vertices.size() == pm2_to_output_vertices.size() ); } -template -struct Triangle_mesh_extension_helper; - -template -struct Triangle_mesh_extension_helper +template +struct Triangle_mesh_extension_helper { typedef boost::graph_traits GT; typedef typename GT::halfedge_descriptor halfedge_descriptor; @@ -1020,13 +1015,16 @@ struct Triangle_mesh_extension_helper typedef typename GT::face_descriptor face_descriptor; EdgeMap& tm_to_output_edges; + VertexMap& tm_to_output_vertices; const TriangleMesh& tm; TriangleMesh& output; Triangle_mesh_extension_helper(EdgeMap& tm_to_output_edges, + VertexMap& tm_to_output_vertices, const TriangleMesh& tm, TriangleMesh& output) : tm_to_output_edges(tm_to_output_edges) + , tm_to_output_vertices(tm_to_output_vertices) , tm(tm) , output(output) {} @@ -1035,63 +1033,32 @@ struct Triangle_mesh_extension_helper { edge_descriptor key = edge(h_tm, tm); edge_descriptor value = get(tm_to_output_edges, key); - CGAL_assertion( value != GT::null_halfedge() ); - return halfedge(key, tm) != h_tm - ? halfedge(value, output) - : opposite(halfedge(value, output), output); - } - - std::array - halfedges(face_descriptor f) - { - halfedge_descriptor h=halfedge(f,tm); - return make_array( get_hedge( h ), - get_hedge( prev(h,tm) ), - get_hedge( next(h,tm) ) ); - } -}; - -template -struct Triangle_mesh_extension_helper -{ - typedef boost::graph_traits GT; - typedef typename GT::halfedge_descriptor halfedge_descriptor; - typedef typename GT::edge_descriptor edge_descriptor; - typedef typename GT::face_descriptor face_descriptor; - - EdgeMap& tm_to_output_edges; - const TriangleMesh& tm; - TriangleMesh& output; - - Triangle_mesh_extension_helper(EdgeMap& tm_to_output_edges, - const TriangleMesh& tm, - TriangleMesh& output) - : tm_to_output_edges(tm_to_output_edges) - , tm(tm) - , output(output) - {} - - halfedge_descriptor get_hedge(halfedge_descriptor h_tm) - { - edge_descriptor key = edge(h_tm, tm); - edge_descriptor value = get(tm_to_output_edges, key); - CGAL_assertion( value != GT::null_halfedge() ); - return halfedge(key, tm) != h_tm - ? halfedge(value, output) - : opposite(halfedge(value, output), output); + CGAL_assertion( value != edge(GT::null_halfedge(), tm) ); + if constexpr(reverse_patch_orientation) + return target(halfedge(value, output), output) == get(tm_to_output_vertices, target(h_tm, tm)) + ? opposite(halfedge(value, output), output) + : halfedge(value, output); + else + return target(halfedge(value, output), output) == get(tm_to_output_vertices, target(h_tm, tm)) + ? halfedge(value, output) + : opposite(halfedge(value, output), output); } std::array halfedges(face_descriptor f) { halfedge_descriptor h=halfedge(f,tm); - return make_array( get_hedge( h ), - get_hedge( next(h,tm) ), - get_hedge( prev(h,tm) ) ); + if constexpr(reverse_patch_orientation) + return make_array( get_hedge( h ), + get_hedge( prev(h,tm) ), + get_hedge( next(h,tm) ) ); + else + return make_array( get_hedge( h ), + get_hedge( next(h,tm) ), + get_hedge( prev(h,tm) ) ); } }; - template < bool reverse_patch_orientation, class TriangleMesh, class PatchContainer, @@ -1121,7 +1088,7 @@ void append_patches_to_triangle_mesh( typedef typename GT::face_descriptor face_descriptor; const TriangleMesh& tm = patches.pm; - Triangle_mesh_extension_helper helper(tm_to_output_edges, tm, output); + Triangle_mesh_extension_helper helper(tm_to_output_edges, tm_to_output_vertices, tm, output); std::vector ids_of_patches_to_append; ids_of_patches_to_append.reserve(patches_to_append.count()); @@ -1591,7 +1558,6 @@ void disconnect_patches( auto e = get(tm1_edge_to_tm2_edge, edge(patch.shared_edges[k], tm1)); auto src = get(tm1_vertex_to_tm2_vertex, source(patch.shared_edges[k], tm1)); auto tgt = get(tm1_vertex_to_tm2_vertex, target(patch.shared_edges[k], tm1)); - CGAL_assertion( e != edge(GT::null_halfedge(), tm2) ); CGAL_assertion( src != GT::null_vertex() ); CGAL_assertion( tgt != GT::null_vertex() ); diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 148785e4d90f..cbb430366a41 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -2891,6 +2891,46 @@ namespace boost { } // namespace boost +namespace CGAL { + +/// Print all mesh elements and their connectivity to an output stream. +template +void print_surface_mesh(const Surface_mesh

& mesh, + std::ostream& out = std::cout) +{ + typedef Surface_mesh

Mesh; + typedef typename Mesh::Vertex_index Vertex_index; + typedef typename Mesh::Halfedge_index Halfedge_index; + typedef typename Mesh::Edge_index Edge_index; + typedef typename Mesh::Face_index Face_index; + + out << "Points:\n"; + for (Vertex_index v : mesh.vertices()) + out << " " << v << ": point=" << mesh.point(v) << '\n'; + + out << "Vertices:\n"; + for (Vertex_index v : mesh.vertices()) + out << " " << v << ": halfedge=" << mesh.halfedge(v) << '\n'; + + out << "Halfedges:\n"; + for (Halfedge_index h : mesh.halfedges()) + { + out << " " << h << ": target=" << mesh.target(h) + << " face=" << mesh.face(h) + << " next=" << mesh.next(h) << '\n'; + } + + out << "Faces:\n"; + for (Face_index f : mesh.faces()) + { + out << " " << f << ": halfedge=" << mesh.halfedge(f) << '\n'; + } +} + +} // namespace CGAL + + + #endif // DOXYGEN_RUNNING #include diff --git a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h new file mode 100644 index 000000000000..0e8c8ac6b418 --- /dev/null +++ b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h @@ -0,0 +1,403 @@ +// Copyright (c) 2026 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Leo Valque + +#ifndef CGAL_SURFACE_MESH_BOOLEAN_OPERATIONS_UTILS_H +#define CGAL_SURFACE_MESH_BOOLEAN_OPERATIONS_UTILS_H + +#include + +#include +#include + +namespace CGAL { +namespace Polygon_mesh_processing { +namespace Corefinement { + +template +struct is_surface_mesh> : std::true_type {}; + +// Specialization of the function for Surface_mesh to exploit vectors structure of Surface_mesh. +template < bool reverse_patch_orientation, + class Point, + class PatchDescription, + class VertexPointMap, + class VertexPointMapOut, + class EdgeMarkMapOut, + class EdgeMarkMapIn, + class EdgeToEdgeMap, + class VertexToVertexMap, + class UserVisitor> +void append_patch( + const Surface_mesh& tm, + Surface_mesh& output, + PatchDescription& patch, + const VertexPointMapOut& vpm_out, + const VertexPointMap& vpm_tm, + EdgeMarkMapOut& edge_mark_map_out, + const EdgeMarkMapIn& edge_mark_map_in, + EdgeToEdgeMap& tm_to_output_edges, + VertexToVertexMap& tm_to_output_vertices, + UserVisitor& user_visitor, + std::size_t vertices_idx_begin, + std::size_t edges_idx_begin, + std::size_t faces_idx_begin) +{ + using SM = Surface_mesh; + using vertex_descriptor = typename SM::Vertex_index; + using edge_descriptor = typename SM::Edge_index; + using halfedge_descriptor = typename SM::Halfedge_index; + using face_descriptor = typename SM::Face_index; + + // Fill Vertex to vertex map and vpm for interior vertices + auto fill_vertex = [&](std::size_t i){ + vertex_descriptor v = patch.interior_vertices[i]; + vertex_descriptor new_v(vertices_idx_begin + i); + + put(tm_to_output_vertices, v, new_v); + put(vpm_out, new_v, get(vpm_tm, v)); + output.set_halfedge(new_v, SM::null_halfedge()); + }; + +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(true){ + tbb::parallel_for(std::size_t(0), patch.interior_vertices.size(), fill_vertex); + } + else +#endif + { + for(std::size_t i=0; i(tm.edge(h), new_edge, + edge_mark_map_in, edge_mark_map_out); + + CGAL_assertion(is_border(new_h, output)); + CGAL_assertion(is_border(opposite(new_h, output), output)); + + // Fill the halfedge of the vertices if it is not set yet + if (tm.halfedge(tm.target(h)) == h && + output.halfedge(output.target(new_h)) == SM::null_halfedge()){ + user_visitor.before_vertex_copy(tm.target(h), tm, output); // Call visitor when the vertex would be complete + output.set_halfedge(output.target(new_h), new_h); + user_visitor.after_vertex_copy(tm.target(h), tm, output.target(new_h), output); + } + + if (tm.halfedge(tm.source(h)) == tm.opposite(h) && + output.halfedge(output.source(new_h)) == SM::null_halfedge()){ + user_visitor.before_vertex_copy(tm.source(h), tm, output); // Call visitor when the vertex would be complete + output.set_halfedge(output.source(new_h), output.opposite(new_h)); + user_visitor.after_vertex_copy(tm.source(h), tm, output.target(new_h), output); + } + }; +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(true){ + tbb::parallel_for(std::size_t(0), patch.interior_edges.size(), fill_edge); + } + else +#endif + { + for(std::size_t i=0; i hedges = { get_halfedge(h_in_1), get_halfedge(h_in_2), get_halfedge(h_in_3) }; + + user_visitor.before_face_copy(f, tm, output); + SM_Face_index new_f(faces_idx_begin + i); + user_visitor.after_face_copy(f, tm, new_f, output); + output.set_halfedge(new_f, hedges[0]); + + for (int i=0;i<3;++i) + { + CGAL_assertion(hedges[i] != null_halfedge()); + if(reverse_patch_orientation) + output.set_next(hedges[i], hedges[(i+2)%3]); + else + output.set_next(hedges[i], hedges[(i+1)%3]); + output.set_face(hedges[i], new_f); + } + }; +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(true){ + tbb::parallel_for(std::size_t(0), patch.faces.size(), fill_face); + } + else +#endif + { + for(std::size_t i=0; i +void append_patches_to_triangle_mesh( + Surface_mesh& output, + const boost::dynamic_bitset<>& patches_to_append, + PatchContainer& patches, + const VertexPointMapOut& vpm_out, + const VertexPointMap& vpm_tm, + EdgeMarkMapOut& edge_mark_map_out, + const EdgeMarkMapIn& edge_mark_map_in, + EdgeToEdgeMap& tm_to_output_edges, + VertexToVertexMap& tm_to_output_vertices, + UserVisitor& user_visitor) +{ + using SM = Surface_mesh; + const SM& tm = patches.pm; + + std::size_t vertices_idx_begin = output.number_of_vertices(); + std::size_t edges_idx_begin = output.number_of_edges(); + std::size_t faces_idx_begin = output.number_of_faces(); + std::size_t tnv = vertices_idx_begin, tne = edges_idx_begin, tnf = faces_idx_begin; + for (std::size_t i= patches_to_append.find_first(); + i < patches_to_append.npos; + i = patches_to_append.find_next(i)) + { + tnv += patches[i].interior_vertices.size(); + tne += patches[i].interior_edges.size(); + tnf += patches[i].faces.size(); + } + output.resize(vertices_idx_begin, edges_idx_begin, faces_idx_begin); + for (std::size_t i= patches_to_append.find_first(); + i < patches_to_append.npos; + i = patches_to_append.find_next(i)) + { + Patch_description& patch=patches[i]; + append_patch(tm, output, patch, + vpm_out, vpm_tm, + edge_mark_map_out, edge_mark_map_in, + tm_to_output_edges, tm_to_output_vertices, + user_visitor, + vertices_idx_begin, edges_idx_begin, faces_idx_begin); + vertices_idx_begin += patch.interior_vertices.size(); + edges_idx_begin += patch.interior_edges.size(); + faces_idx_begin += patch.faces.size(); + } + + // TODO post process borders +} + +// Specialization of fill_new_triangle_mesh for Surface_mesh to exploit vectors structure of Surface_mesh. +template < class Point, + class IntersectionEdgeMap, + class VertexPointMap1, + class VertexPointMap2, + class VertexPointMapOut, + class EdgeMarkMap1, + class EdgeMarkMap2, + class EdgeMarkMapOut, + class IntersectionPolylines, + class PatchContainer1, + class PatchContainer2, + class UserVisitor> +void fill_new_triangle_mesh( + Surface_mesh& output, + const boost::dynamic_bitset<>& patches_of_tm1_to_import, + const boost::dynamic_bitset<>& patches_of_tm2_to_import, + PatchContainer1& patches_of_tm1, + PatchContainer2& patches_of_tm2, + bool reverse_orientation_of_patches_from_tm1, + bool reverse_orientation_of_patches_from_tm2, + const IntersectionPolylines& polylines, + const IntersectionEdgeMap& intersection_edges1, + const IntersectionEdgeMap& intersection_edges2, + const VertexPointMap1& vpm1, + const VertexPointMap2& vpm2, + const VertexPointMapOut& vpm_out, + const EdgeMarkMap1& edge_mark_map1, + const EdgeMarkMap2& edge_mark_map2, + EdgeMarkMapOut& edge_mark_map_out, + std::vector< typename Surface_mesh::Edge_index >& output_shared_edges, + UserVisitor& user_visitor) +{ + std::cout << "Specific"<< std::endl << std::endl; + using SM = Surface_mesh; + using vertex_descriptor = typename SM::Vertex_index; + using edge_descriptor = typename SM::Edge_index; + using halfedge_descriptor = typename SM::Halfedge_index; + using face_descriptor = typename SM::Face_index; + + using V2V_tag = typename CGAL::dynamic_vertex_property_t; + using Vertex_to_vertex_map = typename boost::property_map::const_type; + + using E2E_tag = typename CGAL::dynamic_edge_property_t; + using Edge_to_edge_map = typename boost::property_map::const_type; + + const SM &tm1 = patches_of_tm1.pm; + const SM &tm2 = patches_of_tm2.pm; + + Edge_to_edge_map tm1_to_output_edges = get(E2E_tag(), tm1, SM::null_edge()), + tm2_to_output_edges = get(E2E_tag(), tm2, SM::null_edge()); + Vertex_to_vertex_map tm1_to_output_vertices = get(V2V_tag(), tm1, SM::null_vertex()), + tm2_to_output_vertices = get(V2V_tag(), tm2, SM::null_vertex()); + + std::size_t vertices_idx_begin = output.number_of_vertices(); + std::size_t edges_idx_begin = output.number_of_edges(); + std::size_t faces_idx_begin = output.number_of_faces(); + + output_shared_edges.reserve( std::accumulate(polylines.lengths.begin(), polylines.lengths.end(), std::size_t(0)) ); + std::size_t nb_polylines = polylines.lengths.size(); + for (std::size_t i=0; i < nb_polylines; ++i) + if (!polylines.to_skip.test(i)) + import_polyline(output, + polylines.tm1[i], polylines.tm2[i], + tm1, tm2, + polylines.lengths[i], + tm1_to_output_edges, tm2_to_output_edges, + tm1_to_output_vertices, tm2_to_output_vertices, + intersection_edges1, intersection_edges2, + vpm1, vpm2, vpm_out, + output_shared_edges, + user_visitor); + + // Get ids of patch to append + std::vector ids_of_patches_to_append_from_tm1; + std::vector ids_of_patches_to_append_from_tm2; + ids_of_patches_to_append_from_tm1.reserve(patches_of_tm1_to_import.count()); + for (std::size_t i= patches_of_tm1_to_import.find_first(); + i < patches_of_tm1_to_import.npos; + i = patches_of_tm1_to_import.find_next(i)){ + ids_of_patches_to_append_from_tm1.push_back(i); + } + ids_of_patches_to_append_from_tm2.reserve(patches_of_tm2_to_import.count()); + for (std::size_t i= patches_of_tm2_to_import.find_first(); + i < patches_of_tm2_to_import.npos; + i = patches_of_tm2_to_import.find_next(i)){ + ids_of_patches_to_append_from_tm2.push_back(i); + } + + // Compute final sizes + std::size_t nv = output.number_of_vertices(), ne = output.number_of_edges(), nf = output.number_of_faces(); + std::size_t tnv = output.number_of_vertices(), tne = output.number_of_edges(), tnf = output.number_of_faces(); + for (std::size_t i : ids_of_patches_to_append_from_tm1){ + tnv += patches_of_tm1[i].interior_vertices.size(); + tne += patches_of_tm1[i].interior_edges.size(); + tnf += patches_of_tm1[i].faces.size(); + } + for (std::size_t i : ids_of_patches_to_append_from_tm2){ + tnv += patches_of_tm2[i].interior_vertices.size(); + tne += patches_of_tm2[i].interior_edges.size(); + tnf += patches_of_tm2[i].faces.size(); + } + output.resize(tnv, tne, tnf); + + // Append patches + for (std::size_t i : ids_of_patches_to_append_from_tm1){ + if(reverse_orientation_of_patches_from_tm1) + append_patch(tm1, output, + patches_of_tm1[i], + vpm_out, vpm1, + edge_mark_map_out, + edge_mark_map1, + tm1_to_output_edges, + tm1_to_output_vertices, + user_visitor, + nv, ne, nf); + else + append_patch(tm1, output, + patches_of_tm1[i], + vpm_out, vpm1, + edge_mark_map_out, + edge_mark_map1, + tm1_to_output_edges, + tm1_to_output_vertices, + user_visitor, + nv, ne, nf); + nv += patches_of_tm1[i].interior_vertices.size(); + ne += patches_of_tm1[i].interior_edges.size(); + nf += patches_of_tm1[i].faces.size(); + } + + // TODO post process borders of patches from tm1 + + for(std::size_t i : ids_of_patches_to_append_from_tm2){ + if(reverse_orientation_of_patches_from_tm2) + append_patch(tm2, output, + patches_of_tm2[i], + vpm_out, vpm2, + edge_mark_map_out, + edge_mark_map2, + tm2_to_output_edges, + tm2_to_output_vertices, + user_visitor, + nv, ne, nf); + else + append_patch(tm2, output, + patches_of_tm2[i], + vpm_out, vpm2, + edge_mark_map_out, + edge_mark_map2, + tm2_to_output_edges, + tm2_to_output_vertices, + user_visitor, + nv, ne, nf); + nv += patches_of_tm2[i].interior_vertices.size(); + ne += patches_of_tm2[i].interior_edges.size(); + nf += patches_of_tm2[i].faces.size(); + } + + // TODO post process borders of patches from tm2 +} + +} // namespace Corefinement +} // namespace Polygon_mesh_processing +} // namespace CGAL + +#endif // CGAL_SURFACE_MESH_BOOLEAN_OPERATIONS_UTILS_H \ No newline at end of file From 05ef55f001be12922c93d6586efe65b0b0c0639b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 7 Sep 2026 16:06:12 +0200 Subject: [PATCH 014/136] Remove left over --- .../internal/Corefinement/face_graph_utils.h | 8 +------- .../CGAL/Surface_mesh/internal/boolean_operations_utils.h | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index e9599dd99144..d1ec1a700b16 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -30,9 +30,6 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { -template -struct is_surface_mesh : std::false_type {}; - enum Boolean_operation_type {UNION = 0, INTERSECTION, TM1_MINUS_TM2, TM2_MINUS_TM1, NONE }; @@ -1087,9 +1084,6 @@ void append_patches_to_triangle_mesh( typedef typename GT::vertex_descriptor vertex_descriptor; typedef typename GT::face_descriptor face_descriptor; - CGAL::Real_timer t; - t.start(); - const TriangleMesh& tm = patches.pm; Triangle_mesh_extension_helper helper(tm_to_output_edges, tm_to_output_vertices, tm, output); @@ -1336,7 +1330,7 @@ void fill_new_triangle_mesh( using V2V_tag = typename CGAL::dynamic_vertex_property_t; using Vertex_to_vertex_map = typename boost::property_map::const_type; - using E2E_tag = typename CGAL::dynamic_edge_property_t; + using E2E_tag = typename CGAL::dynamic_edge_property_t; using Edge_to_edge_map = typename boost::property_map::const_type; const TriangleMesh& tm1 = patches_of_tm1.pm; diff --git a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h index 0e8c8ac6b418..27b441b9edcd 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h @@ -267,7 +267,6 @@ void fill_new_triangle_mesh( std::vector< typename Surface_mesh::Edge_index >& output_shared_edges, UserVisitor& user_visitor) { - std::cout << "Specific"<< std::endl << std::endl; using SM = Surface_mesh; using vertex_descriptor = typename SM::Vertex_index; using edge_descriptor = typename SM::Edge_index; From 315c580ed3da0000cb8e34da97cc5a564782e860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 7 Sep 2026 19:23:18 +0200 Subject: [PATCH 015/136] Add postprocess of borders and correct a bug when borders are parts of polylines of intersection --- .../internal/Corefinement/face_graph_utils.h | 244 ++++++++++-------- .../internal/Corefinement/intersection_impl.h | 6 +- .../include/CGAL/Surface_mesh/Surface_mesh.h | 1 - .../internal/boolean_operations_utils.h | 27 +- 4 files changed, 163 insertions(+), 115 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index d1ec1a700b16..624405ba4c74 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -959,6 +959,7 @@ void import_polyline( put(pm2_to_output_edges, edge(prev2, pm2), edge(prev_out, output)); user_visitor.intersection_edge_copy(prev1, pm1, prev2, pm2, h_out, output); + halfedge_descriptor first_h1 = h1, first_h_out = h_out; src=tgt; for (std::size_t i=1; i +void process_borders_after_appending_patches( + TriangleMesh& output, + const std::vector &ids_of_patches_to_append, + PatchContainer& patches, + EdgetoEdgeMap& tm_to_output_edges, + VertextoVertexMap& tm_to_output_vertices) +{ + // handle interior edges that are on the border of the mesh: + // they do not have a prev/next pointer set since only the pointers + // of patch interior halfedges part a face have been. In the following + // (i) we set the next/prev pointer around interior vertices on the mesh + // boundary and (ii) we collect interior mesh border halfedges incident to + // a patch border vertex and set their next/prev pointer (possibly of + // another patch) + + // Containers used for step (ii) for collecting mesh border halfedges + // with source/target on an intersection polyline that needs it prev/next + // pointer to be set + + using GT = boost::graph_traits; + using halfedge_descriptor = typename GT::halfedge_descriptor; + using vertex_descriptor = typename GT::vertex_descriptor; + + const TriangleMesh& tm = patches.pm; + Triangle_mesh_extension_helper helper(tm_to_output_edges, tm_to_output_vertices, tm, output); + + std::vector border_halfedges_source_to_link; + std::vector border_halfedges_target_to_link; + for (std::size_t i : ids_of_patches_to_append) + { + Patch_description& patch = patches[i]; + for(halfedge_descriptor h : patch.border_edges){ + if( (!reverse_patch_orientation && patch.border_with_shared_target.count(h)) || + ( reverse_patch_orientation && patch.border_with_shared_source.count(h)) ) + continue; // since the next halfedge should not be in the same patch + halfedge_descriptor h_out = helper.get_hedge(h); + halfedge_descriptor h_out_next = reverse_patch_orientation + ? helper.get_hedge(prev(h,tm)) + : helper.get_hedge(next(h,tm)); + CGAL_assertion(is_border(h_out,output) && is_border(h_out_next,output)); + set_next(h_out, h_out_next, output); + } + if(reverse_patch_orientation){ + border_halfedges_target_to_link.insert(border_halfedges_target_to_link.begin(), + patch.border_with_shared_source.begin(), + patch.border_with_shared_source.end()); + border_halfedges_source_to_link.insert(border_halfedges_target_to_link.begin(), + patch.border_with_shared_target.begin(), + patch.border_with_shared_target.end()); + } else { + border_halfedges_target_to_link.insert(border_halfedges_target_to_link.begin(), + patch.border_with_shared_target.begin(), + patch.border_with_shared_target.end()); + border_halfedges_source_to_link.insert(border_halfedges_target_to_link.begin(), + patch.border_with_shared_source.begin(), + patch.border_with_shared_source.end()); + } + } + + // now the step (ii) we look for the candidate halfedge by turning around + // the vertex in the direction of the interior of the patch + for(halfedge_descriptor h_out : border_halfedges_target_to_link) + { + halfedge_descriptor candidate = + opposite(prev(opposite(h_out, output), output), output); + CGAL_assertion_code(halfedge_descriptor start=candidate); + while (!is_border(candidate, output)){ + candidate=opposite(prev(candidate, output), output); + CGAL_assertion(candidate!=start); + } + set_next(h_out, candidate, output); + } + + for(halfedge_descriptor h_out : border_halfedges_source_to_link) + { + halfedge_descriptor candidate = + opposite(next(opposite(h_out, output), output), output); + while (!is_border(candidate, output)) + candidate = opposite(next(candidate, output), output); + set_next(candidate, h_out, output); + } + + for (std::size_t i : ids_of_patches_to_append) + { + Patch_description& patch = patches[i]; + // For all patch boundary vertices, update the vertex pointer + // of all but the vertex halfedge + for(halfedge_descriptor h : patch.shared_edges) + { + //check for a halfedge pointing inside an already imported patch + halfedge_descriptor h_out = helper.get_hedge(h); + CGAL_assertion( next(h_out, output)!=GT::null_halfedge() ); + // update the pointers on the target + halfedge_descriptor next_around_target=h_out; + vertex_descriptor v=target(h_out, output); + do{ + next_around_target = opposite(next(next_around_target, output), output); + set_target(next_around_target, v, output); + }while(next(next_around_target, output)!=GT::null_halfedge() && + next_around_target!=h_out && + !is_border(next_around_target, output)); + // update the pointers on the source + halfedge_descriptor next_around_source=prev(h_out, output); + CGAL_assertion(next_around_source!=GT::null_halfedge()); + v = source(h_out, output); + do{ + set_target(next_around_source, v, output); + next_around_source = prev(opposite(next_around_source, output), output); + }while( next_around_source!=GT::null_halfedge() && + next_around_source!=opposite(h_out, output) && + !is_border(next_around_source, output)); + } + } +} + template < bool reverse_patch_orientation, class TriangleMesh, class PatchContainer, @@ -1078,11 +1209,11 @@ void append_patches_to_triangle_mesh( VertextoVertexMap& tm_to_output_vertices, UserVisitor& user_visitor) { - typedef boost::graph_traits GT; - typedef typename GT::halfedge_descriptor halfedge_descriptor; - typedef typename GT::edge_descriptor edge_descriptor; - typedef typename GT::vertex_descriptor vertex_descriptor; - typedef typename GT::face_descriptor face_descriptor; + using GT = boost::graph_traits; + using halfedge_descriptor = typename GT::halfedge_descriptor; + using edge_descriptor = typename GT::edge_descriptor; + using vertex_descriptor = typename GT::vertex_descriptor; + using face_descriptor = typename GT::face_descriptor; const TriangleMesh& tm = patches.pm; Triangle_mesh_extension_helper helper(tm_to_output_edges, tm_to_output_vertices, tm, output); @@ -1190,104 +1321,11 @@ void append_patches_to_triangle_mesh( } } - // handle interior edges that are on the border of the mesh: - // they do not have a prev/next pointer set since only the pointers - // of patch interior halfedges part a face have been. In the following - // (i) we set the next/prev pointer around interior vertices on the mesh - // boundary and (ii) we collect interior mesh border halfedges incident to - // a patch border vertex and set their next/prev pointer (possibly of - // another patch) - - // Containers used for step (ii) for collecting mesh border halfedges - // with source/target on an intersection polyline that needs it prev/next - // pointer to be set - std::vector border_halfedges_source_to_link; - std::vector border_halfedges_target_to_link; - for (std::size_t i : ids_of_patches_to_append) - { - Patch_description& patch = patches[i]; - for(halfedge_descriptor h : patch.border_edges){ - if( (!reverse_patch_orientation && patch.border_with_shared_target.count(h)) || - ( reverse_patch_orientation && patch.border_with_shared_source.count(h)) ) - continue; // since the next halfedge should not be in the same patch - halfedge_descriptor h_out=helper.get_hedge(h); - halfedge_descriptor h_out_next = reverse_patch_orientation - ? helper.get_hedge(prev(h,tm)) - : helper.get_hedge(next(h,tm)); - CGAL_assertion(is_border(h_out,output) && is_border(h_out_next,output)); - set_next(h_out, h_out_next, output); - } - if(reverse_patch_orientation){ - border_halfedges_target_to_link.insert(border_halfedges_target_to_link.begin(), - patch.border_with_shared_source.begin(), - patch.border_with_shared_source.end()); - border_halfedges_source_to_link.insert(border_halfedges_target_to_link.begin(), - patch.border_with_shared_target.begin(), - patch.border_with_shared_target.end()); - } else { - border_halfedges_target_to_link.insert(border_halfedges_target_to_link.begin(), - patch.border_with_shared_target.begin(), - patch.border_with_shared_target.end()); - border_halfedges_source_to_link.insert(border_halfedges_target_to_link.begin(), - patch.border_with_shared_source.begin(), - patch.border_with_shared_source.end()); - } - } - - // now the step (ii) we look for the candidate halfedge by turning around - // the vertex in the direction of the interior of the patch - for(halfedge_descriptor h_out : border_halfedges_target_to_link) - { - halfedge_descriptor candidate = - opposite(prev(opposite(h_out, output), output), output); - CGAL_assertion_code(halfedge_descriptor start=candidate); - while (!is_border(candidate, output)){ - candidate=opposite(prev(candidate, output), output); - CGAL_assertion(candidate!=start); - } - set_next(h_out, candidate, output); - } - - for(halfedge_descriptor h_out : border_halfedges_source_to_link) - { - halfedge_descriptor candidate = - opposite(next(opposite(h_out, output), output), output); - while (!is_border(candidate, output)) - candidate = opposite(next(candidate, output), output); - set_next(candidate, h_out, output); - } - - for (std::size_t i : ids_of_patches_to_append) - { - Patch_description& patch = patches[i]; - // For all patch boundary vertices, update the vertex pointer - // of all but the vertex halfedge - for(halfedge_descriptor h : patch.shared_edges) - { - //check for a halfedge pointing inside an already imported patch - halfedge_descriptor h_out = helper.get_hedge(h); - CGAL_assertion( next(h_out, output)!=GT::null_halfedge() ); - // update the pointers on the target - halfedge_descriptor next_around_target=h_out; - vertex_descriptor v=target(h_out, output); - do{ - next_around_target = opposite(next(next_around_target, output), output); - set_target(next_around_target, v, output); - }while(next(next_around_target, output)!=GT::null_halfedge() && - next_around_target!=h_out && - !is_border(next_around_target, output)); - // update the pointers on the source - halfedge_descriptor next_around_source=prev(h_out, output); - CGAL_assertion(next_around_source!=GT::null_halfedge()); - v = source(h_out, output); - do{ - set_target(next_around_source, v, output); - next_around_source = prev(opposite(next_around_source, output), output); - }while( next_around_source!=GT::null_halfedge() && - next_around_source!=opposite(h_out, output) && - !is_border(next_around_source, output)); - } - } + process_borders_after_appending_patches(output, + ids_of_patches_to_append, + patches, + tm_to_output_edges, + tm_to_output_vertices); } template < class TriangleMesh, diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 0e8db0d47efd..2391513d7755 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -326,8 +326,7 @@ class Intersection_of_triangle_meshes tbb::concurrent_vector> inter; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter), parameters::concurrency_tag(ConcurrencyTag())); - // tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ - for(std::size_t i=0; i& mesh, typedef Surface_mesh

Mesh; typedef typename Mesh::Vertex_index Vertex_index; typedef typename Mesh::Halfedge_index Halfedge_index; - typedef typename Mesh::Edge_index Edge_index; typedef typename Mesh::Face_index Face_index; out << "Points:\n"; diff --git a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h index 27b441b9edcd..c8d1c2dcf975 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h @@ -21,9 +21,6 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { -template -struct is_surface_mesh> : std::true_type {}; - // Specialization of the function for Surface_mesh to exploit vectors structure of Surface_mesh. template < bool reverse_patch_orientation, class Point, @@ -157,7 +154,7 @@ void append_patch( for (int i=0;i<3;++i) { - CGAL_assertion(hedges[i] != null_halfedge()); + CGAL_assertion(hedges[i] != tm.null_halfedge()); if(reverse_patch_orientation) output.set_next(hedges[i], hedges[(i+2)%3]); else @@ -215,10 +212,14 @@ void append_patches_to_triangle_mesh( tnf += patches[i].faces.size(); } output.resize(vertices_idx_begin, edges_idx_begin, faces_idx_begin); + + std::vector ids_of_patches_to_append; + ids_of_patches_to_append.reserve(patches_to_append.count()); for (std::size_t i= patches_to_append.find_first(); i < patches_to_append.npos; i = patches_to_append.find_next(i)) { + ids_of_patches_to_append.push_back(i); Patch_description& patch=patches[i]; append_patch(tm, output, patch, vpm_out, vpm_tm, @@ -231,7 +232,11 @@ void append_patches_to_triangle_mesh( faces_idx_begin += patch.faces.size(); } - // TODO post process borders + process_borders_after_appending_patches(output, + ids_of_patches_to_append, + patches, + tm_to_output_edges, + tm_to_output_vertices); } // Specialization of fill_new_triangle_mesh for Surface_mesh to exploit vectors structure of Surface_mesh. @@ -364,7 +369,11 @@ void fill_new_triangle_mesh( nf += patches_of_tm1[i].faces.size(); } - // TODO post process borders of patches from tm1 + process_borders_after_appending_patches(output, + ids_of_patches_to_append_from_tm1, + patches_of_tm1, + tm1_to_output_edges, + tm1_to_output_vertices); for(std::size_t i : ids_of_patches_to_append_from_tm2){ if(reverse_orientation_of_patches_from_tm2) @@ -392,7 +401,11 @@ void fill_new_triangle_mesh( nf += patches_of_tm2[i].faces.size(); } - // TODO post process borders of patches from tm2 + process_borders_after_appending_patches(output, + ids_of_patches_to_append_from_tm2, + patches_of_tm2, + tm2_to_output_edges, + tm2_to_output_vertices); } } // namespace Corefinement From 08b49de5d0ab84ac37e190fa3a2e5cf23f78a784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 9 Sep 2026 16:30:24 +0200 Subject: [PATCH 016/136] Clean warnings and compilation error in debug --- .../internal/Corefinement/face_graph_utils.h | 58 ++++++++++++------- .../internal/boolean_operations_utils.h | 44 ++++++++------ 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 624405ba4c74..ab70daa8f649 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -715,31 +715,31 @@ void extract_patch_simplices( } } - std::set border_vertices; + std::set shared_vertices; for(halfedge_descriptor h : patch.shared_edges){ - border_vertices.insert( target(h,pm) ); - // if the model is not closed i.e. patch_border_halfedge is not cycle-only + shared_vertices.insert( target(h,pm) ); + // if the model is not closed i.e. patch_shared_halfedge is not cycle-only if(!patch.interior_edges.empty()) - border_vertices.insert( source(h,pm) ); + shared_vertices.insert( source(h,pm) ); } // a patch is a disk v = 2 + e - f - // v_in = v - v_border, e = e_in + e_shared, v_border = e_shared ( +1 if not closed) + // v_in = v - v_shared, e = e_in + e_shared, v_shared = e_shared ( +1 if not closed) // v_in = 2 + e_in - f (-1 if not closed) patch.interior_vertices.reserve(2 + patch.interior_edges.size() - patch.faces.size() ); for(halfedge_descriptor h : patch.interior_edges){ - if ( !border_vertices.count( target(h,pm) ) && + if ( !shared_vertices.count( target(h,pm) ) && halfedge(target(h,pm),pm) == h ) // only add the vertex once patch.interior_vertices.push_back( target(h,pm) ); - if ( !border_vertices.count( source(h,pm) ) && + if ( !shared_vertices.count( source(h,pm) ) && halfedge(source(h,pm),pm) == opposite(h,pm) ) // only add the vertex once patch.interior_vertices.push_back( source(h,pm) ); } for(halfedge_descriptor h : patch.border_edges){ - if ( border_vertices.count( target(h,pm) ) ) + if ( shared_vertices.count( target(h,pm) ) ) patch.border_with_shared_target.emplace(h); - if ( border_vertices.count( source(h,pm) ) ) + if ( shared_vertices.count( source(h,pm) ) ) patch.border_with_shared_source.emplace(h); } } @@ -1115,19 +1115,35 @@ void process_borders_after_appending_patches( set_next(h_out, h_out_next, output); } if(reverse_patch_orientation){ - border_halfedges_target_to_link.insert(border_halfedges_target_to_link.begin(), - patch.border_with_shared_source.begin(), - patch.border_with_shared_source.end()); - border_halfedges_source_to_link.insert(border_halfedges_target_to_link.begin(), - patch.border_with_shared_target.begin(), - patch.border_with_shared_target.end()); + std::cout << "shared target" << std::endl; + for(halfedge_descriptor h : patch.border_with_shared_source){ + halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); + if(!is_border(h_out, output)) h_out = opposite(h_out, output); + border_halfedges_target_to_link.push_back(h_out); + std::cout << h << " " << h_out << std::endl; + } + std::cout << "shared source" << std::endl; + for(halfedge_descriptor h : patch.border_with_shared_target){ + halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); + if(!is_border(h_out, output)) h_out = opposite(h_out, output); + border_halfedges_source_to_link.push_back(h_out); + std::cout << h << " " << h_out << std::endl; + } } else { - border_halfedges_target_to_link.insert(border_halfedges_target_to_link.begin(), - patch.border_with_shared_target.begin(), - patch.border_with_shared_target.end()); - border_halfedges_source_to_link.insert(border_halfedges_target_to_link.begin(), - patch.border_with_shared_source.begin(), - patch.border_with_shared_source.end()); + std::cout << "shared target" << std::endl; + for(halfedge_descriptor h : patch.border_with_shared_target){ + halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); + if(!is_border(h_out, output)) h_out = opposite(h_out, output); + border_halfedges_target_to_link.push_back(h_out); + std::cout << h << " " << h_out << std::endl; + } + std::cout << "shared source" << std::endl; + for(halfedge_descriptor h : patch.border_with_shared_source){ + halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); + if(!is_border(h_out, output)) h_out = opposite(h_out, output); + border_halfedges_source_to_link.push_back(h_out); + std::cout << h << " " << h_out << std::endl; + } } } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h index c8d1c2dcf975..63df2e35406b 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h @@ -130,8 +130,8 @@ void append_patch( else return h_out; } - CGAL_assertion( output.target(h_out) == get(tm_to_output_vertices, output.source(h, tm)) ); - CGAL_assertion( output.source(h_out) == get(tm_to_output_vertices, output.target(h, tm)) ); + CGAL_assertion( output.target(h_out) == get(tm_to_output_vertices, tm.source(h)) ); + CGAL_assertion( output.source(h_out) == get(tm_to_output_vertices, tm.target(h)) ); if constexpr(reverse_patch_orientation) return h_out; else @@ -275,8 +275,6 @@ void fill_new_triangle_mesh( using SM = Surface_mesh; using vertex_descriptor = typename SM::Vertex_index; using edge_descriptor = typename SM::Edge_index; - using halfedge_descriptor = typename SM::Halfedge_index; - using face_descriptor = typename SM::Face_index; using V2V_tag = typename CGAL::dynamic_vertex_property_t; using Vertex_to_vertex_map = typename boost::property_map::const_type; @@ -292,10 +290,6 @@ void fill_new_triangle_mesh( Vertex_to_vertex_map tm1_to_output_vertices = get(V2V_tag(), tm1, SM::null_vertex()), tm2_to_output_vertices = get(V2V_tag(), tm2, SM::null_vertex()); - std::size_t vertices_idx_begin = output.number_of_vertices(); - std::size_t edges_idx_begin = output.number_of_edges(); - std::size_t faces_idx_begin = output.number_of_faces(); - output_shared_edges.reserve( std::accumulate(polylines.lengths.begin(), polylines.lengths.end(), std::size_t(0)) ); std::size_t nb_polylines = polylines.lengths.size(); for (std::size_t i=0; i < nb_polylines; ++i) @@ -369,11 +363,18 @@ void fill_new_triangle_mesh( nf += patches_of_tm1[i].faces.size(); } - process_borders_after_appending_patches(output, - ids_of_patches_to_append_from_tm1, - patches_of_tm1, - tm1_to_output_edges, - tm1_to_output_vertices); + if(reverse_orientation_of_patches_from_tm1) + process_borders_after_appending_patches(output, + ids_of_patches_to_append_from_tm1, + patches_of_tm1, + tm1_to_output_edges, + tm1_to_output_vertices); + else + process_borders_after_appending_patches(output, + ids_of_patches_to_append_from_tm1, + patches_of_tm1, + tm1_to_output_edges, + tm1_to_output_vertices); for(std::size_t i : ids_of_patches_to_append_from_tm2){ if(reverse_orientation_of_patches_from_tm2) @@ -401,11 +402,18 @@ void fill_new_triangle_mesh( nf += patches_of_tm2[i].faces.size(); } - process_borders_after_appending_patches(output, - ids_of_patches_to_append_from_tm2, - patches_of_tm2, - tm2_to_output_edges, - tm2_to_output_vertices); + if(reverse_orientation_of_patches_from_tm2) + process_borders_after_appending_patches(output, + ids_of_patches_to_append_from_tm2, + patches_of_tm2, + tm1_to_output_edges, + tm1_to_output_vertices); + else + process_borders_after_appending_patches(output, + ids_of_patches_to_append_from_tm2, + patches_of_tm2, + tm1_to_output_edges, + tm1_to_output_vertices); } } // namespace Corefinement From 13bd6af13eb994a45367bf9b82585f4151759037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 9 Sep 2026 17:08:46 +0200 Subject: [PATCH 017/136] Rewrite filter_intersections to consider differents callbacks --- .../internal/Corefinement/intersection_impl.h | 254 +++++++++--------- 1 file changed, 133 insertions(+), 121 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 2391513d7755..b010b7877cad 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -259,133 +259,145 @@ class Intersection_of_triangle_meshes using Tree = typename AABB_tree_helper::Tree; AABB_tree_helper helper; - Tree tree1(faces(tm1).begin(), faces(tm1).end(), tm1); - Tree tree2(faces(tm2).begin(), faces(tm2).end(), tm2); + std::vector tm1_faces_intersecting_bb; + std::vector tm2_faces_intersecting_bb; + tm1_faces_intersecting_bb.reserve(num_faces(tm1)); + tm2_faces_intersecting_bb.reserve(num_faces(tm2)); + + for(face_descriptor f: faces(tm1)) + if( do_overlap(face_bbox(f, tm1), bb) ) + tm1_faces_intersecting_bb.push_back(f); + for(face_descriptor f: faces(tm2)) + if( do_overlap(face_bbox(f, tm2), bb) ) + tm2_faces_intersecting_bb.push_back(f); + + Tree tree1(tm1_faces_intersecting_bb.begin(), tm1_faces_intersecting_bb.end(), tm1); + Tree tree2(tm2_faces_intersecting_bb.begin(), tm2_faces_intersecting_bb.end(), tm2); + + // Wrap the call of AABB intersections given two callback functions + auto AABB_call = [&](auto &callback12, auto &callback21){ + #ifdef CGAL_LINKED_WITH_TBB + if constexpr(std::is_same_v) + { + oneapi::tbb::task_group tg; + tg.run([&]{ helper.template build(tree1, tm1, vpm1); }); + helper.template build(tree2, tm2, vpm2); + tg.wait(); + + tbb::concurrent_vector> inter; + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter), parameters::concurrency_tag(ConcurrencyTag())); + + tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ + const auto& [f_1, f_2] = inter[i]; + + halfedge_descriptor hf1_0 = halfedge(f_1, tm1); + halfedge_descriptor hf1_1 = next(hf1_0, tm1); + halfedge_descriptor hf1_2 = next(hf1_1, tm1); + + halfedge_descriptor hf2_0 = halfedge(f_2, tm2); + halfedge_descriptor hf2_1 = next(hf2_0, tm2); + halfedge_descriptor hf2_2 = next(hf2_1, tm2); + + if (is_border(hf2_0, tm2) || hf2_0 < opposite(hf2_0, tm2)) + callback12(hf1_0, hf2_0); + if (is_border(hf2_1, tm2) || hf2_1 < opposite(hf2_1, tm2)) + callback12(hf1_0, hf2_1); + if (is_border(hf2_2, tm2) || hf2_2 < opposite(hf2_2, tm2)) + callback12(hf1_0, hf2_2); + + if (is_border(hf1_0, tm1) || hf1_0 < opposite(hf1_0, tm1)) + callback21(hf2_0, hf1_0); + if (is_border(hf1_1, tm1) || hf1_1 < opposite(hf1_1, tm1)) + callback21(hf2_0, hf1_1); + if (is_border(hf1_2, tm1) || hf1_2 < opposite(hf1_2, tm1)) + callback21(hf2_0, hf1_2); + }); + } + else + #endif + { + helper.template build(tree1, tm1, vpm1); + helper.template build(tree2, tm2, vpm2); + + std::vector> inter; + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter)); + + for(const auto& [f_1, f_2]: inter){ + halfedge_descriptor hf1_0 = halfedge(f_1, tm1); + halfedge_descriptor hf1_1 = next(hf1_0, tm1); + halfedge_descriptor hf1_2 = next(hf1_1, tm1); + + halfedge_descriptor hf2_0 = halfedge(f_2, tm2); + halfedge_descriptor hf2_1 = next(hf2_0, tm2); + halfedge_descriptor hf2_2 = next(hf2_1, tm2); + + if (is_border(hf2_0, tm2) || hf2_0 < opposite(hf2_0, tm2)) + callback12(hf1_0, hf2_0); + if (is_border(hf2_1, tm2) || hf2_1 < opposite(hf2_1, tm2)) + callback12(hf1_0, hf2_1); + if (is_border(hf2_2, tm2) || hf2_2 < opposite(hf2_2, tm2)) + callback12(hf1_0, hf2_2); + + if (is_border(hf1_0, tm1) || hf1_0 < opposite(hf1_0, tm1)) + callback21(hf2_0, hf1_0); + if (is_border(hf1_1, tm1) || hf1_1 < opposite(hf1_1, tm1)) + callback21(hf2_0, hf1_1); + if (is_border(hf1_2, tm1) || hf1_2 < opposite(hf1_2, tm1)) + callback21(hf2_0, hf1_2); + } + } + }; - auto wrap_callback = [&](){ + // Select the desire callbacks #ifdef DO_NOT_HANDLE_COPLANAR_FACES - using Callback = Collect_face_bbox_per_edge_bbox; - Callback callback12(tm1, tm2, ltm_edge_to_stm_faces); - Callback callback21(tm2, tm1, stm_edge_to_ltm_faces); + using Callback = Collect_face_bbox_per_edge_bbox; + Callback callback12(tm1, tm2, ltm_edge_to_stm_faces); + Callback callback21(tm2, tm1, stm_edge_to_ltm_faces); #else - using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling< - TriangleMesh, VPM1, VPM2, Edge_to_faces, Coplanar_face_set, Node_visitor>; - Callback callback12(tm1, tm2, vpm1, vpm2, ltm_edge_to_stm_faces, coplanar_faces, visitor); - Callback callback21(tm2, tm1, vpm2, vpm1, stm_edge_to_ltm_faces, coplanar_faces, visitor); + using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling< + TriangleMesh, VPM1, VPM2, Edge_to_faces, Coplanar_face_set, Node_visitor>; + Callback callback12(tm1, tm2, vpm1, vpm2, ltm_edge_to_stm_faces, coplanar_faces, visitor); + Callback callback21(tm2, tm1, vpm2, vpm1, stm_edge_to_ltm_faces, coplanar_faces, visitor); #endif - // if (throw_on_self_intersection){ - // Callback_with_self_intersection_report callback_si_12(callback12, tm1_faces, tm2_faces); - // Callback_with_self_intersection_report callback_si_21(callback21, tm2_faces, tm1_faces); - // return std::make_pair(callback_si_12, callback_si_21); - // } - // else { - // if (const_mesh_ptr==&tm1) - // { - // auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - // if(!callback12.is_face_degenerated(h1)); - // callback12(h1, h2); - // }; - // auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - // if(!callback21.is_face_degenerated(h1)) - // callback21(h2, h1); - // }; - // return std::make_pair(filtered_callback_12, filtered_callback_21); - // } - // else - // { - // if (const_mesh_ptr==&tm2) - // { - // auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - // if(!callback12.is_face_degenerated(h2)); - // callback12(h1, h2); - // }; - // auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - // if(!callback21.is_face_degenerated(h2)) - // callback21(h2, h1); - // }; - // return std::make_pair(filtered_callback_12, filtered_callback_21); - // } - // else - // { - return std::make_pair(callback12, callback21); - // } - // } - // } - }; - auto [callback12, callback21] = wrap_callback(); - -#ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) - { - oneapi::tbb::task_group tg; - tg.run([&]{ helper.template build(tree1, tm1, vpm1); }); - helper.template build(tree2, tm2, vpm2); - tg.wait(); - - tbb::concurrent_vector> inter; - CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter), parameters::concurrency_tag(ConcurrencyTag())); - - tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ - const auto& [f_1, f_2] = inter[i]; - - halfedge_descriptor hf1_0 = halfedge(f_1, tm1); - halfedge_descriptor hf1_1 = next(hf1_0, tm1); - halfedge_descriptor hf1_2 = next(hf1_1, tm1); - - halfedge_descriptor hf2_0 = halfedge(f_2, tm2); - halfedge_descriptor hf2_1 = next(hf2_0, tm2); - halfedge_descriptor hf2_2 = next(hf2_1, tm2); - - if (is_border(hf2_0, tm2) || hf2_0 < opposite(hf2_0, tm2)) - callback12(hf1_0, hf2_0); - if (is_border(hf2_1, tm2) || hf2_1 < opposite(hf2_1, tm2)) - callback12(hf1_0, hf2_1); - if (is_border(hf2_2, tm2) || hf2_2 < opposite(hf2_2, tm2)) - callback12(hf1_0, hf2_2); - - if (is_border(hf1_0, tm1) || hf1_0 < opposite(hf1_0, tm1)) - callback21(hf2_0, hf1_0); - if (is_border(hf1_1, tm1) || hf1_1 < opposite(hf1_1, tm1)) - callback21(hf2_0, hf1_1); - if (is_border(hf1_2, tm1) || hf1_2 < opposite(hf1_2, tm1)) - callback21(hf2_0, hf1_2); - }); + if (throw_on_self_intersection){ + Callback_with_self_intersection_report callback_si_12(callback12, tm1_faces, tm2_faces); + Callback_with_self_intersection_report callback_si_21(callback21, tm2_faces, tm1_faces); + AABB_call(callback_si_12, callback_si_21); + if (throw_on_self_intersection && (callback_si_21.self_intersections_found() || callback_si_12.self_intersections_found())) + throw Self_intersection_exception(); } - else -#endif - { - helper.template build(tree1, tm1, vpm1); - helper.template build(tree2, tm2, vpm2); - - std::vector> inter; - CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter)); - - for(const auto& [f_1, f_2]: inter){ - halfedge_descriptor hf1_0 = halfedge(f_1, tm1); - halfedge_descriptor hf1_1 = next(hf1_0, tm1); - halfedge_descriptor hf1_2 = next(hf1_1, tm1); - - halfedge_descriptor hf2_0 = halfedge(f_2, tm2); - halfedge_descriptor hf2_1 = next(hf2_0, tm2); - halfedge_descriptor hf2_2 = next(hf2_1, tm2); - - if (is_border(hf2_0, tm2) || hf2_0 < opposite(hf2_0, tm2)) - callback12(hf1_0, hf2_0); - if (is_border(hf2_1, tm2) || hf2_1 < opposite(hf2_1, tm2)) - callback12(hf1_0, hf2_1); - if (is_border(hf2_2, tm2) || hf2_2 < opposite(hf2_2, tm2)) - callback12(hf1_0, hf2_2); - - if (is_border(hf1_0, tm1) || hf1_0 < opposite(hf1_0, tm1)) - callback21(hf2_0, hf1_0); - if (is_border(hf1_1, tm1) || hf1_1 < opposite(hf1_1, tm1)) - callback21(hf2_0, hf1_1); - if (is_border(hf1_2, tm1) || hf1_2 < opposite(hf1_2, tm1)) - callback21(hf2_0, hf1_2); - - // if (throw_on_self_intersection && callback12.self_intersections_found()) - // throw Self_intersection_exception(); + else { + if (const_mesh_ptr==&tm1) + { + auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + if(!callback12.is_face_degenerated(h1)); + callback12(h1, h2); + }; + auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + if(!callback21.is_face_degenerated(h1)) + callback21(h2, h1); + }; + AABB_call(filtered_callback_12, filtered_callback_21); + } + else + { + if (const_mesh_ptr==&tm2) + { + auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + if(!callback12.is_face_degenerated(h2)); + callback12(h1, h2); + }; + auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + if(!callback21.is_face_degenerated(h2)) + callback21(h2, h1); + }; + AABB_call(filtered_callback_12, filtered_callback_21); + } + else + { + AABB_call(callback12, callback21); + } } } } From cb42271870a5abf7d2dd365d06cb4fef91fe2c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 10 Sep 2026 12:45:17 +0200 Subject: [PATCH 018/136] ConcurrencyTag in rebase and clean Callback in intersections_impl --- .../Corefinement/Face_graph_output_builder.h | 2 +- .../internal/Corefinement/face_graph_utils.h | 48 +++++-- .../Corefinement/intersection_callbacks.h | 60 ++------ .../internal/Corefinement/intersection_impl.h | 4 +- .../PMP_Boolean_operations/dependencies | 1 - .../internal/boolean_operations_utils.h | 133 +++++++++++------- 6 files changed, 140 insertions(+), 108 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index c5f72745f495..1807c5b2c313 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -2384,7 +2384,7 @@ class Face_graph_output_builder std::vector shared_edges; #define CGAL_COREF_FUNCTION_CALL_DEF(BO_type) \ - fill_new_triangle_mesh( \ + fill_new_triangle_mesh( \ output, \ patches_of_tm1_used[BO_type], patches_of_tm2_used[BO_type], \ patches_of_tm1, patches_of_tm2, \ diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index ab70daa8f649..f19661fed6bf 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -1115,34 +1115,26 @@ void process_borders_after_appending_patches( set_next(h_out, h_out_next, output); } if(reverse_patch_orientation){ - std::cout << "shared target" << std::endl; for(halfedge_descriptor h : patch.border_with_shared_source){ halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); if(!is_border(h_out, output)) h_out = opposite(h_out, output); border_halfedges_target_to_link.push_back(h_out); - std::cout << h << " " << h_out << std::endl; } - std::cout << "shared source" << std::endl; for(halfedge_descriptor h : patch.border_with_shared_target){ halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); if(!is_border(h_out, output)) h_out = opposite(h_out, output); border_halfedges_source_to_link.push_back(h_out); - std::cout << h << " " << h_out << std::endl; } } else { - std::cout << "shared target" << std::endl; for(halfedge_descriptor h : patch.border_with_shared_target){ halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); if(!is_border(h_out, output)) h_out = opposite(h_out, output); border_halfedges_target_to_link.push_back(h_out); - std::cout << h << " " << h_out << std::endl; } - std::cout << "shared source" << std::endl; for(halfedge_descriptor h : patch.border_with_shared_source){ halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); if(!is_border(h_out, output)) h_out = opposite(h_out, output); border_halfedges_source_to_link.push_back(h_out); - std::cout << h << " " << h_out << std::endl; } } } @@ -1203,7 +1195,8 @@ void process_borders_after_appending_patches( } } -template < bool reverse_patch_orientation, +template < class Concurrency_tag, + bool reverse_patch_orientation, class TriangleMesh, class PatchContainer, class VertexPointMap, @@ -1344,7 +1337,42 @@ void append_patches_to_triangle_mesh( tm_to_output_vertices); } -template < class TriangleMesh, +template < bool reverse_patch_orientation, + class TriangleMesh, + class PatchContainer, + class VertexPointMap, + class VertexPointMapOut, + class EdgeMarkMapOut, + class EdgeMarkMapIn , + class EdgetoEdgeMap, + class VertextoVertexMap, + class UserVisitor> +void append_patches_to_triangle_mesh( + TriangleMesh& output, + const boost::dynamic_bitset<>& patches_to_append, + PatchContainer& patches, + const VertexPointMapOut& vpm_out, + const VertexPointMap& vpm_tm, + EdgeMarkMapOut& edge_mark_map_out, + const EdgeMarkMapIn& edge_mark_map_in, + EdgetoEdgeMap& tm_to_output_edges, + VertextoVertexMap& tm_to_output_vertices, + UserVisitor& user_visitor) +{ + append_patches_to_triangle_mesh(output, + patches_to_append, + patches, + vpm_out, + vpm_tm, + edge_mark_map_out, + edge_mark_map_in, + tm_to_output_edges, + tm_to_output_vertices, + user_visitor); +} + +template < class ConcurrencyTag = Sequential_tag, + class TriangleMesh, class IntersectionEdgeMap, class VertexPointMap1, class VertexPointMap2, diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h index 3694bed5ead4..b25174373f3d 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h @@ -15,7 +15,6 @@ #include -#include #include #include #include @@ -40,9 +39,6 @@ class Collect_face_bbox_per_edge_bbox { typedef typename Graph_traits::face_descriptor face_descriptor; typedef typename Graph_traits::halfedge_descriptor halfedge_descriptor; - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Box; - public: Collect_face_bbox_per_edge_bbox( const TriangleMesh& tm_faces, @@ -53,18 +49,11 @@ class Collect_face_bbox_per_edge_bbox { , edge_to_faces(edge_to_faces) {} - void operator()( const Box& face_box, const Box& edge_box) const + void operator()( halfedge_descriptor fh, halfedge_descriptor eh) const { - halfedge_descriptor fh = face_box.info(); - halfedge_descriptor eh = edge_box.info(); - + // put(edge_to_faces, edge(eh,tm_edges), face(fh, tm_faces)); edge_to_faces[edge(eh,tm_edges)].insert(face(fh, tm_faces)); } - - void operator()( const Box* face_box_ptr, const Box* edge_box_ptr) const - { - operator()(*face_box_ptr, *edge_box_ptr); - } }; template::reference Point; - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Box; - public: Collect_face_bbox_per_edge_bbox_with_coplanar_handling( const TriangleMesh& tm_faces, @@ -182,12 +168,6 @@ class Collect_face_bbox_per_edge_bbox_with_coplanar_handling { return false; } - - void operator()(const Box* face_box_ptr, const Box* edge_box_ptr) const - { - operator()(*face_box_ptr, *edge_box_ptr); - } - void progress(double d) { visitor.progress_filtering_intersections(d); @@ -211,9 +191,6 @@ class Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh { typedef typename Graph_traits::halfedge_descriptor halfedge_descriptor; typedef typename Graph_traits::vertex_descriptor vertex_descriptor; - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Box; - typedef typename boost::property_traits::reference Point; bool is_edge_target_incident_to_face(halfedge_descriptor hd, @@ -274,10 +251,7 @@ class Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh { , coplanar_faces(coplanar_faces) {} - void operator()( const Box& face_box, const Box& edge_box) const { - halfedge_descriptor fh = face_box.info(); - halfedge_descriptor eh = edge_box.info(); - + void operator()(halfedge_descriptor fh, halfedge_descriptor eh) const { if ( face(eh, tm) == face(fh, tm) || face(opposite(eh,tm), tm) == face(fh, tm) ) return; //edge incident to the triangle @@ -355,11 +329,6 @@ class Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh { // non-coplanar case edge_to_faces[edge(eh,tm)].insert(face(fh, tm)); } - - void operator()(const Box* face_box_ptr, const Box* edge_box_ptr) const - { - operator()(*face_box_ptr, *edge_box_ptr); - } }; template @@ -368,7 +337,6 @@ class Callback_with_self_intersection_report { typedef typename Base::face_descriptor face_descriptor; typedef typename Base::halfedge_descriptor halfedge_descriptor; - typedef typename Base::Box Box; std::set* tmf_collected_faces_ptr; std::set* tme_collected_faces_ptr; public: @@ -380,24 +348,24 @@ class Callback_with_self_intersection_report tme_collected_faces_ptr(&tme_collected_faces) {} - void operator()( const Box* fb, const Box* eb) { - 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) ); + void operator()(halfedge_descriptor fh, halfedge_descriptor eh) { + if (!is_border(eh, this->tm_edges)) + tme_collected_faces_ptr->insert( face(eh, this->tm_edges) ); + eh = opposite(eh, this->tm_edges); + if (!is_border(eh, this->tm_edges)) + tme_collected_faces_ptr->insert( face(eh, this->tm_edges) ); + tmf_collected_faces_ptr->insert( face(fh, this->tm_faces) ); // throw if one of the faces are degenerated - if (this->is_face_degenerated(fb->info()) || - this->are_edge_faces_degenerated(h)) + if (this->is_face_degenerated(fh) || + this->are_edge_faces_degenerated(eh)) { throw Self_intersection_exception(); } - Base::operator()(fb, eb); + Base::operator()(fh, eh); } + bool self_intersections_found() { return diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index b010b7877cad..40be5f84d5d9 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -371,7 +371,7 @@ class Intersection_of_triangle_meshes if (const_mesh_ptr==&tm1) { auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - if(!callback12.is_face_degenerated(h1)); + if(!callback12.is_face_degenerated(h1)) callback12(h1, h2); }; auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ @@ -385,7 +385,7 @@ class Intersection_of_triangle_meshes if (const_mesh_ptr==&tm2) { auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - if(!callback12.is_face_degenerated(h2)); + if(!callback12.is_face_degenerated(h2)) callback12(h1, h2); }; auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ diff --git a/PMP_Boolean_operations/package_info/PMP_Boolean_operations/dependencies b/PMP_Boolean_operations/package_info/PMP_Boolean_operations/dependencies index ae85e3b1fb0f..b774cf106c89 100644 --- a/PMP_Boolean_operations/package_info/PMP_Boolean_operations/dependencies +++ b/PMP_Boolean_operations/package_info/PMP_Boolean_operations/dependencies @@ -2,7 +2,6 @@ AABB_tree Algebraic_foundations Arithmetic_kernel BGL -Box_intersection_d CGAL_Core Cartesian_kernel Circulator diff --git a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h index 63df2e35406b..4f54e7521c8c 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h @@ -22,7 +22,8 @@ namespace Polygon_mesh_processing { namespace Corefinement { // Specialization of the function for Surface_mesh to exploit vectors structure of Surface_mesh. -template < bool reverse_patch_orientation, +template < class ConcurrencyTag, + bool reverse_patch_orientation, class Point, class PatchDescription, class VertexPointMap, @@ -64,7 +65,7 @@ void append_patch( }; #ifdef CGAL_LINKED_WITH_TBB - if constexpr(true){ + if constexpr(std::is_same_v){ tbb::parallel_for(std::size_t(0), patch.interior_vertices.size(), fill_vertex); } else @@ -111,7 +112,7 @@ void append_patch( } }; #ifdef CGAL_LINKED_WITH_TBB - if constexpr(true){ + if constexpr(std::is_same_v){ tbb::parallel_for(std::size_t(0), patch.interior_edges.size(), fill_edge); } else @@ -163,7 +164,7 @@ void append_patch( } }; #ifdef CGAL_LINKED_WITH_TBB - if constexpr(true){ + if constexpr(std::is_same_v){ tbb::parallel_for(std::size_t(0), patch.faces.size(), fill_face); } else @@ -174,7 +175,8 @@ void append_patch( } // Specialization of the function for Surface_mesh to exploit vectors structure of Surface_mesh. -template < bool reverse_patch_orientation, +template < class ConcurrencyTag, + bool reverse_patch_orientation, class Point, class PatchContainer, class VertexPointMap, @@ -221,12 +223,12 @@ void append_patches_to_triangle_mesh( { ids_of_patches_to_append.push_back(i); Patch_description& patch=patches[i]; - append_patch(tm, output, patch, - vpm_out, vpm_tm, - edge_mark_map_out, edge_mark_map_in, - tm_to_output_edges, tm_to_output_vertices, - user_visitor, - vertices_idx_begin, edges_idx_begin, faces_idx_begin); + append_patch(tm, output, patch, + vpm_out, vpm_tm, + edge_mark_map_out, edge_mark_map_in, + tm_to_output_edges, tm_to_output_vertices, + user_visitor, + vertices_idx_begin, edges_idx_begin, faces_idx_begin); vertices_idx_begin += patch.interior_vertices.size(); edges_idx_begin += patch.interior_edges.size(); faces_idx_begin += patch.faces.size(); @@ -239,8 +241,43 @@ void append_patches_to_triangle_mesh( tm_to_output_vertices); } +template < bool reverse_patch_orientation, + class Point, + class PatchContainer, + class VertexPointMap, + class VertexPointMapOut, + class EdgeMarkMapOut, + class EdgeMarkMapIn , + class EdgetoEdgeMap, + class VertextoVertexMap, + class UserVisitor> +void append_patches_to_triangle_mesh( + Surface_mesh& output, + const boost::dynamic_bitset<>& patches_to_append, + PatchContainer& patches, + const VertexPointMapOut& vpm_out, + const VertexPointMap& vpm_tm, + EdgeMarkMapOut& edge_mark_map_out, + const EdgeMarkMapIn& edge_mark_map_in, + EdgetoEdgeMap& tm_to_output_edges, + VertextoVertexMap& tm_to_output_vertices, + UserVisitor& user_visitor) +{ + append_patches_to_triangle_mesh(output, + patches_to_append, + patches, + vpm_out, + vpm_tm, + edge_mark_map_out, + edge_mark_map_in, + tm_to_output_edges, + tm_to_output_vertices, + user_visitor); +} + // Specialization of fill_new_triangle_mesh for Surface_mesh to exploit vectors structure of Surface_mesh. -template < class Point, +template < class ConcurrencyTag = Sequential_tag, + class Point, class IntersectionEdgeMap, class VertexPointMap1, class VertexPointMap2, @@ -339,25 +376,25 @@ void fill_new_triangle_mesh( // Append patches for (std::size_t i : ids_of_patches_to_append_from_tm1){ if(reverse_orientation_of_patches_from_tm1) - append_patch(tm1, output, - patches_of_tm1[i], - vpm_out, vpm1, - edge_mark_map_out, - edge_mark_map1, - tm1_to_output_edges, - tm1_to_output_vertices, - user_visitor, - nv, ne, nf); + append_patch(tm1, output, + patches_of_tm1[i], + vpm_out, vpm1, + edge_mark_map_out, + edge_mark_map1, + tm1_to_output_edges, + tm1_to_output_vertices, + user_visitor, + nv, ne, nf); else - append_patch(tm1, output, - patches_of_tm1[i], - vpm_out, vpm1, - edge_mark_map_out, - edge_mark_map1, - tm1_to_output_edges, - tm1_to_output_vertices, - user_visitor, - nv, ne, nf); + append_patch(tm1, output, + patches_of_tm1[i], + vpm_out, vpm1, + edge_mark_map_out, + edge_mark_map1, + tm1_to_output_edges, + tm1_to_output_vertices, + user_visitor, + nv, ne, nf); nv += patches_of_tm1[i].interior_vertices.size(); ne += patches_of_tm1[i].interior_edges.size(); nf += patches_of_tm1[i].faces.size(); @@ -378,25 +415,25 @@ void fill_new_triangle_mesh( for(std::size_t i : ids_of_patches_to_append_from_tm2){ if(reverse_orientation_of_patches_from_tm2) - append_patch(tm2, output, - patches_of_tm2[i], - vpm_out, vpm2, - edge_mark_map_out, - edge_mark_map2, - tm2_to_output_edges, - tm2_to_output_vertices, - user_visitor, - nv, ne, nf); + append_patch(tm2, output, + patches_of_tm2[i], + vpm_out, vpm2, + edge_mark_map_out, + edge_mark_map2, + tm2_to_output_edges, + tm2_to_output_vertices, + user_visitor, + nv, ne, nf); else - append_patch(tm2, output, - patches_of_tm2[i], - vpm_out, vpm2, - edge_mark_map_out, - edge_mark_map2, - tm2_to_output_edges, - tm2_to_output_vertices, - user_visitor, - nv, ne, nf); + append_patch(tm2, output, + patches_of_tm2[i], + vpm_out, vpm2, + edge_mark_map_out, + edge_mark_map2, + tm2_to_output_edges, + tm2_to_output_vertices, + user_visitor, + nv, ne, nf); nv += patches_of_tm2[i].interior_vertices.size(); ne += patches_of_tm2[i].interior_edges.size(); nf += patches_of_tm2[i].faces.size(); From 56f665f6cd0814901eb6dfcdeeddb011d175f9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 10 Sep 2026 16:13:10 +0200 Subject: [PATCH 019/136] Considered non_manifold_feature_map --- .../internal/Corefinement/intersection_impl.h | 140 +++++++++++------- 1 file changed, 85 insertions(+), 55 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 40be5f84d5d9..29caf1e7be90 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -240,7 +240,7 @@ class Intersection_of_triangle_meshes CGAL_assertion_code(bool doing_autorefinement;) // member functions - template + template void filter_intersections(const TriangleMesh& tm1, const TriangleMesh& tm2, const VPM1& vpm1, @@ -251,8 +251,10 @@ class Intersection_of_triangle_meshes std::set& tm1_faces, std::set& tm2_faces, Bbox_3 bb, - ISM1 is_shared_map_1, - ISM2 is_shared_map_2) + ISFM1 is_shared_face_map_1, + ISFM2 is_shared_face_map_2, + ISEM1 is_shared_edge_map_1, + ISEM2 is_shared_edge_map_2) { using GT = typename GetGeomTraits::type; using AABB_tree_helper = internal::AABB_tree_graph_helper; @@ -265,15 +267,70 @@ class Intersection_of_triangle_meshes tm2_faces_intersecting_bb.reserve(num_faces(tm2)); for(face_descriptor f: faces(tm1)) - if( do_overlap(face_bbox(f, tm1), bb) ) + if( !get(is_shared_face_map_1, f) && do_overlap(face_bbox(f, tm1), bb) ) tm1_faces_intersecting_bb.push_back(f); for(face_descriptor f: faces(tm2)) - if( do_overlap(face_bbox(f, tm2), bb) ) + if( !get(is_shared_face_map_2, f) && do_overlap(face_bbox(f, tm2), bb) ) tm2_faces_intersecting_bb.push_back(f); Tree tree1(tm1_faces_intersecting_bb.begin(), tm1_faces_intersecting_bb.end(), tm1); Tree tree2(tm2_faces_intersecting_bb.begin(), tm2_faces_intersecting_bb.end(), tm2); + auto process_candidates_without_non_manifold_map = [&](face_descriptor f_1, face_descriptor f_2, auto &callback12, auto &callback21){ + std::array hf1 = { halfedge(f_1, tm1), + next(halfedge(f_1, tm1), tm1), + next(next(halfedge(f_1, tm1), tm1), tm1) }; + + std::array hf2 = { halfedge(f_2, tm2), + next(halfedge(f_2, tm2), tm2), + next(next(halfedge(f_2, tm2), tm2), tm2) }; + + for(halfedge_descriptor h : hf2){ + edge_descriptor e = edge(h, tm2); + if( !get(is_shared_edge_map_2, e) && (is_border(h, tm2) || h < opposite(h, tm2))) + callback12(hf1[0], h); + } + for(halfedge_descriptor h : hf1){ + edge_descriptor e = edge(h, tm1); + if( !get(is_shared_edge_map_1, e) && (is_border(h, tm1) || h < opposite(h, tm1))) + callback21(hf2[0], h); + } + }; + auto process_candidates_with_non_manifold_map = [&](face_descriptor f_1, face_descriptor f_2, auto &callback12, auto &callback21){ + std::array hf1 = { halfedge(f_1, tm1), + next(halfedge(f_1, tm1), tm1), + next(next(halfedge(f_1, tm1), tm1), tm1) }; + + std::array hf2 = { halfedge(f_2, tm2), + next(halfedge(f_2, tm2), tm2), + next(next(halfedge(f_2, tm2), tm2), tm2) }; + + for(halfedge_descriptor h : hf2){ + edge_descriptor ed = edge(h, tm2); + std::size_t eid=get(non_manifold_feature_map_2.e_nm_id, ed); + if (eid!=NM_NID){ + if (non_manifold_feature_map_2.non_manifold_edges[eid].front()!=ed) continue; + else + // make sure the halfedge used is consistent with stored one + h = halfedge(non_manifold_feature_map_2.non_manifold_edges[eid].front(), tm2); + } + if( !get(is_shared_edge_map_2, ed) && (is_border(h, tm2) || h < opposite(h, tm2))) + callback12(hf1[0], h); + } + for(halfedge_descriptor h : hf1){ + edge_descriptor ed = edge(h, tm1); + std::size_t eid=get(non_manifold_feature_map_1.e_nm_id, ed); + if (eid!=NM_NID){ + if (non_manifold_feature_map_1.non_manifold_edges[eid].front()!=ed) continue; + else + // make sure the halfedge used is consistent with stored one + h = halfedge(non_manifold_feature_map_1.non_manifold_edges[eid].front(), tm2); + } + if( !get(is_shared_edge_map_1, ed) && (is_border(h, tm1) || h < opposite(h, tm1))) + callback21(h, hf2[0]); + } + }; + // Wrap the call of AABB intersections given two callback functions auto AABB_call = [&](auto &callback12, auto &callback21){ #ifdef CGAL_LINKED_WITH_TBB @@ -287,31 +344,16 @@ class Intersection_of_triangle_meshes tbb::concurrent_vector> inter; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter), parameters::concurrency_tag(ConcurrencyTag())); - tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ - const auto& [f_1, f_2] = inter[i]; - - halfedge_descriptor hf1_0 = halfedge(f_1, tm1); - halfedge_descriptor hf1_1 = next(hf1_0, tm1); - halfedge_descriptor hf1_2 = next(hf1_1, tm1); - - halfedge_descriptor hf2_0 = halfedge(f_2, tm2); - halfedge_descriptor hf2_1 = next(hf2_0, tm2); - halfedge_descriptor hf2_2 = next(hf2_1, tm2); - - if (is_border(hf2_0, tm2) || hf2_0 < opposite(hf2_0, tm2)) - callback12(hf1_0, hf2_0); - if (is_border(hf2_1, tm2) || hf2_1 < opposite(hf2_1, tm2)) - callback12(hf1_0, hf2_1); - if (is_border(hf2_2, tm2) || hf2_2 < opposite(hf2_2, tm2)) - callback12(hf1_0, hf2_2); - - if (is_border(hf1_0, tm1) || hf1_0 < opposite(hf1_0, tm1)) - callback21(hf2_0, hf1_0); - if (is_border(hf1_1, tm1) || hf1_1 < opposite(hf1_1, tm1)) - callback21(hf2_0, hf1_1); - if (is_border(hf1_2, tm1) || hf1_2 < opposite(hf1_2, tm1)) - callback21(hf2_0, hf1_2); - }); + if(non_manifold_feature_map_1.non_manifold_edges.empty() && non_manifold_feature_map_2.non_manifold_edges.empty()) + tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ + const auto& [f_1, f_2] = inter[i]; + process_candidates_without_non_manifold_map(f_1, f_2, callback12, callback21); + }); + else + tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ + const auto& [f_1, f_2] = inter[i]; + process_candidates_with_non_manifold_map(f_1, f_2, callback12, callback21); + }); } else #endif @@ -322,29 +364,12 @@ class Intersection_of_triangle_meshes std::vector> inter; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter)); - for(const auto& [f_1, f_2]: inter){ - halfedge_descriptor hf1_0 = halfedge(f_1, tm1); - halfedge_descriptor hf1_1 = next(hf1_0, tm1); - halfedge_descriptor hf1_2 = next(hf1_1, tm1); - - halfedge_descriptor hf2_0 = halfedge(f_2, tm2); - halfedge_descriptor hf2_1 = next(hf2_0, tm2); - halfedge_descriptor hf2_2 = next(hf2_1, tm2); - - if (is_border(hf2_0, tm2) || hf2_0 < opposite(hf2_0, tm2)) - callback12(hf1_0, hf2_0); - if (is_border(hf2_1, tm2) || hf2_1 < opposite(hf2_1, tm2)) - callback12(hf1_0, hf2_1); - if (is_border(hf2_2, tm2) || hf2_2 < opposite(hf2_2, tm2)) - callback12(hf1_0, hf2_2); - - if (is_border(hf1_0, tm1) || hf1_0 < opposite(hf1_0, tm1)) - callback21(hf2_0, hf1_0); - if (is_border(hf1_1, tm1) || hf1_1 < opposite(hf1_1, tm1)) - callback21(hf2_0, hf1_1); - if (is_border(hf1_2, tm1) || hf1_2 < opposite(hf1_2, tm1)) - callback21(hf2_0, hf1_2); - } + if(non_manifold_feature_map_1.non_manifold_edges.empty() && non_manifold_feature_map_2.non_manifold_edges.empty()) + for(const auto& [f_1, f_2]: inter) + process_candidates_without_non_manifold_map(f_1, f_2, callback12, callback21); + else + for(const auto& [f_1, f_2]: inter) + process_candidates_with_non_manifold_map(f_1, f_2, callback12, callback21); } }; @@ -1899,7 +1924,12 @@ class Intersection_of_triangle_meshes if (!identical_meshes) { visitor.start_filtering_intersections(); - filter_intersections(tm1, tm2, vpm1, vpm2, non_manifold_feature_map_1, non_manifold_feature_map_2, throw_on_self_intersection, tm1_faces, tm2_faces, bb12, is_fshared_map1, is_eshared_map2); + filter_intersections(tm1, tm2, vpm1, vpm2, + non_manifold_feature_map_1, non_manifold_feature_map_2, + throw_on_self_intersection, + tm1_faces, tm2_faces, + bb12, + is_fshared_map1, is_fshared_map2, is_eshared_map1, is_eshared_map2); visitor.end_filtering_intersections(); // dumping shared edges in output @@ -1942,7 +1972,7 @@ class Intersection_of_triangle_meshes Static_boolean_property_map is_fshared_map; Static_boolean_property_map is_eshared_map; visitor.start_filtering_intersections(); - filter_intersections(tm1, tm2, vpm1, vpm2, non_manifold_feature_map_1, non_manifold_feature_map_2, throw_on_self_intersection, tm1_faces, tm2_faces, bb12, is_fshared_map, is_eshared_map); + filter_intersections(tm1, tm2, vpm1, vpm2, non_manifold_feature_map_1, non_manifold_feature_map_2, throw_on_self_intersection, tm1_faces, tm2_faces, bb12, is_fshared_map, is_fshared_map, is_eshared_map, is_eshared_map); visitor.end_filtering_intersections(); } From c86415c60bc702c08eb1649b56dc0ba0d80a5bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 11 Sep 2026 17:03:19 +0200 Subject: [PATCH 020/136] Solved a bug with wrong orientation in the output --- .../internal/Corefinement/face_graph_utils.h | 20 ++++++------- .../internal/boolean_operations_utils.h | 28 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index f19661fed6bf..fe4c9f1d6aa7 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -1359,16 +1359,16 @@ void append_patches_to_triangle_mesh( VertextoVertexMap& tm_to_output_vertices, UserVisitor& user_visitor) { - append_patches_to_triangle_mesh(output, - patches_to_append, - patches, - vpm_out, - vpm_tm, - edge_mark_map_out, - edge_mark_map_in, - tm_to_output_edges, - tm_to_output_vertices, - user_visitor); + append_patches_to_triangle_mesh(output, + patches_to_append, + patches, + vpm_out, + vpm_tm, + edge_mark_map_out, + edge_mark_map_in, + tm_to_output_edges, + tm_to_output_vertices, + user_visitor); } template < class ConcurrencyTag = Sequential_tag, diff --git a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h index 4f54e7521c8c..dc55f06fad4f 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h @@ -263,16 +263,16 @@ void append_patches_to_triangle_mesh( VertextoVertexMap& tm_to_output_vertices, UserVisitor& user_visitor) { - append_patches_to_triangle_mesh(output, - patches_to_append, - patches, - vpm_out, - vpm_tm, - edge_mark_map_out, - edge_mark_map_in, - tm_to_output_edges, - tm_to_output_vertices, - user_visitor); + append_patches_to_triangle_mesh(output, + patches_to_append, + patches, + vpm_out, + vpm_tm, + edge_mark_map_out, + edge_mark_map_in, + tm_to_output_edges, + tm_to_output_vertices, + user_visitor); } // Specialization of fill_new_triangle_mesh for Surface_mesh to exploit vectors structure of Surface_mesh. @@ -443,14 +443,14 @@ void fill_new_triangle_mesh( process_borders_after_appending_patches(output, ids_of_patches_to_append_from_tm2, patches_of_tm2, - tm1_to_output_edges, - tm1_to_output_vertices); + tm2_to_output_edges, + tm2_to_output_vertices); else process_borders_after_appending_patches(output, ids_of_patches_to_append_from_tm2, patches_of_tm2, - tm1_to_output_edges, - tm1_to_output_vertices); + tm2_to_output_edges, + tm2_to_output_vertices); } } // namespace Corefinement From 71c4aa93520c2888d759730f4744d2dd0b60afeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 11 Sep 2026 18:10:10 +0200 Subject: [PATCH 021/136] Correctly consider VPM in filter_intersections --- AABB_tree/include/CGAL/AABB_traits_3.h | 2 +- .../internal/Corefinement/intersection_impl.h | 28 +++++++++++-------- .../soup_and_face_graph_tree_helper.h | 4 +-- .../self_intersections.h | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_traits_3.h b/AABB_tree/include/CGAL/AABB_traits_3.h index 2db15ada3a4c..30b59bc8919d 100644 --- a/AABB_tree/include/CGAL/AABB_traits_3.h +++ b/AABB_tree/include/CGAL/AABB_traits_3.h @@ -761,7 +761,7 @@ class AABB_traits_3 } /// Comparison functions - static bool less_x(const Primitive& pr1, const Primitive& pr2,const AABB_traits_3& traits) + static bool less_x(const Primitive& pr1, const Primitive& pr2,const AABB_traits_3& traits) { return GeomTraits().less_x_3_object()( internal::Primitive_helper::get_reference_point(pr1,traits), internal::Primitive_helper::get_reference_point(pr2,traits) ); diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 29caf1e7be90..898bcd4e2971 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -256,10 +256,14 @@ class Intersection_of_triangle_meshes ISEM1 is_shared_edge_map_1, ISEM2 is_shared_edge_map_2) { - using GT = typename GetGeomTraits::type; - using AABB_tree_helper = internal::AABB_tree_graph_helper; - using Tree = typename AABB_tree_helper::Tree; - AABB_tree_helper helper; + using Point = typename boost::property_traits::value_type; + using GT = typename CGAL::Kernel_traits::Kernel; + using AABB_tree_helper_1 = internal::AABB_tree_graph_helper; + using AABB_tree_helper_2 = internal::AABB_tree_graph_helper; + using Tree_1 = typename AABB_tree_helper_1::Tree; + using Tree_2 = typename AABB_tree_helper_2::Tree; + AABB_tree_helper_1 helper_1; + AABB_tree_helper_2 helper_2; std::vector tm1_faces_intersecting_bb; std::vector tm2_faces_intersecting_bb; @@ -273,8 +277,8 @@ class Intersection_of_triangle_meshes if( !get(is_shared_face_map_2, f) && do_overlap(face_bbox(f, tm2), bb) ) tm2_faces_intersecting_bb.push_back(f); - Tree tree1(tm1_faces_intersecting_bb.begin(), tm1_faces_intersecting_bb.end(), tm1); - Tree tree2(tm2_faces_intersecting_bb.begin(), tm2_faces_intersecting_bb.end(), tm2); + Tree_1 tree1(tm1_faces_intersecting_bb.begin(), tm1_faces_intersecting_bb.end(), tm1, vpm1); + Tree_2 tree2(tm2_faces_intersecting_bb.begin(), tm2_faces_intersecting_bb.end(), tm2, vpm2); auto process_candidates_without_non_manifold_map = [&](face_descriptor f_1, face_descriptor f_2, auto &callback12, auto &callback21){ std::array hf1 = { halfedge(f_1, tm1), @@ -337,8 +341,8 @@ class Intersection_of_triangle_meshes if constexpr(std::is_same_v) { oneapi::tbb::task_group tg; - tg.run([&]{ helper.template build(tree1, tm1, vpm1); }); - helper.template build(tree2, tm2, vpm2); + tg.run([&]{ helper_1.template build(tree1, tm1, vpm1); }); + helper_2.template build(tree2, tm2, vpm2); tg.wait(); tbb::concurrent_vector> inter; @@ -358,8 +362,8 @@ class Intersection_of_triangle_meshes else #endif { - helper.template build(tree1, tm1, vpm1); - helper.template build(tree2, tm2, vpm2); + helper_1.template build(tree1, tm1, vpm1); + helper_2.template build(tree2, tm2, vpm2); std::vector> inter; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter)); @@ -433,11 +437,11 @@ class Intersection_of_triangle_meshes const VPM& vpm) { using GT = typename GetGeomTraits::type; - using AABB_tree_helper = internal::AABB_tree_graph_helper; + using AABB_tree_helper = internal::AABB_tree_graph_helper; using Tree = typename AABB_tree_helper::Tree; AABB_tree_helper helper; - Tree tree(faces(tm).begin(), faces(tm).end(), tm); + Tree tree(faces(tm).begin(), faces(tm).end(), tm, vpm); helper.template build(tree, tm, vpm); using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh< diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 7d4ba80a8929..75cb035649b4 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -34,10 +34,10 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace internal { -template +template struct AABB_tree_graph_helper { - using Primitive = AABB_face_graph_triangle_primitive; + using Primitive = AABB_face_graph_triangle_primitive; using Traits = AABB_traits_3; using Tree = AABB_tree; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index 055a8414083e..d62c195359ad 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -68,7 +68,7 @@ struct Triangle_mesh_and_triangle_soup_wrapper using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; using halfedge_descriptor = typename boost::graph_traits::halfedge_descriptor; // private - using Tree_helper = AABB_tree_graph_helper; + using Tree_helper = AABB_tree_graph_helper; using Tree = typename Tree_helper::Tree; template From 0c7ced2f2dea8adb698f20ea4e18a891d676582b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 11 Sep 2026 18:20:51 +0200 Subject: [PATCH 022/136] does_self_intersect does not support Orthogonal_cut_plane_traits, transfer only relevant named parameter in clip --- .../include/CGAL/Polygon_mesh_processing/refine_with_plane.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h index 1d0ca1c95d9a..249089fbe6c9 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h @@ -442,7 +442,7 @@ void refine_with_plane(PolygonMesh& pm, std::sort(test_faces.begin(), test_faces.end()); auto last = std::unique(test_faces.begin(), test_faces.end()); test_faces.erase(last, test_faces.end()); - if (does_self_intersect(test_faces, pm, np)) + if (does_self_intersect(test_faces, pm, parameters::vertex_point_map(vpm).concurrency_tag(Concurrency_tag()))) throw Corefinement::Self_intersection_exception(); } From 6937cc9a68c9c710c74cf858bc226135dc5447ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 14 Sep 2026 14:41:02 +0200 Subject: [PATCH 023/136] Transfer changement of face_graph_utils into boolean_operation_utils of surface_mesh --- .../internal/boolean_operations_utils.h | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h index dc55f06fad4f..3377eb413973 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h @@ -28,8 +28,8 @@ template < class ConcurrencyTag, class PatchDescription, class VertexPointMap, class VertexPointMapOut, - class EdgeMarkMapOut, - class EdgeMarkMapIn, + class EdgeCstMapOut, class EdgeMarkMapOut, + class EdgeCstMapIn , class EdgeMarkMapIn , class EdgeToEdgeMap, class VertexToVertexMap, class UserVisitor> @@ -39,8 +39,8 @@ void append_patch( PatchDescription& patch, const VertexPointMapOut& vpm_out, const VertexPointMap& vpm_tm, - EdgeMarkMapOut& edge_mark_map_out, - const EdgeMarkMapIn& edge_mark_map_in, + EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, + const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgeToEdgeMap& tm_to_output_edges, VertexToVertexMap& tm_to_output_vertices, UserVisitor& user_visitor, @@ -90,8 +90,8 @@ void append_patch( user_visitor.after_edge_copy(h, tm, new_h, output); // copy the mark on input edge to the output edge - copy_edge_mark(tm.edge(h), new_edge, - edge_mark_map_in, edge_mark_map_out); + copy_constraint_status(tm.edge(h), new_edge, edge_cst_map_in, edge_cst_map_out); + copy_constraint_status(tm.edge(h), new_edge, edge_mark_map_in, edge_mark_map_out); CGAL_assertion(is_border(new_h, output)); CGAL_assertion(is_border(opposite(new_h, output), output)); @@ -181,8 +181,8 @@ template < class ConcurrencyTag, class PatchContainer, class VertexPointMap, class VertexPointMapOut, - class EdgeMarkMapOut, - class EdgeMarkMapIn, + class EdgeCstMapOut, class EdgeMarkMapOut, + class EdgeCstMapIn , class EdgeMarkMapIn , class EdgeToEdgeMap, class VertexToVertexMap, class UserVisitor> @@ -192,8 +192,8 @@ void append_patches_to_triangle_mesh( PatchContainer& patches, const VertexPointMapOut& vpm_out, const VertexPointMap& vpm_tm, - EdgeMarkMapOut& edge_mark_map_out, - const EdgeMarkMapIn& edge_mark_map_in, + EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, + const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgeToEdgeMap& tm_to_output_edges, VertexToVertexMap& tm_to_output_vertices, UserVisitor& user_visitor) @@ -225,7 +225,8 @@ void append_patches_to_triangle_mesh( Patch_description& patch=patches[i]; append_patch(tm, output, patch, vpm_out, vpm_tm, - edge_mark_map_out, edge_mark_map_in, + edge_cst_map_out, edge_mark_map_out, + edge_cst_map_in, edge_mark_map_in, tm_to_output_edges, tm_to_output_vertices, user_visitor, vertices_idx_begin, edges_idx_begin, faces_idx_begin); @@ -246,8 +247,8 @@ template < bool reverse_patch_orientation, class PatchContainer, class VertexPointMap, class VertexPointMapOut, - class EdgeMarkMapOut, - class EdgeMarkMapIn , + class EdgeCstMapOut, class EdgeMarkMapOut, + class EdgeCstMapIn , class EdgeMarkMapIn , class EdgetoEdgeMap, class VertextoVertexMap, class UserVisitor> @@ -257,8 +258,8 @@ void append_patches_to_triangle_mesh( PatchContainer& patches, const VertexPointMapOut& vpm_out, const VertexPointMap& vpm_tm, - EdgeMarkMapOut& edge_mark_map_out, - const EdgeMarkMapIn& edge_mark_map_in, + EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, + const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgetoEdgeMap& tm_to_output_edges, VertextoVertexMap& tm_to_output_vertices, UserVisitor& user_visitor) @@ -268,8 +269,8 @@ void append_patches_to_triangle_mesh( patches, vpm_out, vpm_tm, - edge_mark_map_out, - edge_mark_map_in, + edge_cst_map_out, edge_mark_map_out, + edge_cst_map_in, edge_mark_map_in, tm_to_output_edges, tm_to_output_vertices, user_visitor); @@ -282,9 +283,9 @@ template < class ConcurrencyTag = Sequential_tag, class VertexPointMap1, class VertexPointMap2, class VertexPointMapOut, - class EdgeMarkMap1, - class EdgeMarkMap2, - class EdgeMarkMapOut, + class EdgeCstMap1, class EdgeCstMap2, + class EdgeMarkMap1, class EdgeMarkMap2, + class EdgeCstMapOut, class EdgeMarkMapOut, class IntersectionPolylines, class PatchContainer1, class PatchContainer2, @@ -303,9 +304,9 @@ void fill_new_triangle_mesh( const VertexPointMap1& vpm1, const VertexPointMap2& vpm2, const VertexPointMapOut& vpm_out, - const EdgeMarkMap1& edge_mark_map1, - const EdgeMarkMap2& edge_mark_map2, - EdgeMarkMapOut& edge_mark_map_out, + const EdgeCstMap1& edge_cst_map1, const EdgeCstMap2& edge_cst_map2, + const EdgeMarkMap1& edge_mark_map1, const EdgeMarkMap2& edge_mark_map2, + EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, std::vector< typename Surface_mesh::Edge_index >& output_shared_edges, UserVisitor& user_visitor) { @@ -379,7 +380,9 @@ void fill_new_triangle_mesh( append_patch(tm1, output, patches_of_tm1[i], vpm_out, vpm1, + edge_cst_map_out, edge_mark_map_out, + edge_cst_map1, edge_mark_map1, tm1_to_output_edges, tm1_to_output_vertices, @@ -389,7 +392,9 @@ void fill_new_triangle_mesh( append_patch(tm1, output, patches_of_tm1[i], vpm_out, vpm1, + edge_cst_map_out, edge_mark_map_out, + edge_cst_map1, edge_mark_map1, tm1_to_output_edges, tm1_to_output_vertices, @@ -418,7 +423,9 @@ void fill_new_triangle_mesh( append_patch(tm2, output, patches_of_tm2[i], vpm_out, vpm2, + edge_cst_map_out, edge_mark_map_out, + edge_cst_map2, edge_mark_map2, tm2_to_output_edges, tm2_to_output_vertices, @@ -428,7 +435,9 @@ void fill_new_triangle_mesh( append_patch(tm2, output, patches_of_tm2[i], vpm_out, vpm2, + edge_cst_map_out, edge_mark_map_out, + edge_cst_map2, edge_mark_map2, tm2_to_output_edges, tm2_to_output_vertices, From 968b471d2e9c86864ad4bab248b7c4fd875b3662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 14 Sep 2026 16:01:19 +0200 Subject: [PATCH 024/136] Solved a bug in concurrency execution --- .../internal/Corefinement/intersection_impl.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index eded28685c77..060ac65b1c43 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -349,16 +349,16 @@ class Intersection_of_triangle_meshes tbb::concurrent_vector> inter; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter), parameters::concurrency_tag(ConcurrencyTag())); + // Callback are not thread safe since Edge_to_faces is not. + // Edge_to_faces is an unordered_map> + // pass them would be a lot of concurrent write and unefficient, use local vectors then merged and check doublon is probably better + // Currently, in explored examples, this step is negligeable in runtime and thus not parallellized if(non_manifold_feature_map_1.non_manifold_edges.empty() && non_manifold_feature_map_2.non_manifold_edges.empty()) - tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ - const auto& [f_1, f_2] = inter[i]; + for(const auto& [f_1, f_2]: inter) process_candidates_without_non_manifold_map(f_1, f_2, callback12, callback21); - }); else - tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ - const auto& [f_1, f_2] = inter[i]; + for(const auto& [f_1, f_2]: inter) process_candidates_with_non_manifold_map(f_1, f_2, callback12, callback21); - }); } else #endif From 1cd9aca9c463650ab9ef974b60f72303fdaec2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 14 Sep 2026 16:45:59 +0200 Subject: [PATCH 025/136] Move specialization of surface_mesh from package Surface_mesh to PMP --- .../corefinement_mesh_union_progress.cpp | 2 -- .../internal/Corefinement/face_graph_utils.h | 4 ++++ .../internal/Corefinement/surface_mesh_specializations.h | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-) rename Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h => PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h (99%) diff --git a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp index dbf05483c0a1..71707c1457d5 100644 --- a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp +++ b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp @@ -5,8 +5,6 @@ #include #include -#include - #include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index da754146842e..9899bdf48dda 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -2149,4 +2149,8 @@ void remove_disconnected_patches( } } } // CGAL::Polygon_mesh_processing::Corefinement +#ifndef CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS +#include +#endif + #endif // CGAL_POLYGON_MESH_PROCESSING_INTERNAL_FACE_GRAPH_UTILS_H diff --git a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h similarity index 99% rename from Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h rename to PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h index 3377eb413973..f0ef1fafff92 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/internal/boolean_operations_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h @@ -14,8 +14,7 @@ #include -#include -#include +#include namespace CGAL { namespace Polygon_mesh_processing { @@ -149,7 +148,7 @@ void append_patch( std::array hedges = { get_halfedge(h_in_1), get_halfedge(h_in_2), get_halfedge(h_in_3) }; user_visitor.before_face_copy(f, tm, output); - SM_Face_index new_f(faces_idx_begin + i); + face_descriptor new_f(faces_idx_begin + i); user_visitor.after_face_copy(f, tm, new_f, output); output.set_halfedge(new_f, hedges[0]); From fe146e94fb6a23db17bc89dd247199a122320977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 14 Sep 2026 17:47:13 +0200 Subject: [PATCH 026/136] Remove const to reference of mesh to alloid visitors to modify them --- .../internal/Corefinement/face_graph_utils.h | 10 +++++----- .../Corefinement/surface_mesh_specializations.h | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 9899bdf48dda..c46aa0d40ccf 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -1210,7 +1210,7 @@ void append_patches_to_triangle_mesh( using vertex_descriptor = typename GT::vertex_descriptor; using face_descriptor = typename GT::face_descriptor; - const TriangleMesh& tm = patches.pm; + TriangleMesh& tm = patches.pm; Triangle_mesh_extension_helper helper(tm_to_output_edges, tm_to_output_vertices, tm, output); std::vector ids_of_patches_to_append; @@ -1396,13 +1396,13 @@ void fill_new_triangle_mesh( using edge_descriptor = typename GT::edge_descriptor; using V2V_tag = typename CGAL::dynamic_vertex_property_t; - using Vertex_to_vertex_map = typename boost::property_map::const_type; + using Vertex_to_vertex_map = typename boost::property_map::type; using E2E_tag = typename CGAL::dynamic_edge_property_t; - using Edge_to_edge_map = typename boost::property_map::const_type; + using Edge_to_edge_map = typename boost::property_map::type; - const TriangleMesh& tm1 = patches_of_tm1.pm; - const TriangleMesh& tm2 = patches_of_tm2.pm; + TriangleMesh& tm1 = patches_of_tm1.pm; + TriangleMesh& tm2 = patches_of_tm2.pm; Vertex_to_vertex_map tm1_to_output_vertices = get(V2V_tag(), tm1, GT::null_vertex()), tm2_to_output_vertices = get(V2V_tag(), tm2, GT::null_vertex()); diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h index f0ef1fafff92..f6af2cd8320e 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h @@ -33,7 +33,7 @@ template < class ConcurrencyTag, class VertexToVertexMap, class UserVisitor> void append_patch( - const Surface_mesh& tm, + Surface_mesh& tm, Surface_mesh& output, PatchDescription& patch, const VertexPointMapOut& vpm_out, @@ -198,7 +198,7 @@ void append_patches_to_triangle_mesh( UserVisitor& user_visitor) { using SM = Surface_mesh; - const SM& tm = patches.pm; + SM& tm = patches.pm; std::size_t vertices_idx_begin = output.number_of_vertices(); std::size_t edges_idx_begin = output.number_of_edges(); @@ -314,13 +314,13 @@ void fill_new_triangle_mesh( using edge_descriptor = typename SM::Edge_index; using V2V_tag = typename CGAL::dynamic_vertex_property_t; - using Vertex_to_vertex_map = typename boost::property_map::const_type; + using Vertex_to_vertex_map = typename boost::property_map::type; using E2E_tag = typename CGAL::dynamic_edge_property_t; - using Edge_to_edge_map = typename boost::property_map::const_type; + using Edge_to_edge_map = typename boost::property_map::type; - const SM &tm1 = patches_of_tm1.pm; - const SM &tm2 = patches_of_tm2.pm; + SM &tm1 = patches_of_tm1.pm; + SM &tm2 = patches_of_tm2.pm; Edge_to_edge_map tm1_to_output_edges = get(E2E_tag(), tm1, SM::null_edge()), tm2_to_output_edges = get(E2E_tag(), tm2, SM::null_edge()); From 80a599f7b8fc1154dc60a1bf96bfa1b03b5e697c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 15 Sep 2026 14:15:54 +0200 Subject: [PATCH 027/136] Correct bug when doing corefine between a manifold mesh and a non-manifold mesh --- .../internal/Corefinement/intersection_impl.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 060ac65b1c43..da8e16f9cddb 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -312,7 +312,9 @@ class Intersection_of_triangle_meshes for(halfedge_descriptor h : hf2){ edge_descriptor ed = edge(h, tm2); - std::size_t eid=get(non_manifold_feature_map_2.e_nm_id, ed); + std::size_t eid = non_manifold_feature_map_2.non_manifold_edges.empty() + ? NM_NID + : get(non_manifold_feature_map_2.e_nm_id, ed); if (eid!=NM_NID){ if (non_manifold_feature_map_2.non_manifold_edges[eid].front()!=ed) continue; else @@ -324,7 +326,9 @@ class Intersection_of_triangle_meshes } for(halfedge_descriptor h : hf1){ edge_descriptor ed = edge(h, tm1); - std::size_t eid=get(non_manifold_feature_map_1.e_nm_id, ed); + std::size_t eid = non_manifold_feature_map_1.non_manifold_edges.empty() + ? NM_NID + : get(non_manifold_feature_map_1.e_nm_id, ed); if (eid!=NM_NID){ if (non_manifold_feature_map_1.non_manifold_edges[eid].front()!=ed) continue; else @@ -332,7 +336,7 @@ class Intersection_of_triangle_meshes h = halfedge(non_manifold_feature_map_1.non_manifold_edges[eid].front(), tm2); } if( !get(is_shared_edge_map_1, ed) && (is_border(h, tm1) || h < opposite(h, tm1))) - callback21(h, hf2[0]); + callback21(hf2[0], h); } }; From 00ab16764a2f46f62aab2bf3d4bccc5f2cdd42f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 15 Sep 2026 16:17:30 +0200 Subject: [PATCH 028/136] Filter intersections with bbox instead of triangles --- .../internal/AABB_traversal_traits.h | 40 +++++++++++++ .../AABB_two_trees_traversal_traits.h | 58 +++++++++++++++++++ .../include/CGAL/AABB_trees/intersection.h | 53 +++++++++++++++++ .../internal/Corefinement/intersection_impl.h | 16 ++--- 4 files changed, 160 insertions(+), 7 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h index db7a804cc6d1..c0c67a0a3956 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h @@ -183,6 +183,46 @@ class Listing_primitive_traits const AABBTraits& m_traits; }; +/** + * @class Listing_bbox_primitive_traits + */ +template +class Listing_bbox_primitive_traits +{ + typedef typename AABBTraits::FT FT; + typedef typename AABBTraits::Point Point; + typedef typename AABBTraits::Primitive Primitive; + typedef typename AABBTraits::Bounding_box Bounding_box; + typedef typename AABBTraits::Primitive::Id Primitive_id; + typedef typename AABBTraits::Point_and_primitive_id Point_and_primitive_id; + typedef typename AABBTraits::Object_and_primitive_id Object_and_primitive_id; + typedef ::CGAL::AABB_node Node; + +public: + Listing_bbox_primitive_traits(OutputIterator out_it, const AABBTraits& traits) + : m_out_it(out_it), m_traits(traits) {} + + constexpr bool go_further() const { return true; } + + void intersection(const Query& query, const Primitive& primitive) + { + if( m_traits.do_intersect_object()(query.bbox(), + internal::Primitive_helper::get_datum(primitive, m_traits).bbox()) ) + { + *m_out_it++ = primitive.id(); + } + } + + bool do_intersect(const Query& query, const Node& node) const + { + return m_traits.do_intersect_object()(query.bbox(), node.bbox()); + } + +private: + OutputIterator m_out_it; + const AABBTraits& m_traits; +}; + /** * It is more efficient to apply the inverse transformation to the query and then use the original traits, * but except if the constructions are exact, the result may differ from applying the original transformation to the tree. diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 039617cb846e..02994301da8e 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -199,6 +199,64 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation bool m_tr1_has_rotation, m_tr2_has_rotation; }; +template +class Two_trees_listing_primitives_with_overlapping_bbox_traits +{ + typedef typename AABBTraits1::Primitive Primitive1; + typedef typename AABBTraits2::Primitive Primitive2; + typedef ::CGAL::AABB_node Node1; + typedef ::CGAL::AABB_node Node2; + +public: + Two_trees_listing_primitives_with_overlapping_bbox_traits(const AABBTraits1& traits1, const AABBTraits2& traits2, OutputIterator out_) + : m_traits1(traits1), m_traits2(traits2), out(out_) + {} + + bool go_further() const { + return true; + } + + // If true, the next step of traversal continue on A, if false, the next step of traversal is on B + template + bool prefer_A_for_next_step(const Node_A& node_a, const Node_B& node_b, const std::size_t&, const std::size_t&) const { + return node_a.bbox().squared_diagonal_length() > node_b.bbox().squared_diagonal_length(); + } + + void intersection(const Primitive1& primitive1, const Primitive2& primitive2) + { + using Wrap_iterator = Wrap_output_iterator; + Wrap_iterator wrap_out(primitive1.id(), out); + Listing_bbox_primitive_traits traits(wrap_out, m_traits2); + traits.intersection(internal::Primitive_helper::get_datum(primitive1, m_traits1), primitive2); + } + + void intersection(const Primitive1& primitive1, const Node2& node2, std::size_t nb_primitives_2) + { + using Wrap_iterator = Wrap_output_iterator; + Wrap_iterator wrap_out(primitive1.id(), out); + Listing_bbox_primitive_traits traits(wrap_out, m_traits2); + node2.traversal( internal::Primitive_helper::get_datum(primitive1, m_traits1), traits, nb_primitives_2); + } + + void intersection(const Node1& node1, std::size_t nb_primitives_1, const Primitive2& primitive2) + { + using Wrap_iterator= Wrap_output_iterator; + Wrap_iterator wrap_out(primitive2.id(), out); + Listing_bbox_primitive_traits traits(wrap_out, m_traits1); + node1.traversal( internal::Primitive_helper::get_datum(primitive2, m_traits2), traits, nb_primitives_1); + } + + bool do_intersect(const Node1& node1, const Node2& node2) const + { + return do_overlap(node1.bbox(), node2.bbox()); + } + +private: + const AABBTraits1& m_traits1; + const AABBTraits2& m_traits2; + OutputIterator out; +}; + template class Two_trees_do_intersect_traits { diff --git a/AABB_tree/include/CGAL/AABB_trees/intersection.h b/AABB_tree/include/CGAL/AABB_trees/intersection.h index bb0e346caa27..dbe5286374b2 100644 --- a/AABB_tree/include/CGAL/AABB_trees/intersection.h +++ b/AABB_tree/include/CGAL/AABB_trees/intersection.h @@ -211,6 +211,59 @@ namespace AABB_trees { CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); } + /// \ingroup PkgAABBTreeRef + /// + /// \brief computes all pairs of primitives with overlapping bbox from two AABB trees. + /// + /// Both trees are traversed and all pairs of primitives that intersect are collected. + /// Each output element is a pair `(id1, id2)` where: + /// - `id1` is the ID of a primitive from `tree1` + /// - `id2` is the ID of a primitive from `tree2` + /// + /// \tparam AABBTree1 Type of the first AABB tree. + /// \tparam AABBTree2 Type of the second AABB tree. + /// \tparam OutputIterator Output iterator storing std::pair. + /// \tparam NamedParameters1 a sequence of \ref bgl_namedparameters "Named Parameters" + /// \tparam NamedParameters2 a sequence of \ref bgl_namedparameters "Named Parameters" + /// + /// \cgalNamedParamsBegin + /// \cgalParamNBegin{concurrency_tag} + /// \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + /// \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + /// \cgalParamDefault{`CGAL::Sequential_tag`} + /// \cgalParamExtra{`np1` only} + /// \cgalParamNEnd + /// \cgalNamedParamsEnd + /// + /// \see do_intersect() + template< typename AABBTree1, + typename AABBTree2, + typename OutputIterator, + typename NamedParameters1 = parameters::Default_named_parameters, + typename NamedParameters2 = parameters::Default_named_parameters> + void all_pairs_of_primitives_with_overlapping_bbox(const AABBTree1 &tree1, + const AABBTree2 &tree2, + OutputIterator out, + const NamedParameters1& np1 = parameters::default_values(), + const NamedParameters2& np2 = parameters::default_values()) + { + using parameters::get_parameter; + using parameters::choose_parameter; + using parameters::is_default_parameter; + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters1, + Sequential_tag + > ::type; + + // Early exit if one of the trees is empty + if(tree1.empty() || tree2.empty()) + return; + + CGAL::internal::AABB_tree::Two_trees_listing_primitives_with_overlapping_bbox_traits traversal_traits(tree1.traits(), tree2.traits(), out); + CGAL::internal::AABB_tree::two_trees_traversal(tree1, tree2, traversal_traits); + } + }} // end namespace CGAL::AABB_trees #endif \ No newline at end of file diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index da8e16f9cddb..df6884c8780f 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -272,10 +272,12 @@ class Intersection_of_triangle_meshes tm2_faces_intersecting_bb.reserve(num_faces(tm2)); for(face_descriptor f: faces(tm1)) - if( !get(is_shared_face_map_1, f) && do_overlap(face_bbox(f, tm1), bb) ) + if( !get(is_shared_face_map_1, f) && + do_overlap(face_bbox(f, tm1, parameters::vertex_point_map(vpm1)), bb)) tm1_faces_intersecting_bb.push_back(f); for(face_descriptor f: faces(tm2)) - if( !get(is_shared_face_map_2, f) && do_overlap(face_bbox(f, tm2), bb) ) + if( !get(is_shared_face_map_2, f) && + do_overlap(face_bbox(f, tm2, parameters::vertex_point_map(vpm2)), bb)) tm2_faces_intersecting_bb.push_back(f); Tree_1 tree1(tm1_faces_intersecting_bb.begin(), tm1_faces_intersecting_bb.end(), tm1, vpm1); @@ -333,7 +335,7 @@ class Intersection_of_triangle_meshes if (non_manifold_feature_map_1.non_manifold_edges[eid].front()!=ed) continue; else // make sure the halfedge used is consistent with stored one - h = halfedge(non_manifold_feature_map_1.non_manifold_edges[eid].front(), tm2); + h = halfedge(non_manifold_feature_map_1.non_manifold_edges[eid].front(), tm1); } if( !get(is_shared_edge_map_1, ed) && (is_border(h, tm1) || h < opposite(h, tm1))) callback21(hf2[0], h); @@ -351,7 +353,7 @@ class Intersection_of_triangle_meshes tg.wait(); tbb::concurrent_vector> inter; - CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter), parameters::concurrency_tag(ConcurrencyTag())); + CGAL::AABB_trees::all_pairs_of_primitives_with_overlapping_bbox(tree1, tree2, std::back_inserter(inter), parameters::concurrency_tag(ConcurrencyTag())); // Callback are not thread safe since Edge_to_faces is not. // Edge_to_faces is an unordered_map> @@ -371,7 +373,7 @@ class Intersection_of_triangle_meshes helper_2.template build(tree2, tm2, vpm2); std::vector> inter; - CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, std::back_inserter(inter)); + CGAL::AABB_trees::all_pairs_of_primitives_with_overlapping_bbox(tree1, tree2, std::back_inserter(inter)); if(non_manifold_feature_map_1.non_manifold_edges.empty() && non_manifold_feature_map_2.non_manifold_edges.empty()) for(const auto& [f_1, f_2]: inter) @@ -467,7 +469,7 @@ class Intersection_of_triangle_meshes halfedge_descriptor h1 = next(h0, tm); halfedge_descriptor h2 = next(h1, tm); - halfedge_descriptor h_f2 = halfedge(f_1, tm); + halfedge_descriptor h_f2 = halfedge(f_2, tm); if (is_border(h0, tm) || h0 < opposite(h0, tm)) callback(h0, h_f2); @@ -489,7 +491,7 @@ class Intersection_of_triangle_meshes halfedge_descriptor h1 = next(h0, tm); halfedge_descriptor h2 = next(h1, tm); - halfedge_descriptor h_f2 = halfedge(f_1, tm); + halfedge_descriptor h_f2 = halfedge(f_2, tm); if (is_border(h0, tm) || h0 < opposite(h0, tm)) callback(h0, h_f2); From bb4c172ba6e53743e04e5ec27a574de29c6f5324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 16 Sep 2026 07:51:09 +0200 Subject: [PATCH 029/136] Correct filtered_callback of corefine --- .../include/CGAL/AABB_trees/intersection.h | 4 +- .../internal/Corefinement/intersection_impl.h | 50 +++++++++++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_trees/intersection.h b/AABB_tree/include/CGAL/AABB_trees/intersection.h index dbe5286374b2..1d299956763f 100644 --- a/AABB_tree/include/CGAL/AABB_trees/intersection.h +++ b/AABB_tree/include/CGAL/AABB_trees/intersection.h @@ -244,8 +244,8 @@ namespace AABB_trees { void all_pairs_of_primitives_with_overlapping_bbox(const AABBTree1 &tree1, const AABBTree2 &tree2, OutputIterator out, - const NamedParameters1& np1 = parameters::default_values(), - const NamedParameters2& np2 = parameters::default_values()) + const NamedParameters1& /*np1*/ = parameters::default_values(), + const NamedParameters2& /*np2*/ = parameters::default_values()) { using parameters::get_parameter; using parameters::choose_parameter; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index df6884c8780f..c9b41d1ba4eb 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -410,9 +410,31 @@ class Intersection_of_triangle_meshes if(!callback12.is_face_degenerated(h1)) callback12(h1, h2); }; - auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - if(!callback21.is_face_degenerated(h1)) + auto filtered_callback_21 = [&](halfedge_descriptor h2, halfedge_descriptor h1){ + if (get(vpm1, source(h1, tm1)) != get(vpm1, target(h1, tm1))) callback21(h2, h1); + else + { + for (int i=0; i<2; ++i) + { + if (!is_border(h1, tm1)) + { + if ( get(vpm1, target(next(h1, tm1), tm1))==get(vpm1, target(h1, tm1)) && + coplanar(get(vpm2, source(h2, tm2)), + get(vpm2, target(h2, tm2)), + get(vpm2, target(next(h2, tm2), tm2)), + get(vpm1, target(h1, tm1))) ) + { + coplanar_faces.insert( + &tm1 < &tm2 + ? std::make_pair(face(h1, tm1), face(h2, tm2)) + : std::make_pair(face(h2, tm2), face(h1, tm1)) + ); + } + } + h1=opposite(h1, tm1); + } + } }; AABB_call(filtered_callback_12, filtered_callback_21); } @@ -421,8 +443,30 @@ class Intersection_of_triangle_meshes if (const_mesh_ptr==&tm2) { auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - if(!callback12.is_face_degenerated(h2)) + if (get(vpm2, source(h2, tm2)) != get(vpm2, target(h2, tm2))) callback12(h1, h2); + else + { + for (int i=0; i<2; ++i) + { + if (!is_border(h2, tm2)) + { + if ( get(vpm2, target(next(h2, tm2), tm2))==get(vpm2, target(h2, tm2)) && + coplanar(get(vpm1, source(h1, tm1)), + get(vpm1, target(h1, tm1)), + get(vpm1, target(next(h1, tm1), tm1)), + get(vpm2, target(h2, tm2))) ) + { + coplanar_faces.insert( + &tm1 < &tm2 + ? std::make_pair(face(h1, tm1), face(h2, tm2)) + : std::make_pair(face(h2, tm2), face(h1, tm1)) + ); + } + } + h2=opposite(h2, tm2); + } + } }; auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ if(!callback21.is_face_degenerated(h2)) From 117596dcad5d308e22f055baf9b49fbd5f6c4da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 16 Sep 2026 07:51:50 +0200 Subject: [PATCH 030/136] Correct resize of vectors in append_patches for surface_mesh --- .../internal/Corefinement/surface_mesh_specializations.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h index f6af2cd8320e..47b192c91bfd 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h @@ -200,9 +200,9 @@ void append_patches_to_triangle_mesh( using SM = Surface_mesh; SM& tm = patches.pm; - std::size_t vertices_idx_begin = output.number_of_vertices(); - std::size_t edges_idx_begin = output.number_of_edges(); - std::size_t faces_idx_begin = output.number_of_faces(); + std::size_t vertices_idx_begin = output.num_vertices(); + std::size_t edges_idx_begin = output.num_edges(); + std::size_t faces_idx_begin = output.num_faces(); std::size_t tnv = vertices_idx_begin, tne = edges_idx_begin, tnf = faces_idx_begin; for (std::size_t i= patches_to_append.find_first(); i < patches_to_append.npos; @@ -212,7 +212,7 @@ void append_patches_to_triangle_mesh( tne += patches[i].interior_edges.size(); tnf += patches[i].faces.size(); } - output.resize(vertices_idx_begin, edges_idx_begin, faces_idx_begin); + output.resize(tnv, tne, tnf); std::vector ids_of_patches_to_append; ids_of_patches_to_append.reserve(patches_to_append.count()); From 254b3725b6f7757e03411d637c97ed99aebc620e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 17 Sep 2026 09:32:27 +0200 Subject: [PATCH 031/136] Solve a bug with filter_intersections where the descriptors returned are in the wrong order --- .../internal/Corefinement/intersection_impl.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index c9b41d1ba4eb..87fb6e95f54c 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -384,16 +384,22 @@ class Intersection_of_triangle_meshes } }; + Edge_to_faces& tm1_edge_to_tm2_faces = &tm1 < &tm2 + ? stm_edge_to_ltm_faces + : ltm_edge_to_stm_faces; + Edge_to_faces& tm2_edge_to_tm1_faces = &tm2 < &tm1 + ? stm_edge_to_ltm_faces + : ltm_edge_to_stm_faces; // Select the desire callbacks #ifdef DO_NOT_HANDLE_COPLANAR_FACES using Callback = Collect_face_bbox_per_edge_bbox; - Callback callback12(tm1, tm2, ltm_edge_to_stm_faces); - Callback callback21(tm2, tm1, stm_edge_to_ltm_faces); + Callback callback12(tm1, tm2, tm2_edge_to_tm1_faces); + Callback callback21(tm2, tm1, tm1_edge_to_tm2_faces); #else using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling< TriangleMesh, VPM1, VPM2, Edge_to_faces, Coplanar_face_set, Node_visitor>; - Callback callback12(tm1, tm2, vpm1, vpm2, ltm_edge_to_stm_faces, coplanar_faces, visitor); - Callback callback21(tm2, tm1, vpm2, vpm1, stm_edge_to_ltm_faces, coplanar_faces, visitor); + Callback callback12(tm1, tm2, vpm1, vpm2, tm2_edge_to_tm1_faces, coplanar_faces, visitor); + Callback callback21(tm2, tm1, vpm2, vpm1, tm1_edge_to_tm2_faces, coplanar_faces, visitor); #endif if (throw_on_self_intersection){ @@ -468,7 +474,7 @@ class Intersection_of_triangle_meshes } } }; - auto filtered_callback_21 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ + auto filtered_callback_21 = [&](halfedge_descriptor h2, halfedge_descriptor h1){ if(!callback21.is_face_degenerated(h2)) callback21(h2, h1); }; From 82d3b3eae568f8f6082a3bdc5425d52aec0ee905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 17 Sep 2026 10:47:35 +0200 Subject: [PATCH 032/136] Correct wrong if statement for degenerate faces --- .../internal/Corefinement/intersection_impl.h | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 87fb6e95f54c..b13f2d9d6d5c 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -413,23 +413,19 @@ class Intersection_of_triangle_meshes if (const_mesh_ptr==&tm1) { auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - if(!callback12.is_face_degenerated(h1)) + if (get(vpm2, source(h2, tm2)) != get(vpm2, target(h2, tm2))) callback12(h1, h2); - }; - auto filtered_callback_21 = [&](halfedge_descriptor h2, halfedge_descriptor h1){ - if (get(vpm1, source(h1, tm1)) != get(vpm1, target(h1, tm1))) - callback21(h2, h1); else { for (int i=0; i<2; ++i) { - if (!is_border(h1, tm1)) + if (!is_border(h2, tm2)) { - if ( get(vpm1, target(next(h1, tm1), tm1))==get(vpm1, target(h1, tm1)) && - coplanar(get(vpm2, source(h2, tm2)), - get(vpm2, target(h2, tm2)), - get(vpm2, target(next(h2, tm2), tm2)), - get(vpm1, target(h1, tm1))) ) + if ( get(vpm2, target(next(h2, tm2), tm2))==get(vpm2, target(h2, tm2)) && + coplanar(get(vpm1, source(h1, tm1)), + get(vpm1, target(h1, tm1)), + get(vpm1, target(next(h1, tm1), tm1)), + get(vpm2, target(h2, tm2))) ) { coplanar_faces.insert( &tm1 < &tm2 @@ -438,30 +434,39 @@ class Intersection_of_triangle_meshes ); } } - h1=opposite(h1, tm1); + h2=opposite(h2, tm2); } } }; + auto filtered_callback_21 = [&](halfedge_descriptor h2, halfedge_descriptor h1){ + if(!callback21.is_face_degenerated(h2)) + callback21(h2, h1); + }; AABB_call(filtered_callback_12, filtered_callback_21); } else { if (const_mesh_ptr==&tm2) { + // tm2 might feature auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ - if (get(vpm2, source(h2, tm2)) != get(vpm2, target(h2, tm2))) + if(!callback12.is_face_degenerated(h1)) callback12(h1, h2); + }; + auto filtered_callback_21 = [&](halfedge_descriptor h2, halfedge_descriptor h1){ + if (get(vpm1, source(h1, tm1)) != get(vpm1, target(h1, tm1))) + callback21(h2, h1); else { for (int i=0; i<2; ++i) { - if (!is_border(h2, tm2)) + if (!is_border(h1, tm1)) { - if ( get(vpm2, target(next(h2, tm2), tm2))==get(vpm2, target(h2, tm2)) && - coplanar(get(vpm1, source(h1, tm1)), - get(vpm1, target(h1, tm1)), - get(vpm1, target(next(h1, tm1), tm1)), - get(vpm2, target(h2, tm2))) ) + if ( get(vpm1, target(next(h1, tm1), tm1))==get(vpm1, target(h1, tm1)) && + coplanar(get(vpm2, source(h2, tm2)), + get(vpm2, target(h2, tm2)), + get(vpm2, target(next(h2, tm2), tm2)), + get(vpm1, target(h1, tm1))) ) { coplanar_faces.insert( &tm1 < &tm2 @@ -470,14 +475,10 @@ class Intersection_of_triangle_meshes ); } } - h2=opposite(h2, tm2); + h1=opposite(h1, tm1); } } }; - auto filtered_callback_21 = [&](halfedge_descriptor h2, halfedge_descriptor h1){ - if(!callback21.is_face_degenerated(h2)) - callback21(h2, h1); - }; AABB_call(filtered_callback_12, filtered_callback_21); } else From 9a453766695cb0ef57a83fefaba5b727bef1686b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 18 Sep 2026 17:22:59 +0200 Subject: [PATCH 033/136] Treat correctly the case of the faces to test are empty in self_intersections --- .../internal/Corefinement/intersection_impl.h | 4 ++++ .../include/CGAL/Polygon_mesh_processing/self_intersections.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index b13f2d9d6d5c..2ee0f0f6c66c 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -280,6 +280,10 @@ class Intersection_of_triangle_meshes do_overlap(face_bbox(f, tm2, parameters::vertex_point_map(vpm2)), bb)) tm2_faces_intersecting_bb.push_back(f); + // If one set is empty, no intersection + if(tm1_faces_intersecting_bb.empty() || tm2_faces_intersecting_bb.empty()) + return; + Tree_1 tree1(tm1_faces_intersecting_bb.begin(), tm1_faces_intersecting_bb.end(), tm1, vpm1); Tree_2 tree2(tm2_faces_intersecting_bb.begin(), tm2_faces_intersecting_bb.end(), tm2, vpm2); diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index d62c195359ad..5853ef8219e1 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -511,6 +511,10 @@ self_intersections_impl(const FaceRange& face_range, } } + // If no faces to test, no intersection + if(faces_not_degenerated.empty()) + return out; + // In case we are throwing, like in `does_self_intersect()`, we keep the geometric test to throw ASAP. // This is obviously not optimal if there are no or few self-intersections: it would be a greater speed-up // to do the same as for `self_intersections()`. However, doing like `self_intersections()` would From f5078b2298f0973c38ef9422f9af613ce8341f6d Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 21 Sep 2026 11:46:37 +0100 Subject: [PATCH 034/136] Avoid the copy --- .../include/CGAL/AABB_tree/internal/AABB_traversal_traits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h index c0c67a0a3956..3d0c06e4e5a6 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h @@ -275,7 +275,7 @@ class Listing_primitive_traits_with_transformation private: OutputIterator m_out_it; const AABBTraits& m_traits; - AffTransformation m_transfo; + const AffTransformation& m_transfo; bool m_has_rotation; }; From 662f7e132e712bc0a86dc7e5357114c148b8abe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 21 Sep 2026 15:40:42 +0200 Subject: [PATCH 035/136] update depencies --- Alpha_wrap_3/package_info/Alpha_wrap_3/dependencies | 1 - PMP_Remeshing/package_info/PMP_Remeshing/dependencies | 1 - .../internal/soup_and_face_graph_tree_helper.h | 0 3 files changed, 2 deletions(-) rename {PMP_Boolean_operations => Polygon_mesh_processing}/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h (100%) diff --git a/Alpha_wrap_3/package_info/Alpha_wrap_3/dependencies b/Alpha_wrap_3/package_info/Alpha_wrap_3/dependencies index d220894d4fd4..e44bd7a703d1 100644 --- a/Alpha_wrap_3/package_info/Alpha_wrap_3/dependencies +++ b/Alpha_wrap_3/package_info/Alpha_wrap_3/dependencies @@ -3,7 +3,6 @@ Algebraic_foundations Alpha_wrap_3 Arithmetic_kernel BGL -Box_intersection_d CGAL_Core Cartesian_kernel Circulator diff --git a/PMP_Remeshing/package_info/PMP_Remeshing/dependencies b/PMP_Remeshing/package_info/PMP_Remeshing/dependencies index 93ff9a692b37..0eea174a7341 100644 --- a/PMP_Remeshing/package_info/PMP_Remeshing/dependencies +++ b/PMP_Remeshing/package_info/PMP_Remeshing/dependencies @@ -2,7 +2,6 @@ AABB_tree Algebraic_foundations Arithmetic_kernel BGL -Box_intersection_d CGAL_Core Cartesian_kernel Circulator diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h similarity index 100% rename from PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h rename to Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h From e6b02f2b3fc07e6099dd9b2e17768d4ec5735c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 22 Sep 2026 15:27:40 +0200 Subject: [PATCH 036/136] Solve bug in the testsuite --- .../CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h | 4 ++-- AABB_tree/include/CGAL/AABB_trees/intersection.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 02994301da8e..14ed3195f909 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -35,9 +35,9 @@ class Wrap_output_iterator Wrap_output_iterator& operator=(Value second){ if constexpr(in_order) - out = std::make_pair(first, second); + *out = std::make_pair(first, second); else - out = std::make_pair(second, first); + *out = std::make_pair(second, first); return *this; } Wrap_output_iterator& operator*(){ return *this; } diff --git a/AABB_tree/include/CGAL/AABB_trees/intersection.h b/AABB_tree/include/CGAL/AABB_trees/intersection.h index 1d299956763f..33280ce4dcc7 100644 --- a/AABB_tree/include/CGAL/AABB_trees/intersection.h +++ b/AABB_tree/include/CGAL/AABB_trees/intersection.h @@ -207,6 +207,8 @@ namespace AABB_trees { void all_pairs_of_intersecting_primitives(const AABBTree &tree, OutputIterator out) { + if(tree.empty()) + return; CGAL::internal::AABB_tree::Two_trees_listing_intersecting_primitives_traits traversal_traits(tree.traits(), tree.traits(), out); CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); } From 74499f84b334a124766840a560a72f943f3afb4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 22 Sep 2026 17:25:22 +0200 Subject: [PATCH 037/136] Replace box_intersection_d per AABB_tree in PMP/intersection.h --- .../AABB_two_trees_traversal_traits.h | 28 +- .../Constrained_triangulation_3/dependencies | 3 +- .../Polygon_mesh_processing/intersection.h | 556 ++++++++---------- 3 files changed, 268 insertions(+), 319 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 14ed3195f909..29e52608ff33 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -25,15 +25,15 @@ namespace CGAL { namespace internal { namespace AABB_tree { -template +template class Wrap_output_iterator { - Value first; + Value1 first; OutputIterator out; public: - Wrap_output_iterator(Value first_, OutputIterator out_): first(first_), out(out_){} + Wrap_output_iterator(Value1 first_, OutputIterator out_): first(first_), out(out_){} - Wrap_output_iterator& operator=(Value second){ + Wrap_output_iterator& operator=(Value2 second){ if constexpr(in_order) *out = std::make_pair(first, second); else @@ -71,7 +71,7 @@ class Two_trees_listing_intersecting_primitives_traits void intersection(const Primitive1& primitive1, const Primitive2& primitive2) { - using Wrap_iterator = Wrap_output_iterator; + using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive1.id(), out); Listing_primitive_traits traits(wrap_out, m_traits2); traits.intersection(internal::Primitive_helper::get_datum(primitive1, m_traits1), primitive2); @@ -79,7 +79,7 @@ class Two_trees_listing_intersecting_primitives_traits void intersection(const Primitive1& primitive1, const Node2& node2, std::size_t nb_primitives_2) { - using Wrap_iterator = Wrap_output_iterator; + using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive1.id(), out); Listing_primitive_traits traits(wrap_out, m_traits2); node2.traversal( internal::Primitive_helper::get_datum(primitive1, m_traits1), traits, nb_primitives_2); @@ -87,7 +87,7 @@ class Two_trees_listing_intersecting_primitives_traits void intersection(const Node1& node1, std::size_t nb_primitives_1, const Primitive2& primitive2) { - using Wrap_iterator= Wrap_output_iterator; + using Wrap_iterator= Wrap_output_iterator; Wrap_iterator wrap_out(primitive2.id(), out); Listing_primitive_traits traits(wrap_out, m_traits1); node1.traversal( internal::Primitive_helper::get_datum(primitive2, m_traits2), traits, nb_primitives_1); @@ -143,7 +143,7 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation // Use inverse transformation is faster but less numerically stable. if constexpr(Use_inverse_transformation::value) { - using Wrap_iterator = Wrap_output_iterator; + using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive1.id(), out); Listing_primitive_traits traits(wrap_out, m_traits2); auto datum = (internal::Primitive_helper::get_datum(primitive1, m_traits1).transform(m_tr1)).transform(m_tr2_inverse); @@ -151,7 +151,7 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation } else { - using Wrap_iterator = Wrap_output_iterator; + using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive1.id(), out); Listing_primitive_traits_with_transformation traits(wrap_out, m_traits2, m_tr2); auto datum = (internal::Primitive_helper::get_datum(primitive1, m_traits1).transform(m_tr1)); @@ -164,7 +164,7 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation // Use inverse transformation is faster but less numerically stable. if constexpr(Use_inverse_transformation::value) { - using Wrap_iterator = Wrap_output_iterator; + using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive2.id(), out); Listing_primitive_traits traits(wrap_out, m_traits1); auto datum = (internal::Primitive_helper::get_datum(primitive2, m_traits2).transform(m_tr2)).transform(m_tr1_inverse); @@ -172,7 +172,7 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation } else { - using Wrap_iterator = Wrap_output_iterator; + using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive2.id(), out); Listing_primitive_traits_with_transformation traits(wrap_out, m_traits1, m_tr1); auto datum = (internal::Primitive_helper::get_datum(primitive2, m_traits2).transform(m_tr2)); @@ -224,7 +224,7 @@ class Two_trees_listing_primitives_with_overlapping_bbox_traits void intersection(const Primitive1& primitive1, const Primitive2& primitive2) { - using Wrap_iterator = Wrap_output_iterator; + using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive1.id(), out); Listing_bbox_primitive_traits traits(wrap_out, m_traits2); traits.intersection(internal::Primitive_helper::get_datum(primitive1, m_traits1), primitive2); @@ -232,7 +232,7 @@ class Two_trees_listing_primitives_with_overlapping_bbox_traits void intersection(const Primitive1& primitive1, const Node2& node2, std::size_t nb_primitives_2) { - using Wrap_iterator = Wrap_output_iterator; + using Wrap_iterator = Wrap_output_iterator; Wrap_iterator wrap_out(primitive1.id(), out); Listing_bbox_primitive_traits traits(wrap_out, m_traits2); node2.traversal( internal::Primitive_helper::get_datum(primitive1, m_traits1), traits, nb_primitives_2); @@ -240,7 +240,7 @@ class Two_trees_listing_primitives_with_overlapping_bbox_traits void intersection(const Node1& node1, std::size_t nb_primitives_1, const Primitive2& primitive2) { - using Wrap_iterator= Wrap_output_iterator; + using Wrap_iterator= Wrap_output_iterator; Wrap_iterator wrap_out(primitive2.id(), out); Listing_bbox_primitive_traits traits(wrap_out, m_traits1); node1.traversal( internal::Primitive_helper::get_datum(primitive2, m_traits2), traits, nb_primitives_1); diff --git a/Constrained_triangulation_3/package_info/Constrained_triangulation_3/dependencies b/Constrained_triangulation_3/package_info/Constrained_triangulation_3/dependencies index 854e686ee58b..2bdfecd4dc7f 100644 --- a/Constrained_triangulation_3/package_info/Constrained_triangulation_3/dependencies +++ b/Constrained_triangulation_3/package_info/Constrained_triangulation_3/dependencies @@ -1,8 +1,8 @@ +AABB_tree Algebraic_foundations Arithmetic_kernel BGL Basic_viewer -Box_intersection_d CGAL_Core Cartesian_kernel Circulator @@ -33,6 +33,7 @@ SMDS_3 STL_Extension Solver_interface Spatial_sorting +Spatial_searching Stream_support Surface_mesh TDS_2 diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index ad7cbcf36f9f..663ba6a59933 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -17,9 +17,9 @@ #include -#include -#include -#include +#include +#include + #include #include #include @@ -398,71 +398,62 @@ compute_face_face_intersection(const FaceRange& face_range1, CGAL_precondition(CGAL::is_triangle_mesh(tm1)); CGAL_precondition(CGAL::is_triangle_mesh(tm2)); - typedef TriangleMesh TM; - typedef typename boost::graph_traits::face_descriptor face_descriptor; + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters1, + Sequential_tag + > ::type; - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Box; + using GT = typename GetGeomTraits::type; + + using VPM1 = typename GetVertexPointMap::const_type; + using VPM2 = typename GetVertexPointMap::const_type; + + using face_descriptor = typename boost::graph_traits::face_descriptor; + using AABB_tree_helper_1 = internal::AABB_tree_graph_helper; + using AABB_tree_helper_2 = internal::AABB_tree_graph_helper; + using Tree_1 = typename AABB_tree_helper_1::Tree; + using Tree_2 = typename AABB_tree_helper_2::Tree; + AABB_tree_helper_1 helper_1; + AABB_tree_helper_2 helper_2; + + // compute intersections filtered out by boxes CGAL::Bbox_3 b1 = CGAL::Polygon_mesh_processing::bbox(tm1, np1), b2 = CGAL::Polygon_mesh_processing::bbox(tm2, np2); if(!CGAL::do_overlap(b1, b2)) - { return out; - } - - // make one box per facet - std::vector boxes1; - std::vector boxes2; - boxes1.reserve(std::distance(std::begin(face_range1), std::end(face_range1))); - boxes2.reserve(std::distance(std::begin(face_range2), std::end(face_range2))); + Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), + (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); - typedef typename GetVertexPointMap::const_type VertexPointMap1; - typedef typename GetVertexPointMap::const_type VertexPointMap2; - - VertexPointMap1 vpmap1 = choose_parameter(get_parameter(np1, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, tm1)); - VertexPointMap2 vpmap2 = choose_parameter(get_parameter(np2, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, tm2)); + VPM1 vpm1 = choose_parameter(get_parameter(np1, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, tm1)); + VPM2 vpm2 = choose_parameter(get_parameter(np2, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, tm2)); static_assert( (std::is_same< - typename boost::property_traits::value_type, - typename boost::property_traits::value_type + typename boost::property_traits::value_type, + typename boost::property_traits::value_type >::value) ); - for(face_descriptor f : face_range1) - { - boxes1.push_back(Box(Polygon_mesh_processing::face_bbox(f, tm1), f)); - } + std::vector face_to_test1; + std::vector face_to_test2; + for(face_descriptor f : face_range1) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm1), bb)) + face_to_test1.emplace_back(f); for(face_descriptor f : face_range2) - { - boxes2.push_back(Box(Polygon_mesh_processing::face_bbox(f, tm2), f)); - } + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm2), bb)) + face_to_test2.emplace_back(f); - // generate box pointers - std::vector box1_ptr(boost::make_counting_iterator(&boxes1[0]), - boost::make_counting_iterator(&boxes1[0]+boxes1.size())); - std::vector box2_ptr(boost::make_counting_iterator(&boxes2[0]), - boost::make_counting_iterator(&boxes2[0]+boxes2.size())); + Tree_1 tree1; + Tree_2 tree2; + helper_1.template build(tree1, tm1, vpm1); + helper_2.template build(tree2, tm2, vpm2); - // compute intersections filtered out by boxes - typedef typename GetGeomTraits::type GeomTraits; - GeomTraits gt = choose_parameter(get_parameter(np1, internal_np::geom_traits)); - - internal::Intersect_faces Intersect_faces(tm1, tm2, out, vpmap1, vpmap2, gt); - - std::ptrdiff_t cutoff = 2000; - CGAL::box_intersection_d(box1_ptr.begin(), box1_ptr.end(), - box2_ptr.begin(), box2_ptr.end(), - Intersect_faces,cutoff); - return Intersect_faces.m_iterator; + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, out, parameters::concurrency_tag(Concurrency_tag())); + return out; } // Note this is not officially documented @@ -527,75 +518,68 @@ compute_face_polyline_intersection(const FaceRange& face_range, OutputIterator out, const NamedParameters& np) { - using parameters::choose_parameter; using parameters::get_parameter; + using parameters::choose_parameter; CGAL_precondition(CGAL::is_triangle_mesh(tm)); - CGAL::Bbox_3 b1 = CGAL::Polygon_mesh_processing::bbox(tm, np), - b2 = CGAL::bbox_3(polyline.begin(), polyline.end()); + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + >::type; - if(!CGAL::do_overlap(b1,b2)) - return out; - typedef TriangleMesh TM; - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename GetVertexPointMap::const_type VertexPointMap; + using GT = typename GetGeomTraits::type; - VertexPointMap vpmap = choose_parameter(get_parameter(np, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, tm)); - typedef typename boost::property_traits::value_type Point; - static_assert( - (std::is_same::type>::value)); + using VPM = typename GetVertexPointMap::const_type; + using face_descriptor = typename boost::graph_traits::face_descriptor; + using Segment_3 = typename GT::Segment_3; - std::vector faces; - faces.reserve(std::distance(std::begin(face_range), std::end(face_range))); + using AABB_tree_helper = internal::AABB_tree_graph_helper; + using Face_tree = typename AABB_tree_helper::Tree; - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Box; + using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; + using Segment_traits = CGAL::AABB_traits_3; + using Segment_tree = CGAL::AABB_tree; - // make one box per facet - std::vector boxes1; - std::vector boxes2; - boxes1.reserve(std::distance(std::begin(face_range), std::end(face_range))); - boxes2.reserve(std::distance(std::begin(polyline), std::end(polyline)) - 1); + VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, tm)); - for(face_descriptor f : face_range) - { - faces.push_back(f); - boxes1.push_back(Box(Polygon_mesh_processing::face_bbox(f, tm), faces.size()-1)); - } - - for(std::size_t i =0; i< polyline.size()-1; ++i) - { - Point p1 = polyline[i]; - Point p2 = polyline[i+1]; - boxes2.push_back(Box(p1.bbox() + p2.bbox(), i)); - } + Bbox_3 b1 = Polygon_mesh_processing::bbox(tm, np), + b2 = bbox_3(polyline.begin(), polyline.end()); - // generate box pointers - std::vector box1_ptr(boost::make_counting_iterator(&boxes1[0]), - boost::make_counting_iterator(&boxes1[0]+boxes1.size())); - std::vector box2_ptr(boost::make_counting_iterator(&boxes2[0]), - boost::make_counting_iterator(&boxes2[0]+boxes2.size())); + if(!CGAL::do_overlap(b1, b2)) + return out; + Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), + (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); - // compute intersections filtered out by boxes - typedef typename GetGeomTraits::type GeomTraits; - GeomTraits gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); + std::vector segments; + if(polyline.size() < 2) + return out; - internal::Intersect_face_polyline - Intersect_face_polyline(tm, faces, polyline, out, vpmap, gt); + auto pit = std::begin(polyline); + auto prev = pit++; + for(; pit != std::end(polyline); ++pit, ++prev) + segments.emplace_back(*prev, *pit); - std::ptrdiff_t cutoff = 2000; - CGAL::box_intersection_d(box1_ptr.begin(), box1_ptr.end(), - box2_ptr.begin(), box2_ptr.end(), - Intersect_face_polyline, cutoff); - return Intersect_face_polyline.m_iterator; + std::vector face_to_test; + for(face_descriptor f : face_range) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm), bb)) + face_to_test.emplace_back(f); + + AABB_tree_helper helper; + Face_tree face_tree; + + helper.template build(face_tree, tm, vpm); + Segment_tree segment_tree(segments.begin(), segments.end()); + + auto out_converter = boost::make_function_output_iterator( + [&](const auto& pair) { + *out++ = std::make_pair(pair.first, + static_cast(pair.second - segments.begin())); + }); + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(face_tree, segment_tree, out_converter, parameters::concurrency_tag(Concurrency_tag())); + return out; } // Note this is not officially documented @@ -659,282 +643,246 @@ compute_face_polylines_intersection(const FaceRange& face_range, OutputIterator out, const NamedParameters& np) { - using parameters::choose_parameter; using parameters::get_parameter; + using parameters::choose_parameter; CGAL_precondition(CGAL::is_triangle_mesh(tm)); - CGAL::Bbox_3 b1,b2; - b1 = CGAL::Polygon_mesh_processing::bbox(tm, np); - for(std::size_t i =0; i< polyline_range.size(); ++i) - { - b2 += CGAL::bbox_3(polyline_range[i].begin(), - polyline_range[i].end()); - } + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + >::type; - if(!CGAL::do_overlap(b1,b2)) - return out; + using GT = typename GetGeomTraits::type; - typedef TriangleMesh TM; - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename GetVertexPointMap::const_type VertexPointMap; + using VPM = typename GetVertexPointMap::const_type; + using face_descriptor = typename boost::graph_traits::face_descriptor; - VertexPointMap vpmap = choose_parameter(get_parameter(np, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, tm)); - typedef typename boost::property_traits::value_type Point; - typedef typename boost::range_value::type Polyline; - static_assert(std::is_same::type>::value); + using Point_3 = typename GT::Point_3; + using Segment_3 = typename GT::Segment_3; - std::vector faces; - faces.reserve(std::distance( std::begin(face_range), std::end(face_range) )); + using AABB_tree_helper = internal::AABB_tree_graph_helper; + using Face_tree = typename AABB_tree_helper::Tree; - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d, Box_policy> Box; + using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; + using Segment_traits = CGAL::AABB_traits_3; + using Segment_tree = CGAL::AABB_tree; - // make one box per facet - std::vector boxes1; - std::vector boxes2; - boxes1.reserve(std::distance(std::begin(face_range), std::end(face_range))); + VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, tm)); - std::size_t polylines_size = 0; - for(Polyline poly : polyline_range) + Bbox_3 b1 = Polygon_mesh_processing::bbox(tm, np); + auto polyline_it = polyline_range.begin(); + Bbox_3 b2 = bbox_3(polyline_it->begin(), polyline_it->end()); + for(++polyline_it; polyline_it != polyline_range.end(); ++polyline_it) + b2 += bbox_3(polyline_it->begin(), polyline_it->end()); + + if(!CGAL::do_overlap(b1, b2)) + return out; + Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), + (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); + + // We store all polylines in one range and we store the offset of the beginning of each polyline + std::vector segments; + std::vector polyline_begin; + for(std::size_t pi = 0; pi < polyline_range.size(); ++pi) { - polylines_size += std::distance( std::begin(poly), std::end(poly) ) -1; + const auto& polyline = polyline_range[pi]; + + if(polyline.size() < 2) + continue; + + polyline_begin.push_back(segments.size()); + + auto pit = std::begin(polyline); + auto prev = pit++; + for(; pit != std::end(polyline); ++pit, ++prev) + segments.emplace_back(*prev, *pit); } - boxes2.reserve(polylines_size); + std::vector face_to_test; for(face_descriptor f : face_range) - { - faces.push_back(f); - boxes1.push_back(Box(Polygon_mesh_processing::face_bbox(f, tm), std::make_pair(0, faces.size()-1))); - } + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm), bb)) + face_to_test.emplace_back(f); - std::size_t range_size = std::distance( std::begin(polyline_range), std::end(polyline_range) ); - for(std::size_t j = 0; j < range_size; ++j) - { - Polyline poly = polyline_range[j]; - std::size_t size = std::distance( std::begin(poly), std::end(poly) ); - for(std::size_t i =0; i< size - 1; ++i) - { - Point p1 = poly[i]; - Point p2 = poly[i+1]; - boxes2.push_back(Box(p1.bbox() + p2.bbox(), std::make_pair(j, i))); - } - } + AABB_tree_helper helper; + Face_tree face_tree; - // generate box pointers + helper.template build(face_tree, tm, vpm); + Segment_tree segment_tree(segments.begin(), segments.end()); - std::vector box1_ptr(boost::make_counting_iterator(&boxes1[0]), - boost::make_counting_iterator(&boxes1[0]+boxes1.size())); - std::vector box2_ptr(boost::make_counting_iterator(&boxes2[0]), - boost::make_counting_iterator(&boxes2[0]+boxes2.size())); + auto out_converter = + boost::make_function_output_iterator( + [&](const auto& pair) + { + std::size_t index = pair.second - segments.begin(); - // compute intersections filtered out by boxes - typedef typename GetGeomTraits::type GeomTraits; - GeomTraits gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); + // Find the polyline containing this segment. + auto it = std::upper_bound(polyline_begin.begin(), + polyline_begin.end(), + index); - internal::Intersect_face_polylines - Intersect_face_polyline(tm, faces, polyline_range, out, vpmap, gt); + std::size_t polyline_index = static_cast(it - polyline_begin.begin() - 1); + std::size_t segment_index = index - polyline_begin[polyline_index]; - std::ptrdiff_t cutoff = 2000; - CGAL::box_intersection_d(box1_ptr.begin(), box1_ptr.end(), - box2_ptr.begin(), box2_ptr.end(), - Intersect_face_polyline, cutoff); - return Intersect_face_polyline.m_iterator; + *out++ = std::make_pair(pair.first, + std::make_pair(polyline_index, segment_index)); + }); + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(face_tree, segment_tree, out_converter, parameters::concurrency_tag(Concurrency_tag())); + return out; } // Note this is not officially documented /* \ingroup PMP_intersection_grp * - * detects and records intersections between two polylines. + * detects and records intersections between two ranges of polylines. * * This function depends on the package \ref PkgBoxIntersectionD. * * \attention If a polyline vertex intersects another polyline, the intersection will * be reported twice (even more if it is on a vertex). * - * \tparam Polyline a `RandomAccessRange` of points. + * \tparam PolylineRange a `RandomAccessRange` of `RandomAccessRange` of points. * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair`. This OutputIterator will hold the position of the - * elements in their respective range. This position is the index of the segment that holds the - * intersection, so it is the index of the first point of the segment following the range order. + * `std::pair, std::pair >`. + * Each pair holds the index of the face and a pair containing the index of the polyline in the range and the index of + * the first point of the segment in the polyline. * \tparam Kernel a model of `Kernel` * - * \param polyline1 the first polyline to check for intersections. - * \param polyline2 the second polyline to check for intersections. + * \param polylines1 the first range of polylines to check for intersections. + * \param polylines2 the second range of polylines to check for intersections. * \param out output iterator to be filled with all pairs of segments that intersect * \param K an instance of `Kernel` * * \return `out` */ -template < class Polyline, +template < class PolylineRange, class OutputIterator, class Kernel> OutputIterator -compute_polyline_polyline_intersection(const Polyline& polyline1, - const Polyline& polyline2, - OutputIterator out, - const Kernel& K) +compute_polylines_polylines_intersection(const PolylineRange& polylines1, + const PolylineRange& polylines2, + OutputIterator out, + const Kernel& /*K*/) { - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Box; + using parameters::get_parameter; - typedef typename Kernel::Point_3 Point; - // make one box per facet - std::vector boxes1; - std::vector boxes2; - boxes1.reserve(std::distance(std::begin(polyline1), std::end(polyline1)) - 1); - boxes2.reserve(std::distance(std::begin(polyline2), std::end(polyline2)) - 1); + using GT = Kernel; + using Segment_3 = typename GT::Segment_3; + + using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; + using Segment_traits = CGAL::AABB_traits_3; + using Segment_tree = CGAL::AABB_tree; - for(std::size_t i =0; i< polyline1.size()-1; ++i) + std::vector segments1, segments2; + std::vector polyline_begin1, polyline_begin2; + + for(std::size_t pi = 0; pi < polylines1.size(); ++pi) { - const Point& p1 = polyline1[i]; - const Point& p2 = polyline1[i+1]; - boxes1.push_back(Box(p1.bbox() + p2.bbox(), i)); + const auto& polyline = polylines1[pi]; + polyline_begin1.push_back(segments1.size()); + + auto pit = std::begin(polyline); + auto prev = pit++; + for(; pit != std::end(polyline); ++pit, ++prev) + segments1.emplace_back(*prev, *pit); } - for(std::size_t i =0; i< polyline2.size()-1; ++i) + for(std::size_t pi = 0; pi < polylines2.size(); ++pi) { - const Point& p1 = polyline2[i]; - const Point& p2 = polyline2[i+1]; - boxes2.push_back(Box(p1.bbox() + p2.bbox(), i)); + const auto& polyline = polylines2[pi]; + polyline_begin2.push_back(segments2.size()); + + auto pit = std::begin(polyline); + auto prev = pit++; + for(; pit != std::end(polyline); ++pit, ++prev) + segments2.emplace_back(*prev, *pit); } - // generate box pointers - std::vector box1_ptr(boost::make_counting_iterator(&boxes1[0]), - boost::make_counting_iterator(&boxes1[0]+boxes1.size())); - std::vector box2_ptr(boost::make_counting_iterator(&boxes2[0]), - boost::make_counting_iterator(&boxes2[0]+boxes2.size())); + if(segments1.empty() || segments2.empty()) + return out; + + Segment_tree tree1(segments1.begin(), segments1.end()); + Segment_tree tree2(segments2.begin(), segments2.end()); + auto convert_out = + boost::make_function_output_iterator( + [&](const auto& pair) + { + const std::size_t offset1 = static_cast(pair.first - segments1.cbegin()); + const std::size_t offset2 = static_cast(pair.second - segments2.cbegin()); - // compute intersections filtered out by boxes + const auto it1 = std::upper_bound(polyline_begin1.begin(), + polyline_begin1.end(), + offset1); - internal::Intersect_polylines - intersect_polylines(polyline1, polyline2, out, K); + const auto it2 = std::upper_bound(polyline_begin2.begin(), + polyline_begin2.end(), + offset2); - std::ptrdiff_t cutoff = 2000; - CGAL::box_intersection_d(box1_ptr.begin(), box1_ptr.end(), - box2_ptr.begin(), box2_ptr.end(), - intersect_polylines, cutoff); - return intersect_polylines.m_iterator; + const std::size_t pi1 = static_cast(it1 - polyline_begin1.begin() - 1); + const std::size_t pi2 = static_cast(it2 - polyline_begin2.begin() - 1); + + *out++ = std::make_pair( + std::make_pair(pi1, offset1 - polyline_begin1[pi1]), + std::make_pair(pi2, offset2 - polyline_begin2[pi2])); + }); + + CGAL::AABB_trees::all_pairs_of_intersecting_primitives( + tree1, + tree2, + convert_out); + + return out; } // Note this is not officially documented /* \ingroup PMP_intersection_grp * - * detects and records intersections between two ranges of polylines. + * detects and records intersections between two polylines. * * This function depends on the package \ref PkgBoxIntersectionD. * * \attention If a polyline vertex intersects another polyline, the intersection will * be reported twice (even more if it is on a vertex). * - * \tparam PolylineRange a `RandomAccessRange` of `RandomAccessRange` of points. + * \tparam Polyline a `RandomAccessRange` of points. * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair, std::pair >`. - * Each pair holds the index of the face and a pair containing the index of the polyline in the range and the index of - * the first point of the segment in the polyline. + * `std::pair`. This OutputIterator will hold the position of the + * elements in their respective range. This position is the index of the segment that holds the + * intersection, so it is the index of the first point of the segment following the range order. * \tparam Kernel a model of `Kernel` * - * \param polylines1 the first range of polylines to check for intersections. - * \param polylines2 the second range of polylines to check for intersections. + * \param polyline1 the first polyline to check for intersections. + * \param polyline2 the second polyline to check for intersections. * \param out output iterator to be filled with all pairs of segments that intersect * \param K an instance of `Kernel` * * \return `out` */ -template < class PolylineRange, +template < class Polyline, class OutputIterator, class Kernel> OutputIterator -compute_polylines_polylines_intersection(const PolylineRange& polylines1, - const PolylineRange& polylines2, - OutputIterator out, - const Kernel& K) +compute_polyline_polyline_intersection(const Polyline& polyline1, + const Polyline& polyline2, + OutputIterator out, + const Kernel& K) { - //info.first is the index of the polyline in the range, info.second is the index of the point in the polyline - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d, Box_policy> Box; - - typedef typename Kernel::Point_3 Point; - typedef typename boost::range_value::type Polyline; - - // make one box per facet - std::vector boxes1; - std::vector boxes2; - std::size_t polylines_size = 0; - CGAL::Bbox_3 b1, b2; - for(Polyline poly : polylines1) - { - polylines_size += std::distance( std::begin(poly), std::end(poly) ) -1; - b1 += CGAL::bbox_3(poly.begin(), poly.end()); - } - boxes1.reserve( polylines_size ); - - polylines_size = 0; - for(Polyline poly : polylines2) - { - polylines_size += std::distance( std::begin(poly), std::end(poly) ) -1; - b2 += CGAL::bbox_3(poly.begin(), poly.end()); - } - boxes2.reserve(polylines_size); - - if(!CGAL::do_overlap(b1,b2)) - return out; - - std::size_t range_size = std::distance( std::begin(polylines1), std::end(polylines1) ); - for(std::size_t j = 0; j < range_size; ++j) - { - Polyline poly = polylines1[j]; - std::size_t size = std::distance( std::begin(poly), std::end(poly) ); - for(std::size_t i =0; i< size - 1; ++i) - { - const Point& p1 = poly[i]; - const Point& p2 = poly[i+1]; - boxes1.push_back(Box(p1.bbox() + p2.bbox(), std::make_pair(j, i))); - } - } - - range_size = std::distance( std::begin(polylines2), std::end(polylines2) ); - for(std::size_t j = 0; j < range_size; ++j) - { - Polyline poly = polylines2[j]; - std::size_t size = std::distance( std::begin(poly), std::end(poly) ); - for(std::size_t i =0; i< size - 1; ++i) - { - const Point& p1 = poly[i]; - const Point& p2 = poly[i+1]; - boxes2.push_back(Box(p1.bbox() + p2.bbox(), std::make_pair(j, i))); - } - } - - // generate box pointers - std::vector box1_ptr(boost::make_counting_iterator(&boxes1[0]), - boost::make_counting_iterator(&boxes1[0]+boxes1.size())); - std::vector box2_ptr(boost::make_counting_iterator(&boxes2[0]), - boost::make_counting_iterator(&boxes2[0]+boxes2.size())); - - - // compute intersections filtered out by boxes - internal::Intersect_polyline_ranges - intersect_polylines(polylines1, polylines2, out, K); - - std::ptrdiff_t cutoff = 2000; - CGAL::box_intersection_d(box1_ptr.begin(), box1_ptr.end(), - box2_ptr.begin(), box2_ptr.end(), - intersect_polylines, cutoff); - return intersect_polylines.m_iterator; + std::array polylines1{{polyline1}}; + std::array polylines2{{polyline2}}; + + auto polyline_out = + boost::make_function_output_iterator( + [&](const auto& pair) + { + *out++ = std::make_pair(pair.first.second, + pair.second.second); + }); + + compute_polylines_polylines_intersection(polylines1, polylines2, polyline_out, K); + return out; } // Note this is not officially documented From 503b55ccfeec54b14d96ad7576376a03931adf07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 22 Sep 2026 18:00:11 +0200 Subject: [PATCH 038/136] Remove unused include --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 663ba6a59933..a3e8238cc2c6 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -21,7 +21,6 @@ #include #include -#include #include #include #include From 1a52c6471b79dc67840b0e322d6161e7519752bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 23 Sep 2026 15:48:33 +0200 Subject: [PATCH 039/136] Replace box_intersection_d per AABB_tree in intersecting_meshes --- .../Polygon_mesh_processing/intersection.h | 143 ++++++++++++++---- 1 file changed, 116 insertions(+), 27 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index a3e8238cc2c6..a9fa121e8d3f 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -657,8 +657,6 @@ compute_face_polylines_intersection(const FaceRange& face_range, using VPM = typename GetVertexPointMap::const_type; using face_descriptor = typename boost::graph_traits::face_descriptor; - - using Point_3 = typename GT::Point_3; using Segment_3 = typename GT::Segment_3; using AABB_tree_helper = internal::AABB_tree_graph_helper; @@ -1526,6 +1524,34 @@ struct Mesh_callback }; }//end internal +namespace internal { + template + struct AABB_indexed_bbox_primitive + { + using Id = std::size_t; + using Datum = CGAL::Bbox_3; + + AABB_indexed_bbox_primitive() = default; + + AABB_indexed_bbox_primitive(Iterator it) + : m_it(it) + {} + + Id id() const + { + return m_it->index; + } + + const Datum& datum() const + { + return m_it->bbox; + } + + private: + Iterator m_it; + }; +} + /*! * \ingroup PMP_intersection_grp * @@ -1552,6 +1578,12 @@ struct Mesh_callback * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`, * where `Point` is the value type of the vertex point map of the meshes} * \cgalParamNEnd + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd * * \cgalParamNBegin{do_overlap_test_of_bounded_sides} * \cgalParamDescription{If `true`, reports also overlap of bounded sides of meshes. @@ -1581,42 +1613,99 @@ template -OutputIterator intersecting_meshes(const TriangleMeshRange& range, - OutputIterator out, - const NamedParameters& np, - const NamedParametersRange& nps) +OutputIterator +intersecting_meshes(const TriangleMeshRange& range, + OutputIterator out, + const NamedParameters& /*np*/, + const NamedParametersRange& nps) { using parameters::choose_parameter; using parameters::get_parameter; - typedef typename TriangleMeshRange::const_iterator TriangleMeshIterator; + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + > ::type; + + using TriangleMeshIterator = typename TriangleMeshRange::const_iterator; + using TriangleMesh = typename std::iterator_traits::value_type; + using GT = typename GetGeomTraits::type; + + struct Indexed_bbox + { + Bbox_3 bbox; + std::size_t index; + }; + + std::vector indexed_bboxes; + indexed_bboxes.reserve(range.size()); + for(std::size_t i = 0; i < range.size(); ++i) + indexed_bboxes.push_back({ Polygon_mesh_processing::bbox(range[i], nps[i]), i }); - bool report_overlap = choose_parameter(get_parameter(np, internal_np::overlap_test),false); + if(indexed_bboxes.empty()) + return out; - typedef CGAL::Box_intersection_d::ID_FROM_BOX_ADDRESS Box_policy; - typedef CGAL::Box_intersection_d::Box_with_info_d Mesh_box; + // // AABB_traits expects a bbox map associating the primitive ID + // // with its bounding box. + // struct Bbox_map + // { + // using key_type = std::size_t; + // using value_type = Bbox_3; + // using reference = const Bbox_3&; + // using category = boost::readable_property_map_tag; - std::vector boxes; - boxes.reserve(std::distance(range.begin(), range.end())); + // const std::vector* bboxes; - for(TriangleMeshIterator it = range.begin(); it != range.end(); ++it) + // reference operator[](key_type i) const { return (*bboxes)[i].bbox; } + // static reference get(const Bbox_map& map, key_type i) { return map[i]; } + // }; + using Bbox_map = boost::vector_property_map; + + // The primitive ID is the index of the mesh. + struct AABB_indexed_bbox_primitive { - boxes.push_back( Mesh_box(Polygon_mesh_processing::bbox(*it), it) ); - } + using Id = std::size_t; + using Datum = Bbox_3; + using Point = typename GT::Point_3; + + AABB_indexed_bbox_primitive() = default; + AABB_indexed_bbox_primitive(typename std::vector::const_iterator it, const Bbox_map&) + : m_it(it) + {} + + Id id() const { return m_it->index; } + const Datum& datum() const { return m_it->bbox; } + Point reference_point() const { + const Bbox_3& b = m_it->bbox; + return Point(b.xmin(), b.ymin(), b.zmin()); + } - std::vector boxes_ptr(boost::make_counting_iterator(&boxes[0]), - boost::make_counting_iterator(&boxes[0]+boxes.size())); + private: + typename std::vector::const_iterator m_it; + }; - typedef typename boost::range_value::type NP_rng; - typedef typename boost::range_value::type TriangleMesh; - typedef typename GetGeomTraits::type GT; - GT gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); - - //get all the pairs of meshes intersecting (no strict inclusion test) - std::ptrdiff_t cutoff = 2000; - internal::Mesh_callback callback(range, out, report_overlap, gt, nps); - CGAL::box_self_intersection_d(boxes_ptr.begin(), boxes_ptr.end(), callback, cutoff); - return callback.m_iterator; + using Primitive = AABB_indexed_bbox_primitive; + using Traits = CGAL::AABB_traits_3; + using Tree = CGAL::AABB_tree; + + boost::vector_property_map bbox_map(indexed_bboxes.size()); + for(const auto& ib : indexed_bboxes) + put(bbox_map, ib.index, ib.bbox); + Tree tree(indexed_bboxes.begin(), indexed_bboxes.end(), bbox_map); + + std::vector> candidates; + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(candidates)); + + for(const auto& p : candidates) + { + const TriangleMesh &mesh1 = range[p.first]; + const TriangleMesh &mesh2 = range[p.second]; + + if(CGAL::Polygon_mesh_processing::do_intersect(mesh1, mesh2, nps[p.first], nps[p.second])) + *out++ = p; + } + return out; } template From 21043fc22f316ec9d50b4444bf600c557573f455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 23 Sep 2026 16:09:40 +0200 Subject: [PATCH 040/136] Apply suggestions --- .../internal/Corefinement/intersection_impl.h | 20 ++++--------------- .../Polygon_mesh_processing/intersection.h | 12 ----------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 2ee0f0f6c66c..97dd6e4f0ff0 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -298,12 +298,12 @@ class Intersection_of_triangle_meshes for(halfedge_descriptor h : hf2){ edge_descriptor e = edge(h, tm2); - if( !get(is_shared_edge_map_2, e) && (is_border(h, tm2) || h < opposite(h, tm2))) + if( is_border(h, tm2) || h < opposite(h, tm2)) callback12(hf1[0], h); } for(halfedge_descriptor h : hf1){ edge_descriptor e = edge(h, tm1); - if( !get(is_shared_edge_map_1, e) && (is_border(h, tm1) || h < opposite(h, tm1))) + if( is_border(h, tm1) || h < opposite(h, tm1)) callback21(hf2[0], h); } }; @@ -348,7 +348,7 @@ class Intersection_of_triangle_meshes // Wrap the call of AABB intersections given two callback functions auto AABB_call = [&](auto &callback12, auto &callback21){ - #ifdef CGAL_LINKED_WITH_TBB +#ifdef CGAL_LINKED_WITH_TBB if constexpr(std::is_same_v) { oneapi::tbb::task_group tg; @@ -371,7 +371,7 @@ class Intersection_of_triangle_meshes process_candidates_with_non_manifold_map(f_1, f_2, callback12, callback21); } else - #endif +#endif { helper_1.template build(tree1, tm1, vpm1); helper_2.template build(tree2, tm2, vpm2); @@ -395,16 +395,10 @@ class Intersection_of_triangle_meshes ? stm_edge_to_ltm_faces : ltm_edge_to_stm_faces; // Select the desire callbacks -#ifdef DO_NOT_HANDLE_COPLANAR_FACES - using Callback = Collect_face_bbox_per_edge_bbox; - Callback callback12(tm1, tm2, tm2_edge_to_tm1_faces); - Callback callback21(tm2, tm1, tm1_edge_to_tm2_faces); -#else using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling< TriangleMesh, VPM1, VPM2, Edge_to_faces, Coplanar_face_set, Node_visitor>; Callback callback12(tm1, tm2, vpm1, vpm2, tm2_edge_to_tm1_faces, coplanar_faces, visitor); Callback callback21(tm2, tm1, vpm2, vpm1, tm1_edge_to_tm2_faces, coplanar_faces, visitor); -#endif if (throw_on_self_intersection){ Callback_with_self_intersection_report callback_si_12(callback12, tm1_faces, tm2_faces); @@ -1174,11 +1168,7 @@ class Intersection_of_triangle_meshes typename std::vector::iterator it_edge=all_edges.begin(); switch(type){ case COPLANAR_TRIANGLES: - #ifndef DO_NOT_HANDLE_COPLANAR_FACES - CGAL_error_msg("COPLANAR_TRIANGLES : this point should never be reached!"); - #else //nothing needs to be done, cf. comments at the beginning of the file - #endif break; case EMPTY: fset.erase(fset.begin()); @@ -2046,7 +2036,6 @@ class Intersection_of_triangle_meshes Node_id current_node((std::numeric_limits::max)()); CGAL_assertion(current_node+1==0); // TODO: handle non-manifold edges in coplanar - #ifndef DO_NOT_HANDLE_COPLANAR_FACES //first handle coplanar triangles if (&tm1<&tm2) compute_intersection_of_coplanar_faces(current_node, tm1, tm2, vpm1, vpm2, non_manifold_feature_map_1, non_manifold_feature_map_2); @@ -2056,7 +2045,6 @@ class Intersection_of_triangle_meshes visitor.set_number_of_intersection_points_from_coplanar_faces(current_node+1); if (!coplanar_faces.empty()) visitor.input_have_coplanar_faces(); - #endif // not DO_NOT_HANDLE_COPLANAR_FACES //compute intersection points of segments and triangles. //build the nodes of the graph and connectivity infos diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index a9fa121e8d3f..89c6a165f6ec 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -1648,18 +1648,6 @@ intersecting_meshes(const TriangleMeshRange& range, // // AABB_traits expects a bbox map associating the primitive ID // // with its bounding box. - // struct Bbox_map - // { - // using key_type = std::size_t; - // using value_type = Bbox_3; - // using reference = const Bbox_3&; - // using category = boost::readable_property_map_tag; - - // const std::vector* bboxes; - - // reference operator[](key_type i) const { return (*bboxes)[i].bbox; } - // static reference get(const Bbox_map& map, key_type i) { return map[i]; } - // }; using Bbox_map = boost::vector_property_map; // The primitive ID is the index of the mesh. From 1421c4ae42c57297e02ea7851aeea11220288b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 23 Sep 2026 19:35:02 +0200 Subject: [PATCH 041/136] Solvebug in self-intersection --- .../internal/Corefinement/intersection_impl.h | 23 ++++++++++++------- .../Polygon_mesh_processing/intersection.h | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 97dd6e4f0ff0..7504c12245ce 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -284,8 +284,8 @@ class Intersection_of_triangle_meshes if(tm1_faces_intersecting_bb.empty() || tm2_faces_intersecting_bb.empty()) return; - Tree_1 tree1(tm1_faces_intersecting_bb.begin(), tm1_faces_intersecting_bb.end(), tm1, vpm1); - Tree_2 tree2(tm2_faces_intersecting_bb.begin(), tm2_faces_intersecting_bb.end(), tm2, vpm2); + Tree_1 tree1; + Tree_2 tree2; auto process_candidates_without_non_manifold_map = [&](face_descriptor f_1, face_descriptor f_2, auto &callback12, auto &callback21){ std::array hf1 = { halfedge(f_1, tm1), @@ -297,12 +297,10 @@ class Intersection_of_triangle_meshes next(next(halfedge(f_2, tm2), tm2), tm2) }; for(halfedge_descriptor h : hf2){ - edge_descriptor e = edge(h, tm2); if( is_border(h, tm2) || h < opposite(h, tm2)) callback12(hf1[0], h); } for(halfedge_descriptor h : hf1){ - edge_descriptor e = edge(h, tm1); if( is_border(h, tm1) || h < opposite(h, tm1)) callback21(hf2[0], h); } @@ -352,8 +350,8 @@ class Intersection_of_triangle_meshes if constexpr(std::is_same_v) { oneapi::tbb::task_group tg; - tg.run([&]{ helper_1.template build(tree1, tm1, vpm1); }); - helper_2.template build(tree2, tm2, vpm2); + tg.run([&]{ helper_1.template build(tm1_faces_intersecting_bb, tree1, tm1, vpm1); }); + helper_2.template build(tm2_faces_intersecting_bb, tree2, tm2, vpm2); tg.wait(); tbb::concurrent_vector> inter; @@ -497,8 +495,8 @@ class Intersection_of_triangle_meshes using Tree = typename AABB_tree_helper::Tree; AABB_tree_helper helper; - Tree tree(faces(tm).begin(), faces(tm).end(), tm, vpm); - helper.template build(tree, tm, vpm); + Tree tree; + helper.template build(faces(tm), tree, tm, vpm); using Callback = Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh< TriangleMesh, VPM, Edge_to_faces, Coplanar_face_set>; @@ -541,6 +539,8 @@ class Intersection_of_triangle_meshes halfedge_descriptor h2 = next(h1, tm); halfedge_descriptor h_f2 = halfedge(f_2, tm); + halfedge_descriptor h1_f2 = next(h_f2, tm); + halfedge_descriptor h2_f2 = next(h1_f2, tm); if (is_border(h0, tm) || h0 < opposite(h0, tm)) callback(h0, h_f2); @@ -548,6 +548,13 @@ class Intersection_of_triangle_meshes callback(h1, h_f2); if (is_border(h2, tm) || h2 < opposite(h2, tm)) callback(h2, h_f2); + + if (is_border(h_f2, tm) || h_f2 < opposite(h_f2, tm)) + callback(h_f2, h0); + if (is_border(h1_f2, tm) || h1_f2 < opposite(h1_f2, tm)) + callback(h1_f2, h0); + if (is_border(h2_f2, tm) || h2_f2 < opposite(h2_f2, tm)) + callback(h2_f2, h0); } } } diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 89c6a165f6ec..2251da7a258c 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -448,8 +448,8 @@ compute_face_face_intersection(const FaceRange& face_range1, Tree_1 tree1; Tree_2 tree2; - helper_1.template build(tree1, tm1, vpm1); - helper_2.template build(tree2, tm2, vpm2); + helper_1.template build(face_to_test1, tree1, tm1, vpm1); + helper_2.template build(face_to_test2, tree2, tm2, vpm2); CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, out, parameters::concurrency_tag(Concurrency_tag())); return out; From 775a309dbbd89389a5059cb3383bac1dcc860dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 23 Sep 2026 20:22:04 +0200 Subject: [PATCH 042/136] Rename callback halfedges --- .../internal/Corefinement/intersection_impl.h | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 7504c12245ce..119494b260b9 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -512,18 +512,27 @@ class Intersection_of_triangle_meshes for(std::size_t i=0; i Date: Wed, 23 Sep 2026 21:32:54 +0200 Subject: [PATCH 043/136] Solved a bug with invalid halfedges if the border of a remove patch has a shared vertex in its middle --- .../internal/Corefinement/face_graph_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index c46aa0d40ccf..b2ba9d65497e 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -1811,7 +1811,7 @@ remove_patches(TriangleMesh& tm, // look for the halfedge belonging to shared_edges // having the prev pointer not correctly set halfedge_descriptor nxt=next(h, tm); - while(!is_border(nxt, tm)) + while(!is_border(nxt, tm) || patch.border_with_shared_source.count(nxt)) nxt=next(opposite(nxt, tm), tm); CGAL_assertion( is_border(nxt, tm) );//we marked it above! // now update the prev pointer From 2a8e5ee4f36d96edfe000e162922bfd359f025c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 23 Sep 2026 22:53:22 +0200 Subject: [PATCH 044/136] Reorder callback of autorefine --- .../internal/Corefinement/intersection_impl.h | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 119494b260b9..b5481002eef0 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -521,18 +521,18 @@ class Intersection_of_triangle_meshes halfedge_descriptor h2_f2 = next(h1_f2, tm); if (is_border(h0_f1, tm) || h0_f1 < opposite(h0_f1, tm)) - callback(h0_f1, h0_f2); + callback(h0_f2, h0_f1); if (is_border(h1_f1, tm) || h1_f1 < opposite(h1_f1, tm)) - callback(h1_f1, h0_f2); + callback(h0_f2, h1_f1); if (is_border(h2_f1, tm) || h2_f1 < opposite(h2_f1, tm)) - callback(h2_f1, h0_f2); + callback(h0_f2, h2_f1); if (is_border(h0_f2, tm) || h0_f2 < opposite(h0_f2, tm)) - callback(h0_f2, h0_f1); + callback(h0_f1, h0_f2); if (is_border(h1_f2, tm) || h1_f2 < opposite(h1_f2, tm)) - callback(h1_f2, h0_f1); + callback(h0_f1, h1_f2); if (is_border(h2_f2, tm) || h2_f2 < opposite(h2_f2, tm)) - callback(h2_f2, h0_f1); + callback(h0_f1, h2_f2); // }); } } @@ -552,18 +552,18 @@ class Intersection_of_triangle_meshes halfedge_descriptor h2_f2 = next(h1_f2, tm); if (is_border(h0_f1, tm) || h0_f1 < opposite(h0_f1, tm)) - callback(h0_f1, h0_f2); + callback(h0_f2, h0_f1); if (is_border(h1_f1, tm) || h1_f1 < opposite(h1_f1, tm)) - callback(h1_f1, h0_f2); + callback(h0_f2, h1_f1); if (is_border(h2_f1, tm) || h2_f1 < opposite(h2_f1, tm)) - callback(h2_f1, h0_f2); + callback(h0_f2, h2_f1); if (is_border(h0_f2, tm) || h0_f2 < opposite(h0_f2, tm)) - callback(h0_f2, h0_f1); + callback(h0_f1, h0_f2); if (is_border(h1_f2, tm) || h1_f2 < opposite(h1_f2, tm)) - callback(h1_f2, h0_f1); + callback(h0_f1, h1_f2); if (is_border(h2_f2, tm) || h2_f2 < opposite(h2_f2, tm)) - callback(h2_f2, h0_f1); + callback(h0_f1, h2_f2); } } } From 7f9aa4ab0c5257d867ad557ed387391ba2770171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 24 Sep 2026 10:17:58 +0200 Subject: [PATCH 045/136] solve a bug of bad border connection when removed a patch --- .../internal/AABB_two_trees_traversal.h | 4 ++++ .../Output_builder_for_autorefinement.h | 1 + .../internal/Corefinement/face_graph_utils.h | 24 ++++++++++++++++--- .../Polygon_mesh_processing/intersection.h | 4 ++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h index 7aaa626c1d71..317d1ab9d682 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h @@ -18,6 +18,10 @@ #include #include +#if CGAL_LINKED_WITH_TBB +#include +#endif + namespace CGAL { namespace internal { namespace AABB_tree { diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Output_builder_for_autorefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Output_builder_for_autorefinement.h index 5940288ac576..7bae36ef6382 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Output_builder_for_autorefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Output_builder_for_autorefinement.h @@ -1185,6 +1185,7 @@ class Output_builder_for_autorefinement Patches patches(tm, patch_ids, fids, intersection_edges, nb_patches); //remove the extra patch remove_patches(tm, ~patches_to_keep,patches, ecm, ecm); // WARNING there should be edge_mark_map but this file will disappear soon + CGAL_assertion(is_valid_polygon_mesh(tm)); stitch_borders(tm, hedge_pairs_to_stitch, parameters::vertex_point_map(vpm)); } diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index b2ba9d65497e..cce7cc857783 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -1811,11 +1811,29 @@ remove_patches(TriangleMesh& tm, // look for the halfedge belonging to shared_edges // having the prev pointer not correctly set halfedge_descriptor nxt=next(h, tm); - while(!is_border(nxt, tm) || patch.border_with_shared_source.count(nxt)) - nxt=next(opposite(nxt, tm), tm); - CGAL_assertion( is_border(nxt, tm) );//we marked it above! + CGAL_assertion(is_border(nxt, tm)); + // now update the prev pointer halfedge_descriptor prv=prev(opposite(h, tm), tm); + while(!is_border(prv, tm)) + prv=prev(opposite(prv, tm), tm); + + set_next(prv, nxt, tm); + set_halfedge(target(prv, tm), prv, tm); + } + + for(halfedge_descriptor h : patch.border_with_shared_source) + { + // look for the halfedge belonging to shared_edges + // having the prev pointer not correctly set + halfedge_descriptor prv=prev(h, tm); + CGAL_assertion(is_border(prv, tm)); + + // now update the next pointer + halfedge_descriptor nxt=next(opposite(h, tm), tm); + while(!is_border(nxt, tm)) + nxt=next(opposite(nxt, tm), tm); + set_next(prv, nxt, tm); set_halfedge(target(prv, tm), prv, tm); } diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 2251da7a258c..e7a48e1a653d 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -1616,7 +1616,11 @@ template Date: Thu, 24 Sep 2026 12:04:38 +0200 Subject: [PATCH 046/136] Solve a bug with bad constructing tree --- .../include/CGAL/AABB_trees/intersection.h | 21 ++++++++++++ .../Polygon_mesh_processing/intersection.h | 32 +++++++++---------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_trees/intersection.h b/AABB_tree/include/CGAL/AABB_trees/intersection.h index 33280ce4dcc7..552b6b34581b 100644 --- a/AABB_tree/include/CGAL/AABB_trees/intersection.h +++ b/AABB_tree/include/CGAL/AABB_trees/intersection.h @@ -266,6 +266,27 @@ namespace AABB_trees { CGAL::internal::AABB_tree::two_trees_traversal(tree1, tree2, traversal_traits); } + /// \ingroup PkgAABBTreeRef + /// + /// \brief computes all pairs of primitives from a single AABB tree that are intersecting. + /// + /// \note Two primitives do intersect if their datum do intersect according to the traits of the tree. Thus, with all documented traits in CGAL, two triangles sharing + /// a vertex are considered to intersect, and similarly for other primitives types and types of intersection. + /// + /// Intersections of a primitive with itself are not reported, and each intersecting + /// pair of distinct primitives is reported only once. + template< typename Concurrency_tag = Sequential_tag, + typename AABBTree, + typename OutputIterator> + void all_pairs_of_primitives_with_overlapping_bbox(const AABBTree &tree, + OutputIterator out) + { + if(tree.empty()) + return; + CGAL::internal::AABB_tree::Two_trees_listing_primitives_with_overlapping_bbox_traits traversal_traits(tree.traits(), tree.traits(), out); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); + } + }} // end namespace CGAL::AABB_trees #endif \ No newline at end of file diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index e7a48e1a653d..cac837ce6ea4 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -1616,11 +1616,7 @@ template ::type; + bool report_overlap = choose_parameter(get_parameter(np, internal_np::overlap_test),false); + using TriangleMeshIterator = typename TriangleMeshRange::const_iterator; using TriangleMesh = typename std::iterator_traits::value_type; using GT = typename GetGeomTraits::type; @@ -1650,24 +1648,26 @@ intersecting_meshes(const TriangleMeshRange& range, if(indexed_bboxes.empty()) return out; - // // AABB_traits expects a bbox map associating the primitive ID - // // with its bounding box. - using Bbox_map = boost::vector_property_map; - // The primitive ID is the index of the mesh. struct AABB_indexed_bbox_primitive { using Id = std::size_t; - using Datum = Bbox_3; + struct Datum : public Bbox_3 + { + Datum() = default; + Datum(const Bbox_3& bbox) : Bbox_3(bbox) {} + + const Datum& bbox() const { return *this; } + }; using Point = typename GT::Point_3; AABB_indexed_bbox_primitive() = default; - AABB_indexed_bbox_primitive(typename std::vector::const_iterator it, const Bbox_map&) + AABB_indexed_bbox_primitive(typename std::vector::const_iterator it) : m_it(it) {} Id id() const { return m_it->index; } - const Datum& datum() const { return m_it->bbox; } + Datum datum() const { return Datum(m_it->bbox); } Point reference_point() const { const Bbox_3& b = m_it->bbox; return Point(b.xmin(), b.ymin(), b.zmin()); @@ -1678,13 +1678,10 @@ intersecting_meshes(const TriangleMeshRange& range, }; using Primitive = AABB_indexed_bbox_primitive; - using Traits = CGAL::AABB_traits_3; + using Traits = CGAL::AABB_traits_3; using Tree = CGAL::AABB_tree; - boost::vector_property_map bbox_map(indexed_bboxes.size()); - for(const auto& ib : indexed_bboxes) - put(bbox_map, ib.index, ib.bbox); - Tree tree(indexed_bboxes.begin(), indexed_bboxes.end(), bbox_map); + Tree tree(indexed_bboxes.begin(), indexed_bboxes.end()); std::vector> candidates; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(candidates)); @@ -1694,7 +1691,8 @@ intersecting_meshes(const TriangleMeshRange& range, const TriangleMesh &mesh1 = range[p.first]; const TriangleMesh &mesh2 = range[p.second]; - if(CGAL::Polygon_mesh_processing::do_intersect(mesh1, mesh2, nps[p.first], nps[p.second])) + if(CGAL::Polygon_mesh_processing::do_intersect(mesh1, mesh2, nps[p.first].do_overlap_test_of_bounded_sides(report_overlap), + nps[p.second].do_overlap_test_of_bounded_sides(report_overlap))) *out++ = p; } return out; From 8c8e4918470db503ff626eba8953d112e8aa7250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 24 Sep 2026 13:49:15 +0200 Subject: [PATCH 047/136] Treat correctly singleton tree --- AABB_tree/include/CGAL/AABB_tree.h | 3 ++- .../AABB_tree/internal/AABB_two_trees_traversal.h | 11 ++++++++++- AABB_tree/include/CGAL/AABB_trees/intersection.h | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index c9881698a9a6..c84132776756 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -691,11 +691,12 @@ namespace CGAL { return std::addressof(m_nodes[0]); } - private: + /// @private const Primitive& singleton_data() const { CGAL_assertion(size() == 1); return *m_primitives.begin(); } + private: // search KD-tree mutable std::unique_ptr m_p_search_tree; diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h index 317d1ab9d682..13f94d6302eb 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h @@ -125,7 +125,16 @@ void two_trees_traversal(const Tree_A& tree_A, TwoTreeTraversalTraits &traits) { CGAL_precondition(tree_A.size() != 0 && tree_B.size() != 0); - two_trees_traversal(*tree_A.root_node(), *tree_B.root_node(), tree_A.size(), tree_B.size(), traits); + if(tree_A.size() == 1){ + if(tree_B.size() == 1) + traits.intersection(tree_A.singleton_data(), tree_B.singleton_data()); + else + traits.intersection(tree_A.singleton_data(), *tree_B.root_node(), tree_B.size()); + } + else if(tree_B.size() == 1) + traits.intersection(*tree_A.root_node(), tree_A.size(), tree_A.singleton_data()); + else + two_trees_traversal(*tree_A.root_node(), *tree_B.root_node(), tree_A.size(), tree_B.size(), traits); } // An optimization to traverse a tree with itself diff --git a/AABB_tree/include/CGAL/AABB_trees/intersection.h b/AABB_tree/include/CGAL/AABB_trees/intersection.h index 552b6b34581b..d55e3d7866b5 100644 --- a/AABB_tree/include/CGAL/AABB_trees/intersection.h +++ b/AABB_tree/include/CGAL/AABB_trees/intersection.h @@ -207,7 +207,7 @@ namespace AABB_trees { void all_pairs_of_intersecting_primitives(const AABBTree &tree, OutputIterator out) { - if(tree.empty()) + if(tree.size() <= 1) return; CGAL::internal::AABB_tree::Two_trees_listing_intersecting_primitives_traits traversal_traits(tree.traits(), tree.traits(), out); CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); @@ -281,7 +281,7 @@ namespace AABB_trees { void all_pairs_of_primitives_with_overlapping_bbox(const AABBTree &tree, OutputIterator out) { - if(tree.empty()) + if(tree.size() <= 1) return; CGAL::internal::AABB_tree::Two_trees_listing_primitives_with_overlapping_bbox_traits traversal_traits(tree.traits(), tree.traits(), out); CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); From 5e486a8a3908a81490cfde4d8e8f0f94de866785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 24 Sep 2026 14:44:25 +0200 Subject: [PATCH 048/136] Singleton tree case --- .../include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h index 13f94d6302eb..1067e317763c 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h @@ -132,7 +132,7 @@ void two_trees_traversal(const Tree_A& tree_A, traits.intersection(tree_A.singleton_data(), *tree_B.root_node(), tree_B.size()); } else if(tree_B.size() == 1) - traits.intersection(*tree_A.root_node(), tree_A.size(), tree_A.singleton_data()); + traits.intersection(*tree_A.root_node(), tree_A.size(), tree_B.singleton_data()); else two_trees_traversal(*tree_A.root_node(), *tree_B.root_node(), tree_A.size(), tree_B.size(), traits); } From 2d2b48151c2634d7110367f4c1194b23e3b1c268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 24 Sep 2026 16:52:28 +0200 Subject: [PATCH 049/136] Add missing function for singleton tree case --- .../AABB_two_trees_traversal_traits.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 29e52608ff33..4fb32988b162 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -280,6 +280,14 @@ class Two_trees_do_intersect_traits return node_a.bbox().squared_diagonal_length() > node_b.bbox().squared_diagonal_length(); } + void intersection(const Primitive1& primitive1, const Primitive2& primitive2) + { + Do_intersect_traits traits(m_traits2); + traits.intersection(internal::Primitive_helper::get_datum(primitive1, m_traits1), primitive2); + if(traits.is_intersection_found()) + m_is_found = true; + } + void intersection(const Primitive1& primitive1, const Node2& node2, std::size_t nb_primitives_2) { Do_intersect_traits traits(m_traits2); @@ -341,6 +349,28 @@ class Two_trees_do_intersect_traits_with_transformation return node_a.bbox().squared_diagonal_length() > node_b.bbox().squared_diagonal_length(); } + void intersection(const Primitive1& primitive1, const Primitive2& primitive2) + { + Do_intersect_traits traits(m_traits2); + traits.intersection(internal::Primitive_helper::get_datum(primitive1, m_traits1), primitive2); + if constexpr(Use_inverse_transformation::value) + { + Do_intersect_traits traits(m_traits2); + auto datum = (internal::Primitive_helper::get_datum(primitive1, m_traits1).transform(m_tr1)).transform(m_tr2_inverse); + traits.intersection(datum, primitive2); + if(traits.is_intersection_found()) + m_is_found = true; + } + else + { + Do_intersect_traits_with_transformation traits(m_traits2, m_tr2); + auto datum = (internal::Primitive_helper::get_datum(primitive1, m_traits1).transform(m_tr1)); + traits.intersection(datum, primitive2); + if(traits.is_intersection_found()) + m_is_found = true; + } + } + void intersection(const Primitive1& primitive1, const Node2& node2, std::size_t nb_primitives_2) { // It is more efficient to apply the inverse transformation to the query and then use the original traits, From 18f675f98eedd50396427bd6c5252c79fbeab34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 24 Sep 2026 16:53:29 +0200 Subject: [PATCH 050/136] Make Throw_at_output and Throw_at_count thread safe --- .../Polygon_mesh_processing/self_intersections.h | 15 +++++++++++---- STL_Extension/include/CGAL/exceptions.h | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index 5853ef8219e1..a442ee2b25a5 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -223,14 +223,16 @@ struct Throw_at_count_reached_output_iterator { using Self = Throw_at_count_reached_output_iterator; std::atomic &counter; + std::atomic &stop; const unsigned int &maxval; OutputIterator out; using iterator_category = std::output_iterator_tag; Throw_at_count_reached_output_iterator(std::atomic &counter, + std::atomic &stop, const unsigned int &maxval, OutputIterator out) - : counter(counter), maxval(maxval), out(out) + : counter(counter), stop(stop), maxval(maxval), out(out) {} template @@ -238,8 +240,8 @@ struct Throw_at_count_reached_output_iterator { *out++ = t; ++counter; - if(counter >= maxval) - throw CGAL::internal::Throw_at_output_exception(); + if(counter >= maxval && !stop.exchange(true, std::memory_order_relaxed)) + throw CGAL::internal::Throw_at_output_exception(); return *this; } @@ -519,7 +521,11 @@ self_intersections_impl(const FaceRange& face_range, // This is obviously not optimal if there are no or few self-intersections: it would be a greater speed-up // to do the same as for `self_intersections()`. However, doing like `self_intersections()` would // be a major slow-down over sequential code if there are a lot of self-intersections... +#if !defined(CGAL_LINKED_WITH_TBB) using Throwing_output_iterator = boost::function_output_iterator; +#else + using Throwing_output_iterator = boost::function_output_iterator; +#endif Throwing_output_iterator throwing_filter; AABB_tree tree; @@ -550,7 +556,8 @@ self_intersections_impl(const FaceRange& face_range, try { std::atomic atomic_counter(counter); - Throw_iterator throwing_count(atomic_counter, maximum_number, std::back_inserter(face_pairs)); + std::atomic atomic_flag(false); + Throw_iterator throwing_count(atomic_counter, atomic_flag, maximum_number, std::back_inserter(face_pairs)); Throw_at_count_reached_output_iterator count_filter(throwing_count); all_pairs_of_intersecting_faces(tree, count_filter); } diff --git a/STL_Extension/include/CGAL/exceptions.h b/STL_Extension/include/CGAL/exceptions.h index 7141ab71dcd4..b46ddae17916 100644 --- a/STL_Extension/include/CGAL/exceptions.h +++ b/STL_Extension/include/CGAL/exceptions.h @@ -17,6 +17,7 @@ #include #include #include +#include namespace CGAL { @@ -183,6 +184,19 @@ struct Throw_at_output void operator()(const T& /* t */) const { throw Throw_at_output_exception(); } }; +struct Concurrent_throw_at_output +{ + std::shared_ptr> called = std::make_shared>(false); + + template + void operator()(const T& /* t */) const + { + if(!called->exchange(true, std::memory_order_relaxed)) + throw Throw_at_output_exception(); + } +}; + + } // namespace internal } //namespace CGAL From 16e82e4f20e1f87fc42a26f4d8cc6f371ad4d576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 24 Sep 2026 17:29:23 +0200 Subject: [PATCH 051/136] Reintroduce depencies to Box_intersection_d, it is used by PMP_mesh_repair --- .../package_info/PMP_Boolean_operations/dependencies | 1 + 1 file changed, 1 insertion(+) diff --git a/PMP_Boolean_operations/package_info/PMP_Boolean_operations/dependencies b/PMP_Boolean_operations/package_info/PMP_Boolean_operations/dependencies index b774cf106c89..ae85e3b1fb0f 100644 --- a/PMP_Boolean_operations/package_info/PMP_Boolean_operations/dependencies +++ b/PMP_Boolean_operations/package_info/PMP_Boolean_operations/dependencies @@ -2,6 +2,7 @@ AABB_tree Algebraic_foundations Arithmetic_kernel BGL +Box_intersection_d CGAL_Core Cartesian_kernel Circulator From de53663b2fbf403306bce3a4cd920d38faca08fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 25 Sep 2026 13:25:52 +0200 Subject: [PATCH 052/136] Add missing function for singleton case --- .../AABB_tree/internal/AABB_two_trees_traversal_traits.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 4fb32988b162..3e45475a7f53 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -138,6 +138,15 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation return node_a.bbox().squared_diagonal_length() > node_b.bbox().squared_diagonal_length(); } + void intersection(const Primitive1& primitive1, const Primitive2& primitive2) + { + using Wrap_iterator = Wrap_output_iterator; + Wrap_iterator wrap_out(primitive1.id(), out); + Listing_primitive_traits_with_transformation traits(wrap_out, m_traits2, m_tr2); + auto datum1 = (internal::Primitive_helper::get_datum(primitive1, m_traits1).transform(m_tr1)); + traits.intersection( datum1, primitive2); + } + void intersection(const Primitive1& primitive1, const Node2& node2, std::size_t nb_primitives_2) { // Use inverse transformation is faster but less numerically stable. From 0c3d3b0a09ff542c3bf3b3b3c2444f13b9fa32a7 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Fri, 25 Sep 2026 17:26:49 +0200 Subject: [PATCH 053/136] resolved ambiguity --- .../internal/Corefinement/face_graph_utils.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index cce7cc857783..6b40598bb509 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -26,10 +26,25 @@ #include #include + namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { +// Generic C++17 Detection SFINAE helper +template > +struct has_clear_without_removing_property_maps : std::false_type {}; + +// Specialization matches if the expression is valid +template +struct has_clear_without_removing_property_maps().clear_without_removing_property_maps()) + >> : std::true_type {}; + +// Inline helper variable (C++17) +template +inline constexpr bool has_clear_without_removing_property_maps_v = has_clear_without_removing_property_maps::value; + enum Boolean_operation_type {UNION = 0, INTERSECTION, TM1_MINUS_TM2, TM2_MINUS_TM1, NONE }; @@ -1370,7 +1385,7 @@ template < class ConcurrencyTag = Sequential_tag, class PatchContainer1, class PatchContainer2, class UserVisitor> -void fill_new_triangle_mesh( +auto fill_new_triangle_mesh( TriangleMesh& output, const boost::dynamic_bitset<>& patches_of_tm1_to_import, const boost::dynamic_bitset<>& patches_of_tm2_to_import, @@ -1389,7 +1404,7 @@ void fill_new_triangle_mesh( EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, std::vector< typename boost::graph_traits::edge_descriptor>& output_shared_edges, - UserVisitor& user_visitor) + UserVisitor& user_visitor) -> std::enable_if_t, void> { using GT = boost::graph_traits; using vertex_descriptor = typename GT::vertex_descriptor; From f46bdaa7dfb51ef58c59f127bc4a4b153ddb31fc Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Mon, 28 Sep 2026 11:02:10 +0200 Subject: [PATCH 054/136] added is_derived_from_Surface_mesh --- .../CGAL/Surface_mesh/Surface_mesh_fwd.h | 6 ++++++ .../internal/Corefinement/face_graph_utils.h | 17 ++--------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h index 844abe803bf8..2dfa55f62741 100644 --- a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h +++ b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h @@ -20,6 +20,12 @@ namespace CGAL { template class Surface_mesh; +template +struct is_derived_from_Surface_mesh : std::false_type {}; + +template +struct is_derived_from_Surface_mesh> : std::true_type {}; + } // CGAL #endif diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 6b40598bb509..b93499d9c5a7 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -31,20 +32,6 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { -// Generic C++17 Detection SFINAE helper -template > -struct has_clear_without_removing_property_maps : std::false_type {}; - -// Specialization matches if the expression is valid -template -struct has_clear_without_removing_property_maps().clear_without_removing_property_maps()) - >> : std::true_type {}; - -// Inline helper variable (C++17) -template -inline constexpr bool has_clear_without_removing_property_maps_v = has_clear_without_removing_property_maps::value; - enum Boolean_operation_type {UNION = 0, INTERSECTION, TM1_MINUS_TM2, TM2_MINUS_TM1, NONE }; @@ -1404,7 +1391,7 @@ auto fill_new_triangle_mesh( EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, std::vector< typename boost::graph_traits::edge_descriptor>& output_shared_edges, - UserVisitor& user_visitor) -> std::enable_if_t, void> + UserVisitor& user_visitor) -> std::enable_if_t::value> { using GT = boost::graph_traits; using vertex_descriptor = typename GT::vertex_descriptor; From 23bc3ccfc2e91d9b0c714139e257a7648a984ba9 Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Mon, 28 Sep 2026 14:44:37 +0200 Subject: [PATCH 055/136] renaming is_derived_from_Surface_mesh to is_Surface_mesh and moving into face_graph_utils.h --- Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h | 6 ------ .../internal/Corefinement/face_graph_utils.h | 8 +++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h index 2dfa55f62741..844abe803bf8 100644 --- a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h +++ b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h @@ -20,12 +20,6 @@ namespace CGAL { template class Surface_mesh; -template -struct is_derived_from_Surface_mesh : std::false_type {}; - -template -struct is_derived_from_Surface_mesh> : std::true_type {}; - } // CGAL #endif diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index b93499d9c5a7..21f9c550c0d5 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -32,6 +32,12 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { +template +struct is_Surface_mesh : std::false_type {}; + +template +struct is_Surface_mesh> : std::true_type {}; + enum Boolean_operation_type {UNION = 0, INTERSECTION, TM1_MINUS_TM2, TM2_MINUS_TM1, NONE }; @@ -1391,7 +1397,7 @@ auto fill_new_triangle_mesh( EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, std::vector< typename boost::graph_traits::edge_descriptor>& output_shared_edges, - UserVisitor& user_visitor) -> std::enable_if_t::value> + UserVisitor& user_visitor) -> std::enable_if_t::value> { using GT = boost::graph_traits; using vertex_descriptor = typename GT::vertex_descriptor; From 656a69d137db8a16c43bc667d972c828a570f60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 28 Sep 2026 17:25:27 +0200 Subject: [PATCH 056/136] Make specialization compatible with derivation of surface mesh --- .../CGAL/Surface_mesh/Surface_mesh_fwd.h | 12 ++++++ .../internal/Corefinement/face_graph_utils.h | 16 +++----- .../surface_mesh_specializations.h | 38 +++++++++---------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h index 844abe803bf8..0d09aaa15bdf 100644 --- a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h +++ b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h @@ -13,13 +13,25 @@ /// \file Surface_mesh_fwd.h /// Forward declarations of the Surface_mesh package. +#include + #ifndef DOXYGEN_RUNNING + namespace CGAL { +BOOST_MPL_HAS_XXX_TRAIT_DEF(Point_3) // fwdS for the public interface template class Surface_mesh; +template +struct is_surface_mesh : std::false_type {}; + +template +struct is_surface_mesh::value>>: std::is_base_of< CGAL::Surface_mesh, T> +{}; + + } // CGAL #endif diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 21f9c550c0d5..1e4a08d4b620 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -32,12 +32,6 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { -template -struct is_Surface_mesh : std::false_type {}; - -template -struct is_Surface_mesh> : std::true_type {}; - enum Boolean_operation_type {UNION = 0, INTERSECTION, TM1_MINUS_TM2, TM2_MINUS_TM1, NONE }; @@ -1200,7 +1194,7 @@ template < class Concurrency_tag, class EdgetoEdgeMap, class VertextoVertexMap, class UserVisitor> -void append_patches_to_triangle_mesh( +auto append_patches_to_triangle_mesh( TriangleMesh& output, const boost::dynamic_bitset<>& patches_to_append, PatchContainer& patches, @@ -1210,7 +1204,7 @@ void append_patches_to_triangle_mesh( const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgetoEdgeMap& tm_to_output_edges, VertextoVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) + UserVisitor& user_visitor) -> std::enable_if_t::value> { using GT = boost::graph_traits; using halfedge_descriptor = typename GT::halfedge_descriptor; @@ -1341,7 +1335,7 @@ template < bool reverse_patch_orientation, class EdgetoEdgeMap, class VertextoVertexMap, class UserVisitor> -void append_patches_to_triangle_mesh( +auto append_patches_to_triangle_mesh( TriangleMesh& output, const boost::dynamic_bitset<>& patches_to_append, PatchContainer& patches, @@ -1351,7 +1345,7 @@ void append_patches_to_triangle_mesh( const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgetoEdgeMap& tm_to_output_edges, VertextoVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) + UserVisitor& user_visitor) -> std::enable_if_t::value> { append_patches_to_triangle_mesh(output, patches_to_append, @@ -1397,7 +1391,7 @@ auto fill_new_triangle_mesh( EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, std::vector< typename boost::graph_traits::edge_descriptor>& output_shared_edges, - UserVisitor& user_visitor) -> std::enable_if_t::value> + UserVisitor& user_visitor) -> std::enable_if_t::value> { using GT = boost::graph_traits; using vertex_descriptor = typename GT::vertex_descriptor; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h index 47b192c91bfd..f98932135edc 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h @@ -23,7 +23,7 @@ namespace Corefinement { // Specialization of the function for Surface_mesh to exploit vectors structure of Surface_mesh. template < class ConcurrencyTag, bool reverse_patch_orientation, - class Point, + class SurfaceMesh, class PatchDescription, class VertexPointMap, class VertexPointMapOut, @@ -33,8 +33,8 @@ template < class ConcurrencyTag, class VertexToVertexMap, class UserVisitor> void append_patch( - Surface_mesh& tm, - Surface_mesh& output, + SurfaceMesh& tm, + SurfaceMesh& output, PatchDescription& patch, const VertexPointMapOut& vpm_out, const VertexPointMap& vpm_tm, @@ -47,7 +47,7 @@ void append_patch( std::size_t edges_idx_begin, std::size_t faces_idx_begin) { - using SM = Surface_mesh; + using SM = SurfaceMesh; using vertex_descriptor = typename SM::Vertex_index; using edge_descriptor = typename SM::Edge_index; using halfedge_descriptor = typename SM::Halfedge_index; @@ -176,7 +176,7 @@ void append_patch( // Specialization of the function for Surface_mesh to exploit vectors structure of Surface_mesh. template < class ConcurrencyTag, bool reverse_patch_orientation, - class Point, + class SurfaceMesh, class PatchContainer, class VertexPointMap, class VertexPointMapOut, @@ -185,8 +185,8 @@ template < class ConcurrencyTag, class EdgeToEdgeMap, class VertexToVertexMap, class UserVisitor> -void append_patches_to_triangle_mesh( - Surface_mesh& output, +auto append_patches_to_triangle_mesh( + SurfaceMesh& output, const boost::dynamic_bitset<>& patches_to_append, PatchContainer& patches, const VertexPointMapOut& vpm_out, @@ -195,9 +195,9 @@ void append_patches_to_triangle_mesh( const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgeToEdgeMap& tm_to_output_edges, VertexToVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) + UserVisitor& user_visitor) -> std::enable_if_t::value> { - using SM = Surface_mesh; + using SM = SurfaceMesh; SM& tm = patches.pm; std::size_t vertices_idx_begin = output.num_vertices(); @@ -242,7 +242,7 @@ void append_patches_to_triangle_mesh( } template < bool reverse_patch_orientation, - class Point, + class SurfaceMesh, class PatchContainer, class VertexPointMap, class VertexPointMapOut, @@ -251,8 +251,8 @@ template < bool reverse_patch_orientation, class EdgetoEdgeMap, class VertextoVertexMap, class UserVisitor> -void append_patches_to_triangle_mesh( - Surface_mesh& output, +auto append_patches_to_triangle_mesh( + SurfaceMesh& output, const boost::dynamic_bitset<>& patches_to_append, PatchContainer& patches, const VertexPointMapOut& vpm_out, @@ -261,7 +261,7 @@ void append_patches_to_triangle_mesh( const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgetoEdgeMap& tm_to_output_edges, VertextoVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) + UserVisitor& user_visitor) -> std::enable_if_t::value> { append_patches_to_triangle_mesh(output, patches_to_append, @@ -277,7 +277,7 @@ void append_patches_to_triangle_mesh( // Specialization of fill_new_triangle_mesh for Surface_mesh to exploit vectors structure of Surface_mesh. template < class ConcurrencyTag = Sequential_tag, - class Point, + class SurfaceMesh, class IntersectionEdgeMap, class VertexPointMap1, class VertexPointMap2, @@ -289,8 +289,8 @@ template < class ConcurrencyTag = Sequential_tag, class PatchContainer1, class PatchContainer2, class UserVisitor> -void fill_new_triangle_mesh( - Surface_mesh& output, +auto fill_new_triangle_mesh( + SurfaceMesh& output, const boost::dynamic_bitset<>& patches_of_tm1_to_import, const boost::dynamic_bitset<>& patches_of_tm2_to_import, PatchContainer1& patches_of_tm1, @@ -306,10 +306,10 @@ void fill_new_triangle_mesh( const EdgeCstMap1& edge_cst_map1, const EdgeCstMap2& edge_cst_map2, const EdgeMarkMap1& edge_mark_map1, const EdgeMarkMap2& edge_mark_map2, EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, - std::vector< typename Surface_mesh::Edge_index >& output_shared_edges, - UserVisitor& user_visitor) + std::vector< typename SurfaceMesh::Edge_index >& output_shared_edges, + UserVisitor& user_visitor) -> std::enable_if_t::value> { - using SM = Surface_mesh; + using SM = SurfaceMesh; using vertex_descriptor = typename SM::Vertex_index; using edge_descriptor = typename SM::Edge_index; From e6320192651c36db9d33a92b517c1afca21d75ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 29 Sep 2026 16:05:29 +0200 Subject: [PATCH 057/136] warning --- STL_Extension/include/CGAL/exceptions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/STL_Extension/include/CGAL/exceptions.h b/STL_Extension/include/CGAL/exceptions.h index b46ddae17916..8df4f1947b62 100644 --- a/STL_Extension/include/CGAL/exceptions.h +++ b/STL_Extension/include/CGAL/exceptions.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace CGAL { From 8895de517a8657a0314b08599c0716e657312b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 29 Sep 2026 18:17:05 +0200 Subject: [PATCH 058/136] Go through face_range instead of all faces of the mesh --- .../internal/soup_and_face_graph_tree_helper.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 75cb035649b4..c543ec6084f4 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -95,8 +95,8 @@ struct AABB_tree_graph_helper #ifdef CGAL_LINKED_WITH_TBB if constexpr(std::is_same_v) { - tbb::parallel_for(std::size_t(0), faces(tm).size(), [&](std::size_t i){ - face_descriptor f(i); + tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ + face_descriptor f = face_range[i]; put(bb_map, f, face_bbox(f, tm)); put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); }); @@ -104,7 +104,7 @@ struct AABB_tree_graph_helper else #endif { - for(face_descriptor f : faces(tm)){ + for(face_descriptor f : face_range){ put(bb_map, f, face_bbox(f, tm)); put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); } From 017ec9f86a0505de0abd93459314e6176a805f3d Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Wed, 30 Sep 2026 15:56:13 +0200 Subject: [PATCH 059/136] full namespace for IPCP --- .../internal/Corefinement/intersection_impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index b5481002eef0..c80d4b595418 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -259,8 +259,8 @@ class Intersection_of_triangle_meshes { using Point = typename boost::property_traits::value_type; using GT = typename CGAL::Kernel_traits::Kernel; - using AABB_tree_helper_1 = internal::AABB_tree_graph_helper; - using AABB_tree_helper_2 = internal::AABB_tree_graph_helper; + using AABB_tree_helper_1 = CGAL::Polygon_mesh_processing::internal::AABB_tree_graph_helper; + using AABB_tree_helper_2 = CGAL::Polygon_mesh_processing::internal::AABB_tree_graph_helper; using Tree_1 = typename AABB_tree_helper_1::Tree; using Tree_2 = typename AABB_tree_helper_2::Tree; AABB_tree_helper_1 helper_1; @@ -491,7 +491,7 @@ class Intersection_of_triangle_meshes const VPM& vpm) { using GT = typename GetGeomTraits::type; - using AABB_tree_helper = internal::AABB_tree_graph_helper; + using AABB_tree_helper = CGAL::Polygon_mesh_processing::internal::AABB_tree_graph_helper; using Tree = typename AABB_tree_helper::Tree; AABB_tree_helper helper; From 49a02073ecb9b7a105e7d46afb78d3305c59578e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 1 Oct 2026 10:49:54 +0200 Subject: [PATCH 060/136] Add a test to check that output of aabb and box_intersection_d are identical --- AABB_tree/include/CGAL/AABB_traits_3.h | 5 +- .../aabb_vs_box_intersection_d_test.cpp | 152 ++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp diff --git a/AABB_tree/include/CGAL/AABB_traits_3.h b/AABB_tree/include/CGAL/AABB_traits_3.h index 30b59bc8919d..54f325f1202d 100644 --- a/AABB_tree/include/CGAL/AABB_traits_3.h +++ b/AABB_tree/include/CGAL/AABB_traits_3.h @@ -757,7 +757,10 @@ class AABB_traits_3 Bounding_box compute_bbox(const Primitive& pr, const Default&)const { - return internal::Primitive_helper::get_datum(pr,*this).bbox(); + if constexpr(std::is_same_v) + return internal::Primitive_helper::get_datum(pr,*this); + else + return internal::Primitive_helper::get_datum(pr,*this).bbox(); } /// Comparison functions diff --git a/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp b/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp new file mode 100644 index 000000000000..30acb7c52df3 --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp @@ -0,0 +1,152 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +using Box = CGAL::Box_intersection_d::Box_with_info_d; +using BoxRange = std::vector; +using K = CGAL::Simple_cartesian; + +template +struct Iterator_to_bbox_property_map{ + typedef Iterator key_type; + typedef CGAL::Bbox_3 value_type; + typedef value_type reference; + typedef boost::readable_property_map_tag category; + typedef Iterator_to_bbox_property_map Self; + + inline friend reference + get(Self, key_type it) + { + return it->bbox(); + } +}; + +template +struct Point_in_bbox_3_iterator_property_map{ + typedef Iterator key_type; + typedef typename GeomTraits::Point_3 value_type; + typedef value_type reference; + typedef boost::readable_property_map_tag category; + typedef Point_in_bbox_3_iterator_property_map Self; + + inline friend reference + get(Self, key_type it) + { + return typename GeomTraits::Point_3( it->bbox().xmin(), it->bbox().ymin(), it->bbox().zmin() ); + } +}; + +template < class GeomTraits, class Iterator> +struct AABB_box_primitive_3 : public CGAL::AABB_primitive< Iterator, + Iterator_to_bbox_property_map, + Point_in_bbox_3_iterator_property_map, + CGAL::Tag_false, CGAL::Tag_false > +{ + typedef CGAL::AABB_primitive< Iterator, + Iterator_to_bbox_property_map, + Point_in_bbox_3_iterator_property_map, + CGAL::Tag_false, CGAL::Tag_false > Base; + AABB_box_primitive_3(Iterator it) : Base(it){} +}; +using Primitive = AABB_box_primitive_3; +using AABB_traits = CGAL::AABB_traits_3; +using Tree = CGAL::AABB_tree; + +void test(BoxRange& r1, BoxRange& r2) +{ + int aabb_count = 0, + box_intersection_count = 0; + + Tree tree1(r1.begin(), r1.end()); + Tree tree2(r2.begin(), r2.end()); + + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, boost::make_function_output_iterator( [&](auto&&) { ++aabb_count; }) ); + CGAL::box_intersection_d(r1.begin(), r1.end(), r2.begin(), r2.end(), [&](auto&, auto&){ ++box_intersection_count; }); + + assert(aabb_count == box_intersection_count); +} + +void random_test(std::size_t n = 1000) +{ + CGAL::Random r; + + BoxRange boxes1, boxes2; + boxes1.reserve(n); + boxes2.reserve(n); + + auto generate_boxes = [&](BoxRange& boxes) + { + for(std::size_t i = 0; i < n; ++i){ + const double x1 = r.get_double(0,10), + y1 = r.get_double(0,10), + z1 = r.get_double(0,10); + const double x2 = r.get_double(0,10), + y2 = r.get_double(0,10), + z2 = r.get_double(0,10); + boxes.emplace_back(CGAL::Bbox_3(std::min(x1,x2), std::min(y1,y2), std::min(z1,z2), + std::max(x1,x2), std::max(y1,y2), std::max(z1,z2)), i); + } + }; + auto generate_unit_boxes = [&](BoxRange& boxes) + { + for(std::size_t i = 0; i < n; ++i){ + const double x = r.get_double(0,9), + y = r.get_double(0,9), + z = r.get_double(0,9); + boxes.emplace_back(CGAL::Bbox_3(x, y, z, x+1, y+1, z+1), i); + } + }; + generate_boxes(boxes1); + generate_boxes(boxes2); + test(boxes1, boxes2); + boxes1.clear(); boxes2.clear(); + generate_unit_boxes(boxes1); + generate_unit_boxes(boxes2); + test(boxes1, boxes2); +} + +void test_from_data(std::string filename1, std::string filename2) +{ + using Mesh = CGAL::Surface_mesh; + + Mesh mesh1, mesh2; + if(!CGAL::IO::read_polygon_mesh(filename1, mesh1) || !CGAL::IO::read_polygon_mesh(filename2, mesh2)){ + std::cout << "Files not found." << std::endl; + return; + } + + auto make_boxes = [](const Mesh& mesh){ + BoxRange boxes; + std::size_t i = 0; + for(auto f: mesh.faces()) + boxes.emplace_back(CGAL::Polygon_mesh_processing::face_bbox(f, mesh), i++); + return boxes; + }; + + BoxRange boxes1 = make_boxes(mesh1); + BoxRange boxes2 = make_boxes(mesh2); + test(boxes1, boxes2); +} + +int main() +{ + test_from_data(CGAL::data_file_path("meshes/diplodocus.off"), CGAL::data_file_path("meshes/bunny00.off")); + test_from_data(CGAL::data_file_path("meshes/bear.off"), CGAL::data_file_path("meshes/man.off")); + test_from_data(CGAL::data_file_path("meshes/sphere.off"), CGAL::data_file_path("meshes/elephant.off")); + test_from_data(CGAL::data_file_path("meshes/cow.off"), CGAL::data_file_path("meshes/cross.off")); + random_test(); + return 0; +} \ No newline at end of file From 1fc31c611a6adb144796a946c1d7b1219f460bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 1 Oct 2026 12:18:30 +0200 Subject: [PATCH 061/136] Fix bug where the specialization was not taken --- Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h | 4 ++-- .../test/PMP_Boolean_operations/test_corefinement_bool_op.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h index 0d09aaa15bdf..2c05549c88de 100644 --- a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h +++ b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h @@ -18,7 +18,7 @@ #ifndef DOXYGEN_RUNNING namespace CGAL { -BOOST_MPL_HAS_XXX_TRAIT_DEF(Point_3) +BOOST_MPL_HAS_XXX_TRAIT_DEF(Point) // fwdS for the public interface template @@ -28,7 +28,7 @@ template struct is_surface_mesh : std::false_type {}; template -struct is_surface_mesh::value>>: std::is_base_of< CGAL::Surface_mesh, T> +struct is_surface_mesh::value>>: std::is_base_of< CGAL::Surface_mesh, T> {}; diff --git a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp index 49a182d2bd31..9c712b5c53b7 100644 --- a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp +++ b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp @@ -276,6 +276,9 @@ void run(char* P_fname, char* Q_fname, int k, int main(int argc,char** argv) { + // Check if DerivedMesh is correctly identified + assert( CGAL::is_surface_mesh::value ); + if (argc<3){ std::cerr << "Usage "<< argv[0] << " file1.off file2.off [scenario_id/ALL] [0/1 0/1 0/1 0/1 (expected valid operations U I P-Q Q-P)]\n"; return 1; From 73a064b8acda010aaf15e0554ed2779e10667e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 1 Oct 2026 15:53:28 +0200 Subject: [PATCH 062/136] Bench of fill_new_triangle_mesh + parallellization of extract_patch_simplices --- .../corefinement_mesh_union_progress.cpp | 1 - .../internal/Corefinement/face_graph_utils.h | 9 ++- .../surface_mesh_specializations.h | 59 +++++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp index 71707c1457d5..381ccf7047b4 100644 --- a/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp +++ b/PMP_Boolean_operations/examples/PMP_Boolean_operations/corefinement_mesh_union_progress.cpp @@ -203,7 +203,6 @@ int main(int argc, char* argv[]) Visitor visitor; bool valid_union = PMP::corefine_and_compute_union (mesh1,mesh2, out, CGAL::parameters::visitor(visitor).concurrency_tag(CGAL::Parallel_if_available_tag())); - // bool valid_union = PMP::corefine_and_compute_union (mesh1,mesh2, out, CGAL::parameters::visitor(visitor)); std::cout << "Global timer = " << t.time() << " sec." << std::endl; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 1e4a08d4b620..6a5347b54a50 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -761,12 +761,15 @@ struct Patch_container{ patches[patch_ids[ get(fids, f) ]].faces.push_back( f ); } - Patch_description& operator[](std::size_t i) { - if ( !patches[i].is_initialized ) - { + void extract_patch(std::size_t i) { + if ( !patches[i].is_initialized ) { extract_patch_simplices(pm, patches[i], is_intersection_edge); patches[i].is_initialized=true; } + } + + Patch_description& operator[](std::size_t i) { + extract_patch(i); return patches[i]; } diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h index f98932135edc..ec7cc36d6841 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h @@ -16,6 +16,14 @@ #include +#ifdef CGAL_LINKED_WITH_TBB +#include +#endif + +#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION +#include +#endif + namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { @@ -327,6 +335,12 @@ auto fill_new_triangle_mesh( Vertex_to_vertex_map tm1_to_output_vertices = get(V2V_tag(), tm1, SM::null_vertex()), tm2_to_output_vertices = get(V2V_tag(), tm2, SM::null_vertex()); +#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION + CGAL::Real_timer t, tt; + t.start(); tt.start(); + std::cout << "Progress fill new triangle mesh" << std::endl; +#endif + output_shared_edges.reserve( std::accumulate(polylines.lengths.begin(), polylines.lengths.end(), std::size_t(0)) ); std::size_t nb_polylines = polylines.lengths.size(); for (std::size_t i=0; i < nb_polylines; ++i) @@ -342,6 +356,11 @@ auto fill_new_triangle_mesh( output_shared_edges, user_visitor); +#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION + std::cout << "Import polylines: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; + tt.reset(); +#endif + // Get ids of patch to append std::vector ids_of_patches_to_append_from_tm1; std::vector ids_of_patches_to_append_from_tm2; @@ -358,9 +377,33 @@ auto fill_new_triangle_mesh( ids_of_patches_to_append_from_tm2.push_back(i); } +#ifdef CGAL_LINKED_WITH_TBB + if constexpr(ConcurrencyTag::is_parallel){ + tbb::task_group tasks; + tasks.run([&]{ + tbb::parallel_for(std::size_t(0), ids_of_patches_to_append_from_tm1.size(), [&](std::size_t j){ patches_of_tm1.extract_patch(ids_of_patches_to_append_from_tm1[j]); }); + }); + tbb::parallel_for(std::size_t(0), ids_of_patches_to_append_from_tm2.size(), [&](std::size_t j){ patches_of_tm2.extract_patch(ids_of_patches_to_append_from_tm2[j]); }); + tasks.wait(); + } + else +#endif + { + for (std::size_t i : ids_of_patches_to_append_from_tm1) + patches_of_tm1.extract_patch(i); + for (std::size_t i : ids_of_patches_to_append_from_tm2) + patches_of_tm2.extract_patch(i); + } + +#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION + std::cout << "Extract patches: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; + tt.reset(); +#endif + // Compute final sizes std::size_t nv = output.number_of_vertices(), ne = output.number_of_edges(), nf = output.number_of_faces(); std::size_t tnv = output.number_of_vertices(), tne = output.number_of_edges(), tnf = output.number_of_faces(); + for (std::size_t i : ids_of_patches_to_append_from_tm1){ tnv += patches_of_tm1[i].interior_vertices.size(); tne += patches_of_tm1[i].interior_edges.size(); @@ -403,6 +446,10 @@ auto fill_new_triangle_mesh( ne += patches_of_tm1[i].interior_edges.size(); nf += patches_of_tm1[i].faces.size(); } +#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION + std::cout << "Append patch of first mesh: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; + tt.reset(); +#endif if(reverse_orientation_of_patches_from_tm1) process_borders_after_appending_patches(output, @@ -416,6 +463,10 @@ auto fill_new_triangle_mesh( patches_of_tm1, tm1_to_output_edges, tm1_to_output_vertices); +#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION + std::cout << "Process borders of first mesh: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; + tt.reset(); +#endif for(std::size_t i : ids_of_patches_to_append_from_tm2){ if(reverse_orientation_of_patches_from_tm2) @@ -446,6 +497,10 @@ auto fill_new_triangle_mesh( ne += patches_of_tm2[i].interior_edges.size(); nf += patches_of_tm2[i].faces.size(); } +#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION + std::cout << "Append patch of second mesh: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; + tt.reset(); +#endif if(reverse_orientation_of_patches_from_tm2) process_borders_after_appending_patches(output, @@ -459,6 +514,10 @@ auto fill_new_triangle_mesh( patches_of_tm2, tm2_to_output_edges, tm2_to_output_vertices); +#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION + std::cout << "Process borders of second mesh: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; + tt.reset(); +#endif } } // namespace Corefinement From 8ccbe52e699ec284ac430e3a0cb988ee64f5a5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 1 Oct 2026 17:29:09 +0200 Subject: [PATCH 063/136] Apply suggestions from Laurent review --- AABB_tree/include/CGAL/AABB_traits_3.h | 5 +--- .../include/CGAL/Cartesian/function_objects.h | 24 +++++++++++++++++++ .../CGAL/Homogeneous/function_objects.h | 24 +++++++++++++++++++ Kernel_23/include/CGAL/Bbox_2.h | 15 ++++++++++++ Kernel_23/include/CGAL/Bbox_3.h | 15 ++++++++++++ .../test_corefinement_bool_op.cpp | 2 +- 6 files changed, 80 insertions(+), 5 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_traits_3.h b/AABB_tree/include/CGAL/AABB_traits_3.h index 54f325f1202d..30b59bc8919d 100644 --- a/AABB_tree/include/CGAL/AABB_traits_3.h +++ b/AABB_tree/include/CGAL/AABB_traits_3.h @@ -757,10 +757,7 @@ class AABB_traits_3 Bounding_box compute_bbox(const Primitive& pr, const Default&)const { - if constexpr(std::is_same_v) - return internal::Primitive_helper::get_datum(pr,*this); - else - return internal::Primitive_helper::get_datum(pr,*this).bbox(); + return internal::Primitive_helper::get_datum(pr,*this).bbox(); } /// Comparison functions diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index d541b2754625..01eb9d1f22d2 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -1887,6 +1887,18 @@ namespace CartesianKernelFunctors { typedef typename K::Circle_2 Circle_2; public: + const Bbox_2& + operator()(const Bbox_2& b) const + { + return b; + } + + Bbox_2& + operator()(Bbox_2& b) const + { + return b; + } + Bbox_2 operator()(const Point_2& p) const { @@ -1959,6 +1971,18 @@ namespace CartesianKernelFunctors { typedef typename K::Circle_3 Circle_3; public: + const Bbox_3& + operator()(const Bbox_3& b) const + { + return b; + } + + Bbox_3& + operator()(Bbox_3& b) const + { + return b; + } + Bbox_3 operator()(const Point_3& p) const { diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index a0629653fc62..deca99b0ac4c 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -1889,6 +1889,18 @@ namespace HomogeneousKernelFunctors { typedef typename K::Circle_2 Circle_2; public: + const Bbox_2& + operator()(const Bbox_2& b) const + { + return b; + } + + Bbox_2& + operator()(Bbox_2& b) const + { + return b; + } + Bbox_2 operator()( const Point_2& p) const { @@ -1953,6 +1965,18 @@ namespace HomogeneousKernelFunctors { typedef typename K::Sphere_3 Sphere_3; public: + const Bbox_3& + operator()(const Bbox_3& b) const + { + return b; + } + + Bbox_3& + operator()(Bbox_3& b) const + { + return b; + } + Bbox_3 operator()(const Point_3& p) const { diff --git a/Kernel_23/include/CGAL/Bbox_2.h b/Kernel_23/include/CGAL/Bbox_2.h index f80cd0ba7ad7..6d69e1123c49 100644 --- a/Kernel_23/include/CGAL/Bbox_2.h +++ b/Kernel_23/include/CGAL/Bbox_2.h @@ -71,6 +71,9 @@ class Bbox_2 inline Bbox_2 operator+(const Bbox_2 &b) const; inline Bbox_2& operator+=(const Bbox_2 &b); + inline const Bbox_2& bbox() const; + inline Bbox_2& bbox(); + inline int largest_span_index() const; inline void dilate(int dist); @@ -151,6 +154,18 @@ Bbox_2::max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const return ymax(); } +inline +const Bbox_2& +Bbox_2::bbox() const{ + return *this; +} + +inline +Bbox_2& +Bbox_2::bbox(){ + return *this; +} + inline Bbox_2 Bbox_2::operator+(const Bbox_2 &b) const diff --git a/Kernel_23/include/CGAL/Bbox_3.h b/Kernel_23/include/CGAL/Bbox_3.h index fa3bdd90bdcc..f41d3b6ddd53 100644 --- a/Kernel_23/include/CGAL/Bbox_3.h +++ b/Kernel_23/include/CGAL/Bbox_3.h @@ -79,6 +79,9 @@ class Bbox_3 Bbox_3 operator+(const Bbox_3& b) const; Bbox_3& operator+=(const Bbox_3& b); + inline const Bbox_3& bbox() const; + inline Bbox_3& bbox(); + inline void dilate(int dist); inline void scale(double factor); }; @@ -149,6 +152,18 @@ Bbox_3::operator!=(const Bbox_3 &b) const return ! (b == *this); } +inline +const Bbox_3& +Bbox_3::bbox() const{ + return *this; +} + +inline +Bbox_3& +Bbox_3::bbox(){ + return *this; +} + inline int Bbox_3::dimension() const diff --git a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp index 9c712b5c53b7..2c4343b734ab 100644 --- a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp +++ b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp @@ -277,7 +277,7 @@ void run(char* P_fname, char* Q_fname, int k, int main(int argc,char** argv) { // Check if DerivedMesh is correctly identified - assert( CGAL::is_surface_mesh::value ); + static_assert( CGAL::is_surface_mesh::value ); if (argc<3){ std::cerr << "Usage "<< argv[0] << " file1.off file2.off [scenario_id/ALL] [0/1 0/1 0/1 0/1 (expected valid operations U I P-Q Q-P)]\n"; From e197a5f29c0d84080250a2e75f4b3865bc360089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 1 Oct 2026 17:47:42 +0200 Subject: [PATCH 064/136] Add ConstructBbox23(Bbox) in the documentation --- .../doc/Kernel_23/Concepts/FunctionObjectConcepts.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index 3102b1d808fe..dbc4b5cc40a2 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -3872,6 +3872,12 @@ class ConstructBbox_2 { /// A model of this concept must provide: /// @{ + /*! + returns `b`. + */ + CGAL::Bbox_2 operator()(const Kernel::Bbox_2 + &b); + /*! returns a bounding box of `p`. */ @@ -3920,6 +3926,12 @@ class ConstructBbox_3 { /// A model of this concept must provide: /// @{ + /*! + returns `b`. + */ + CGAL::Bbox_3 operator()(const Kernel::Bbox_3 + &b); + /*! returns a bounding box of `c`. */ From fbb023848d36ea5b2ed20fdca055a9b0b9f34495 Mon Sep 17 00:00:00 2001 From: lvalque <131978677+LeoValque@users.noreply.github.com> Date: Mon, 5 Oct 2026 08:18:28 +0200 Subject: [PATCH 065/136] Update AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp Co-authored-by: Andreas Fabri --- AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp b/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp index 30acb7c52df3..9047b7ccd587 100644 --- a/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp @@ -96,8 +96,8 @@ void random_test(std::size_t n = 1000) const double x2 = r.get_double(0,10), y2 = r.get_double(0,10), z2 = r.get_double(0,10); - boxes.emplace_back(CGAL::Bbox_3(std::min(x1,x2), std::min(y1,y2), std::min(z1,z2), - std::max(x1,x2), std::max(y1,y2), std::max(z1,z2)), i); + boxes.emplace_back(CGAL::Bbox_3((std::min)(x1,x2), (std::min)(y1,y2), (std::min)(z1,z2), + (std::max)(x1,x2), (std::max)(y1,y2), (std::max)(z1,z2)), i); } }; auto generate_unit_boxes = [&](BoxRange& boxes) From 6bc7155ccdffe6d17a1217cb70b8ac8f8efdbff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 5 Oct 2026 14:22:34 +0200 Subject: [PATCH 066/136] Replace set per property_map in connected_component --- .../connected_components.h | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h index a389e983957b..40bf990f5649 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h @@ -124,6 +124,9 @@ connected_component(typename boost::graph_traits::face_descriptor s using parameters::choose_parameter; using parameters::get_parameter; + using face_descriptor = typename boost::graph_traits::face_descriptor; + using halfedge_descriptor = typename boost::graph_traits::halfedge_descriptor; + typedef typename internal_np::Lookup_named_param_def < internal_np::edge_is_constrained_t, NamedParameters, @@ -132,27 +135,28 @@ connected_component(typename boost::graph_traits::face_descriptor s EdgeConstraintMap ecmap = choose_parameter(get_parameter(np, internal_np::edge_is_constrained)); - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - std::set already_processed; + using Face_bool_tag = typename CGAL::dynamic_face_property_t; + using Bool_map = typename boost::property_map::const_type; + + Bool_map already_processed = get(Face_bool_tag(), pmesh, false); std::vector< face_descriptor > stack; stack.push_back(seed_face); while (!stack.empty()) + { + seed_face=stack.back(); + stack.pop_back(); + if (get(already_processed, seed_face)) continue; + put(already_processed, seed_face, true); + *out++=seed_face; + for(halfedge_descriptor hd: halfedges_around_face(halfedge(seed_face, pmesh), pmesh) ) { - seed_face=stack.back(); - stack.pop_back(); - if (!already_processed.insert(seed_face).second) continue; - *out++=seed_face; - for(halfedge_descriptor hd : - halfedges_around_face(halfedge(seed_face, pmesh), pmesh) ) - { - if(! get(ecmap, edge(hd, pmesh))){ - face_descriptor neighbor = face( opposite(hd, pmesh), pmesh ); - if ( neighbor != boost::graph_traits::null_face() ) - stack.push_back(neighbor); - } + if(! get(ecmap, edge(hd, pmesh))){ + face_descriptor neighbor = face( opposite(hd, pmesh), pmesh ); + if ( neighbor != boost::graph_traits::null_face() ) + stack.push_back(neighbor); } } + } return out; } From dba32e6975a10038148e306dc9704347cf1ed908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 5 Oct 2026 18:50:13 +0200 Subject: [PATCH 067/136] Add are_equal_polygon_soups and are_equal_meshes --- .../PMP_Boolean_operations/test_pmp_equal.cpp | 146 +++++++++++++++ .../CGAL/Polygon_mesh_processing/equal.h | 170 ++++++++++++++++++ 2 files changed, 316 insertions(+) create mode 100644 PMP_Boolean_operations/test/PMP_Boolean_operations/test_pmp_equal.cpp create mode 100644 Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/equal.h diff --git a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_pmp_equal.cpp b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_pmp_equal.cpp new file mode 100644 index 000000000000..a75bde0fc22a --- /dev/null +++ b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_pmp_equal.cpp @@ -0,0 +1,146 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace PMP = CGAL::Polygon_mesh_processing; + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Surface_mesh Surface_mesh; +typedef CGAL::Polyhedron_3 Polyhedron; + +template +void test() +{ + Mesh a, b; + CGAL::make_hexahedron(K::Point_3(0, 0, 0), K::Point_3(1, 0, 0), + K::Point_3(1, 1, 0), K::Point_3(0, 1, 0), + K::Point_3(0, 0, 1), K::Point_3(1, 0, 1), + K::Point_3(1, 1, 1), K::Point_3(0, 1, 1), a); + CGAL::make_hexahedron(K::Point_3(0, 0, 0), K::Point_3(1, 0, 0), + K::Point_3(1, 1, 0), K::Point_3(0, 1, 0), + K::Point_3(0, 0, 1), K::Point_3(1, 0, 1), + K::Point_3(1, 1, 1), K::Point_3(0, 1, 1), b); + + // Identical meshes. + assert(PMP::are_equal_meshes(a, b)); + assert(PMP::are_equal_meshes(b, a)); + + // Different geometry. + PMP::transform(K::Aff_transformation_3(CGAL::TRANSLATION, + K::Vector_3(2, 0, 0)), b); + assert(!PMP::are_equal_meshes(a, b)); + + PMP::transform(K::Aff_transformation_3(CGAL::TRANSLATION, + K::Vector_3(-2, 0, 0)), b); + assert(PMP::are_equal_meshes(a, b)); + + // Opposite orientation. + PMP::reverse_face_orientations(b); + assert(!PMP::are_equal_meshes(a, b)); + PMP::reverse_face_orientations(b); + assert(PMP::are_equal_meshes(a, b)); + + // Different vertex/face indexing. + Mesh c; + std::vector points; + std::vector > polygons; + PMP::polygon_mesh_to_polygon_soup(a, points, polygons); + + std::reverse(points.begin(), points.end()); + // Reindex polygons according to the reversed point order. + for (auto& p : polygons) + for (std::size_t& i : p) + i = points.size() - 1 - i; + + PMP::polygon_soup_to_polygon_mesh(points, polygons, c); + assert(PMP::are_equal_meshes(a, c)); + assert(PMP::are_equal_meshes(c, a)); +} + +void test_polygon_soup() +{ + std::vector points_a = {K::Point_3(0, 0, 0), + K::Point_3(1, 0, 0), + K::Point_3(0, 1, 0)}; + std::vector points_b = points_a; + std::vector > polygons_a{{0, 1, 2}}; + std::vector > polygons_b{{0, 1, 2}}; + + assert(PMP::are_equal_polygon_soups(points_a, polygons_a, + points_b, polygons_b)); + + // Different vertex indexing. + std::swap(points_b[0], points_b[1]); + for (auto& p : polygons_b) + for (std::size_t& i : p) + i = (i == 0 ? 1 : i == 1 ? 0 : i); + + assert(PMP::are_equal_polygon_soups(points_a, polygons_a, + points_b, polygons_b)); + + // Different cyclic ordering of the vertices of a polygon. + points_b = points_a; + polygons_b = polygons_a; + std::rotate(polygons_b[0].begin(), + polygons_b[0].begin() + 1, + polygons_b[0].end()); + + assert(PMP::are_equal_polygon_soups(points_a, polygons_a, + points_b, polygons_b)); + + // Different orientation. + points_b = points_a; + polygons_b = polygons_a; + std::reverse(polygons_b[0].begin(), polygons_b[0].end()); + + assert(!PMP::are_equal_polygon_soups(points_a, polygons_a, + points_b, polygons_b)); + + // Different geometry. + points_b = points_a; + polygons_b = polygons_a; + points_b[0] = K::Point_3(2, 0, 0); + + assert(!PMP::are_equal_polygon_soups(points_a, polygons_a, + points_b, polygons_b)); + + // Different number of polygons. + points_b = points_a; + polygons_b = polygons_a; + polygons_b.push_back(polygons_b.front()); + + assert(!PMP::are_equal_polygon_soups(points_a, polygons_a, + points_b, polygons_b)); +} + +int main(int argc, char* argv[]) +{ + if (argc == 3) + { + Surface_mesh a, b; + if (!CGAL::IO::read_polygon_mesh(argv[1], a) || + !CGAL::IO::read_polygon_mesh(argv[2], b)) + { + std::cerr << "Could not read polygon meshes\n"; + return EXIT_FAILURE; + } + + const bool equal = PMP::are_equal_meshes(a, b); + std::cout << (equal ? "Meshes are equal\n" : "Meshes are not equal\n"); + return equal ? EXIT_SUCCESS : EXIT_FAILURE; + } + + test_polygon_soup(); + test(); + test(); + return EXIT_SUCCESS; +} diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/equal.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/equal.h new file mode 100644 index 000000000000..d5ba44b4b984 --- /dev/null +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/equal.h @@ -0,0 +1,170 @@ +// Copyright (c) 2026 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Valque Léo + +#ifndef CGAL_POLYGON_MESH_PROCESSING_EQUAL_H +#define CGAL_POLYGON_MESH_PROCESSING_EQUAL_H + +#include +#include +#include + +#include + +#include +#include + +namespace PMP = CGAL::Polygon_mesh_processing; + +template +struct Point_less +{ + bool operator()(const Point& p, const Point& q) const + { + if(p < q) return true; + if(q < p) return false; + return false; + } +}; + +namespace CGAL { + +namespace Polygon_mesh_processing { + +/** + * Reorders the points and polygons in a canonical way. + */ +template +bool +canonical_soup(PointRange& points, + PolygonRange& polygons) +{ + using Point = typename PointRange::value_type; + using Polygon = typename PolygonRange::value_type; + using Kernel = typename Kernel_traits::Kernel; + typename Kernel::Less_xyz_3 less_xyz_3 = Kernel().less_xyz_3_object(); + + std::vector new_to_old_index(points.size()); + std::iota(new_to_old_index.begin(), new_to_old_index.end(), std::size_t(0)); + std::sort(new_to_old_index.begin(), new_to_old_index.end(), + [&](std::size_t i, std::size_t j) + { return less_xyz_3(points[i], points[j]); }); + + std::vector old_to_new_index(points.size()); + for(std::size_t new_index = 0; new_index < points.size(); ++new_index) + old_to_new_index[new_to_old_index[new_index]] = new_index; + + std::vector reordered_points(points.size()); + for(std::size_t new_index = 0; new_index < points.size(); ++new_index) + reordered_points[new_index] = points[new_to_old_index[new_index]]; + points = std::move(reordered_points); + + for(Polygon& polygon : polygons) + { + Polygon face; + face.reserve(polygon.size()); + for(std::size_t i : polygon) + face.push_back(old_to_new_index[i]); + + auto first = std::min_element(face.begin(), face.end()); + std::rotate(face.begin(), first, face.end()); + polygon = std::move(face); + } + + auto lexicographical_less = [](const Polygon& p1, const Polygon& p2) + { + return std::lexicographical_compare(p1.begin(), p1.end(), + p2.begin(), p2.end()); + }; + std::sort(polygons.begin(), polygons.end(), lexicographical_less); + return true; +} + +/** + * Checks whether two polygon soups are equal, ignoring the order of their + * points and polygons. The input ranges are reordered in place. + */ +template +bool are_equal_polygon_soups( + PointRange1& points1, + PolygonRange1& polygons1, + PointRange2& points2, + PolygonRange2& polygons2) +{ + if(polygons1.size() != polygons2.size() || points1.size() != points2.size()) + return false; + + // The number of distinct geometric points must also agree. + canonical_soup(points1, polygons1); + canonical_soup(points2, polygons2); + + return std::equal(polygons1.begin(), polygons1.end(), polygons2.begin(), polygons2.end()) && + std::equal(points1.begin(), points1.end(), points2.begin(), points2.end()); +} + +/** + * Checks whether two polygon soups are equal, ignoring the order of their + * points and polygons. The input ranges are not modified. + */ +template +bool are_equal_polygon_soups( + const PointRange1& points1, + const PolygonRange1& polygons1, + const PointRange2& points2, + const PolygonRange2& polygons2) +{ + PointRange1 points1_copy(points1); + PolygonRange1 polygons1_copy(polygons1); + PointRange2 points2_copy(points2); + PolygonRange2 polygons2_copy(polygons2); + + return are_equal_polygon_soups(points1_copy, polygons1_copy, + points2_copy, polygons2_copy); +} + +/** + * Checks whether two polygon meshes are equal, ignoring the order of their + * vertices and faces. The meshes are converted to polygon soups for the + * comparison. + */ +template +bool are_equal_meshes(const Mesh1& mesh1, + const Mesh2& mesh2, + const NamedParameters1& np1 = parameters::default_values(), + const NamedParameters2& np2 = parameters::default_values()) +{ + using VPM_helper_1 = GetVertexPointMap; + using VPM_helper_2 = GetVertexPointMap; + using VPM1 = typename VPM_helper_1::const_type; + using VPM2 = typename VPM_helper_2::const_type; + VPM1 vpm1 = VPM_helper_1::get_const_map(np1, mesh1); + VPM2 vpm2 = VPM_helper_2::get_const_map(np2, mesh2); + using Point1 = typename boost::property_traits::value_type; + using Point2 = typename boost::property_traits::value_type; + + std::vector points1; + std::vector > polygons1; + polygon_mesh_to_polygon_soup(mesh1, points1, polygons1, parameters::vertex_point_map(vpm1)); + + std::vector points2; + std::vector > polygons2; + polygon_mesh_to_polygon_soup(mesh2, points2, polygons2, parameters::vertex_point_map(vpm2)); + + return are_equal_polygon_soups(points1, polygons1, + points2, polygons2); +} + + +} // namespace Polygon_mesh_processing +} // namespace CGAL +#endif //CGAL_POLYGON_MESH_PROCESSING_EQUAL_H From 530f46687380717b82eade9e9e5bbe018882d6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 6 Oct 2026 10:25:32 +0200 Subject: [PATCH 068/136] compatibility with fs --- AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp b/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp index 9047b7ccd587..29c92a393a88 100644 --- a/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_vs_box_intersection_d_test.cpp @@ -118,7 +118,8 @@ void random_test(std::size_t n = 1000) test(boxes1, boxes2); } -void test_from_data(std::string filename1, std::string filename2) +template +void test_from_data(Path filename1, Path filename2) { using Mesh = CGAL::Surface_mesh; From fad5231abcc5e746aebdf2d3fbb039f6bd43d52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 6 Oct 2026 14:41:28 +0200 Subject: [PATCH 069/136] Revert "Add are_equal_polygon_soups and are_equal_meshes" This reverts commit dba32e6975a10038148e306dc9704347cf1ed908. --- .../PMP_Boolean_operations/test_pmp_equal.cpp | 146 --------------- .../CGAL/Polygon_mesh_processing/equal.h | 170 ------------------ 2 files changed, 316 deletions(-) delete mode 100644 PMP_Boolean_operations/test/PMP_Boolean_operations/test_pmp_equal.cpp delete mode 100644 Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/equal.h diff --git a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_pmp_equal.cpp b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_pmp_equal.cpp deleted file mode 100644 index a75bde0fc22a..000000000000 --- a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_pmp_equal.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace PMP = CGAL::Polygon_mesh_processing; - -typedef CGAL::Exact_predicates_inexact_constructions_kernel K; -typedef CGAL::Surface_mesh Surface_mesh; -typedef CGAL::Polyhedron_3 Polyhedron; - -template -void test() -{ - Mesh a, b; - CGAL::make_hexahedron(K::Point_3(0, 0, 0), K::Point_3(1, 0, 0), - K::Point_3(1, 1, 0), K::Point_3(0, 1, 0), - K::Point_3(0, 0, 1), K::Point_3(1, 0, 1), - K::Point_3(1, 1, 1), K::Point_3(0, 1, 1), a); - CGAL::make_hexahedron(K::Point_3(0, 0, 0), K::Point_3(1, 0, 0), - K::Point_3(1, 1, 0), K::Point_3(0, 1, 0), - K::Point_3(0, 0, 1), K::Point_3(1, 0, 1), - K::Point_3(1, 1, 1), K::Point_3(0, 1, 1), b); - - // Identical meshes. - assert(PMP::are_equal_meshes(a, b)); - assert(PMP::are_equal_meshes(b, a)); - - // Different geometry. - PMP::transform(K::Aff_transformation_3(CGAL::TRANSLATION, - K::Vector_3(2, 0, 0)), b); - assert(!PMP::are_equal_meshes(a, b)); - - PMP::transform(K::Aff_transformation_3(CGAL::TRANSLATION, - K::Vector_3(-2, 0, 0)), b); - assert(PMP::are_equal_meshes(a, b)); - - // Opposite orientation. - PMP::reverse_face_orientations(b); - assert(!PMP::are_equal_meshes(a, b)); - PMP::reverse_face_orientations(b); - assert(PMP::are_equal_meshes(a, b)); - - // Different vertex/face indexing. - Mesh c; - std::vector points; - std::vector > polygons; - PMP::polygon_mesh_to_polygon_soup(a, points, polygons); - - std::reverse(points.begin(), points.end()); - // Reindex polygons according to the reversed point order. - for (auto& p : polygons) - for (std::size_t& i : p) - i = points.size() - 1 - i; - - PMP::polygon_soup_to_polygon_mesh(points, polygons, c); - assert(PMP::are_equal_meshes(a, c)); - assert(PMP::are_equal_meshes(c, a)); -} - -void test_polygon_soup() -{ - std::vector points_a = {K::Point_3(0, 0, 0), - K::Point_3(1, 0, 0), - K::Point_3(0, 1, 0)}; - std::vector points_b = points_a; - std::vector > polygons_a{{0, 1, 2}}; - std::vector > polygons_b{{0, 1, 2}}; - - assert(PMP::are_equal_polygon_soups(points_a, polygons_a, - points_b, polygons_b)); - - // Different vertex indexing. - std::swap(points_b[0], points_b[1]); - for (auto& p : polygons_b) - for (std::size_t& i : p) - i = (i == 0 ? 1 : i == 1 ? 0 : i); - - assert(PMP::are_equal_polygon_soups(points_a, polygons_a, - points_b, polygons_b)); - - // Different cyclic ordering of the vertices of a polygon. - points_b = points_a; - polygons_b = polygons_a; - std::rotate(polygons_b[0].begin(), - polygons_b[0].begin() + 1, - polygons_b[0].end()); - - assert(PMP::are_equal_polygon_soups(points_a, polygons_a, - points_b, polygons_b)); - - // Different orientation. - points_b = points_a; - polygons_b = polygons_a; - std::reverse(polygons_b[0].begin(), polygons_b[0].end()); - - assert(!PMP::are_equal_polygon_soups(points_a, polygons_a, - points_b, polygons_b)); - - // Different geometry. - points_b = points_a; - polygons_b = polygons_a; - points_b[0] = K::Point_3(2, 0, 0); - - assert(!PMP::are_equal_polygon_soups(points_a, polygons_a, - points_b, polygons_b)); - - // Different number of polygons. - points_b = points_a; - polygons_b = polygons_a; - polygons_b.push_back(polygons_b.front()); - - assert(!PMP::are_equal_polygon_soups(points_a, polygons_a, - points_b, polygons_b)); -} - -int main(int argc, char* argv[]) -{ - if (argc == 3) - { - Surface_mesh a, b; - if (!CGAL::IO::read_polygon_mesh(argv[1], a) || - !CGAL::IO::read_polygon_mesh(argv[2], b)) - { - std::cerr << "Could not read polygon meshes\n"; - return EXIT_FAILURE; - } - - const bool equal = PMP::are_equal_meshes(a, b); - std::cout << (equal ? "Meshes are equal\n" : "Meshes are not equal\n"); - return equal ? EXIT_SUCCESS : EXIT_FAILURE; - } - - test_polygon_soup(); - test(); - test(); - return EXIT_SUCCESS; -} diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/equal.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/equal.h deleted file mode 100644 index d5ba44b4b984..000000000000 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/equal.h +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright (c) 2026 GeometryFactory (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Valque Léo - -#ifndef CGAL_POLYGON_MESH_PROCESSING_EQUAL_H -#define CGAL_POLYGON_MESH_PROCESSING_EQUAL_H - -#include -#include -#include - -#include - -#include -#include - -namespace PMP = CGAL::Polygon_mesh_processing; - -template -struct Point_less -{ - bool operator()(const Point& p, const Point& q) const - { - if(p < q) return true; - if(q < p) return false; - return false; - } -}; - -namespace CGAL { - -namespace Polygon_mesh_processing { - -/** - * Reorders the points and polygons in a canonical way. - */ -template -bool -canonical_soup(PointRange& points, - PolygonRange& polygons) -{ - using Point = typename PointRange::value_type; - using Polygon = typename PolygonRange::value_type; - using Kernel = typename Kernel_traits::Kernel; - typename Kernel::Less_xyz_3 less_xyz_3 = Kernel().less_xyz_3_object(); - - std::vector new_to_old_index(points.size()); - std::iota(new_to_old_index.begin(), new_to_old_index.end(), std::size_t(0)); - std::sort(new_to_old_index.begin(), new_to_old_index.end(), - [&](std::size_t i, std::size_t j) - { return less_xyz_3(points[i], points[j]); }); - - std::vector old_to_new_index(points.size()); - for(std::size_t new_index = 0; new_index < points.size(); ++new_index) - old_to_new_index[new_to_old_index[new_index]] = new_index; - - std::vector reordered_points(points.size()); - for(std::size_t new_index = 0; new_index < points.size(); ++new_index) - reordered_points[new_index] = points[new_to_old_index[new_index]]; - points = std::move(reordered_points); - - for(Polygon& polygon : polygons) - { - Polygon face; - face.reserve(polygon.size()); - for(std::size_t i : polygon) - face.push_back(old_to_new_index[i]); - - auto first = std::min_element(face.begin(), face.end()); - std::rotate(face.begin(), first, face.end()); - polygon = std::move(face); - } - - auto lexicographical_less = [](const Polygon& p1, const Polygon& p2) - { - return std::lexicographical_compare(p1.begin(), p1.end(), - p2.begin(), p2.end()); - }; - std::sort(polygons.begin(), polygons.end(), lexicographical_less); - return true; -} - -/** - * Checks whether two polygon soups are equal, ignoring the order of their - * points and polygons. The input ranges are reordered in place. - */ -template -bool are_equal_polygon_soups( - PointRange1& points1, - PolygonRange1& polygons1, - PointRange2& points2, - PolygonRange2& polygons2) -{ - if(polygons1.size() != polygons2.size() || points1.size() != points2.size()) - return false; - - // The number of distinct geometric points must also agree. - canonical_soup(points1, polygons1); - canonical_soup(points2, polygons2); - - return std::equal(polygons1.begin(), polygons1.end(), polygons2.begin(), polygons2.end()) && - std::equal(points1.begin(), points1.end(), points2.begin(), points2.end()); -} - -/** - * Checks whether two polygon soups are equal, ignoring the order of their - * points and polygons. The input ranges are not modified. - */ -template -bool are_equal_polygon_soups( - const PointRange1& points1, - const PolygonRange1& polygons1, - const PointRange2& points2, - const PolygonRange2& polygons2) -{ - PointRange1 points1_copy(points1); - PolygonRange1 polygons1_copy(polygons1); - PointRange2 points2_copy(points2); - PolygonRange2 polygons2_copy(polygons2); - - return are_equal_polygon_soups(points1_copy, polygons1_copy, - points2_copy, polygons2_copy); -} - -/** - * Checks whether two polygon meshes are equal, ignoring the order of their - * vertices and faces. The meshes are converted to polygon soups for the - * comparison. - */ -template -bool are_equal_meshes(const Mesh1& mesh1, - const Mesh2& mesh2, - const NamedParameters1& np1 = parameters::default_values(), - const NamedParameters2& np2 = parameters::default_values()) -{ - using VPM_helper_1 = GetVertexPointMap; - using VPM_helper_2 = GetVertexPointMap; - using VPM1 = typename VPM_helper_1::const_type; - using VPM2 = typename VPM_helper_2::const_type; - VPM1 vpm1 = VPM_helper_1::get_const_map(np1, mesh1); - VPM2 vpm2 = VPM_helper_2::get_const_map(np2, mesh2); - using Point1 = typename boost::property_traits::value_type; - using Point2 = typename boost::property_traits::value_type; - - std::vector points1; - std::vector > polygons1; - polygon_mesh_to_polygon_soup(mesh1, points1, polygons1, parameters::vertex_point_map(vpm1)); - - std::vector points2; - std::vector > polygons2; - polygon_mesh_to_polygon_soup(mesh2, points2, polygons2, parameters::vertex_point_map(vpm2)); - - return are_equal_polygon_soups(points1, polygons1, - points2, polygons2); -} - - -} // namespace Polygon_mesh_processing -} // namespace CGAL -#endif //CGAL_POLYGON_MESH_PROCESSING_EQUAL_H From 80346e2e4e87089bb5426675b5a1c5a99e08b228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 6 Oct 2026 14:50:21 +0200 Subject: [PATCH 070/136] reorder depencies --- .../package_info/Constrained_triangulation_3/dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Constrained_triangulation_3/package_info/Constrained_triangulation_3/dependencies b/Constrained_triangulation_3/package_info/Constrained_triangulation_3/dependencies index 2bdfecd4dc7f..8bfb0c669839 100644 --- a/Constrained_triangulation_3/package_info/Constrained_triangulation_3/dependencies +++ b/Constrained_triangulation_3/package_info/Constrained_triangulation_3/dependencies @@ -32,8 +32,8 @@ Random_numbers SMDS_3 STL_Extension Solver_interface -Spatial_sorting Spatial_searching +Spatial_sorting Stream_support Surface_mesh TDS_2 From e002d60fe187b7b9bccfc0ead1dc9b44b46814ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 6 Oct 2026 15:34:26 +0200 Subject: [PATCH 071/136] Solve warnings of conversion to std::size_t to SM::size_type --- .../surface_mesh_specializations.h | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h index ec7cc36d6841..bbc7fc409868 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h @@ -56,6 +56,7 @@ void append_patch( std::size_t faces_idx_begin) { using SM = SurfaceMesh; + using size_type = typename SM::size_type; using vertex_descriptor = typename SM::Vertex_index; using edge_descriptor = typename SM::Edge_index; using halfedge_descriptor = typename SM::Halfedge_index; @@ -64,7 +65,7 @@ void append_patch( // Fill Vertex to vertex map and vpm for interior vertices auto fill_vertex = [&](std::size_t i){ vertex_descriptor v = patch.interior_vertices[i]; - vertex_descriptor new_v(vertices_idx_begin + i); + vertex_descriptor new_v(static_cast(vertices_idx_begin + i)); put(tm_to_output_vertices, v, new_v); put(vpm_out, new_v, get(vpm_tm, v)); @@ -85,7 +86,7 @@ void append_patch( // Also fill target of halfedges and halfedge of vertices auto fill_edge = [&](std::size_t i){ halfedge_descriptor h = patch.interior_edges[i]; - edge_descriptor new_edge(i+edges_idx_begin); + edge_descriptor new_edge(static_cast(i+edges_idx_begin)); halfedge_descriptor new_h = output.halfedge(new_edge); vertex_descriptor src = get(tm_to_output_vertices, tm.source(h)); @@ -156,7 +157,7 @@ void append_patch( std::array hedges = { get_halfedge(h_in_1), get_halfedge(h_in_2), get_halfedge(h_in_3) }; user_visitor.before_face_copy(f, tm, output); - face_descriptor new_f(faces_idx_begin + i); + face_descriptor new_f(static_cast(faces_idx_begin + i)); user_visitor.after_face_copy(f, tm, new_f, output); output.set_halfedge(new_f, hedges[0]); @@ -220,7 +221,7 @@ auto append_patches_to_triangle_mesh( tne += patches[i].interior_edges.size(); tnf += patches[i].faces.size(); } - output.resize(tnv, tne, tnf); + output.resize(static_cast(tnv), static_cast(tne), static_cast(tnf)); std::vector ids_of_patches_to_append; ids_of_patches_to_append.reserve(patches_to_append.count()); @@ -320,6 +321,7 @@ auto fill_new_triangle_mesh( using SM = SurfaceMesh; using vertex_descriptor = typename SM::Vertex_index; using edge_descriptor = typename SM::Edge_index; + using size_type = typename SM::size_type; using V2V_tag = typename CGAL::dynamic_vertex_property_t; using Vertex_to_vertex_map = typename boost::property_map::type; @@ -365,15 +367,15 @@ auto fill_new_triangle_mesh( std::vector ids_of_patches_to_append_from_tm1; std::vector ids_of_patches_to_append_from_tm2; ids_of_patches_to_append_from_tm1.reserve(patches_of_tm1_to_import.count()); - for (std::size_t i= patches_of_tm1_to_import.find_first(); - i < patches_of_tm1_to_import.npos; - i = patches_of_tm1_to_import.find_next(i)){ + for (std::size_t i = patches_of_tm1_to_import.find_first(); + i < patches_of_tm1_to_import.npos; + i = patches_of_tm1_to_import.find_next(i)){ ids_of_patches_to_append_from_tm1.push_back(i); } ids_of_patches_to_append_from_tm2.reserve(patches_of_tm2_to_import.count()); - for (std::size_t i= patches_of_tm2_to_import.find_first(); - i < patches_of_tm2_to_import.npos; - i = patches_of_tm2_to_import.find_next(i)){ + for (std::size_t i = patches_of_tm2_to_import.find_first(); + i < patches_of_tm2_to_import.npos; + i = patches_of_tm2_to_import.find_next(i)){ ids_of_patches_to_append_from_tm2.push_back(i); } @@ -414,7 +416,7 @@ auto fill_new_triangle_mesh( tne += patches_of_tm2[i].interior_edges.size(); tnf += patches_of_tm2[i].faces.size(); } - output.resize(tnv, tne, tnf); + output.resize(static_cast(tnv), static_cast(tne), static_cast(tnf)); // Append patches for (std::size_t i : ids_of_patches_to_append_from_tm1){ From d46095f955a5c0fb72db0bc36d6b7d9f7d4b8e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 6 Oct 2026 15:53:04 +0200 Subject: [PATCH 072/136] Add missing def --- .../internal/Corefinement/surface_mesh_specializations.h | 1 + 1 file changed, 1 insertion(+) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h index bbc7fc409868..ee244ee4b1b4 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h @@ -207,6 +207,7 @@ auto append_patches_to_triangle_mesh( UserVisitor& user_visitor) -> std::enable_if_t::value> { using SM = SurfaceMesh; + using size_type = typename SM::size_type; SM& tm = patches.pm; std::size_t vertices_idx_begin = output.num_vertices(); From aed7ba1c3898ca7c98095f183d84b8e1e42a1680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 7 Oct 2026 11:34:07 +0200 Subject: [PATCH 073/136] Add missing concurrency_tag and changes the associate wording in the documentation --- .../Polygon_mesh_processing/autorefinement.h | 2 +- .../CGAL/Polygon_mesh_processing/clip.h | 36 +++++++++++++++++-- .../Polygon_mesh_processing/corefinement.h | 24 +++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h index 55063f358896..8b930172443e 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h @@ -1716,7 +1716,7 @@ bool autorefine_triangle_soup(PointRange& soup_points, * * \cgalNamedParamsBegin * \cgalParamNBegin{concurrency_tag} - * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} * \cgalParamDefault{`CGAL::Sequential_tag`} * \cgalParamNEnd diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/clip.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/clip.h index f6fa1676617a..85bfee261d88 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/clip.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/clip.h @@ -820,6 +820,13 @@ struct Visitor_wrapper_for_triangulate_face * * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np_tm` only} + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm` (resp. `clipper`)} * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -938,7 +945,7 @@ clip(TriangleMesh& tm, * \cgalNamedParamsBegin * * \cgalParamNBegin{concurrency_tag} - * \cgalParamDescription{a tag indicating if the task should be performed using one or several threads.} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} * \cgalParamDefault{`CGAL::Sequential_tag`} * \cgalParamNEnd @@ -1179,6 +1186,12 @@ bool clip(PolygonMesh& pm, * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm`} * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -1291,6 +1304,13 @@ bool clip(TriangleMesh& tm, * @param np_s an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np_tm` only} + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm` (`splitter`)} * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -1342,6 +1362,12 @@ void split(TriangleMesh& tm, using parameters::get_parameter; using parameters::choose_parameter; + typedef typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters1, + Sequential_tag + > ::type Concurrency_tag; + typedef typename GetVertexPointMap::type VPM1; typedef typename GetVertexPointMap::type VPM2; @@ -1368,7 +1394,7 @@ void split(TriangleMesh& tm, const bool do_not_modify_splitter = choose_parameter(get_parameter(np_s, internal_np::do_not_modify), false); PMP::corefine(tm, splitter, - CGAL::parameters::vertex_point_map(vpm_tm).edge_is_marked_map(ecm).visitor(uv), + CGAL::parameters::vertex_point_map(vpm_tm).edge_is_marked_map(ecm).visitor(uv).concurrency_tag(Concurrency_tag()), CGAL::parameters::vertex_point_map(vpm_s).do_not_modify(do_not_modify_splitter)); //split mesh along marked edges @@ -1511,6 +1537,12 @@ void split(PolygonMesh& pm, * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm`} * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h index 28a7c1ad140c..c92425449ae1 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h @@ -181,9 +181,10 @@ enum Boolean_operation_type {UNION = 0, INTERSECTION=1, * * \cgalNamedParamsBegin * \cgalParamNBegin{concurrency_tag} - * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} * \cgalParamNEnd * * \cgalParamNBegin{vertex_point_map} @@ -532,9 +533,10 @@ corefine_and_compute_boolean_operations( * * \cgalNamedParamsBegin * \cgalParamNBegin{concurrency_tag} - * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} * \cgalParamNEnd * * \cgalParamNBegin{vertex_point_map} @@ -731,6 +733,13 @@ corefine_and_compute_difference( TriangleMesh& tm1, * @param np2 an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm1` (`tm2`)} * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -884,6 +893,12 @@ namespace experimental { * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamNEnd + * * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm`} * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -983,6 +998,11 @@ autorefine( TriangleMesh& tm, * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag specifying whether the task should be performed using a single or multiple threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamNEnd * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm`} * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` From ed4734d2dd774e04d6929f6925ad86c0c1954cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 7 Oct 2026 12:16:00 +0200 Subject: [PATCH 074/136] Update changes.md --- Installation/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index c11620892c39..413ee000a70b 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -51,6 +51,8 @@ Release date: December 2026 - The corefinement based operations (including Boolean operations) has been optimized to better handle cases when some identical faces are shared between the input meshes. This leads to a significant speed up in those cases. +- `corefine()` and its variants now have a named parameter `concurrency_tag`, specifying whether the task should be performed using a single or multiple threads. +- The running time of `corefine()`, `autorefine()` and their variants has been improved. ### [Basic Viewer](https://doc.cgal.org/6.3/Manual/packages.html#PkgBasicViewer) From f44d56934678aed21e2224be1ad99d535d170293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 7 Oct 2026 16:51:54 +0200 Subject: [PATCH 075/136] Benchmark for autorefine and boolop --- .../benchmark/CMakeLists.txt | 12 ++- .../Performance/performance_autorefine.cpp | 36 +++++++++ .../Performance/performance_boolop.cpp | 43 +++++++++++ .../Performance/run_performance_autorefine.sh | 20 +++++ .../Performance/run_performance_boolop.sh | 14 ++++ ...performance.sh => run_performance_snap.sh} | 9 ++- .../benchmark/Quality/quality_autorefine.cpp | 53 +++++++++++++ .../benchmark/Quality/quality_boolop.cpp | 59 ++++++++++++++ .../Quality/run_quality_autorefine.sh | 16 ++++ .../benchmark/Quality/run_quality_boolop.sh | 12 +++ .../{run_quality.sh => run_quality_snap.sh} | 0 .../Robustness/robustness_autorefine.cpp | 41 ++++++++++ .../Robustness/robustness_boolop.cpp | 77 +++++++++++++++++++ .../Robustness/run_robustness_autorefine.sh | 27 +++++++ .../Robustness/run_robustness_boolop.sh | 10 +++ ...n_robustness.sh => run_robustness_snap.sh} | 0 .../benchmarking_snap_polygon_soup.sh | 6 +- 17 files changed, 428 insertions(+), 7 deletions(-) create mode 100644 PMP_Boolean_operations/benchmark/Performance/performance_autorefine.cpp create mode 100644 PMP_Boolean_operations/benchmark/Performance/performance_boolop.cpp create mode 100755 PMP_Boolean_operations/benchmark/Performance/run_performance_autorefine.sh create mode 100755 PMP_Boolean_operations/benchmark/Performance/run_performance_boolop.sh rename PMP_Boolean_operations/benchmark/Performance/{run_performance.sh => run_performance_snap.sh} (65%) create mode 100644 PMP_Boolean_operations/benchmark/Quality/quality_autorefine.cpp create mode 100644 PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp create mode 100755 PMP_Boolean_operations/benchmark/Quality/run_quality_autorefine.sh create mode 100755 PMP_Boolean_operations/benchmark/Quality/run_quality_boolop.sh rename PMP_Boolean_operations/benchmark/Quality/{run_quality.sh => run_quality_snap.sh} (100%) create mode 100644 PMP_Boolean_operations/benchmark/Robustness/robustness_autorefine.cpp create mode 100644 PMP_Boolean_operations/benchmark/Robustness/robustness_boolop.cpp create mode 100755 PMP_Boolean_operations/benchmark/Robustness/run_robustness_autorefine.sh create mode 100755 PMP_Boolean_operations/benchmark/Robustness/run_robustness_boolop.sh rename PMP_Boolean_operations/benchmark/Robustness/{run_robustness.sh => run_robustness_snap.sh} (100%) diff --git a/PMP_Boolean_operations/benchmark/CMakeLists.txt b/PMP_Boolean_operations/benchmark/CMakeLists.txt index 1cd65d7416b7..06f801b003f5 100644 --- a/PMP_Boolean_operations/benchmark/CMakeLists.txt +++ b/PMP_Boolean_operations/benchmark/CMakeLists.txt @@ -14,8 +14,16 @@ create_single_source_cgal_program("Performance/performance_snap_polygon_soup.cpp create_single_source_cgal_program("Robustness/robustness_snap_polygon_soup.cpp") create_single_source_cgal_program("Quality/quality_snap_polygon_soup.cpp") -create_single_source_cgal_program("polygon_mesh_slicer.cpp") -target_link_libraries(polygon_mesh_slicer PRIVATE CGAL::Eigen3_support) +create_single_source_cgal_program("Performance/performance_autorefine.cpp") +create_single_source_cgal_program("Robustness/robustness_autorefine.cpp") +create_single_source_cgal_program("Quality/quality_autorefine.cpp") + +create_single_source_cgal_program("Performance/performance_boolop.cpp") +create_single_source_cgal_program("Robustness/robustness_boolop.cpp") +create_single_source_cgal_program("Quality/quality_boolop.cpp") + +#create_single_source_cgal_program("polygon_mesh_slicer.cpp") +#target_link_libraries(polygon_mesh_slicer PRIVATE CGAL::Eigen3_support) find_package(TBB QUIET) include(CGAL_TBB_support) diff --git a/PMP_Boolean_operations/benchmark/Performance/performance_autorefine.cpp b/PMP_Boolean_operations/benchmark/Performance/performance_autorefine.cpp new file mode 100644 index 000000000000..b7afe903e75a --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Performance/performance_autorefine.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include + +#include + +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Point_3 = Kernel::Point_3; +using Surface_mesh = CGAL::Surface_mesh; +namespace PMP = CGAL::Polygon_mesh_processing; + +int main(int argc, char** argv) +{ + if(argc < 2) + { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + Surface_mesh mesh; + if(!CGAL::IO::read_polygon_mesh(argv[1], mesh) || mesh.is_empty()) + { + std::cerr << "Cannot read " << argv[1] << "\n"; + return 1; + } + + if(!CGAL::is_triangle_mesh(mesh)) + PMP::triangulate_faces(mesh); + + PMP::autorefine(mesh, + CGAL::parameters::concurrency_tag(CGAL::Parallel_if_available_tag())); + + return 0; +} diff --git a/PMP_Boolean_operations/benchmark/Performance/performance_boolop.cpp b/PMP_Boolean_operations/benchmark/Performance/performance_boolop.cpp new file mode 100644 index 000000000000..27fff1fd75eb --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Performance/performance_boolop.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +#include + +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Point_3 = Kernel::Point_3; +using Vector_3 = Kernel::Vector_3; +using Mesh = CGAL::Surface_mesh; +namespace PMP = CGAL::Polygon_mesh_processing; + +int main(int argc, char** argv) +{ + if(argc < 2) + { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + Mesh tm1; + if(!CGAL::IO::read_polygon_mesh(argv[1], tm1) || tm1.is_empty()) + { + std::cerr << "Cannot read " << argv[1] << "\n"; + return 1; + } + + Mesh tm2 = tm1; + const CGAL::Bbox_3 bb = PMP::bbox(tm1); + const Vector_3 translation((bb.xmax()-bb.xmin()) * 0.2, + (bb.ymax()-bb.ymin()) * 0.2, + (bb.zmax()-bb.zmin()) * 0.2); + for(auto v : tm2.vertices()) + tm2.point(v) = tm2.point(v) + translation; + + Mesh out; + PMP::corefine_and_compute_union( + tm1, tm2, out, + CGAL::parameters::concurrency_tag(CGAL::Parallel_if_available_tag())); + return 0; +} diff --git a/PMP_Boolean_operations/benchmark/Performance/run_performance_autorefine.sh b/PMP_Boolean_operations/benchmark/Performance/run_performance_autorefine.sh new file mode 100755 index 000000000000..e073d571ad46 --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Performance/run_performance_autorefine.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +if [ "$#" -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +INPUT_FILE=$1 +TIMEOUT=$2 + +TMP_LOG=$(mktemp) +/usr/bin/time -f "TIME:%e\nMEM:%M" timeout "$TIMEOUT"s performance_autorefine "$INPUT_FILE" 2> "$TMP_LOG" + +SECONDS=$(grep "TIME" "$TMP_LOG" | cut -d':' -f2) +MEMORY=$(grep "MEM" "$TMP_LOG" | cut -d':' -f2) + +rm -f "$TMP_LOG" +echo "{\"seconds\": \"$SECONDS\", \"memory_peaks\": \"$MEMORY\"}" diff --git a/PMP_Boolean_operations/benchmark/Performance/run_performance_boolop.sh b/PMP_Boolean_operations/benchmark/Performance/run_performance_boolop.sh new file mode 100755 index 000000000000..6794fa944140 --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Performance/run_performance_boolop.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e +if [ "$#" -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi +INPUT_FILE=$1 +TIMEOUT=$2 +TMP_LOG=$(mktemp) +/usr/bin/time -f "TIME:%e\nMEM:%M" timeout "$TIMEOUT"s performance_boolop "$INPUT_FILE" 2> "$TMP_LOG" +SECONDS=$(grep "TIME" "$TMP_LOG" | cut -d':' -f2) +MEMORY=$(grep "MEM" "$TMP_LOG" | cut -d':' -f2) +rm -f "$TMP_LOG" +echo "{\"seconds\": \"$SECONDS\", \"memory_peaks\": \"$MEMORY\"}" diff --git a/PMP_Boolean_operations/benchmark/Performance/run_performance.sh b/PMP_Boolean_operations/benchmark/Performance/run_performance_snap.sh similarity index 65% rename from PMP_Boolean_operations/benchmark/Performance/run_performance.sh rename to PMP_Boolean_operations/benchmark/Performance/run_performance_snap.sh index aa6ea1a28ba0..d50f65f808cd 100755 --- a/PMP_Boolean_operations/benchmark/Performance/run_performance.sh +++ b/PMP_Boolean_operations/benchmark/Performance/run_performance_snap.sh @@ -13,10 +13,15 @@ GRID_SIZE=$3 ERASE_ALL_DUPLICATE=$4 # Use /usr/bin/time for memory usage (maximum resident set size in KB) -TMP_LOG=$(mktemp) +TMP_LOG_BOOLOP=$(mktemp) +TMP_LOG_AUTOREFINE=$(mktemp) +TMP_LOG_SNAP=$(mktemp) + # Run the benchmarked command -/usr/bin/time -f "TIME:%e\nMEM:%M" timeout "$TIMEOUT"s performance_snap_polygon_soup "$INPUT_FILE" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2> "$TMP_LOG" +/usr/bin/time -f "TIME:%e\nMEM:%M" timeout "$TIMEOUT"s performance_boolop "$INPUT_FILE" 2> "$TMP_LOG_BOOLOP" +/usr/bin/time -f "TIME:%e\nMEM:%M" timeout "$TIMEOUT"s performance_autorefine "$INPUT_FILE" 2> "$TMP_LOG_AUTOREFINE" +/usr/bin/time -f "TIME:%e\nMEM:%M" timeout "$TIMEOUT"s performance_snap_polygon_soup "$INPUT_FILE" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2> "$TMP_LOG_SNAP" # Parse time and memory SECONDS=$(grep "TIME" "$TMP_LOG" | cut -d':' -f2) diff --git a/PMP_Boolean_operations/benchmark/Quality/quality_autorefine.cpp b/PMP_Boolean_operations/benchmark/Quality/quality_autorefine.cpp new file mode 100644 index 000000000000..cc567b93f943 --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Quality/quality_autorefine.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Point_3 = Kernel::Point_3; +using Surface_mesh = CGAL::Surface_mesh; +namespace PMP = CGAL::Polygon_mesh_processing; + +int main(int argc, char** argv) +{ + if(argc < 2) + { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + Surface_mesh mesh; + if(!CGAL::IO::read_polygon_mesh(argv[1], mesh) || mesh.is_empty()) + { + std::cerr << "Cannot read " << argv[1] << "\n"; + return 1; + } + + if(!CGAL::is_triangle_mesh(mesh)) + PMP::triangulate_faces(mesh); + + PMP::autorefine(mesh, CGAL::parameters::concurrency_tag(CGAL::Parallel_if_available_tag())); + + const bool self_intersecting = + PMP::does_self_intersect(mesh); + + std::cout << "{\n" + << " \"Nb_output_vertices\": " << num_vertices(mesh) << ",\n" + << " \"Nb_output_edges\": " << num_edges(mesh) << ",\n" + << " \"Nb_output_faces\": " << num_faces(mesh) << ",\n" + << " \"Is_triangle_mesh\": \"" << (CGAL::is_triangle_mesh(mesh) ? "True" : "False") << "\",\n" + << " \"Is_valid\": \"" << (CGAL::is_valid_polygon_mesh(mesh) ? "True" : "False") << "\",\n" + << " \"Self_intersecting\": \"" << (self_intersecting ? "True" : "False") << "\",\n" + << " \"Closed\": \"" << (CGAL::is_closed(mesh) ? "True" : "False") << "\",\n" + << " \"Output_bound_a_volume\": \"" << (PMP::does_bound_a_volume(mesh) ? "True" : "False") << "\"\n" + << "}\n"; + + return 0; +} diff --git a/PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp b/PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp new file mode 100644 index 000000000000..7d1097221214 --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Point_3 = Kernel::Point_3; +using Vector_3 = Kernel::Vector_3; +using Mesh = CGAL::Surface_mesh; +namespace PMP = CGAL::Polygon_mesh_processing; + +int main(int argc, char** argv) +{ + if(argc < 2) + { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + Mesh tm1; + if(!CGAL::IO::read_polygon_mesh(argv[1], tm1) || tm1.is_empty()) + return 1; + + Mesh tm2 = tm1; + const CGAL::Bbox_3 bb = PMP::bbox(tm1); + const Vector_3 translation((bb.xmax()-bb.xmin()) * 0.5, + (bb.ymax()-bb.ymin()) * 0.5, + (bb.zmax()-bb.zmin()) * 0.5); + for(auto v : tm2.vertices()) + tm2.point(v) = tm2.point(v) + translation; + + Mesh outputs[4]; + std::array, 4> output = { + &outputs[0], &outputs[1], &outputs[2], &outputs[3] + }; + + const auto success = PMP::corefine_and_compute_boolean_operations( + tm1, tm2, output, + CGAL::parameters::concurrency_tag(CGAL::Parallel_if_available_tag())); + + std::cout << "{\n"; + const char* names[] = {"union", "intersection", "tm1_minus_tm2", "tm2_minus_tm1"}; + for(std::size_t i=0; i<4; ++i) + { + std::cout << " \"" << names[i] << "\": {\"success\": " + << (success[i] ? "true" : "false") + << ", \"vertices\": " << num_vertices(outputs[i]) + << ", \"faces\": " << num_faces(outputs[i]) << "}"; + if(i != 3) std::cout << ','; + std::cout << '\n'; + } + std::cout << "}\n"; + return 0; +} diff --git a/PMP_Boolean_operations/benchmark/Quality/run_quality_autorefine.sh b/PMP_Boolean_operations/benchmark/Quality/run_quality_autorefine.sh new file mode 100755 index 000000000000..bd6382863f59 --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Quality/run_quality_autorefine.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +if [ "$#" -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +INPUT_FILE=$1 +TIMEOUT=$2 + +TMP_LOG=$(mktemp) +timeout "$TIMEOUT"s quality_autorefine "$INPUT_FILE" > "$TMP_LOG" +cat "$TMP_LOG" +rm -f "$TMP_LOG" diff --git a/PMP_Boolean_operations/benchmark/Quality/run_quality_boolop.sh b/PMP_Boolean_operations/benchmark/Quality/run_quality_boolop.sh new file mode 100755 index 000000000000..163646e428bb --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Quality/run_quality_boolop.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e +if [ "$#" -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi +INPUT_FILE=$1 +TIMEOUT=$2 +TMP_LOG=$(mktemp) +timeout "$TIMEOUT"s quality_boolop "$INPUT_FILE" > "$TMP_LOG" +cat "$TMP_LOG" +rm -f "$TMP_LOG" diff --git a/PMP_Boolean_operations/benchmark/Quality/run_quality.sh b/PMP_Boolean_operations/benchmark/Quality/run_quality_snap.sh similarity index 100% rename from PMP_Boolean_operations/benchmark/Quality/run_quality.sh rename to PMP_Boolean_operations/benchmark/Quality/run_quality_snap.sh diff --git a/PMP_Boolean_operations/benchmark/Robustness/robustness_autorefine.cpp b/PMP_Boolean_operations/benchmark/Robustness/robustness_autorefine.cpp new file mode 100644 index 000000000000..8eca1dbb0a30 --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Robustness/robustness_autorefine.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include + +#include + +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Point_3 = Kernel::Point_3; +using Surface_mesh = CGAL::Surface_mesh; +namespace PMP = CGAL::Polygon_mesh_processing; + +enum EXIT_CODES { VALID_OUTPUT=0, + INVALID_INPUT=1, + SELF_INTERSECTING_OUTPUT=3, + SIGSEGV=10, + SIGSABRT=11, + SIGFPE=12, + TIMEOUT=13 }; + +int main(int argc, char** argv) +{ + if(argc < 2) + return INVALID_INPUT; + + Surface_mesh mesh; + if(!CGAL::IO::read_polygon_mesh(argv[1], mesh) || mesh.is_empty()) + return INVALID_INPUT; + + if(!CGAL::is_triangle_mesh(mesh)) + PMP::triangulate_faces(mesh); + + PMP::autorefine(mesh, CGAL::parameters::concurrency_tag(CGAL::Parallel_if_available_tag())); + + if(PMP::does_self_intersect(mesh)) + return SELF_INTERSECTING_OUTPUT; + + return VALID_OUTPUT; +} diff --git a/PMP_Boolean_operations/benchmark/Robustness/robustness_boolop.cpp b/PMP_Boolean_operations/benchmark/Robustness/robustness_boolop.cpp new file mode 100644 index 000000000000..5f05cbeebf5c --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Robustness/robustness_boolop.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Point_3 = Kernel::Point_3; +using Vector_3 = Kernel::Vector_3; +using Mesh = CGAL::Surface_mesh; +namespace PMP = CGAL::Polygon_mesh_processing; + +using Output_array = std::array, 4>; + +enum Output_type { OUTPLACE, INPLACE_TM1, INPLACE_TM2 }; + +bool run_case(const Mesh& input, const Vector_3& translation, + const std::size_t operation, const Output_type output_type) +{ + Mesh tm1 = input; + Mesh tm2 = input; + for(auto v : tm2.vertices()) + tm2.point(v) = tm2.point(v) + translation; + + Mesh out; + Output_array output = {std::nullopt, std::nullopt, std::nullopt, std::nullopt}; + + switch(output_type) + { + case OUTPLACE: output[operation] = &out; break; + case INPLACE_TM1: output[operation] = &tm1; break; + case INPLACE_TM2: output[operation] = &tm2; break; + } + + const auto success = PMP::corefine_and_compute_boolean_operations( + tm1, tm2, output, + CGAL::parameters::concurrency_tag(CGAL::Parallel_if_available_tag())); + + Mesh* result = output[operation].value(); + return success[operation] && result != nullptr && !result->is_empty(); +} + +int main(int argc, char** argv) +{ + if(argc < 2) + { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + Mesh input; + if(!CGAL::IO::read_polygon_mesh(argv[1], input) || input.is_empty()) + return 1; + + const CGAL::Bbox_3 bb = PMP::bbox(input); + const Vector_3 translation((bb.xmax()-bb.xmin()) * 0.5, + (bb.ymax()-bb.ymin()) * 0.5, + (bb.zmax()-bb.zmin()) * 0.5); + + const char* output_names[] = {"outplace", "inplace_tm1", "inplace_tm2"}; + for(std::size_t op=0; op<4; ++op) + { + for(int type=OUTPLACE; type<=INPLACE_TM2; ++type) + { + const bool ok = run_case(input, translation, op, static_cast(type)); + std::cout << "output_" << op << "." << output_names[type] + << ": " << (ok ? "OK" : "FAILED") << '\n'; + if(!ok) + return 1; + } + } + return 0; +} diff --git a/PMP_Boolean_operations/benchmark/Robustness/run_robustness_autorefine.sh b/PMP_Boolean_operations/benchmark/Robustness/run_robustness_autorefine.sh new file mode 100755 index 000000000000..92822c894a4e --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Robustness/run_robustness_autorefine.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +if [ "$#" -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +INPUT_FILE=$1 +TIMEOUT=$2 + +timeout --foreground "$TIMEOUT"s robustness_autorefine "$INPUT_FILE" +EXIT_CODE=$? + +declare -A TAGS +TAGS[0]="VALID_OUTPUT" +TAGS[1]="INPUT_IS_INVALID" +TAGS[3]="SELF_INTERSECTING_OUTPUT" +TAGS[139]="SIGSEGV" +TAGS[11]="SIGSEGV" +TAGS[6]="SIGABRT" +TAGS[8]="SIGFPE" +TAGS[132]="SIGILL" +TAGS[124]="TIMEOUT" + +TAG_NAME=${TAGS[$EXIT_CODE]:-UNKNOWN} +TAG_DESC=$([[ "$EXIT_CODE" -eq 0 ]] && echo "OK" || echo "Error") +echo "{\"TAG_NAME\": \"$TAG_NAME\", \"TAG\": \"$TAG_DESC\"}" diff --git a/PMP_Boolean_operations/benchmark/Robustness/run_robustness_boolop.sh b/PMP_Boolean_operations/benchmark/Robustness/run_robustness_boolop.sh new file mode 100755 index 000000000000..23a51c5a38c5 --- /dev/null +++ b/PMP_Boolean_operations/benchmark/Robustness/run_robustness_boolop.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +if [ "$#" -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi +INPUT_FILE=$1 +TIMEOUT=$2 +timeout --foreground "$TIMEOUT"s robustness_boolop "$INPUT_FILE" +echo '{"TAG_NAME": "VALID_OUTPUT", "TAG": "OK"}' diff --git a/PMP_Boolean_operations/benchmark/Robustness/run_robustness.sh b/PMP_Boolean_operations/benchmark/Robustness/run_robustness_snap.sh similarity index 100% rename from PMP_Boolean_operations/benchmark/Robustness/run_robustness.sh rename to PMP_Boolean_operations/benchmark/Robustness/run_robustness_snap.sh diff --git a/PMP_Boolean_operations/benchmark/benchmarking_snap_polygon_soup.sh b/PMP_Boolean_operations/benchmark/benchmarking_snap_polygon_soup.sh index da3f363566a4..5373a2bff176 100755 --- a/PMP_Boolean_operations/benchmark/benchmarking_snap_polygon_soup.sh +++ b/PMP_Boolean_operations/benchmark/benchmarking_snap_polygon_soup.sh @@ -22,13 +22,13 @@ process_file() { echo " \"$INPUT_ID\": {" echo " \"path\": \"$INPUT_PATH\"," - PERF_OUTPUT=$(bash "$PROJECT_DIR/Performance/run_performance.sh" "$INPUT_PATH" "$TIMEOUT" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2>> "$OUTPUT_DIR/Logs/$COMPONENT_NAME/Performance/$INPUT_ID.log") + PERF_OUTPUT=$(bash "$PROJECT_DIR/Performance/run_performance_snap.sh" "$INPUT_PATH" "$TIMEOUT" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2>> "$OUTPUT_DIR/Logs/$COMPONENT_NAME/Performance/$INPUT_ID.log") echo " \"Performance\": $PERF_OUTPUT," - QUALITY_OUTPUT=$(bash "$PROJECT_DIR/Quality/run_quality.sh" "$INPUT_PATH" "$TIMEOUT" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2>> "$OUTPUT_DIR/Logs/$COMPONENT_NAME/Quality/$INPUT_ID.log") + QUALITY_OUTPUT=$(bash "$PROJECT_DIR/Quality/run_quality_snap.sh" "$INPUT_PATH" "$TIMEOUT" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2>> "$OUTPUT_DIR/Logs/$COMPONENT_NAME/Quality/$INPUT_ID.log") echo " \"Quality\": $QUALITY_OUTPUT," - ROBUST_OUTPUT=$(bash "$PROJECT_DIR/Robustness/run_robustness.sh" "$INPUT_PATH" "$TIMEOUT" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2>> "$OUTPUT_DIR/Logs/$COMPONENT_NAME/Robustness/$INPUT_ID.log") + ROBUST_OUTPUT=$(bash "$PROJECT_DIR/Robustness/run_robustness_snap.sh" "$INPUT_PATH" "$TIMEOUT" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2>> "$OUTPUT_DIR/Logs/$COMPONENT_NAME/Robustness/$INPUT_ID.log") echo " \"Robustness\": $ROBUST_OUTPUT" echo " }" From 7acbe0d0721f1bac5029d6579b828797ad94a13c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Wed, 7 Oct 2026 17:42:40 +0200 Subject: [PATCH 076/136] Reduce shift of the duplicate in tesrt --- PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp | 6 +++--- .../benchmark/Robustness/robustness_boolop.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp b/PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp index 7d1097221214..7f35135886d4 100644 --- a/PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp +++ b/PMP_Boolean_operations/benchmark/Quality/quality_boolop.cpp @@ -28,9 +28,9 @@ int main(int argc, char** argv) Mesh tm2 = tm1; const CGAL::Bbox_3 bb = PMP::bbox(tm1); - const Vector_3 translation((bb.xmax()-bb.xmin()) * 0.5, - (bb.ymax()-bb.ymin()) * 0.5, - (bb.zmax()-bb.zmin()) * 0.5); + const Vector_3 translation((bb.xmax()-bb.xmin()) * 0.2, + (bb.ymax()-bb.ymin()) * 0.2, + (bb.zmax()-bb.zmin()) * 0.2); for(auto v : tm2.vertices()) tm2.point(v) = tm2.point(v) + translation; diff --git a/PMP_Boolean_operations/benchmark/Robustness/robustness_boolop.cpp b/PMP_Boolean_operations/benchmark/Robustness/robustness_boolop.cpp index 5f05cbeebf5c..5d554da84a87 100644 --- a/PMP_Boolean_operations/benchmark/Robustness/robustness_boolop.cpp +++ b/PMP_Boolean_operations/benchmark/Robustness/robustness_boolop.cpp @@ -57,9 +57,9 @@ int main(int argc, char** argv) return 1; const CGAL::Bbox_3 bb = PMP::bbox(input); - const Vector_3 translation((bb.xmax()-bb.xmin()) * 0.5, - (bb.ymax()-bb.ymin()) * 0.5, - (bb.zmax()-bb.zmin()) * 0.5); + const Vector_3 translation((bb.xmax()-bb.xmin()) * 0.2, + (bb.ymax()-bb.ymin()) * 0.2, + (bb.zmax()-bb.zmin()) * 0.2); const char* output_names[] = {"outplace", "inplace_tm1", "inplace_tm2"}; for(std::size_t op=0; op<4; ++op) From c1fd3c455a4ddd01ee6c2a13c82878237c2a979b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 16 Oct 2026 11:24:12 +0200 Subject: [PATCH 077/136] re-add operators for compatibility with exterior code --- .../internal/Corefinement/intersection_callbacks.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h index b25174373f3d..d28adc9e3ef7 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h @@ -329,6 +329,20 @@ class Collect_face_bbox_per_edge_bbox_with_coplanar_handling_one_mesh { // non-coplanar case edge_to_faces[edge(eh,tm)].insert(face(fh, tm)); } + + template + void operator()(const Box& face_box, const Box& edge_box) const + { + halfedge_descriptor fh = face_box.info(); + halfedge_descriptor eh = edge_box.info(); + return operator()(fh, eh); + } + + template + void operator()(Box* const face_box_ptr, Box* const edge_box_ptr) const + { + operator()(*face_box_ptr, *edge_box_ptr); + } }; template From 791b561dc718ecc0e666b67548e13282654586c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 16 Oct 2026 12:36:13 +0200 Subject: [PATCH 078/136] Add singleton case to self_intersection --- .../AABB_tree/internal/AABB_two_trees_traversal.h | 4 +++- .../self_intersection_triangle_soup_test.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h index 1067e317763c..ec6f853b639f 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h @@ -205,7 +205,9 @@ template(*tree.root_node(), tree.size(), traits); } diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/self_intersection_triangle_soup_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/self_intersection_triangle_soup_test.cpp index f56b2524dc2c..bfd068e1acff 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/self_intersection_triangle_soup_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/self_intersection_triangle_soup_test.cpp @@ -188,6 +188,19 @@ int main(int argc, char** argv) r += test_limited_self_intersections(filename); // extra hand written tests + { + // Empty test + std::vector points; + std::vector< std::array > triangles; + assert(!PMP::does_triangle_soup_self_intersect(points, triangles)); + } + { + // Singleton + typedef EPICK::Point_3 Point_3; + std::vector points = {Point_3(0,0,0), Point_3(1,0,0), Point_3(0,1,0)}; + std::vector< std::array > triangles={{0,1,2}}; + assert(!PMP::does_triangle_soup_self_intersect(points, triangles)); + } { // shared edge with same point: no self-intersection typedef EPICK::Point_3 Point_3; From ef85b041c6d166b4fc8bbe60dc1fa7e82048d1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 19 Oct 2026 11:24:50 +0200 Subject: [PATCH 079/136] Desactivate enable_if if CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS is defined --- .../internal/Corefinement/face_graph_utils.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 6a5347b54a50..fa511e0d9725 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -1207,7 +1207,10 @@ auto append_patches_to_triangle_mesh( const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgetoEdgeMap& tm_to_output_edges, VertextoVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) -> std::enable_if_t::value> + UserVisitor& user_visitor) +#ifndef CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS + -> std::enable_if_t::value> +#endif { using GT = boost::graph_traits; using halfedge_descriptor = typename GT::halfedge_descriptor; @@ -1348,7 +1351,10 @@ auto append_patches_to_triangle_mesh( const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, EdgetoEdgeMap& tm_to_output_edges, VertextoVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) -> std::enable_if_t::value> + UserVisitor& user_visitor) +#ifndef CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS + -> std::enable_if_t::value> +#endif { append_patches_to_triangle_mesh(output, patches_to_append, @@ -1394,7 +1400,10 @@ auto fill_new_triangle_mesh( EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, std::vector< typename boost::graph_traits::edge_descriptor>& output_shared_edges, - UserVisitor& user_visitor) -> std::enable_if_t::value> + UserVisitor& user_visitor) +#ifndef CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS + -> std::enable_if_t::value> +#endif { using GT = boost::graph_traits; using vertex_descriptor = typename GT::vertex_descriptor; From e29408a6089a1aae638af398ff4cbc9a2629923b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Thu, 22 Oct 2026 16:06:56 +0200 Subject: [PATCH 080/136] Update borders of a patch when removing an edge from shared edges --- .../Corefinement/Face_graph_output_builder.h | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index e5d19fe4f2e8..5657c918b2d8 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -2570,33 +2570,36 @@ class Face_graph_output_builder } if (!to_rm.empty()) { - // Here there are an assumption that edges in to_rm are necessarly the last of shared edges std::reverse(to_rm.begin(), to_rm.end()); + // Move edges to rm from shared edges to interiors and borders for(Hedge_iterator it : to_rm) { patches_of_tm1[i].interior_edges.push_back(*it); if (it!=std::prev(patches_of_tm1[i].shared_edges.end())) std::swap(patches_of_tm1[i].shared_edges.back(), *it); patches_of_tm1[i].shared_edges.pop_back(); + patches_of_tm1[i].border_edges.emplace(opposite(*it, tm1)); } - //now update interior vertices - std::set border_vertices; + // compute new shared vertices + std::set shared_vertices; for(halfedge_descriptor h : patches_of_tm1[i].shared_edges) { - border_vertices.insert( target(h,tm1) ); - border_vertices.insert( source(h,tm1) ); + shared_vertices.insert( target(h,tm1) ); + shared_vertices.insert( source(h,tm1) ); } - std::set vertices_to_add; - for(halfedge_descriptor h : patches_of_tm1[i].interior_edges) + // update interior_vertices and border with shared vertices + for(Hedge_iterator it : to_rm) { - if ( !border_vertices.count( target(h,tm1) ) ) - vertices_to_add.insert(target(h, tm1)); - if ( !border_vertices.count( source(h,tm1) ) ) - vertices_to_add.insert(source(h, tm1)); + if ( shared_vertices.count( target(*it, tm1) ) ) + patches_of_tm1[i].border_with_shared_target.emplace(opposite(*it, tm1)); + else + patches_of_tm1[i].interior_vertices.push_back( target(*it, tm1) ); + + if ( shared_vertices.count( source(*it, tm1) ) ) + patches_of_tm1[i].border_with_shared_source.emplace(opposite(*it, tm1)); } - patches_of_tm1[i].interior_vertices.insert(patches_of_tm1[i].interior_vertices.end(), vertices_to_add.begin(), vertices_to_add.end() ); } } From b26223d963362ba15d47e3c96952ae08c2a7cc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 26 Oct 2026 12:09:39 +0100 Subject: [PATCH 081/136] Remove output building modifications --- .../include/CGAL/Polygon_mesh_processing/corefinement.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h index c92425449ae1..75b4d8f9dec3 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/corefinement.h @@ -469,8 +469,7 @@ corefine_and_compute_boolean_operations( Default, Edge_properties_in, Edge_properties_out, - User_visitor, - ConcurrencyTag> Ob; + User_visitor> Ob; typedef Corefinement::Surface_intersection_visitor_for_corefinement< TriangleMesh, VPM1, VPM2, Ob, Edge_properties_in, User_visitor> Algo_visitor; From 8db2046b592f623b710cc4e8ec06ef287e061c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 26 Oct 2026 18:25:51 +0100 Subject: [PATCH 082/136] Remove output building modifications --- .../Corefinement/Face_graph_output_builder.h | 141 ++- .../internal/Corefinement/face_graph_utils.h | 823 ++++++++---------- 2 files changed, 396 insertions(+), 568 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index 5657c918b2d8..c7a8a9f29512 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -17,7 +17,6 @@ #include -#include #include #include @@ -26,7 +25,6 @@ #include #include -#include #include #include @@ -468,8 +466,7 @@ template + class UserVisitor> class Face_graph_output_builder { typedef typename Has_extra_functions::type VUNDF; //shortcut @@ -478,12 +475,12 @@ class Face_graph_output_builder static constexpr bool has_soup_visitor = HSV::value; // graph_traits typedefs - using TM = TriangleMesh; - using GT = boost::graph_traits; - using edge_descriptor = typename GT::edge_descriptor; - using face_descriptor = typename GT::face_descriptor; - using halfedge_descriptor = typename GT::halfedge_descriptor; - using vertex_descriptor = typename GT::vertex_descriptor; + typedef TriangleMesh TM; + typedef boost::graph_traits GT; + typedef typename GT::edge_descriptor edge_descriptor; + typedef typename GT::face_descriptor face_descriptor; + typedef typename GT::halfedge_descriptor halfedge_descriptor; + typedef typename GT::vertex_descriptor vertex_descriptor; // Internal typedefs typedef std::size_t Node_id; typedef std::pair Node_id_pair; @@ -498,7 +495,8 @@ class Face_graph_output_builder An_edge_per_polyline_map; typedef std::unordered_map Node_id_map; - + typedef std::unordered_map Edge_map; //Data members TriangleMesh &tm1, &tm2; // property maps of input meshes @@ -846,7 +844,7 @@ class Face_graph_output_builder bool input_have_coplanar_faces, const boost::dynamic_bitset<>& is_node_of_degree_one, const Mesh_to_map_node&, - const std::vector>& identical_patches) + const std::vector>& identical_patches) { const bool used_to_classify_patches = requested_output[UNION]==std::nullopt && requested_output[TM1_MINUS_TM2]==std::nullopt && @@ -1060,51 +1058,32 @@ class Face_graph_output_builder // (1) Assign a patch id to each facet indicating in which connected // component limited by intersection edges of the surface they are. + // ... for tm1 std::vector tm1_patch_ids( num_faces(tm1),NID ); + Border_edge_map is_marked_1(intersection_edges1, tm1); + std::size_t nb_patches_tm1 = + connected_components(tm1, + make_compose_property_map(fids1,make_property_map(&tm1_patch_ids[0])), + parameters::edge_is_constrained_map(is_marked_1) + .face_index_map(fids1)); + + std::vector tm1_patch_sizes(nb_patches_tm1, 0); + for(std::size_t i : tm1_patch_ids) + if(i!=NID) + ++tm1_patch_sizes[i]; + // ... for tm2 std::vector tm2_patch_ids( num_faces(tm2),NID ); - std::vector tm1_patch_sizes, tm2_patch_sizes; - std::size_t nb_patches_tm1, nb_patches_tm2; - auto connected_components_1=[&]() - { - // ... for tm1 - Border_edge_map is_marked_1(intersection_edges1, tm1); - nb_patches_tm1 = connected_components(tm1, - make_compose_property_map(fids1,make_property_map(&tm1_patch_ids[0])), - parameters::edge_is_constrained_map(is_marked_1) - .face_index_map(fids1)); - - tm1_patch_sizes.resize(nb_patches_tm1, 0); - for(std::size_t i : tm1_patch_ids) - if(i!=NID) - ++tm1_patch_sizes[i]; - }; - - auto connected_components_2=[&]() - { - // ... for tm2 - Border_edge_map is_marked_2(intersection_edges2, tm2); - nb_patches_tm2 = connected_components(tm2, - make_compose_property_map(fids2,make_property_map(&tm2_patch_ids[0])), - parameters::edge_is_constrained_map(is_marked_2) - .face_index_map(fids2)); - - tm2_patch_sizes.resize(nb_patches_tm2, 0); - for(Node_id i : tm2_patch_ids) - if(i!=NID) - ++tm2_patch_sizes[i]; - }; - -#ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) - { - tbb::parallel_invoke(connected_components_1, connected_components_2); - } - else -#endif - { - connected_components_1(); - connected_components_2(); - } + Border_edge_map is_marked_2(intersection_edges2, tm2); + std::size_t nb_patches_tm2 = + connected_components(tm2, + make_compose_property_map(fids2,make_property_map(&tm2_patch_ids[0])), + parameters::edge_is_constrained_map(is_marked_2) + .face_index_map(fids2)); + + std::vector tm2_patch_sizes(nb_patches_tm2, 0); + for(Node_id i : tm2_patch_ids) + if(i!=NID) + ++tm2_patch_sizes[i]; #ifdef CGAL_COREFINEMENT_DEBUG std::cout << "nb_patches_tm1 = " << nb_patches_tm1 << "\n"; @@ -1808,8 +1787,10 @@ class Face_graph_output_builder } } - for (auto [f1, f2] : identical_patches) + for (auto [h1, h2] : identical_patches) { + face_descriptor f1=face(h1, tm1), f2=face(h2, tm2); + std::size_t pid1 = tm1_patch_ids[ get(fids1, f1) ]; std::size_t pid2 = tm2_patch_ids[ get(fids2, f2) ]; @@ -2365,7 +2346,7 @@ class Face_graph_output_builder std::vector shared_edges; #define CGAL_COREF_FUNCTION_CALL_DEF(BO_type) \ - fill_new_triangle_mesh( \ + fill_new_triangle_mesh( \ output, \ patches_of_tm1_used[BO_type], patches_of_tm2_used[BO_type], \ patches_of_tm1, patches_of_tm2, \ @@ -2387,14 +2368,7 @@ class Face_graph_output_builder set_on_intersection(out_edge_mark_maps, shared_edges, operation); } - using V2V_tag = typename CGAL::dynamic_vertex_property_t; - using Vertex_to_vertex_map = typename boost::property_map::type; - - using E2E_tag = typename CGAL::dynamic_edge_property_t; - using Edge_to_edge_map = typename boost::property_map::type; - - Vertex_to_vertex_map disconnected_patches_vertex_to_tm2_vertex = get(V2V_tag(), tm1, GT::null_vertex()); - Edge_to_edge_map disconnected_patches_edge_to_tm2_edge = get(E2E_tag(), tm1, edge(GT::null_halfedge(), tm2)); + Edge_map disconnected_patches_edge_to_tm2_edge; /// handle the operations updating tm1 and/or tm2 if ( inplace_operation_tm1!=NONE ) @@ -2476,7 +2450,6 @@ class Face_graph_output_builder std::get(out_edge_mark_maps.edge_cst_tuple), \ std::get(out_edge_mark_maps.edge_mark_tuple), \ disconnected_patches_edge_to_tm2_edge, \ - disconnected_patches_vertex_to_tm2_vertex, \ user_visitor) CGAL_COREF_FUNCTION_CALL(inplace_operation_tm1) #undef CGAL_COREF_FUNCTION_CALL_DEF @@ -2499,7 +2472,6 @@ class Face_graph_output_builder std::get(out_edge_mark_maps.edge_cst_tuple), \ std::get(out_edge_mark_maps.edge_mark_tuple), \ disconnected_patches_edge_to_tm2_edge, \ - disconnected_patches_vertex_to_tm2_vertex, \ user_visitor) CGAL_COREF_FUNCTION_CALL(inplace_operation_tm2) #undef CGAL_COREF_FUNCTION_CALL_DEF @@ -2571,34 +2543,27 @@ class Face_graph_output_builder if (!to_rm.empty()) { std::reverse(to_rm.begin(), to_rm.end()); - // Move edges to rm from shared edges to interiors and borders for(Hedge_iterator it : to_rm) { patches_of_tm1[i].interior_edges.push_back(*it); if (it!=std::prev(patches_of_tm1[i].shared_edges.end())) std::swap(patches_of_tm1[i].shared_edges.back(), *it); patches_of_tm1[i].shared_edges.pop_back(); - patches_of_tm1[i].border_edges.emplace(opposite(*it, tm1)); } - - // compute new shared vertices - std::set shared_vertices; + //now update interior vertices + std::set border_vertices; for(halfedge_descriptor h : patches_of_tm1[i].shared_edges) { - shared_vertices.insert( target(h,tm1) ); - shared_vertices.insert( source(h,tm1) ); + border_vertices.insert( target(h,tm1) ); + border_vertices.insert( source(h,tm1) ); } - // update interior_vertices and border with shared vertices - for(Hedge_iterator it : to_rm) + for(halfedge_descriptor h : patches_of_tm1[i].interior_edges) { - if ( shared_vertices.count( target(*it, tm1) ) ) - patches_of_tm1[i].border_with_shared_target.emplace(opposite(*it, tm1)); - else - patches_of_tm1[i].interior_vertices.push_back( target(*it, tm1) ); - - if ( shared_vertices.count( source(*it, tm1) ) ) - patches_of_tm1[i].border_with_shared_source.emplace(opposite(*it, tm1)); + if ( !border_vertices.count( target(h,tm1) ) ) + patches_of_tm1[i].interior_vertices.insert( target(h,tm1) ); + if ( !border_vertices.count( source(h,tm1) ) ) + patches_of_tm1[i].interior_vertices.insert( source(h,tm1) ); } } } @@ -2624,14 +2589,8 @@ class Face_graph_output_builder if (all_removed) id_p_rm.erase(id_p_rm.begin()); // remove the vertex from the interior vertices of patches to be removed - for(std::size_t pid : id_p_rm){ - auto it = std::find( patches_of_tm1[pid].interior_vertices.begin(), - patches_of_tm1[pid].interior_vertices.end(), - vd); // Linear time, expensive - if (it!=std::prev(patches_of_tm1[pid].interior_vertices.end())) - std::swap(*it, patches_of_tm1[pid].interior_vertices.back()); - patches_of_tm1[pid].interior_vertices.pop_back(); - } + for(std::size_t pid : id_p_rm) + patches_of_tm1[pid].interior_vertices.erase(vd); // we now need to update the next/prev relationship induced by the future removal of patches // that will not be updated after patch removal diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index fa511e0d9725..ef7a20aaa53a 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -15,10 +15,6 @@ #include -#include -#include -#include -#include #include #include @@ -27,7 +23,6 @@ #include #include - namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { @@ -517,6 +512,7 @@ triangulate_a_face( ::halfedge_descriptor>& edge_to_hedge, const CDT& cdt, const VertexPointMap& vpm, + bool orientation_flipped, OutputBuilder& output_builder, UserVisitor& user_visitor) { @@ -583,6 +579,9 @@ triangulate_a_face( typename CDT::Vertex_handle cdt_v1=it->vertex(1); typename CDT::Vertex_handle cdt_v2=it->vertex(2); + if (orientation_flipped) + std::swap(cdt_v0, cdt_v2); + Node_id i0=cdt_v0->info(), i1=cdt_v1->info(), i2=cdt_v2->info(); CGAL_assertion(edge_to_hedge.count(std::make_pair(i0,i1))!= 0); @@ -658,15 +657,9 @@ struct Patch_description{ typedef typename GT::vertex_descriptor vertex_descriptor; std::vector faces; - std::vector interior_vertices; + std::set interior_vertices; std::vector interior_edges; std::vector shared_edges; - - // Three sets used only for patch with borders not shared, their are empty if not - std::set border_edges; - std::set border_with_shared_target; - std::set border_with_shared_source; - bool is_initialized; Patch_description(): is_initialized(false) {}; @@ -678,7 +671,10 @@ struct Patch_description{ template void extract_patch_simplices( PolygonMesh& pm, - Patch_description& patch, + std::vector::face_descriptor>& patch_faces, + std::set::vertex_descriptor>& interior_vertices, + std::vector::halfedge_descriptor>& interior_edges, + std::vector::halfedge_descriptor>& shared_edges, const IsIntersectionEdge& is_intersection_edge) { typedef boost::graph_traits GT; @@ -686,49 +682,35 @@ void extract_patch_simplices( typedef typename GT::vertex_descriptor vertex_descriptor; typedef typename GT::face_descriptor face_descriptor; - for(face_descriptor f : patch.faces) { - for(halfedge_descriptor h : halfedges_around_face(halfedge(f, pm),pm)) { + for(face_descriptor f : patch_faces) + { + for(halfedge_descriptor h : + halfedges_around_face(halfedge(f, pm),pm)) + { if ( !is_intersection_edge.count(edge(h, pm)) ) { - halfedge_descriptor h_opp = opposite(h, pm); - if(is_border(h_opp,pm)){ - patch.border_edges.insert(h_opp); - patch.interior_edges.push_back(h); - } - else if ( h < h_opp) - patch.interior_edges.push_back(h); + if ( h < opposite(h,pm) || is_border(opposite(h,pm),pm) ) + interior_edges.push_back( h ); } else - patch.shared_edges.push_back(h); + shared_edges.push_back(h); } } - std::set shared_vertices; - for(halfedge_descriptor h : patch.shared_edges){ - shared_vertices.insert( target(h,pm) ); - // if the model is not closed i.e. patch_shared_halfedge is not cycle-only - if(!patch.interior_edges.empty()) - shared_vertices.insert( source(h,pm) ); - } - - // a patch is a disk v = 2 + e - f - // v_in = v - v_shared, e = e_in + e_shared, v_shared = e_shared ( +1 if not closed) - // v_in = 2 + e_in - f (-1 if not closed) - patch.interior_vertices.reserve(2 + patch.interior_edges.size() - patch.faces.size() ); - for(halfedge_descriptor h : patch.interior_edges){ - if ( !shared_vertices.count( target(h,pm) ) && - halfedge(target(h,pm),pm) == h ) // only add the vertex once - patch.interior_vertices.push_back( target(h,pm) ); - if ( !shared_vertices.count( source(h,pm) ) && - halfedge(source(h,pm),pm) == opposite(h,pm) ) // only add the vertex once - patch.interior_vertices.push_back( source(h,pm) ); + std::set border_vertices; + for(halfedge_descriptor h : shared_edges) + { + border_vertices.insert( target(h,pm) ); + // if the model is not closed i.e. patch_border_halfedge is not cycle-only + border_vertices.insert( source(h,pm) ); } - for(halfedge_descriptor h : patch.border_edges){ - if ( shared_vertices.count( target(h,pm) ) ) - patch.border_with_shared_target.emplace(h); - if ( shared_vertices.count( source(h,pm) ) ) - patch.border_with_shared_source.emplace(h); + for(halfedge_descriptor h : interior_edges) + { + if ( !border_vertices.count( target(h,pm) ) ) + interior_vertices.insert( target(h,pm) ); + if ( !border_vertices.count( source(h,pm) ) ) + interior_vertices.insert( source(h,pm) ); } } @@ -761,15 +743,18 @@ struct Patch_container{ patches[patch_ids[ get(fids, f) ]].faces.push_back( f ); } - void extract_patch(std::size_t i) { - if ( !patches[i].is_initialized ) { - extract_patch_simplices(pm, patches[i], is_intersection_edge); + Patch_description& operator[](std::size_t i) { + if ( !patches[i].is_initialized ) + { + extract_patch_simplices( + pm, + patches[i].faces, patches[i].interior_vertices, + patches[i].interior_edges, patches[i].shared_edges, + is_intersection_edge + ); + patches[i].is_initialized=true; } - } - - Patch_description& operator[](std::size_t i) { - extract_patch(i); return patches[i]; } @@ -880,7 +865,6 @@ void import_polyline( EdgeMap& pm1_to_output_edges, EdgeMap& pm2_to_output_edges, VertexMap& pm1_to_output_vertices, - VertexMap& pm2_to_output_vertices, const IntersectionEdgeMap& intersection_edges1, const IntersectionEdgeMap& intersection_edges2, const VertexPointMap1& vpm1, @@ -897,44 +881,47 @@ void import_polyline( output_shared_edges.push_back(add_edge(output)); halfedge_descriptor h_out = halfedge(output_shared_edges.back(),output); - auto set_output_vertex = [&](vertex_descriptor v, halfedge_descriptor h_out){ - user_visitor.before_vertex_copy(v, pm1, output); - vertex_descriptor new_v = add_vertex(output); - set_halfedge(new_v, h_out, output); - put(vpm_out, new_v, get(vpm1, v)); - user_visitor.after_vertex_copy(v, pm1, new_v, output); - return new_v; - }; - //make sure the first vertex does not already exist vertex_descriptor src = GT::null_vertex(); - if( get(pm1_to_output_vertices, source(h1,pm1)) == GT::null_vertex() ) + std::pair< typename VertexMap::iterator, bool > insert_res= + pm1_to_output_vertices.insert( std::make_pair( source(h1,pm1), src ) ); + + if( insert_res.second ) { - src = set_output_vertex(source(h1, pm1), opposite(h_out, output)); - put(pm1_to_output_vertices, source(h1,pm1), src); - put(pm2_to_output_vertices, source(h2,pm2), src); + user_visitor.before_vertex_copy(source(h1,pm1), pm1, output); + src = add_vertex(output); + set_halfedge(src, opposite(h_out,output),output); + put(vpm_out, src, get(vpm1, source(h1,pm1))); + user_visitor.after_vertex_copy(source(h1,pm1), pm1, src, output); + insert_res.first->second = src; } else - src = get(pm1_to_output_vertices, source(h1,pm1)); + src = insert_res.first->second; //make sure the target vertex does not already exist if it is a polyline endpoint - vertex_descriptor tgt = GT::null_vertex(); + vertex_descriptor tgt=GT::null_vertex(); if ( nb_segments==1 ) { - if( get(pm1_to_output_vertices, target(h1,pm1)) == GT::null_vertex() ) + insert_res = + pm1_to_output_vertices.insert( std::make_pair( target(h1,pm1), tgt ) ); + if( insert_res.second ) { - tgt = set_output_vertex(target(h1, pm1), h_out); - put(pm1_to_output_vertices, target(h1,pm1), tgt); - put(pm2_to_output_vertices, target(h2,pm2), tgt); + user_visitor.before_vertex_copy(target(h1,pm1), pm1, output); + tgt = add_vertex(output); + set_halfedge(tgt, h_out, output); + put(vpm_out, tgt, get(vpm1, target(h1,pm1))); + user_visitor.after_vertex_copy(target(h1,pm1), pm1, tgt, output); + insert_res.first->second = tgt; } else - tgt = get(pm1_to_output_vertices, target(h1,pm1)); + tgt = insert_res.first->second; } - else - { - tgt = set_output_vertex(target(h1, pm1), h_out); - put(pm1_to_output_vertices, target(h1,pm1), tgt); - put(pm2_to_output_vertices, target(h2,pm2), tgt); + else{ + user_visitor.before_vertex_copy(target(h1,pm1), pm1, output); + tgt = add_vertex(output); + set_halfedge(tgt, h_out, output); + put(vpm_out, tgt, get(vpm1, target(h1,pm1))); + user_visitor.after_vertex_copy(target(h1,pm1), pm1, tgt, output); } //update source and target vertex of the edge created @@ -946,11 +933,12 @@ void import_polyline( halfedge_descriptor prev2=h2; //set the correspondence - put(pm1_to_output_edges, edge(prev1, pm1), edge(prev_out, output)); - put(pm2_to_output_edges, edge(prev2, pm2), edge(prev_out, output)); + pm1_to_output_edges.insert( + std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); + pm2_to_output_edges.insert( + std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); user_visitor.intersection_edge_copy(prev1, pm1, prev2, pm2, h_out, output); - halfedge_descriptor first_h1 = h1, first_h_out = h_out; src=tgt; for (std::size_t i=1; i insert_res = + pm1_to_output_vertices.insert(std::make_pair(target(h1,pm1), tgt)); + if (insert_res.second) { - tgt = set_output_vertex(target(h1, pm1), h_out); - put( pm1_to_output_vertices, target(h1,pm1), tgt ); - put( pm2_to_output_vertices, target(h2,pm2), tgt ); + user_visitor.before_vertex_copy(target(h1,pm1), pm1, output); + tgt=add_vertex(output); + set_halfedge(tgt, h_out, output); + put(vpm_out, tgt, get(vpm1, target(h1,pm1))); + insert_res.first->second = tgt; + user_visitor.after_vertex_copy(target(h1,pm1), pm1, tgt, output); } else - tgt = get(pm1_to_output_vertices, target(h1,pm1)); - - if( target(h1, pm1) == source(first_h1, pm1) ) - { - // polyline is a loop - set_next(h_out, first_h_out, output); - set_next(opposite(first_h_out, output), opposite(h_out, output), output); - } + tgt = insert_res.first->second; } set_target(h_out, tgt, output); set_target(opposite(h_out, output), src, output); - set_next(prev_out, h_out, output); - set_next(opposite(h_out, output), opposite(prev_out, output), output); - prev_out=h_out; prev1 = h1; prev2 = h2; src = tgt; - put(pm1_to_output_edges, edge(prev1, pm1), edge(prev_out, output)); - put(pm2_to_output_edges, edge(prev2, pm2), edge(prev_out, output)); + pm1_to_output_edges.insert( + std::make_pair(edge(prev1, pm1), edge(prev_out, output)) ); + pm2_to_output_edges.insert( + std::make_pair(edge(prev2, pm2), edge(prev_out, output)) ); } } -template -struct Triangle_mesh_extension_helper +template +struct Triangle_mesh_extension_helper; + +template +struct Triangle_mesh_extension_helper { typedef boost::graph_traits GT; typedef typename GT::halfedge_descriptor halfedge_descriptor; typedef typename GT::edge_descriptor edge_descriptor; typedef typename GT::face_descriptor face_descriptor; - EdgeMap& tm_to_output_edges; - VertexMap& tm_to_output_vertices; + typedef std::unordered_map< edge_descriptor, edge_descriptor> Edge_map; + Edge_map& tm_to_output_edges; const TriangleMesh& tm; TriangleMesh& output; - Triangle_mesh_extension_helper(EdgeMap& tm_to_output_edges, - VertexMap& tm_to_output_vertices, + Triangle_mesh_extension_helper(Edge_map& tm_to_output_edges, const TriangleMesh& tm, TriangleMesh& output) : tm_to_output_edges(tm_to_output_edges) - , tm_to_output_vertices(tm_to_output_vertices) , tm(tm) , output(output) {} halfedge_descriptor get_hedge(halfedge_descriptor h_tm) { - edge_descriptor key = edge(h_tm, tm); - edge_descriptor value = get(tm_to_output_edges, key); - CGAL_assertion( value != edge(GT::null_halfedge(), tm) ); - if constexpr(reverse_patch_orientation) - return target(halfedge(value, output), output) == get(tm_to_output_vertices, target(h_tm, tm)) - ? opposite(halfedge(value, output), output) - : halfedge(value, output); - else - return target(halfedge(value, output), output) == get(tm_to_output_vertices, target(h_tm, tm)) - ? halfedge(value, output) - : opposite(halfedge(value, output), output); + CGAL_assertion( tm_to_output_edges.count(edge(h_tm, tm))!=0 ); + const std::pair& key_and_value = + *tm_to_output_edges.find(edge(h_tm, tm)); + return halfedge(key_and_value.first,tm) != h_tm + ? halfedge(key_and_value.second, output) + : opposite(halfedge(key_and_value.second, output), output); } std::array halfedges(face_descriptor f) { halfedge_descriptor h=halfedge(f,tm); - if constexpr(reverse_patch_orientation) - return make_array( get_hedge( h ), - get_hedge( prev(h,tm) ), - get_hedge( next(h,tm) ) ); - else - return make_array( get_hedge( h ), - get_hedge( next(h,tm) ), - get_hedge( prev(h,tm) ) ); + return make_array( get_hedge( h ), + get_hedge( prev(h,tm) ), + get_hedge( next(h,tm) ) ); } }; -template < bool reverse_patch_orientation, - class TriangleMesh, - class PatchContainer, - class EdgetoEdgeMap, - class VertextoVertexMap> -void process_borders_after_appending_patches( - TriangleMesh& output, - const std::vector &ids_of_patches_to_append, - PatchContainer& patches, - EdgetoEdgeMap& tm_to_output_edges, - VertextoVertexMap& tm_to_output_vertices) +template +struct Triangle_mesh_extension_helper { - // handle interior edges that are on the border of the mesh: - // they do not have a prev/next pointer set since only the pointers - // of patch interior halfedges part a face have been. In the following - // (i) we set the next/prev pointer around interior vertices on the mesh - // boundary and (ii) we collect interior mesh border halfedges incident to - // a patch border vertex and set their next/prev pointer (possibly of - // another patch) - - // Containers used for step (ii) for collecting mesh border halfedges - // with source/target on an intersection polyline that needs it prev/next - // pointer to be set - - using GT = boost::graph_traits; - using halfedge_descriptor = typename GT::halfedge_descriptor; - using vertex_descriptor = typename GT::vertex_descriptor; + typedef boost::graph_traits GT; + typedef typename GT::halfedge_descriptor halfedge_descriptor; + typedef typename GT::edge_descriptor edge_descriptor; + typedef typename GT::face_descriptor face_descriptor; - const TriangleMesh& tm = patches.pm; - Triangle_mesh_extension_helper helper(tm_to_output_edges, tm_to_output_vertices, tm, output); + typedef std::unordered_map< edge_descriptor, edge_descriptor> Edge_map; + Edge_map& tm_to_output_edges; + const TriangleMesh& tm; + TriangleMesh& output; - std::vector border_halfedges_source_to_link; - std::vector border_halfedges_target_to_link; - for (std::size_t i : ids_of_patches_to_append) - { - Patch_description& patch = patches[i]; - for(halfedge_descriptor h : patch.border_edges){ - if( (!reverse_patch_orientation && patch.border_with_shared_target.count(h)) || - ( reverse_patch_orientation && patch.border_with_shared_source.count(h)) ) - continue; // since the next halfedge should not be in the same patch - halfedge_descriptor h_out = helper.get_hedge(h); - halfedge_descriptor h_out_next = reverse_patch_orientation - ? helper.get_hedge(prev(h,tm)) - : helper.get_hedge(next(h,tm)); - CGAL_assertion(is_border(h_out,output) && is_border(h_out_next,output)); - set_next(h_out, h_out_next, output); - } - if(reverse_patch_orientation){ - for(halfedge_descriptor h : patch.border_with_shared_source){ - halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); - if(!is_border(h_out, output)) h_out = opposite(h_out, output); - border_halfedges_target_to_link.push_back(h_out); - } - for(halfedge_descriptor h : patch.border_with_shared_target){ - halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); - if(!is_border(h_out, output)) h_out = opposite(h_out, output); - border_halfedges_source_to_link.push_back(h_out); - } - } else { - for(halfedge_descriptor h : patch.border_with_shared_target){ - halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); - if(!is_border(h_out, output)) h_out = opposite(h_out, output); - border_halfedges_target_to_link.push_back(h_out); - } - for(halfedge_descriptor h : patch.border_with_shared_source){ - halfedge_descriptor h_out = halfedge(get(tm_to_output_edges, edge(h, tm)), tm); - if(!is_border(h_out, output)) h_out = opposite(h_out, output); - border_halfedges_source_to_link.push_back(h_out); - } - } - } + Triangle_mesh_extension_helper(Edge_map& tm_to_output_edges, + const TriangleMesh& tm, + TriangleMesh& output) + : tm_to_output_edges(tm_to_output_edges) + , tm(tm) + , output(output) + {} - // now the step (ii) we look for the candidate halfedge by turning around - // the vertex in the direction of the interior of the patch - for(halfedge_descriptor h_out : border_halfedges_target_to_link) + halfedge_descriptor get_hedge(halfedge_descriptor h_tm) { - halfedge_descriptor candidate = - opposite(prev(opposite(h_out, output), output), output); - CGAL_assertion_code(halfedge_descriptor start=candidate); - while (!is_border(candidate, output)){ - candidate=opposite(prev(candidate, output), output); - CGAL_assertion(candidate!=start); - } - set_next(h_out, candidate, output); + CGAL_assertion( tm_to_output_edges.count(edge(h_tm, tm))!=0 ); + const std::pair& key_and_value = + *tm_to_output_edges.find(edge(h_tm, tm)); + return halfedge(key_and_value.first,tm) == h_tm + ? halfedge(key_and_value.second, output) + : opposite(halfedge(key_and_value.second, output), output); } - for(halfedge_descriptor h_out : border_halfedges_source_to_link) + std::array + halfedges(face_descriptor f) { - halfedge_descriptor candidate = - opposite(next(opposite(h_out, output), output), output); - while (!is_border(candidate, output)) - candidate = opposite(next(candidate, output), output); - set_next(candidate, h_out, output); + halfedge_descriptor h=halfedge(f,tm); + return make_array( get_hedge( h ), + get_hedge( next(h,tm) ), + get_hedge( prev(h,tm) ) ); } +}; - for (std::size_t i : ids_of_patches_to_append) - { - Patch_description& patch = patches[i]; - // For all patch boundary vertices, update the vertex pointer - // of all but the vertex halfedge - for(halfedge_descriptor h : patch.shared_edges) - { - //check for a halfedge pointing inside an already imported patch - halfedge_descriptor h_out = helper.get_hedge(h); - CGAL_assertion( next(h_out, output)!=GT::null_halfedge() ); - // update the pointers on the target - halfedge_descriptor next_around_target=h_out; - vertex_descriptor v=target(h_out, output); - do{ - next_around_target = opposite(next(next_around_target, output), output); - set_target(next_around_target, v, output); - }while(next(next_around_target, output)!=GT::null_halfedge() && - next_around_target!=h_out && - !is_border(next_around_target, output)); - // update the pointers on the source - halfedge_descriptor next_around_source=prev(h_out, output); - CGAL_assertion(next_around_source!=GT::null_halfedge()); - v = source(h_out, output); - do{ - set_target(next_around_source, v, output); - next_around_source = prev(opposite(next_around_source, output), output); - }while( next_around_source!=GT::null_halfedge() && - next_around_source!=opposite(h_out, output) && - !is_border(next_around_source, output)); - } - } -} -template < class Concurrency_tag, - bool reverse_patch_orientation, +template < bool reverse_patch_orientation, class TriangleMesh, class PatchContainer, class VertexPointMap, class VertexPointMapOut, class EdgeCstMapOut, class EdgeMarkMapOut, class EdgeCstMapIn , class EdgeMarkMapIn , - class EdgetoEdgeMap, - class VertextoVertexMap, class UserVisitor> -auto append_patches_to_triangle_mesh( +void append_patches_to_triangle_mesh( TriangleMesh& output, const boost::dynamic_bitset<>& patches_to_append, PatchContainer& patches, @@ -1205,21 +1094,21 @@ auto append_patches_to_triangle_mesh( const VertexPointMap& vpm_tm, EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, - EdgetoEdgeMap& tm_to_output_edges, - VertextoVertexMap& tm_to_output_vertices, + std::unordered_map< + typename boost::graph_traits::edge_descriptor, + typename boost::graph_traits::edge_descriptor + >& tm_to_output_edges, UserVisitor& user_visitor) -#ifndef CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS - -> std::enable_if_t::value> -#endif { - using GT = boost::graph_traits; - using halfedge_descriptor = typename GT::halfedge_descriptor; - using edge_descriptor = typename GT::edge_descriptor; - using vertex_descriptor = typename GT::vertex_descriptor; - using face_descriptor = typename GT::face_descriptor; + typedef boost::graph_traits GT; + typedef typename GT::halfedge_descriptor halfedge_descriptor; + typedef typename GT::edge_descriptor edge_descriptor; + typedef typename GT::vertex_descriptor vertex_descriptor; + typedef typename GT::face_descriptor face_descriptor; - TriangleMesh& tm = patches.pm; - Triangle_mesh_extension_helper helper(tm_to_output_edges, tm_to_output_vertices, tm, output); + const TriangleMesh& tm = patches.pm; + Triangle_mesh_extension_helper + helper(tm_to_output_edges, tm, output); std::vector ids_of_patches_to_append; ids_of_patches_to_append.reserve(patches_to_append.count()); @@ -1230,6 +1119,7 @@ auto append_patches_to_triangle_mesh( ids_of_patches_to_append.push_back(i); } + std::vector interior_vertex_halfedges; for (std::size_t i : ids_of_patches_to_append) { #ifdef CGAL_COREFINEMENT_POLYHEDRA_DEBUG @@ -1241,17 +1131,7 @@ auto append_patches_to_triangle_mesh( Patch_description& patch = patches[i]; - // copy the vertices in the output without connecting them - for(vertex_descriptor v: patch.interior_vertices) - { - vertex_descriptor new_v = add_vertex(output); - set_halfedge(new_v, GT::null_halfedge(), output); - - put(tm_to_output_vertices, v, new_v); - put(vpm_out, new_v, get(vpm_tm, v)); - } - - // insert interior halfedges and connect vertices + //insert interior halfedges and create interior vertices for(halfedge_descriptor h : patch.interior_edges) { user_visitor.before_edge_copy(h, tm, output); @@ -1263,7 +1143,7 @@ auto append_patches_to_triangle_mesh( copy_constraint_status(ed, new_edge, edge_mark_map_in, edge_mark_map_out); halfedge_descriptor new_h = halfedge(new_edge, output); - put(tm_to_output_edges, ed, new_edge); + tm_to_output_edges[ed] = new_edge; set_face(new_h, GT::null_face(), output); set_face(opposite(new_h, output), GT::null_face(), output); @@ -1272,31 +1152,28 @@ auto append_patches_to_triangle_mesh( CGAL_assertion(is_border(opposite(new_h,output), output)); //create a copy of interior vertices only once - auto fill_vertex = [&](vertex_descriptor v, vertex_descriptor new_v, halfedge_descriptor new_h){ - user_visitor.before_vertex_copy(v, tm, output); - set_halfedge(new_v, new_h, output); - user_visitor.after_vertex_copy(v, tm, new_v, output); - }; - - vertex_descriptor tgt = target(h, tm); - vertex_descriptor new_tgt = get(tm_to_output_vertices, tgt); - CGAL_assertion( new_tgt != GT::null_vertex() ); - set_target(new_h, new_tgt, output); - if ( halfedge(tgt,tm)==h && - halfedge(new_tgt, output) == GT::null_halfedge()) + if ( halfedge(target(h,tm),tm)==h && + patch.interior_vertices.count(target(h, tm)) ) { - fill_vertex(tgt, new_tgt, new_h); + user_visitor.before_vertex_copy(target(h,tm), tm, output); + vertex_descriptor v = add_vertex(output); + set_halfedge(v, new_h, output); + set_target(new_h, v, output); + put(vpm_out, v, get(vpm_tm, target(h, tm) ) ); + user_visitor.after_vertex_copy(target(h,tm), tm, v, output); + interior_vertex_halfedges.push_back( new_h ); } - - vertex_descriptor src = source(h, tm); - vertex_descriptor new_src = get(tm_to_output_vertices, src); - CGAL_assertion( new_src != GT::null_vertex() ); - halfedge_descriptor new_h_opp = opposite(new_h, output); - set_target(new_h_opp, new_src, output); - if ( halfedge(src,tm)==opposite(h, tm) && - halfedge(new_src, output) == GT::null_halfedge()) + if ( halfedge(source(h,tm),tm)==opposite(h,tm) && + patch.interior_vertices.count(source(h,tm)) ) { - fill_vertex(src, new_src, new_h_opp); + user_visitor.before_vertex_copy(source(h,tm), tm, output); + vertex_descriptor v = add_vertex(output); + halfedge_descriptor new_h_opp = opposite(new_h, output); + set_halfedge(v, new_h_opp, output); + set_target(new_h_opp, v, output); + put(vpm_out, v, get(vpm_tm, source(h, tm) ) ); + user_visitor.after_vertex_copy(source(h,tm), tm, v, output); + interior_vertex_halfedges.push_back( new_h_opp ); } } } @@ -1324,52 +1201,120 @@ auto append_patches_to_triangle_mesh( } } - process_borders_after_appending_patches(output, - ids_of_patches_to_append, - patches, - tm_to_output_edges, - tm_to_output_vertices); -} + // handle interior edges that are on the border of the mesh: + // they do not have a prev/next pointer set since only the pointers + // of patch interior halfedges part a face have been. In the following + // (i) we set the next/prev pointer around interior vertices on the mesh + // boundary and (ii) we collect interior mesh border halfedges incident to + // a patch border vertex and set their next/prev pointer (possibly of + // another patch) -template < bool reverse_patch_orientation, - class TriangleMesh, - class PatchContainer, - class VertexPointMap, - class VertexPointMapOut, - class EdgeCstMapOut, class EdgeMarkMapOut, - class EdgeCstMapIn , class EdgeMarkMapIn , - class EdgetoEdgeMap, - class VertextoVertexMap, - class UserVisitor> -auto append_patches_to_triangle_mesh( - TriangleMesh& output, - const boost::dynamic_bitset<>& patches_to_append, - PatchContainer& patches, - const VertexPointMapOut& vpm_out, - const VertexPointMap& vpm_tm, - EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, - const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, - EdgetoEdgeMap& tm_to_output_edges, - VertextoVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) -#ifndef CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS - -> std::enable_if_t::value> -#endif -{ - append_patches_to_triangle_mesh(output, - patches_to_append, - patches, - vpm_out, - vpm_tm, - edge_cst_map_out, edge_mark_map_out, - edge_cst_map_in, edge_mark_map_in, - tm_to_output_edges, - tm_to_output_vertices, - user_visitor); + // Containers used for step (ii) for collecting mesh border halfedges + // with source/target on an intersection polyline that needs it prev/next + // pointer to be set + std::vector border_halfedges_source_to_link; + std::vector border_halfedges_target_to_link; + for (std::size_t i : ids_of_patches_to_append) + { + Patch_description& patch = patches[i]; + for(halfedge_descriptor h : patch.interior_edges) + if (is_border_edge(h,tm)) + { + if (!is_border(h, tm)) h=opposite(h, tm); + + vertex_descriptor src = source(h, tm); + vertex_descriptor tgt = target(h, tm); + if (reverse_patch_orientation) std::swap(src, tgt); + + if ( !patch.interior_vertices.count(src) ) + border_halfedges_source_to_link.push_back(helper.get_hedge(h)); + if ( !patch.interior_vertices.count(tgt) ){ + border_halfedges_target_to_link.push_back(helper.get_hedge(h)); + continue; // since the next halfedge should not be in the same patch + } + CGAL_assertion( is_border(h, tm) && + is_border(prev(h, tm),tm) && + is_border(next(h, tm),tm)); + // step (i) + halfedge_descriptor h_out=helper.get_hedge(h); + halfedge_descriptor h_out_next = reverse_patch_orientation + ? helper.get_hedge(prev(h,tm)) + : helper.get_hedge(next(h,tm)); + CGAL_assertion(is_border(h_out,output) && is_border(h_out_next,output)); + set_next(h_out, h_out_next, output); + } + } + + // now the step (ii) we look for the candidate halfedge by turning around + // the vertex in the direction of the interior of the patch + for(halfedge_descriptor h_out : border_halfedges_target_to_link) + { + halfedge_descriptor candidate = + opposite(prev(opposite(h_out, output), output), output); + CGAL_assertion_code(halfedge_descriptor start=candidate); + while (!is_border(candidate, output)){ + candidate=opposite(prev(candidate, output), output); + CGAL_assertion(candidate!=start); + } + set_next(h_out, candidate, output); + } + + for(halfedge_descriptor h_out : border_halfedges_source_to_link) + { + halfedge_descriptor candidate = + opposite(next(opposite(h_out, output), output), output); + while (!is_border(candidate, output)) + candidate = opposite(next(candidate, output), output); + set_next(candidate, h_out, output); + } + + // For all interior vertices, update the vertex pointer + // of all but the vertex halfedge + for(halfedge_descriptor h_out : interior_vertex_halfedges) + { + vertex_descriptor v = target(h_out, output); + halfedge_descriptor next_around_vertex=h_out; + do{ + CGAL_assertion(next(next_around_vertex, output) != GT::null_halfedge()); + next_around_vertex=opposite(next(next_around_vertex, output), output); + set_target(next_around_vertex, v, output); + }while(h_out != next_around_vertex); + } + + for (std::size_t i : ids_of_patches_to_append) + { + Patch_description& patch = patches[i]; + // For all patch boundary vertices, update the vertex pointer + // of all but the vertex halfedge + for(halfedge_descriptor h : patch.shared_edges) + { + //check for a halfedge pointing inside an already imported patch + halfedge_descriptor h_out = helper.get_hedge(h); + CGAL_assertion( next(h_out, output)!=GT::null_halfedge() ); + // update the pointers on the target + halfedge_descriptor next_around_target=h_out; + vertex_descriptor v=target(h_out, output); + do{ + next_around_target = opposite(next(next_around_target, output), output); + set_target(next_around_target, v, output); + }while(next(next_around_target, output)!=GT::null_halfedge() && + next_around_target!=h_out && + !is_border(next_around_target, output)); + // update the pointers on the source + halfedge_descriptor next_around_source=prev(h_out, output); + CGAL_assertion(next_around_source!=GT::null_halfedge()); + v = source(h_out, output); + do{ + set_target(next_around_source, v, output); + next_around_source = prev(opposite(next_around_source, output), output); + }while( next_around_source!=GT::null_halfedge() && + next_around_source!=opposite(h_out, output) && + !is_border(next_around_source, output)); + } + } } -template < class ConcurrencyTag = Sequential_tag, - class TriangleMesh, +template < class TriangleMesh, class IntersectionEdgeMap, class VertexPointMap1, class VertexPointMap2, @@ -1381,7 +1326,7 @@ template < class ConcurrencyTag = Sequential_tag, class PatchContainer1, class PatchContainer2, class UserVisitor> -auto fill_new_triangle_mesh( +void fill_new_triangle_mesh( TriangleMesh& output, const boost::dynamic_bitset<>& patches_of_tm1_to_import, const boost::dynamic_bitset<>& patches_of_tm2_to_import, @@ -1401,43 +1346,31 @@ auto fill_new_triangle_mesh( std::vector< typename boost::graph_traits::edge_descriptor>& output_shared_edges, UserVisitor& user_visitor) -#ifndef CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS - -> std::enable_if_t::value> -#endif { - using GT = boost::graph_traits; - using vertex_descriptor = typename GT::vertex_descriptor; - using edge_descriptor = typename GT::edge_descriptor; - - using V2V_tag = typename CGAL::dynamic_vertex_property_t; - using Vertex_to_vertex_map = typename boost::property_map::type; - - using E2E_tag = typename CGAL::dynamic_edge_property_t; - using Edge_to_edge_map = typename boost::property_map::type; - - TriangleMesh& tm1 = patches_of_tm1.pm; - TriangleMesh& tm2 = patches_of_tm2.pm; - - Vertex_to_vertex_map tm1_to_output_vertices = get(V2V_tag(), tm1, GT::null_vertex()), - tm2_to_output_vertices = get(V2V_tag(), tm2, GT::null_vertex()); - Edge_to_edge_map tm1_to_output_edges = get(E2E_tag(), tm1, edge(GT::null_halfedge(), tm1)), - tm2_to_output_edges = get(E2E_tag(), tm2, edge(GT::null_halfedge(), tm2)); + typedef boost::graph_traits GT; + typedef typename GT::vertex_descriptor vertex_descriptor; + typedef typename GT::edge_descriptor edge_descriptor; // this is the minimal number of edges that will be marked (intersection edge). // We cannot easily have the total number since some patch interior edges might be marked - output_shared_edges.reserve(std::accumulate(polylines.lengths.begin(),polylines.lengths.end(),std::size_t(0)) ); + output_shared_edges.reserve( + std::accumulate(polylines.lengths.begin(),polylines.lengths.end(),std::size_t(0)) ); //add a polyline inside O for each intersection polyline std::size_t nb_polylines = polylines.lengths.size(); + std::unordered_map tm1_to_output_vertices; + std::unordered_map tm1_to_output_edges, + tm2_to_output_edges; for (std::size_t i=0; i < nb_polylines; ++i) if (!polylines.to_skip.test(i)) import_polyline(output, polylines.tm1[i], polylines.tm2[i], - tm1, tm2, + patches_of_tm1.pm, + patches_of_tm2.pm, polylines.lengths[i], tm1_to_output_edges, tm2_to_output_edges, - tm1_to_output_vertices, tm2_to_output_vertices, + tm1_to_output_vertices, intersection_edges1, intersection_edges2, vpm1, vpm2, vpm_out, output_shared_edges, @@ -1455,7 +1388,6 @@ auto fill_new_triangle_mesh( edge_cst_map1, edge_mark_map1, tm1_to_output_edges, - tm1_to_output_vertices, user_visitor); else append_patches_to_triangle_mesh(output, @@ -1468,7 +1400,6 @@ auto fill_new_triangle_mesh( edge_cst_map1, edge_mark_map1, tm1_to_output_edges, - tm1_to_output_vertices, user_visitor); //import patches from tm2 @@ -1483,7 +1414,6 @@ auto fill_new_triangle_mesh( edge_cst_map2, edge_mark_map2, tm2_to_output_edges, - tm2_to_output_vertices, user_visitor); else append_patches_to_triangle_mesh(output, @@ -1496,14 +1426,12 @@ auto fill_new_triangle_mesh( edge_cst_map2, edge_mark_map2, tm2_to_output_edges, - tm2_to_output_vertices, user_visitor); } template void disconnect_patches( TriangleMesh& tm1, @@ -1511,8 +1439,6 @@ void disconnect_patches( PatchContainer& patches_of_tm1, const EdgeMap& tm1_edge_to_tm2_edge, //map intersection edges of tm1 to the equivalent in tm2 EdgeMap& new_tm1_edge_to_tm2_edge, //map the new intersection edges of tm1 to the equivalent in tm2 - VertexMap& tm1_vertex_to_tm2_vertex, //map intersection vertices of tm1 to the equivalent in tm2 - VertexMap& new_tm1_vertex_to_tm2_vertex, //map the new intersection vertices UserVisitor& user_visitor) { typedef boost::graph_traits GT; @@ -1642,22 +1568,14 @@ void disconnect_patches( CGAL_assertion( is_border(next(opposite(new_patch_border[k], tm1), tm1), tm1) ); CGAL_assertion( is_border(prev(opposite(new_patch_border[k], tm1), tm1), tm1) ); - auto e = get(tm1_edge_to_tm2_edge, edge(patch.shared_edges[k], tm1)); - auto src = get(tm1_vertex_to_tm2_vertex, source(patch.shared_edges[k], tm1)); - auto tgt = get(tm1_vertex_to_tm2_vertex, target(patch.shared_edges[k], tm1)); - CGAL_assertion( src != GT::null_vertex() ); - CGAL_assertion( tgt != GT::null_vertex() ); + typename EdgeMap::const_iterator it_res = + tm1_edge_to_tm2_edge.find( edge(patch.shared_edges[k], tm1) ); + CGAL_assertion( it_res != tm1_edge_to_tm2_edge.end() ); - /* halfedge(edge(h, g)) == h is a requirement of the concept and so the if is useless, TODO Sebastien can you confirm - put(new_tm1_edge_to_tm2_edge, - patch.shared_edges[k]==halfedge(edge(patch.shared_edges[k], tm1), tm1) + new_tm1_edge_to_tm2_edge[ + patch.shared_edges[k]==halfedge(it_res->first, tm1) ? edge(new_patch_border[k], tm1) - : edge(opposite(new_patch_border[k], tm1), tm1), - e); - */ - put(new_tm1_edge_to_tm2_edge, edge(new_patch_border[k], tm1), e); - put(new_tm1_vertex_to_tm2_vertex, target(new_patch_border[k], tm1), tgt); - put(new_tm1_vertex_to_tm2_vertex, source(new_patch_border[k], tm1), src); + : edge(opposite(new_patch_border[k], tm1), tm1) ] = it_res->second; } patch.shared_edges.swap(new_patch_border); @@ -1669,7 +1587,6 @@ template GT; - typedef typename GT::vertex_descriptor vertex_descriptor; typedef typename GT::edge_descriptor edge_descriptor; typedef typename GT::halfedge_descriptor halfedge_descriptor; + typedef std::unordered_map Edge_map; - using V2V_tag = typename CGAL::dynamic_vertex_property_t; - using E2E_tag = typename CGAL::dynamic_edge_property_t; - - EdgeMap tm2_edge_to_tm1_edge = get(E2E_tag(), tm2, edge(GT::null_halfedge(), tm2)), - tm1_edge_to_tm2_edge = get(E2E_tag(), tm1, edge(GT::null_halfedge(), tm1)); - VertexMap tm2_vertex_to_tm1_vertex = get(V2V_tag(), tm2, GT::null_vertex()), - tm1_vertex_to_tm2_vertex = get(V2V_tag(), tm1, GT::null_vertex()); + Edge_map tm2_edge_to_tm1_edge, tm1_edge_to_tm2_edge; //maps intersection edges from tm2 to tm1 std::size_t nb_polylines = polylines.lengths.size(); for(std::size_t i=0; i(tm1, @@ -1770,7 +1673,6 @@ void compute_inplace_operation_delay_removal_and_insideout( edge_cst_map2, edge_mark_map2, tm2_edge_to_tm1_edge, - tm2_vertex_to_tm1_vertex, user_visitor); } @@ -1820,37 +1722,24 @@ remove_patches(TriangleMesh& tm, // prev pointer set correctly. To fix that, we consider all interior edges // and check for one that is on the border of the patch and that is incident // to a border vertex and use it to get the missing prev pointer. - for(halfedge_descriptor h : patch.border_with_shared_target) - { - // look for the halfedge belonging to shared_edges - // having the prev pointer not correctly set - halfedge_descriptor nxt=next(h, tm); - CGAL_assertion(is_border(nxt, tm)); - - // now update the prev pointer - halfedge_descriptor prv=prev(opposite(h, tm), tm); - while(!is_border(prv, tm)) - prv=prev(opposite(prv, tm), tm); - - set_next(prv, nxt, tm); - set_halfedge(target(prv, tm), prv, tm); - } - - for(halfedge_descriptor h : patch.border_with_shared_source) - { - // look for the halfedge belonging to shared_edges - // having the prev pointer not correctly set - halfedge_descriptor prv=prev(h, tm); - CGAL_assertion(is_border(prv, tm)); - - // now update the next pointer - halfedge_descriptor nxt=next(opposite(h, tm), tm); - while(!is_border(nxt, tm)) - nxt=next(opposite(nxt, tm), tm); - - set_next(prv, nxt, tm); - set_halfedge(target(prv, tm), prv, tm); - } + for(halfedge_descriptor h : patch.interior_edges) + if(is_border_edge(h, tm)) + { + if (is_border(h, tm)) h=opposite(h, tm); + if ( !patch.interior_vertices.count(target(h, tm)) ) + { + // look for the halfedge belonging to shared_edges + // having the prev pointer not correctly set + halfedge_descriptor nxt=next(h, tm); + while(!is_border(nxt, tm)) + nxt=next(opposite(nxt, tm), tm); + CGAL_assertion( is_border(nxt, tm) );//we marked it above! + // now update the prev pointer + halfedge_descriptor prv=prev(opposite(h, tm), tm); + set_next(prv, nxt, tm); + set_halfedge(target(prv, tm), prv, tm); + } + } //now remove the simplices for(halfedge_descriptor h : patch.interior_edges) @@ -1870,12 +1759,10 @@ template void compute_inplace_operation( TriangleMesh& tm1, - const TriangleMesh& tm2, + const TriangleMesh& /*tm2*/, const boost::dynamic_bitset<>& patches_of_tm1_to_keep, const boost::dynamic_bitset<>& patches_of_tm2_to_import, PatchContainer1& patches_of_tm1, @@ -1887,11 +1774,15 @@ void compute_inplace_operation( EdgeCstMapIn1 edge_cst_map_in1, EdgeCstMapIn2 edge_cst_map_in2, EdgeMarkMapIn1 edge_mark_map_in1, EdgeMarkMapIn2 edge_mark_map_in2, EdgeCstMapOut edge_cst_map_out, EdgeMarkMapOut edge_mark_map_out, - EdgeToEdgeMap& tm2_edge_to_tm1_edge, - VertexToVertexMap& tm2_vertex_to_tm1_vertex, - UserVisitor& user_visitor) + std::unordered_map< + typename boost::graph_traits::edge_descriptor, + typename boost::graph_traits::edge_descriptor + >& tm2_edge_to_tm1_edge, + UserVisitor& user_visitor) { - using edge_descriptor = typename boost::graph_traits::edge_descriptor; + typedef std::unordered_map< + typename boost::graph_traits::edge_descriptor, + typename boost::graph_traits::edge_descriptor> EdgeMap; //clean up patches not kept remove_patches(tm1, ~patches_of_tm1_to_keep, patches_of_tm1, edge_cst_map_in1, edge_mark_map_in1); @@ -1900,14 +1791,12 @@ void compute_inplace_operation( copy_constraint_status(tm1, edge_mark_map_in1, edge_mark_map_out); if (reverse_patch_orientation_tm1){ - Polygon_mesh_processing::reverse_face_orientations_of_mesh_with_polylines(tm1); + Polygon_mesh_processing:: + reverse_face_orientations_of_mesh_with_polylines(tm1); // here we need to update the mapping to use the correct border // halfedges while appending the patches from tm2 - for(edge_descriptor e2: edges(tm2)){ - edge_descriptor e1 = get(tm2_edge_to_tm1_edge, e2); - if (e1 != edge(boost::graph_traits::null_halfedge(), tm1)) - put(tm2_edge_to_tm1_edge, e2, edge(opposite(halfedge(e1, tm1), tm1), tm1)); - } + for(typename EdgeMap::value_type& v : tm2_edge_to_tm1_edge) + v.second=edge(opposite(halfedge(v.second, tm1), tm1), tm1); } //we import patches from tm2 @@ -1922,7 +1811,6 @@ void compute_inplace_operation( edge_cst_map_in2, edge_mark_map_in2, tm2_edge_to_tm1_edge, - tm2_vertex_to_tm1_vertex, user_visitor); else append_patches_to_triangle_mesh(tm1, @@ -1935,7 +1823,6 @@ void compute_inplace_operation( edge_cst_map_in2, edge_mark_map_in2, tm2_edge_to_tm1_edge, - tm2_vertex_to_tm1_vertex, user_visitor); } @@ -1943,16 +1830,14 @@ template + class EdgeMap> void compute_border_edge_map( const TriangleMesh& tm1, const TriangleMesh& tm2, const IntersectionPolylines& polylines, PatchContainer1& patches_of_tm1, PatchContainer2& patches_of_tm2, - EdgeMap& tm2_edge_to_tm1_edge, - VertexMap& tm2_vertex_to_tm1_vertex) + EdgeMap& tm2_edge_to_tm1_edge) { typedef boost::graph_traits GT; typedef typename GT::halfedge_descriptor halfedge_descriptor; @@ -1967,9 +1852,7 @@ void compute_border_edge_map( for (std::size_t k=0;;) { - put(tm2_edge_to_tm1_edge, edge(h2, tm2), edge(h1, tm1)); - put(tm2_vertex_to_tm1_vertex, target(h2, tm2), target(h1, tm1)); - put(tm2_vertex_to_tm1_vertex, source(h2, tm2), source(h1, tm1)); + tm2_edge_to_tm1_edge[edge(h2, tm2)]=edge(h1, tm1); if (++k==nb_segments) break; h2 = next_marked_halfedge_around_target_vertex( h2, tm2, patches_of_tm2.is_intersection_edge); @@ -2009,23 +1892,14 @@ void compute_inplace_operation( { typedef boost::graph_traits GT; typedef typename GT::edge_descriptor edge_descriptor; - typedef typename GT::vertex_descriptor vertex_descriptor; - using V2V_tag = typename CGAL::dynamic_vertex_property_t; - using Vertex_to_vertex_map = typename boost::property_map::const_type; - - using E2E_tag = typename CGAL::dynamic_edge_property_t; - using Edge_to_edge_map = typename boost::property_map::const_type; - - Edge_to_edge_map tm2_edge_to_tm1_edge = get(E2E_tag(), tm2); - Vertex_to_vertex_map tm2_vertex_to_tm1_vertex = get(V2V_tag(), tm2, GT::null_vertex()); + std::unordered_map tm2_edge_to_tm1_edge; //maps intersection edges from tm2 to the equivalent in tm1 compute_border_edge_map(tm1, tm2, polylines, patches_of_tm1, patches_of_tm2, - tm2_edge_to_tm1_edge, - tm2_vertex_to_tm1_vertex); + tm2_edge_to_tm1_edge); compute_inplace_operation(tm1, tm2, patches_of_tm1_to_keep, patches_of_tm2_to_import, @@ -2038,7 +1912,6 @@ void compute_inplace_operation( edge_mark_map_in1, edge_mark_map_in2, edge_cst_map_out, edge_mark_map_out, tm2_edge_to_tm1_edge, - tm2_vertex_to_tm1_vertex, user_visitor); } @@ -2181,8 +2054,4 @@ void remove_disconnected_patches( } } } // CGAL::Polygon_mesh_processing::Corefinement -#ifndef CGAL_DO_NOT_USE_SURFACE_MESH_SPECIALIZATIONS -#include -#endif - #endif // CGAL_POLYGON_MESH_PROCESSING_INTERNAL_FACE_GRAPH_UTILS_H From 02eb118c624cef77fc3220cf102f42d526d5cedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 26 Oct 2026 18:49:31 +0100 Subject: [PATCH 083/136] Solved conflict with main --- Installation/CHANGES.md | 3 --- .../include/CGAL/Polygon_mesh_processing/autorefinement.h | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 3f57dcd26692..ae9c69805436 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -71,10 +71,8 @@ Release date: December 2026 - The corefinement based operations (including Boolean operations) has been optimized to better handle cases when some identical faces are shared between the input meshes. This leads to a significant speed up in those cases. -<<<<<<< HEAD - `corefine()` and its variants now have a named parameter `concurrency_tag`, specifying whether the task should be performed using a single or multiple threads. - The running time of `corefine()`, `autorefine()` and their variants has been improved. -======= - Added new multithreading compatible functions operating directly on triangle soups, enabling the handling of non-manifold input and output volumes: `CGAL::Polygon_mesh_processing::compute_union()`, `CGAL::Polygon_mesh_processing::compute_intersection()`, and `CGAL::Polygon_mesh_processing::compute_difference()`. @@ -84,7 +82,6 @@ Release date: December 2026 - **Breaking change** The return type as well as type of the parameter for the file name passed to IO functions is changed from `std::string` to `std::filesystem::path`, which enables to use non latin languages like Chinese for directory and file names. - Added overloaded versions of the functions `CGAL::IO::read_MEDIT()` and `CGAL::IO::write_MEDIT()`, for indexed tetrahedron soups. ->>>>>>> origin/main ### [Basic Viewer](https://doc.cgal.org/6.3/Manual/packages.html#PkgBasicViewer) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h index eaf53038719e..547b232cbebe 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h @@ -24,6 +24,8 @@ #include #include +#include + #ifdef CGAL_AUTOREF_USE_PROGRESS_DISPLAY #include #endif From d1595b339f14f1515e256dbed8d3c296fb4df793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 26 Oct 2026 18:51:26 +0100 Subject: [PATCH 084/136] remove surface_mesh_specializations.h --- .../surface_mesh_specializations.h | 530 ------------------ 1 file changed, 530 deletions(-) delete mode 100644 PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h deleted file mode 100644 index ee244ee4b1b4..000000000000 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/surface_mesh_specializations.h +++ /dev/null @@ -1,530 +0,0 @@ -// Copyright (c) 2026 GeometryFactory (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Leo Valque - -#ifndef CGAL_SURFACE_MESH_BOOLEAN_OPERATIONS_UTILS_H -#define CGAL_SURFACE_MESH_BOOLEAN_OPERATIONS_UTILS_H - -#include - -#include - -#ifdef CGAL_LINKED_WITH_TBB -#include -#endif - -#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION -#include -#endif - -namespace CGAL { -namespace Polygon_mesh_processing { -namespace Corefinement { - -// Specialization of the function for Surface_mesh to exploit vectors structure of Surface_mesh. -template < class ConcurrencyTag, - bool reverse_patch_orientation, - class SurfaceMesh, - class PatchDescription, - class VertexPointMap, - class VertexPointMapOut, - class EdgeCstMapOut, class EdgeMarkMapOut, - class EdgeCstMapIn , class EdgeMarkMapIn , - class EdgeToEdgeMap, - class VertexToVertexMap, - class UserVisitor> -void append_patch( - SurfaceMesh& tm, - SurfaceMesh& output, - PatchDescription& patch, - const VertexPointMapOut& vpm_out, - const VertexPointMap& vpm_tm, - EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, - const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, - EdgeToEdgeMap& tm_to_output_edges, - VertexToVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor, - std::size_t vertices_idx_begin, - std::size_t edges_idx_begin, - std::size_t faces_idx_begin) -{ - using SM = SurfaceMesh; - using size_type = typename SM::size_type; - using vertex_descriptor = typename SM::Vertex_index; - using edge_descriptor = typename SM::Edge_index; - using halfedge_descriptor = typename SM::Halfedge_index; - using face_descriptor = typename SM::Face_index; - - // Fill Vertex to vertex map and vpm for interior vertices - auto fill_vertex = [&](std::size_t i){ - vertex_descriptor v = patch.interior_vertices[i]; - vertex_descriptor new_v(static_cast(vertices_idx_begin + i)); - - put(tm_to_output_vertices, v, new_v); - put(vpm_out, new_v, get(vpm_tm, v)); - output.set_halfedge(new_v, SM::null_halfedge()); - }; - -#ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v){ - tbb::parallel_for(std::size_t(0), patch.interior_vertices.size(), fill_vertex); - } - else -#endif - { - for(std::size_t i=0; i(i+edges_idx_begin)); - halfedge_descriptor new_h = output.halfedge(new_edge); - - vertex_descriptor src = get(tm_to_output_vertices, tm.source(h)); - vertex_descriptor tgt = get(tm_to_output_vertices, tm.target(h)); - user_visitor.before_edge_copy(h, tm, output); - put(tm_to_output_edges, tm.edge(h), new_edge); - output.set_target(output.opposite(new_h), src); - output.set_target(new_h, tgt); - user_visitor.after_edge_copy(h, tm, new_h, output); - - // copy the mark on input edge to the output edge - copy_constraint_status(tm.edge(h), new_edge, edge_cst_map_in, edge_cst_map_out); - copy_constraint_status(tm.edge(h), new_edge, edge_mark_map_in, edge_mark_map_out); - - CGAL_assertion(is_border(new_h, output)); - CGAL_assertion(is_border(opposite(new_h, output), output)); - - // Fill the halfedge of the vertices if it is not set yet - if (tm.halfedge(tm.target(h)) == h && - output.halfedge(output.target(new_h)) == SM::null_halfedge()){ - user_visitor.before_vertex_copy(tm.target(h), tm, output); // Call visitor when the vertex would be complete - output.set_halfedge(output.target(new_h), new_h); - user_visitor.after_vertex_copy(tm.target(h), tm, output.target(new_h), output); - } - - if (tm.halfedge(tm.source(h)) == tm.opposite(h) && - output.halfedge(output.source(new_h)) == SM::null_halfedge()){ - user_visitor.before_vertex_copy(tm.source(h), tm, output); // Call visitor when the vertex would be complete - output.set_halfedge(output.source(new_h), output.opposite(new_h)); - user_visitor.after_vertex_copy(tm.source(h), tm, output.target(new_h), output); - } - }; -#ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v){ - tbb::parallel_for(std::size_t(0), patch.interior_edges.size(), fill_edge); - } - else -#endif - { - for(std::size_t i=0; i hedges = { get_halfedge(h_in_1), get_halfedge(h_in_2), get_halfedge(h_in_3) }; - - user_visitor.before_face_copy(f, tm, output); - face_descriptor new_f(static_cast(faces_idx_begin + i)); - user_visitor.after_face_copy(f, tm, new_f, output); - output.set_halfedge(new_f, hedges[0]); - - for (int i=0;i<3;++i) - { - CGAL_assertion(hedges[i] != tm.null_halfedge()); - if(reverse_patch_orientation) - output.set_next(hedges[i], hedges[(i+2)%3]); - else - output.set_next(hedges[i], hedges[(i+1)%3]); - output.set_face(hedges[i], new_f); - } - }; -#ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v){ - tbb::parallel_for(std::size_t(0), patch.faces.size(), fill_face); - } - else -#endif - { - for(std::size_t i=0; i -auto append_patches_to_triangle_mesh( - SurfaceMesh& output, - const boost::dynamic_bitset<>& patches_to_append, - PatchContainer& patches, - const VertexPointMapOut& vpm_out, - const VertexPointMap& vpm_tm, - EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, - const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, - EdgeToEdgeMap& tm_to_output_edges, - VertexToVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) -> std::enable_if_t::value> -{ - using SM = SurfaceMesh; - using size_type = typename SM::size_type; - SM& tm = patches.pm; - - std::size_t vertices_idx_begin = output.num_vertices(); - std::size_t edges_idx_begin = output.num_edges(); - std::size_t faces_idx_begin = output.num_faces(); - std::size_t tnv = vertices_idx_begin, tne = edges_idx_begin, tnf = faces_idx_begin; - for (std::size_t i= patches_to_append.find_first(); - i < patches_to_append.npos; - i = patches_to_append.find_next(i)) - { - tnv += patches[i].interior_vertices.size(); - tne += patches[i].interior_edges.size(); - tnf += patches[i].faces.size(); - } - output.resize(static_cast(tnv), static_cast(tne), static_cast(tnf)); - - std::vector ids_of_patches_to_append; - ids_of_patches_to_append.reserve(patches_to_append.count()); - for (std::size_t i= patches_to_append.find_first(); - i < patches_to_append.npos; - i = patches_to_append.find_next(i)) - { - ids_of_patches_to_append.push_back(i); - Patch_description& patch=patches[i]; - append_patch(tm, output, patch, - vpm_out, vpm_tm, - edge_cst_map_out, edge_mark_map_out, - edge_cst_map_in, edge_mark_map_in, - tm_to_output_edges, tm_to_output_vertices, - user_visitor, - vertices_idx_begin, edges_idx_begin, faces_idx_begin); - vertices_idx_begin += patch.interior_vertices.size(); - edges_idx_begin += patch.interior_edges.size(); - faces_idx_begin += patch.faces.size(); - } - - process_borders_after_appending_patches(output, - ids_of_patches_to_append, - patches, - tm_to_output_edges, - tm_to_output_vertices); -} - -template < bool reverse_patch_orientation, - class SurfaceMesh, - class PatchContainer, - class VertexPointMap, - class VertexPointMapOut, - class EdgeCstMapOut, class EdgeMarkMapOut, - class EdgeCstMapIn , class EdgeMarkMapIn , - class EdgetoEdgeMap, - class VertextoVertexMap, - class UserVisitor> -auto append_patches_to_triangle_mesh( - SurfaceMesh& output, - const boost::dynamic_bitset<>& patches_to_append, - PatchContainer& patches, - const VertexPointMapOut& vpm_out, - const VertexPointMap& vpm_tm, - EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, - const EdgeCstMapIn& edge_cst_map_in, const EdgeMarkMapIn& edge_mark_map_in, - EdgetoEdgeMap& tm_to_output_edges, - VertextoVertexMap& tm_to_output_vertices, - UserVisitor& user_visitor) -> std::enable_if_t::value> -{ - append_patches_to_triangle_mesh(output, - patches_to_append, - patches, - vpm_out, - vpm_tm, - edge_cst_map_out, edge_mark_map_out, - edge_cst_map_in, edge_mark_map_in, - tm_to_output_edges, - tm_to_output_vertices, - user_visitor); -} - -// Specialization of fill_new_triangle_mesh for Surface_mesh to exploit vectors structure of Surface_mesh. -template < class ConcurrencyTag = Sequential_tag, - class SurfaceMesh, - class IntersectionEdgeMap, - class VertexPointMap1, - class VertexPointMap2, - class VertexPointMapOut, - class EdgeCstMap1, class EdgeCstMap2, - class EdgeMarkMap1, class EdgeMarkMap2, - class EdgeCstMapOut, class EdgeMarkMapOut, - class IntersectionPolylines, - class PatchContainer1, - class PatchContainer2, - class UserVisitor> -auto fill_new_triangle_mesh( - SurfaceMesh& output, - const boost::dynamic_bitset<>& patches_of_tm1_to_import, - const boost::dynamic_bitset<>& patches_of_tm2_to_import, - PatchContainer1& patches_of_tm1, - PatchContainer2& patches_of_tm2, - bool reverse_orientation_of_patches_from_tm1, - bool reverse_orientation_of_patches_from_tm2, - const IntersectionPolylines& polylines, - const IntersectionEdgeMap& intersection_edges1, - const IntersectionEdgeMap& intersection_edges2, - const VertexPointMap1& vpm1, - const VertexPointMap2& vpm2, - const VertexPointMapOut& vpm_out, - const EdgeCstMap1& edge_cst_map1, const EdgeCstMap2& edge_cst_map2, - const EdgeMarkMap1& edge_mark_map1, const EdgeMarkMap2& edge_mark_map2, - EdgeCstMapOut& edge_cst_map_out, EdgeMarkMapOut& edge_mark_map_out, - std::vector< typename SurfaceMesh::Edge_index >& output_shared_edges, - UserVisitor& user_visitor) -> std::enable_if_t::value> -{ - using SM = SurfaceMesh; - using vertex_descriptor = typename SM::Vertex_index; - using edge_descriptor = typename SM::Edge_index; - using size_type = typename SM::size_type; - - using V2V_tag = typename CGAL::dynamic_vertex_property_t; - using Vertex_to_vertex_map = typename boost::property_map::type; - - using E2E_tag = typename CGAL::dynamic_edge_property_t; - using Edge_to_edge_map = typename boost::property_map::type; - - SM &tm1 = patches_of_tm1.pm; - SM &tm2 = patches_of_tm2.pm; - - Edge_to_edge_map tm1_to_output_edges = get(E2E_tag(), tm1, SM::null_edge()), - tm2_to_output_edges = get(E2E_tag(), tm2, SM::null_edge()); - Vertex_to_vertex_map tm1_to_output_vertices = get(V2V_tag(), tm1, SM::null_vertex()), - tm2_to_output_vertices = get(V2V_tag(), tm2, SM::null_vertex()); - -#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION - CGAL::Real_timer t, tt; - t.start(); tt.start(); - std::cout << "Progress fill new triangle mesh" << std::endl; -#endif - - output_shared_edges.reserve( std::accumulate(polylines.lengths.begin(), polylines.lengths.end(), std::size_t(0)) ); - std::size_t nb_polylines = polylines.lengths.size(); - for (std::size_t i=0; i < nb_polylines; ++i) - if (!polylines.to_skip.test(i)) - import_polyline(output, - polylines.tm1[i], polylines.tm2[i], - tm1, tm2, - polylines.lengths[i], - tm1_to_output_edges, tm2_to_output_edges, - tm1_to_output_vertices, tm2_to_output_vertices, - intersection_edges1, intersection_edges2, - vpm1, vpm2, vpm_out, - output_shared_edges, - user_visitor); - -#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION - std::cout << "Import polylines: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; - tt.reset(); -#endif - - // Get ids of patch to append - std::vector ids_of_patches_to_append_from_tm1; - std::vector ids_of_patches_to_append_from_tm2; - ids_of_patches_to_append_from_tm1.reserve(patches_of_tm1_to_import.count()); - for (std::size_t i = patches_of_tm1_to_import.find_first(); - i < patches_of_tm1_to_import.npos; - i = patches_of_tm1_to_import.find_next(i)){ - ids_of_patches_to_append_from_tm1.push_back(i); - } - ids_of_patches_to_append_from_tm2.reserve(patches_of_tm2_to_import.count()); - for (std::size_t i = patches_of_tm2_to_import.find_first(); - i < patches_of_tm2_to_import.npos; - i = patches_of_tm2_to_import.find_next(i)){ - ids_of_patches_to_append_from_tm2.push_back(i); - } - -#ifdef CGAL_LINKED_WITH_TBB - if constexpr(ConcurrencyTag::is_parallel){ - tbb::task_group tasks; - tasks.run([&]{ - tbb::parallel_for(std::size_t(0), ids_of_patches_to_append_from_tm1.size(), [&](std::size_t j){ patches_of_tm1.extract_patch(ids_of_patches_to_append_from_tm1[j]); }); - }); - tbb::parallel_for(std::size_t(0), ids_of_patches_to_append_from_tm2.size(), [&](std::size_t j){ patches_of_tm2.extract_patch(ids_of_patches_to_append_from_tm2[j]); }); - tasks.wait(); - } - else -#endif - { - for (std::size_t i : ids_of_patches_to_append_from_tm1) - patches_of_tm1.extract_patch(i); - for (std::size_t i : ids_of_patches_to_append_from_tm2) - patches_of_tm2.extract_patch(i); - } - -#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION - std::cout << "Extract patches: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; - tt.reset(); -#endif - - // Compute final sizes - std::size_t nv = output.number_of_vertices(), ne = output.number_of_edges(), nf = output.number_of_faces(); - std::size_t tnv = output.number_of_vertices(), tne = output.number_of_edges(), tnf = output.number_of_faces(); - - for (std::size_t i : ids_of_patches_to_append_from_tm1){ - tnv += patches_of_tm1[i].interior_vertices.size(); - tne += patches_of_tm1[i].interior_edges.size(); - tnf += patches_of_tm1[i].faces.size(); - } - for (std::size_t i : ids_of_patches_to_append_from_tm2){ - tnv += patches_of_tm2[i].interior_vertices.size(); - tne += patches_of_tm2[i].interior_edges.size(); - tnf += patches_of_tm2[i].faces.size(); - } - output.resize(static_cast(tnv), static_cast(tne), static_cast(tnf)); - - // Append patches - for (std::size_t i : ids_of_patches_to_append_from_tm1){ - if(reverse_orientation_of_patches_from_tm1) - append_patch(tm1, output, - patches_of_tm1[i], - vpm_out, vpm1, - edge_cst_map_out, - edge_mark_map_out, - edge_cst_map1, - edge_mark_map1, - tm1_to_output_edges, - tm1_to_output_vertices, - user_visitor, - nv, ne, nf); - else - append_patch(tm1, output, - patches_of_tm1[i], - vpm_out, vpm1, - edge_cst_map_out, - edge_mark_map_out, - edge_cst_map1, - edge_mark_map1, - tm1_to_output_edges, - tm1_to_output_vertices, - user_visitor, - nv, ne, nf); - nv += patches_of_tm1[i].interior_vertices.size(); - ne += patches_of_tm1[i].interior_edges.size(); - nf += patches_of_tm1[i].faces.size(); - } -#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION - std::cout << "Append patch of first mesh: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; - tt.reset(); -#endif - - if(reverse_orientation_of_patches_from_tm1) - process_borders_after_appending_patches(output, - ids_of_patches_to_append_from_tm1, - patches_of_tm1, - tm1_to_output_edges, - tm1_to_output_vertices); - else - process_borders_after_appending_patches(output, - ids_of_patches_to_append_from_tm1, - patches_of_tm1, - tm1_to_output_edges, - tm1_to_output_vertices); -#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION - std::cout << "Process borders of first mesh: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; - tt.reset(); -#endif - - for(std::size_t i : ids_of_patches_to_append_from_tm2){ - if(reverse_orientation_of_patches_from_tm2) - append_patch(tm2, output, - patches_of_tm2[i], - vpm_out, vpm2, - edge_cst_map_out, - edge_mark_map_out, - edge_cst_map2, - edge_mark_map2, - tm2_to_output_edges, - tm2_to_output_vertices, - user_visitor, - nv, ne, nf); - else - append_patch(tm2, output, - patches_of_tm2[i], - vpm_out, vpm2, - edge_cst_map_out, - edge_mark_map_out, - edge_cst_map2, - edge_mark_map2, - tm2_to_output_edges, - tm2_to_output_vertices, - user_visitor, - nv, ne, nf); - nv += patches_of_tm2[i].interior_vertices.size(); - ne += patches_of_tm2[i].interior_edges.size(); - nf += patches_of_tm2[i].faces.size(); - } -#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION - std::cout << "Append patch of second mesh: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; - tt.reset(); -#endif - - if(reverse_orientation_of_patches_from_tm2) - process_borders_after_appending_patches(output, - ids_of_patches_to_append_from_tm2, - patches_of_tm2, - tm2_to_output_edges, - tm2_to_output_vertices); - else - process_borders_after_appending_patches(output, - ids_of_patches_to_append_from_tm2, - patches_of_tm2, - tm2_to_output_edges, - tm2_to_output_vertices); -#ifdef CGAL_BENCH_BOOL_OP_OUTPUT_CONSTRUCTION - std::cout << "Process borders of second mesh: " << tt.time() << "s (" << t.time() << "s total)" << std::endl; - tt.reset(); -#endif -} - -} // namespace Corefinement -} // namespace Polygon_mesh_processing -} // namespace CGAL - -#endif // CGAL_SURFACE_MESH_BOOLEAN_OPERATIONS_UTILS_H \ No newline at end of file From 8dca07b11abaa94aae8fb9c9d17a076b22064f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 6 Nov 2026 17:13:25 +0100 Subject: [PATCH 085/136] fix filtering of edges I think it was working just by chance, but without the patch, some halfedges of faces could be ignored if no the boundary --- .../internal/Corefinement/intersection_impl.h | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 2bd984451dee..3681f6bd4234 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -297,11 +297,11 @@ class Intersection_of_triangle_meshes next(next(halfedge(f_2, tm2), tm2), tm2) }; for(halfedge_descriptor h : hf2){ - if( is_border(h, tm2) || h < opposite(h, tm2)) + if( is_border_edge(h, tm2) || h < opposite(h, tm2)) callback12(hf1[0], h); } for(halfedge_descriptor h : hf1){ - if( is_border(h, tm1) || h < opposite(h, tm1)) + if( is_border_edge(h, tm1) || h < opposite(h, tm1)) callback21(hf2[0], h); } }; @@ -325,7 +325,7 @@ class Intersection_of_triangle_meshes // make sure the halfedge used is consistent with stored one h = halfedge(non_manifold_feature_map_2.non_manifold_edges[eid].front(), tm2); } - if( !get(is_shared_edge_map_2, ed) && (is_border(h, tm2) || h < opposite(h, tm2))) + if( !get(is_shared_edge_map_2, ed) && (is_border_edge(h, tm2) || h < opposite(h, tm2))) callback12(hf1[0], h); } for(halfedge_descriptor h : hf1){ @@ -339,7 +339,7 @@ class Intersection_of_triangle_meshes // make sure the halfedge used is consistent with stored one h = halfedge(non_manifold_feature_map_1.non_manifold_edges[eid].front(), tm1); } - if( !get(is_shared_edge_map_1, ed) && (is_border(h, tm1) || h < opposite(h, tm1))) + if( !get(is_shared_edge_map_1, ed) && (is_border_edge(h, tm1) || h < opposite(h, tm1))) callback21(hf2[0], h); } }; @@ -520,18 +520,18 @@ class Intersection_of_triangle_meshes halfedge_descriptor h1_f2 = next(h0_f2, tm); halfedge_descriptor h2_f2 = next(h1_f2, tm); - if (is_border(h0_f1, tm) || h0_f1 < opposite(h0_f1, tm)) + if (is_border_edge(h0_f1, tm) || h0_f1 < opposite(h0_f1, tm)) callback(h0_f2, h0_f1); - if (is_border(h1_f1, tm) || h1_f1 < opposite(h1_f1, tm)) + if (is_border_edge(h1_f1, tm) || h1_f1 < opposite(h1_f1, tm)) callback(h0_f2, h1_f1); - if (is_border(h2_f1, tm) || h2_f1 < opposite(h2_f1, tm)) + if (is_border_edge(h2_f1, tm) || h2_f1 < opposite(h2_f1, tm)) callback(h0_f2, h2_f1); - if (is_border(h0_f2, tm) || h0_f2 < opposite(h0_f2, tm)) + if (is_border_edge(h0_f2, tm) || h0_f2 < opposite(h0_f2, tm)) callback(h0_f1, h0_f2); - if (is_border(h1_f2, tm) || h1_f2 < opposite(h1_f2, tm)) + if (is_border_edge(h1_f2, tm) || h1_f2 < opposite(h1_f2, tm)) callback(h0_f1, h1_f2); - if (is_border(h2_f2, tm) || h2_f2 < opposite(h2_f2, tm)) + if (is_border_edge(h2_f2, tm) || h2_f2 < opposite(h2_f2, tm)) callback(h0_f1, h2_f2); // }); } @@ -551,18 +551,18 @@ class Intersection_of_triangle_meshes halfedge_descriptor h1_f2 = next(h0_f2, tm); halfedge_descriptor h2_f2 = next(h1_f2, tm); - if (is_border(h0_f1, tm) || h0_f1 < opposite(h0_f1, tm)) + if (is_border_edge(h0_f1, tm) || h0_f1 < opposite(h0_f1, tm)) callback(h0_f2, h0_f1); - if (is_border(h1_f1, tm) || h1_f1 < opposite(h1_f1, tm)) + if (is_border_edge(h1_f1, tm) || h1_f1 < opposite(h1_f1, tm)) callback(h0_f2, h1_f1); - if (is_border(h2_f1, tm) || h2_f1 < opposite(h2_f1, tm)) + if (is_border_edge(h2_f1, tm) || h2_f1 < opposite(h2_f1, tm)) callback(h0_f2, h2_f1); - if (is_border(h0_f2, tm) || h0_f2 < opposite(h0_f2, tm)) + if (is_border_edge(h0_f2, tm) || h0_f2 < opposite(h0_f2, tm)) callback(h0_f1, h0_f2); - if (is_border(h1_f2, tm) || h1_f2 < opposite(h1_f2, tm)) + if (is_border_edge(h1_f2, tm) || h1_f2 < opposite(h1_f2, tm)) callback(h0_f1, h1_f2); - if (is_border(h2_f2, tm) || h2_f2 < opposite(h2_f2, tm)) + if (is_border_edge(h2_f2, tm) || h2_f2 < opposite(h2_f2, tm)) callback(h0_f1, h2_f2); } } From 0a52acd41524a5ff2aa721828bae2a0e70ebc4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 6 Nov 2026 17:27:24 +0100 Subject: [PATCH 086/136] cosmetic --- .../internal/Corefinement/intersection_impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 3681f6bd4234..138d819e1efd 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -347,7 +347,7 @@ class Intersection_of_triangle_meshes // Wrap the call of AABB intersections given two callback functions auto AABB_call = [&](auto &callback12, auto &callback21){ #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(ConcurrencyTag::is_parallel) { oneapi::tbb::task_group tg; tg.run([&]{ helper_1.template build(tm1_faces_intersecting_bb, tree1, tm1, vpm1); }); @@ -503,7 +503,7 @@ class Intersection_of_triangle_meshes Callback callback(tm, vpm, stm_edge_to_ltm_faces, coplanar_faces); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(ConcurrencyTag::is_parallel) { tbb::concurrent_vector> inter; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(inter)); From eff08ef2cfd0c8e455a0dda516880f9aebd4a51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 6 Nov 2026 17:27:31 +0100 Subject: [PATCH 087/136] filter faces in sequential mode too --- .../internal/Corefinement/intersection_impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 138d819e1efd..d6fcb11e4c79 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -371,8 +371,8 @@ class Intersection_of_triangle_meshes else #endif { - helper_1.template build(tree1, tm1, vpm1); - helper_2.template build(tree2, tm2, vpm2); + helper_1.template build(tm1_faces_intersecting_bb, tree1, tm1, vpm1); + helper_2.template build(tm2_faces_intersecting_bb, tree2, tm2, vpm2) std::vector> inter; CGAL::AABB_trees::all_pairs_of_primitives_with_overlapping_bbox(tree1, tree2, std::back_inserter(inter)); From 17d427ea3b5ec37f0d4724c836e7a4144f601e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 09:05:39 +0100 Subject: [PATCH 088/136] filter out shared edges in manifold case too --- .../internal/Corefinement/intersection_impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index d6fcb11e4c79..6f9abb101ca6 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -297,11 +297,11 @@ class Intersection_of_triangle_meshes next(next(halfedge(f_2, tm2), tm2), tm2) }; for(halfedge_descriptor h : hf2){ - if( is_border_edge(h, tm2) || h < opposite(h, tm2)) + if( (is_border_edge(h, tm2) || h < opposite(h, tm2)) && !get(is_shared_edge_map_2, edge(h, tm2)) ) callback12(hf1[0], h); } for(halfedge_descriptor h : hf1){ - if( is_border_edge(h, tm1) || h < opposite(h, tm1)) + if( (is_border_edge(h, tm1) || h < opposite(h, tm1)) && !get(is_shared_edge_map_1, edge(h, tm1)) ) callback21(hf2[0], h); } }; @@ -372,7 +372,7 @@ class Intersection_of_triangle_meshes #endif { helper_1.template build(tm1_faces_intersecting_bb, tree1, tm1, vpm1); - helper_2.template build(tm2_faces_intersecting_bb, tree2, tm2, vpm2) + helper_2.template build(tm2_faces_intersecting_bb, tree2, tm2, vpm2); std::vector> inter; CGAL::AABB_trees::all_pairs_of_primitives_with_overlapping_bbox(tree1, tree2, std::back_inserter(inter)); From 982d75ace8cc22dd2ccf498f0fa4e8e57e4f3a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 09:14:51 +0100 Subject: [PATCH 089/136] missing vertex point map --- .../internal/soup_and_face_graph_tree_helper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index c543ec6084f4..40d0bb23c65a 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -97,7 +97,7 @@ struct AABB_tree_graph_helper { tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ face_descriptor f = face_range[i]; - put(bb_map, f, face_bbox(f, tm)); + put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); }); } @@ -105,7 +105,7 @@ struct AABB_tree_graph_helper #endif { for(face_descriptor f : face_range){ - put(bb_map, f, face_bbox(f, tm)); + put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); } } From 65a59d0000daad0d73641167aacc321febc87cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 09:17:34 +0100 Subject: [PATCH 090/136] avoid reference to dangling transformation the class cannot control the lifetime outside of the class and set_transformation can't work --- .../include/CGAL/AABB_tree/internal/AABB_traversal_traits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h index 3d0c06e4e5a6..c0c67a0a3956 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h @@ -275,7 +275,7 @@ class Listing_primitive_traits_with_transformation private: OutputIterator m_out_it; const AABBTraits& m_traits; - const AffTransformation& m_transfo; + AffTransformation m_transfo; bool m_has_rotation; }; From 81030fbd8a246c016b9c14c1a189692817924732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 09:29:15 +0100 Subject: [PATCH 091/136] do not write twice self-intersecting pairs --- .../include/CGAL/Polygon_mesh_processing/self_intersections.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index a442ee2b25a5..dd383115dc19 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -566,6 +566,7 @@ self_intersections_impl(const FaceRange& face_range, // Sequentially write into the output iterator for(std::size_t i=0; i Date: Mon, 9 Nov 2026 09:39:00 +0100 Subject: [PATCH 092/136] restrict the test to collected faces --- .../Polygon_mesh_processing/intersection.h | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index cac837ce6ea4..e8bc583c2b59 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -436,20 +436,20 @@ compute_face_face_intersection(const FaceRange& face_range1, typename boost::property_traits::value_type >::value) ); - std::vector face_to_test1; - std::vector face_to_test2; + std::vector faces_to_test1; + std::vector faces_to_test2; for(face_descriptor f : face_range1) if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm1), bb)) - face_to_test1.emplace_back(f); + faces_to_test1.emplace_back(f); for(face_descriptor f : face_range2) if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm2), bb)) - face_to_test2.emplace_back(f); + faces_to_test2.emplace_back(f); Tree_1 tree1; Tree_2 tree2; - helper_1.template build(face_to_test1, tree1, tm1, vpm1); - helper_2.template build(face_to_test2, tree2, tm2, vpm2); + helper_1.template build(faces_to_test1, tree1, tm1, vpm1); + helper_2.template build(faces_to_test2, tree2, tm2, vpm2); CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, out, parameters::concurrency_tag(Concurrency_tag())); return out; @@ -561,15 +561,15 @@ compute_face_polyline_intersection(const FaceRange& face_range, for(; pit != std::end(polyline); ++pit, ++prev) segments.emplace_back(*prev, *pit); - std::vector face_to_test; + std::vector faces_to_test; for(face_descriptor f : face_range) if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm), bb)) - face_to_test.emplace_back(f); + faces_to_test.emplace_back(f); AABB_tree_helper helper; Face_tree face_tree; - helper.template build(face_tree, tm, vpm); + helper.template build(faces_to_test, face_tree, tm, vpm); Segment_tree segment_tree(segments.begin(), segments.end()); auto out_converter = boost::make_function_output_iterator( @@ -698,15 +698,15 @@ compute_face_polylines_intersection(const FaceRange& face_range, segments.emplace_back(*prev, *pit); } - std::vector face_to_test; + std::vector faces_to_test; for(face_descriptor f : face_range) if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm), bb)) - face_to_test.emplace_back(f); + faces_to_test.emplace_back(f); AABB_tree_helper helper; Face_tree face_tree; - helper.template build(face_tree, tm, vpm); + helper.template build(faces_to_test, face_tree, tm, vpm); Segment_tree segment_tree(segments.begin(), segments.end()); auto out_converter = From 4136b41f4672acdb8485fb94478f38e67625598f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 10:05:30 +0100 Subject: [PATCH 093/136] handle empty polyline range + restrict bbox to face_range --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index e8bc583c2b59..8cd355f09ff5 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -642,6 +642,9 @@ compute_face_polylines_intersection(const FaceRange& face_range, OutputIterator out, const NamedParameters& np) { + if (face_range.empty() || polyline_range.empty()) + return out; + using parameters::get_parameter; using parameters::choose_parameter; @@ -669,9 +672,11 @@ compute_face_polylines_intersection(const FaceRange& face_range, VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), get_const_property_map(boost::vertex_point, tm)); - Bbox_3 b1 = Polygon_mesh_processing::bbox(tm, np); + Bbox_3 b1; + for (face_descriptor f : face_range) + b1 += Polygon_mesh_processing::face_bbox(f, tm, np); auto polyline_it = polyline_range.begin(); - Bbox_3 b2 = bbox_3(polyline_it->begin(), polyline_it->end()); + Bbox_3 b2 = bbox_3(polyline_it->begin(), polyline_it->end()); // can deref the polyline_it as we already checked it's not empty for(++polyline_it; polyline_it != polyline_range.end(); ++polyline_it) b2 += bbox_3(polyline_it->begin(), polyline_it->end()); From d819efa6b3e723c573621fd8634d1fc933ecf4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 10:06:07 +0100 Subject: [PATCH 094/136] handle update of output iterator returned --- .../AABB_two_trees_traversal_traits.h | 8 +++---- .../include/CGAL/AABB_trees/intersection.h | 21 +++++++++++-------- .../Polygon_mesh_processing/intersection.h | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 3e45475a7f53..00da12c3b5bc 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -55,7 +55,7 @@ class Two_trees_listing_intersecting_primitives_traits typedef ::CGAL::AABB_node Node2; public: - Two_trees_listing_intersecting_primitives_traits(const AABBTraits1& traits1, const AABBTraits2& traits2, OutputIterator out_) + Two_trees_listing_intersecting_primitives_traits(const AABBTraits1& traits1, const AABBTraits2& traits2, OutputIterator& out_) : m_traits1(traits1), m_traits2(traits2), out(out_) {} @@ -101,7 +101,7 @@ class Two_trees_listing_intersecting_primitives_traits private: const AABBTraits1& m_traits1; const AABBTraits2& m_traits2; - OutputIterator out; + OutputIterator& out; }; template @@ -114,7 +114,7 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation public: Two_trees_listing_intersecting_primitives_traits_with_transformation(const AABBTraits1& traits1, const AABBTraits2& traits2, - OutputIterator out_, + OutputIterator& out_, const AffTransformation &tr1, const AffTransformation &tr2) : m_traits1(traits1), m_traits2(traits2), out(out_), @@ -200,7 +200,7 @@ class Two_trees_listing_intersecting_primitives_traits_with_transformation private: const AABBTraits1& m_traits1; const AABBTraits2& m_traits2; - OutputIterator out; + OutputIterator& out; const AffTransformation& m_tr1; const AffTransformation& m_tr2; AffTransformation m_tr1_inverse; diff --git a/AABB_tree/include/CGAL/AABB_trees/intersection.h b/AABB_tree/include/CGAL/AABB_trees/intersection.h index d55e3d7866b5..f26e080fecf9 100644 --- a/AABB_tree/include/CGAL/AABB_trees/intersection.h +++ b/AABB_tree/include/CGAL/AABB_trees/intersection.h @@ -150,11 +150,11 @@ namespace AABB_trees { typename OutputIterator, typename NamedParameters1 = parameters::Default_named_parameters, typename NamedParameters2 = parameters::Default_named_parameters> - void all_pairs_of_intersecting_primitives(const AABBTree1 &tree1, - const AABBTree2 &tree2, - OutputIterator out, - const NamedParameters1& np1 = parameters::default_values(), - const NamedParameters2& np2 = parameters::default_values()) + OutputIterator all_pairs_of_intersecting_primitives(const AABBTree1 &tree1, + const AABBTree2 &tree2, + OutputIterator out, + const NamedParameters1& np1 = parameters::default_values(), + const NamedParameters2& np2 = parameters::default_values()) { using parameters::get_parameter; using parameters::choose_parameter; @@ -167,7 +167,7 @@ namespace AABB_trees { // Early exit if one of the trees is empty if(tree1.empty() || tree2.empty()) - return; + return out; if constexpr(is_default_parameter::value && is_default_parameter::value) @@ -190,6 +190,8 @@ namespace AABB_trees { traversal_traits(tree1.traits(), tree2.traits(), out, tr1, tr2); CGAL::internal::AABB_tree::two_trees_traversal(tree1, tree2, traversal_traits); } + + return out; } /// \ingroup PkgAABBTreeRef @@ -204,13 +206,14 @@ namespace AABB_trees { template< typename Concurrency_tag = Sequential_tag, typename AABBTree, typename OutputIterator> - void all_pairs_of_intersecting_primitives(const AABBTree &tree, - OutputIterator out) + OutputIterator all_pairs_of_intersecting_primitives(const AABBTree &tree, + OutputIterator out) { if(tree.size() <= 1) - return; + return out; CGAL::internal::AABB_tree::Two_trees_listing_intersecting_primitives_traits traversal_traits(tree.traits(), tree.traits(), out); CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); + return out; } /// \ingroup PkgAABBTreeRef diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 8cd355f09ff5..ff1df10fcd30 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -451,7 +451,7 @@ compute_face_face_intersection(const FaceRange& face_range1, helper_1.template build(faces_to_test1, tree1, tm1, vpm1); helper_2.template build(faces_to_test2, tree2, tm2, vpm2); - CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, out, parameters::concurrency_tag(Concurrency_tag())); + out = CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, out, parameters::concurrency_tag(Concurrency_tag())); return out; } From 16cefdbe033eac18f8c1f3cb324024e496e34b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 10:16:23 +0100 Subject: [PATCH 095/136] remove extra useless call --- .../CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 00da12c3b5bc..b201580812fc 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -360,8 +360,6 @@ class Two_trees_do_intersect_traits_with_transformation void intersection(const Primitive1& primitive1, const Primitive2& primitive2) { - Do_intersect_traits traits(m_traits2); - traits.intersection(internal::Primitive_helper::get_datum(primitive1, m_traits1), primitive2); if constexpr(Use_inverse_transformation::value) { Do_intersect_traits traits(m_traits2); From 3b1512ba4626fccea9019048aae44a54021fb00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 13:28:31 +0100 Subject: [PATCH 096/136] copy/paste error --- .../benchmark/Performance/run_performance_snap.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/PMP_Boolean_operations/benchmark/Performance/run_performance_snap.sh b/PMP_Boolean_operations/benchmark/Performance/run_performance_snap.sh index d50f65f808cd..417b7dc3741a 100755 --- a/PMP_Boolean_operations/benchmark/Performance/run_performance_snap.sh +++ b/PMP_Boolean_operations/benchmark/Performance/run_performance_snap.sh @@ -24,10 +24,8 @@ TMP_LOG_SNAP=$(mktemp) /usr/bin/time -f "TIME:%e\nMEM:%M" timeout "$TIMEOUT"s performance_snap_polygon_soup "$INPUT_FILE" "$GRID_SIZE" "$ERASE_ALL_DUPLICATE" 2> "$TMP_LOG_SNAP" # Parse time and memory -SECONDS=$(grep "TIME" "$TMP_LOG" | cut -d':' -f2) -MEMORY=$(grep "MEM" "$TMP_LOG" | cut -d':' -f2) - -rm -f "$TMP_LOG" +SECONDS=$(grep "TIME" "$TMP_LOG_BOOLOP" | cut -d':' -f2) +MEMORY=$(grep "MEM" "$TMP_LOG_BOOLOP" | cut -d':' -f2) # Output JSON echo "{\"seconds\": \"$SECONDS\", \"memory_peaks\": \"$MEMORY\"}" From f2d8aa0fd74c2228a9985efc100a66c82192162b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 13:31:49 +0100 Subject: [PATCH 097/136] fix license,, clean up and add TODO --- .../internal/soup_and_face_graph_tree_helper.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 40d0bb23c65a..93d393a79d93 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -13,7 +13,7 @@ #ifndef CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SOUP_AND_TREE_HELPER_H #define CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SOUP_AND_TREE_HELPER_H -#include +#include #include @@ -96,7 +96,7 @@ struct AABB_tree_graph_helper if constexpr(std::is_same_v) { tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ - face_descriptor f = face_range[i]; + face_descriptor f = face_range[i]; // TODO: does not work if face_range is faces(tm) put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); }); @@ -207,11 +207,11 @@ struct AABB_tree_soup_helper if constexpr(std::is_same_v) { tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ - i = face_range[i]; - put(bb_map, i, get(vpm, triangles[i][0]).bbox() + - get(vpm, triangles[i][1]).bbox() + - get(vpm, triangles[i][2]).bbox()); - put(rp_map, i, to_input(get(vpm, triangles[i][0])) ); + auto tid = face_range[i]; + put(bb_map, tid, get(vpm, triangles[tid][0]).bbox() + + get(vpm, triangles[tid][1]).bbox() + + get(vpm, triangles[tid][2]).bbox()); + put(rp_map, tid, to_input(get(vpm, triangles[tid][0])) ); }); } else From 80ebee09fcbce86e0a1026497f749b9683e609dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 13:42:36 +0100 Subject: [PATCH 098/136] hide non-accepted/reviewed APIs --- AABB_tree/include/CGAL/AABB_trees/intersection.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_trees/intersection.h b/AABB_tree/include/CGAL/AABB_trees/intersection.h index f26e080fecf9..a7fa8a44f031 100644 --- a/AABB_tree/include/CGAL/AABB_trees/intersection.h +++ b/AABB_tree/include/CGAL/AABB_trees/intersection.h @@ -216,7 +216,9 @@ namespace AABB_trees { return out; } - /// \ingroup PkgAABBTreeRef +// not officially documented for now +#ifndef DOXYGEN_RUNNING + /// \ingroup PkgAABBTreeRef /// /// \brief computes all pairs of primitives with overlapping bbox from two AABB trees. /// @@ -252,9 +254,6 @@ namespace AABB_trees { const NamedParameters1& /*np1*/ = parameters::default_values(), const NamedParameters2& /*np2*/ = parameters::default_values()) { - using parameters::get_parameter; - using parameters::choose_parameter; - using parameters::is_default_parameter; using Concurrency_tag = typename internal_np::Lookup_named_param_def < internal_np::concurrency_tag_t, NamedParameters1, @@ -278,7 +277,7 @@ namespace AABB_trees { /// /// Intersections of a primitive with itself are not reported, and each intersecting /// pair of distinct primitives is reported only once. - template< typename Concurrency_tag = Sequential_tag, + template< typename Concurrency_tag = Sequential_tag, // TODO: shouldn't it be a named parameter? typename AABBTree, typename OutputIterator> void all_pairs_of_primitives_with_overlapping_bbox(const AABBTree &tree, @@ -289,6 +288,7 @@ namespace AABB_trees { CGAL::internal::AABB_tree::Two_trees_listing_primitives_with_overlapping_bbox_traits traversal_traits(tree.traits(), tree.traits(), out); CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); } +#endif }} // end namespace CGAL::AABB_trees From 6642fe871a6e63e0b4d68b5bb6786bd5c73f7640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 13:49:13 +0100 Subject: [PATCH 099/136] remove self-reference --- Kernel_23/include/CGAL/Bbox_2.h | 7 ------- Kernel_23/include/CGAL/Bbox_3.h | 7 ------- 2 files changed, 14 deletions(-) diff --git a/Kernel_23/include/CGAL/Bbox_2.h b/Kernel_23/include/CGAL/Bbox_2.h index f125cda29ff0..26a820cc89f9 100644 --- a/Kernel_23/include/CGAL/Bbox_2.h +++ b/Kernel_23/include/CGAL/Bbox_2.h @@ -72,7 +72,6 @@ class Bbox_2 inline Bbox_2& operator+=(const Bbox_2 &b); inline const Bbox_2& bbox() const; - inline Bbox_2& bbox(); inline int largest_span_index() const; @@ -161,12 +160,6 @@ Bbox_2::bbox() const{ return *this; } -inline -Bbox_2& -Bbox_2::bbox(){ - return *this; -} - inline Bbox_2 Bbox_2::operator+(const Bbox_2 &b) const diff --git a/Kernel_23/include/CGAL/Bbox_3.h b/Kernel_23/include/CGAL/Bbox_3.h index a6c2af8b5a33..41d99b64661e 100644 --- a/Kernel_23/include/CGAL/Bbox_3.h +++ b/Kernel_23/include/CGAL/Bbox_3.h @@ -80,7 +80,6 @@ class Bbox_3 Bbox_3& operator+=(const Bbox_3& b); inline const Bbox_3& bbox() const; - inline Bbox_3& bbox(); inline void dilate(int dist); inline void scale(double factor); @@ -159,12 +158,6 @@ Bbox_3::bbox() const{ return *this; } -inline -Bbox_3& -Bbox_3::bbox(){ - return *this; -} - inline int Bbox_3::dimension() const From f10baba1ddecbb3979e43bfbdbe73f6e71ed705f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 15:08:10 +0100 Subject: [PATCH 100/136] remove leftover no longer used --- .../CGAL/Surface_mesh/Surface_mesh_fwd.h | 1 + .../Corefinement/intersection_callbacks.h | 28 -- .../Polygon_mesh_processing/intersection.h | 396 ------------------ 3 files changed, 1 insertion(+), 424 deletions(-) diff --git a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h index 2c05549c88de..0b0aa3f63c01 100644 --- a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h +++ b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h @@ -14,6 +14,7 @@ /// Forward declarations of the Surface_mesh package. #include +#include #ifndef DOXYGEN_RUNNING diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h index d28adc9e3ef7..1dd2de61188c 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_callbacks.h @@ -28,34 +28,6 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace Corefinement { -template -class Collect_face_bbox_per_edge_bbox { -protected: - const TriangleMesh& tm_faces; - const TriangleMesh& tm_edges; - EdgeToFaces& edge_to_faces; - - typedef boost::graph_traits Graph_traits; - typedef typename Graph_traits::face_descriptor face_descriptor; - typedef typename Graph_traits::halfedge_descriptor halfedge_descriptor; - -public: - Collect_face_bbox_per_edge_bbox( - const TriangleMesh& tm_faces, - const TriangleMesh& tm_edges, - EdgeToFaces& edge_to_faces) - : tm_faces(tm_faces) - , tm_edges(tm_edges) - , edge_to_faces(edge_to_faces) - {} - - void operator()( halfedge_descriptor fh, halfedge_descriptor eh) const - { - // put(edge_to_faces, edge(eh,tm_edges), face(fh, tm_faces)); - edge_to_faces[edge(eh,tm_edges)].insert(face(fh, tm_faces)); - } -}; - template #include -#include #include #include #include @@ -39,286 +38,6 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace internal { -template -struct Intersect_faces -{ - // typedefs - typedef typename Kernel::Segment_3 Segment; - typedef typename Kernel::Triangle_3 Triangle; - - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef typename boost::property_map::const_type Ppmap; - - // members - const TM& m_tm1; - const VertexPointMap1 m_vpmap1; - const TM& m_tm2; - const VertexPointMap2 m_vpmap2; - mutable OutputIterator m_iterator; - - typename Kernel::Construct_triangle_3 triangle_functor; - typename Kernel::Do_intersect_3 do_intersect_3_functor; - - Intersect_faces(const TM& tm1, const TM& tm2, - OutputIterator it, - VertexPointMap1 vpmap1, VertexPointMap2 vpmap2, - const Kernel& kernel) - : - m_tm1(tm1), - m_vpmap1(vpmap1), - m_tm2(tm2), - m_vpmap2(vpmap2), - m_iterator(it), - triangle_functor(kernel.construct_triangle_3_object()), - do_intersect_3_functor(kernel.do_intersect_3_object()) - { } - - void operator()(const Box* b, const Box* c) const - { - halfedge_descriptor h = halfedge(b->info(), m_tm1); - halfedge_descriptor g = halfedge(c->info(), m_tm2); - - - // check for geometric intersection - Triangle t1 = triangle_functor( get(m_vpmap1, target(h,m_tm1)), - get(m_vpmap1, target(next(h,m_tm1),m_tm1)), - get(m_vpmap1, source(h,m_tm1))); - - Triangle t2 = triangle_functor( get(m_vpmap2, target(g,m_tm2)), - get(m_vpmap2, target(next(g,m_tm2),m_tm2)), - get(m_vpmap2, source(g,m_tm2))); - if(do_intersect_3_functor(t1, t2)){ - *m_iterator++ = std::make_pair(b->info(), c->info()); - } - } // end operator () -}; // end struct Intersect_faces - -template -struct Intersect_face_polyline -{ - // wrapper to check whether anything is inserted to output iterator - - // typedefs - typedef typename Kernel::Segment_3 Segment; - typedef typename Kernel::Triangle_3 Triangle; - - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::property_map::const_type Ppmap; - typedef typename boost::property_traits::value_type Point; - - - // members - const TM& m_tm; - const std::vector& faces; - const VertexPointMap m_vpmap; - const Polyline& polyline; - mutable OutputIterator m_iterator; - - typename Kernel::Construct_segment_3 segment_functor; - typename Kernel::Construct_triangle_3 triangle_functor; - typename Kernel::Do_intersect_3 do_intersect_3_functor; - - Intersect_face_polyline(const TM& tm, - const std::vector& faces, - const Polyline& polyline, - OutputIterator it, - VertexPointMap vpmap, - const Kernel& kernel) - : - m_tm(tm), - faces(faces), - m_vpmap(vpmap), - polyline(polyline), - m_iterator(it), - segment_functor(kernel.construct_segment_3_object()), - triangle_functor(kernel.construct_triangle_3_object()), - do_intersect_3_functor(kernel.do_intersect_3_object()) - { } - - void operator()(const Box* b, const Box* c) const - { - halfedge_descriptor h = halfedge(faces[b->info()], m_tm); - - - // check for geometric intersection - Triangle t = triangle_functor( get(m_vpmap, target(h,m_tm)), - get(m_vpmap, target(next(h,m_tm),m_tm)), - get(m_vpmap, source(h,m_tm))); - - Segment s = segment_functor(polyline[c->info()], polyline[c->info() + 1]); - if(do_intersect_3_functor(t, s)){ - *m_iterator++ = std::make_pair(b->info(), c->info()); - } - } // end operator () -}; // end struct Intersect_face_polyline - -template -struct Intersect_face_polylines -{ - // wrapper to check whether anything is inserted to output iterator - - // typedefs - typedef typename Kernel::Segment_3 Segment; - typedef typename Kernel::Triangle_3 Triangle; - - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::property_map::const_type Ppmap; - typedef typename boost::property_traits::value_type Point; - - // members - const TM& m_tm; - const std::vector& faces; - const VertexPointMap m_vpmap; - const PolylineRange& polylines; - mutable OutputIterator m_iterator; - - typename Kernel::Construct_segment_3 segment_functor; - typename Kernel::Construct_triangle_3 triangle_functor; - typename Kernel::Do_intersect_3 do_intersect_3_functor; - - Intersect_face_polylines(const TM& tm, - const std::vector& faces, - const PolylineRange& polylines, - OutputIterator it, - VertexPointMap vpmap, - const Kernel& kernel) - : - m_tm(tm), - faces(faces), - m_vpmap(vpmap), - polylines(polylines), - m_iterator(it), - segment_functor(kernel.construct_segment_3_object()), - triangle_functor(kernel.construct_triangle_3_object()), - do_intersect_3_functor(kernel.do_intersect_3_object()) - { } - - void operator()(const Box* b, const Box* c) const - { - halfedge_descriptor h = halfedge(faces[b->info().second], m_tm); - - - // check for geometric intersection - Triangle t = triangle_functor( get(m_vpmap, target(h,m_tm)), - get(m_vpmap, target(next(h,m_tm),m_tm)), - get(m_vpmap, source(h,m_tm))); - - Segment s = segment_functor(polylines[c->info().first][c->info().second], polylines[c->info().first][c->info().second + 1]); - if(do_intersect_3_functor(t, s)){ - *m_iterator++ = std::make_pair(b->info().second, c->info()); - } - } // end operator () -}; // end struct Intersect_face_polylines - - -template -struct Intersect_polylines -{ - // typedefs - typedef typename Kernel::Segment_3 Segment; - typedef typename Kernel::Point_3 Point; - - - // members - const Polyline& polyline1; - const Polyline& polyline2; - mutable OutputIterator m_iterator; - - typename Kernel::Construct_segment_3 segment_functor; - typename Kernel::Do_intersect_3 do_intersect_3_functor; - - Intersect_polylines(const Polyline& polyline1, - const Polyline& polyline2, - OutputIterator it, - const Kernel& kernel) - : - polyline1(polyline1), - polyline2(polyline2), - m_iterator(it), - segment_functor(kernel.construct_segment_3_object()), - do_intersect_3_functor(kernel.do_intersect_3_object()) - { } - - void operator()(const Box* b, const Box* c) const - { - - - // check for geometric intersection - - Segment s1 = segment_functor(polyline1[b->info()], polyline1[b->info() + 1]); - Segment s2 = segment_functor(polyline2[c->info()], polyline2[c->info() + 1]); - if(do_intersect_3_functor(s1, s2)){ - *m_iterator++ = std::make_pair(b->info(), c->info()); - } - } // end operator () -}; // end struct Intersect_polylines - -template -struct Intersect_polyline_ranges -{ - // typedefs - typedef typename Kernel::Segment_3 Segment; - typedef typename Kernel::Point_3 Point; - - - // members - const PolylineRange& polyline1; - const PolylineRange& polyline2; - mutable OutputIterator m_iterator; - - typename Kernel::Construct_segment_3 segment_functor; - typename Kernel::Do_intersect_3 do_intersect_3_functor; - - Intersect_polyline_ranges(const PolylineRange& polyline1, - const PolylineRange& polyline2, - OutputIterator it, - const Kernel& kernel) - : - polyline1(polyline1), - polyline2(polyline2), - m_iterator(it), - segment_functor(kernel.construct_segment_3_object()), - do_intersect_3_functor(kernel.do_intersect_3_object()) - { } - - void operator()(const Box* b, const Box* c) const - { - - - // check for geometric intersection - - Segment s1 = segment_functor(polyline1[b->info().first][b->info().second], polyline1[b->info().first][b->info().second + 1]); - Segment s2 = segment_functor(polyline2[c->info().first][c->info().second], polyline2[c->info().first][c->info().second + 1]); - - if(do_intersect_3_functor(s1, s2)){ - *m_iterator++ = std::make_pair(b->info(), c->info()); - } - } // end operator () -}; // end struct Intersect_polyline_ranges - struct Throw_at_first_output { class Throw_at_first_output_exception: public std::exception { }; @@ -1414,121 +1133,6 @@ bool do_intersect(const TriangleMesh& tm, return false; } -namespace internal { - -template -struct Mesh_callback -{ - typedef typename boost::range_value::type TriangleMesh; - typedef typename boost::range_value::type NamedParameters; - typedef typename GetVertexPointMap::const_type VPM; - typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits_3 Traits; - typedef CGAL::AABB_tree AABBTree; - typedef typename boost::graph_traits::face_descriptor face_descriptor; - - // fill them in the operator and test for inclusion with - // Side_of_triangle_mesh. - const TriangleMeshRange& meshes; - OutputIterator m_iterator; - const bool report_overlap; - const NamedParametersRange& nps; - std::vector trees; - GT gt; - - std::vector > > points_of_interest; - - Mesh_callback(const TriangleMeshRange& meshes, - OutputIterator iterator, - const bool report_overlap, - const GT& gt, - const NamedParametersRange& nps) - : meshes(meshes), m_iterator(iterator), - report_overlap(report_overlap), nps(nps), gt(gt) - { - std::size_t size = std::distance(meshes.begin(), meshes.end()); - trees = std::vector(size, nullptr); - points_of_interest.resize(size); - } - - ~Mesh_callback() - { - for(AABBTree* tree : trees) - { - delete tree; - } - } - - template - bool is_mesh2_in_mesh1(const TriangleMesh& tm1, - const TriangleMesh& tm2, - const std::size_t mesh_id_1, - const std::size_t mesh_id_2, - const VPM& vpm1, - const VPM& vpm2) - { - //test if tm2 is included in tm1 - - //get AABB_tree for tm1 - if(!trees[mesh_id_1]) - { - trees[mesh_id_1] = new AABBTree(faces(tm1).begin(), - faces(tm1).end(), - tm1, vpm1); - } - //get a face-index map for tm2 - if(points_of_interest[mesh_id_2].size() == 0) - get_one_point_per_cc(tm2, vpm2, points_of_interest[mesh_id_2]); - - //test if tm2 is included in tm1: - return is_mesh2_in_mesh1_impl( - *trees[mesh_id_1], points_of_interest[mesh_id_2], gt); - } - - template - void operator()(const Mesh_box* b1, const Mesh_box* b2) - { - using parameters::choose_parameter; - using parameters::get_parameter; - - std::size_t mesh_id_1 = std::distance(meshes.begin(), b1->info()); - std::size_t mesh_id_2 = std::distance(meshes.begin(), b2->info()); - - - VPM vpm1 = choose_parameter(get_parameter(*(nps.begin() + mesh_id_1), internal_np::vertex_point), - get_const_property_map(CGAL::vertex_point, *b1->info())); - - VPM vpm2 = choose_parameter(get_parameter(*(nps.begin() + mesh_id_2), internal_np::vertex_point), - get_const_property_map(CGAL::vertex_point, *b2->info())); - - //surfacic test - if(Polygon_mesh_processing::do_intersect(*b1->info(), - *b2->info(), - parameters::vertex_point_map(vpm1) - .geom_traits(gt), - parameters::vertex_point_map(vpm2) - .geom_traits(gt))) - { - *m_iterator++ = std::make_pair(mesh_id_1, mesh_id_2); - } - //volumic test - else if(report_overlap) - { - if(!CGAL::do_overlap(b1->bbox(), b2->bbox())) - return; - if(is_mesh2_in_mesh1(*b1->info(), *b2->info(), mesh_id_1, mesh_id_2, vpm1, vpm2)) - *m_iterator++ = std::make_pair(mesh_id_1, mesh_id_2); - else if(is_mesh2_in_mesh1(*b2->info(), *b1->info(), mesh_id_2, mesh_id_1, vpm2, vpm1)) - *m_iterator++ = std::make_pair(mesh_id_2, mesh_id_1); - } - } -}; -}//end internal - namespace internal { template struct AABB_indexed_bbox_primitive From 89b835567034c7e5469eedd40b291de2ee3528f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 15:18:47 +0100 Subject: [PATCH 101/136] cosmetic --- .../include/AABB_meshes_intersections.h | 12 ++++++------ .../internal/soup_and_face_graph_tree_helper.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/include/AABB_meshes_intersections.h b/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/include/AABB_meshes_intersections.h index a8cb29fb73b6..de3096de98d8 100644 --- a/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/include/AABB_meshes_intersections.h +++ b/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/include/AABB_meshes_intersections.h @@ -111,7 +111,7 @@ void mixed_meshes_intersections(const TriangleMesh1 &tm1, Bbox_pmap_1 bb1 = get(Face_bbox_tag(), tm1); Bbox_pmap_2 bb2 = get(Face_bbox_tag(), tm2); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(Concurrency_tag::is_parallel) { oneapi::tbb::parallel_for( oneapi::tbb::blocked_range(0, faces(tm1).size()), @@ -151,7 +151,7 @@ void mixed_meshes_intersections(const TriangleMesh1 &tm1, tree2.insert(faces(tm2).first, faces(tm2).second, tm2); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(Concurrency_tag::is_parallel) { CGAL_MUTEX m; oneapi::tbb::task_group tg; @@ -474,7 +474,7 @@ void AABB_two_trees_meshes_intersections(const TriangleMesh1 &tm1, Ref_point_map_2 rpm2 = get(Face_ref_point_tag(), tm); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(Concurrency_tag::is_parallel) { tbb::parallel_for(std::size_t(0), faces(tm1).size(), [&](std::size_t i){ face_descriptor f(i); @@ -512,7 +512,7 @@ void AABB_two_trees_meshes_intersections(const TriangleMesh1 &tm1, tree2.insert(faces(tm2).first, faces(tm2).second, tm2); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(Concurrency_tag::is_parallel) { oneapi::tbb::task_group tg; tg.run([&]{ tree1.template custom_build(compute_bbox1, split_primitives1); }); @@ -578,7 +578,7 @@ void AABB_self_intersections(const TriangleMesh &tm, OutputIterator out, const N tree.template build(); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(Concurrency_tag::is_parallel) { CGAL_MUTEX mutex; tbb::concurrent_vector> inter; @@ -679,7 +679,7 @@ void AABB_meshes_intersections(const TriangleMesh1 &tm1, tree.template build(); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(Concurrency_tag::is_parallel) { CGAL_MUTEX mutex; tbb::concurrent_vector> inter; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 93d393a79d93..467b0cb377e9 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -93,7 +93,7 @@ struct AABB_tree_graph_helper Ref_point_map rp_map = get(Face_ref_point_tag(), tm); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(Concurrency_tag::is_parallel) { tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ face_descriptor f = face_range[i]; // TODO: does not work if face_range is faces(tm) @@ -204,7 +204,7 @@ struct AABB_tree_soup_helper Ref_point_map rp_map = make_property_map(rp_vector); #ifdef CGAL_LINKED_WITH_TBB - if constexpr(std::is_same_v) + if constexpr(ConcurrencyTag::is_parallel) { tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ auto tid = face_range[i]; From a8db7b2fc274bf781b377bf347fbec9401d036fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 9 Nov 2026 15:16:46 +0100 Subject: [PATCH 102/136] Make the build compatible with non-random-access ranges --- .../soup_and_face_graph_tree_helper.h | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 93d393a79d93..1345b48bc006 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -95,11 +95,26 @@ struct AABB_tree_graph_helper #ifdef CGAL_LINKED_WITH_TBB if constexpr(std::is_same_v) { - tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ - face_descriptor f = face_range[i]; // TODO: does not work if face_range is faces(tm) - put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); - put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); - }); + // if face_range is not a random access range, we need to copy it to a vector first + // if face range is a random access range, it is penalized per a copy of the range + using Iterator = decltype(face_range.begin()); + constexpr bool is_random_access = std::is_base_of_v::iterator_category>; + auto parallel_call = [&](const auto& range){ + tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ + face_descriptor f = *(range.begin() + i); + put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); + put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); + }); + }; + if constexpr(is_random_access) + { + parallel_call(face_range); + } + else + { + std::vector face_range_vector(face_range.begin(), face_range.end()); + parallel_call(face_range_vector); + } } else #endif From 3affed82138bca0d0c1373ba24fe1f826d65db06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 15:21:58 +0100 Subject: [PATCH 103/136] missing include --- .../internal/Corefinement/intersection_impl.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 6f9abb101ca6..29969de9bea6 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -27,6 +27,10 @@ #include #include +#ifdef CGAL_LINKED_WITH_TBB +#include +#endif + #include #include #include From d99485992561729e528c29553a76ba79d120b3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 9 Nov 2026 17:15:35 +0100 Subject: [PATCH 104/136] Reintroduce polygon_mesh_slicer in PMP benchmark --- PMP_Boolean_operations/benchmark/CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PMP_Boolean_operations/benchmark/CMakeLists.txt b/PMP_Boolean_operations/benchmark/CMakeLists.txt index 06f801b003f5..6397f3061152 100644 --- a/PMP_Boolean_operations/benchmark/CMakeLists.txt +++ b/PMP_Boolean_operations/benchmark/CMakeLists.txt @@ -6,6 +6,8 @@ project(PMP_Boolean_operations_Benchmarks) # CGAL and its components find_package(CGAL REQUIRED) +find_package(Eigen3 QUIET) +include(CGAL_Eigen3_support) create_single_source_cgal_program("rotated_cubes_autorefinement.cpp") create_single_source_cgal_program("coplanar_cubes_autorefinement.cpp") @@ -22,8 +24,12 @@ create_single_source_cgal_program("Performance/performance_boolop.cpp") create_single_source_cgal_program("Robustness/robustness_boolop.cpp") create_single_source_cgal_program("Quality/quality_boolop.cpp") -#create_single_source_cgal_program("polygon_mesh_slicer.cpp") -#target_link_libraries(polygon_mesh_slicer PRIVATE CGAL::Eigen3_support) +if(TARGET CGAL::Eigen3_support) + create_single_source_cgal_program("polygon_mesh_slicer.cpp") + target_link_libraries(polygon_mesh_slicer PRIVATE CGAL::Eigen3_support) +else() + message(STATUS "NOTICE: Eigen3 not found. polygon_mesh_slicer will not be built.") +endif() find_package(TBB QUIET) include(CGAL_TBB_support) From 67e10714a37089f1171615d3020bfec73e9c5108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 9 Nov 2026 17:17:16 +0100 Subject: [PATCH 105/136] Rewrite parallelisation to avoid std::next(begin, i) potentially expensive for Surface_mesh --- .../soup_and_face_graph_tree_helper.h | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 1bcf6075ffba..09abb0d92966 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -95,26 +95,20 @@ struct AABB_tree_graph_helper #ifdef CGAL_LINKED_WITH_TBB if constexpr(Concurrency_tag::is_parallel) { - // if face_range is not a random access range, we need to copy it to a vector first - // if face range is a random access range, it is penalized per a copy of the range - using Iterator = decltype(face_range.begin()); - constexpr bool is_random_access = std::is_base_of_v::iterator_category>; - auto parallel_call = [&](const auto& range){ - tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ - face_descriptor f = *(range.begin() + i); - put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); - put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); - }); - }; - if constexpr(is_random_access) + tbb::parallel_for( + tbb::blocked_range(0, face_range.size()), + [&](const tbb::blocked_range& block) { - parallel_call(face_range); - } - else - { - std::vector face_range_vector(face_range.begin(), face_range.end()); - parallel_call(face_range_vector); - } + auto it = std::next(std::begin(face_range), block.begin()); + + for (std::size_t i = block.begin(); i != block.end(); ++i, ++it) + { + face_descriptor f = *it; + + put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); + put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm)))); + } + }); } else #endif From 2e99a603a5be0e6286e51cb1cf018e9e66b00cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 9 Nov 2026 17:18:06 +0100 Subject: [PATCH 106/136] Apply suggestions from the review --- .../Polygon_mesh_processing/intersection.h | 32 ++----------------- .../self_intersections.h | 1 - 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 5e5e226e0363..f885fe73d794 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -591,8 +591,8 @@ compute_polyline_polyline_intersection(const Polyline& polyline1, OutputIterator out, const Kernel& K) { - std::array polylines1{{polyline1}}; - std::array polylines2{{polyline2}}; + std::array, 1> polylines1{{std::cref(polyline1)}}; + std::array, 1> polylines2{{std::cref(polyline2)}}; auto polyline_out = boost::make_function_output_iterator( @@ -1133,34 +1133,6 @@ bool do_intersect(const TriangleMesh& tm, return false; } -namespace internal { - template - struct AABB_indexed_bbox_primitive - { - using Id = std::size_t; - using Datum = CGAL::Bbox_3; - - AABB_indexed_bbox_primitive() = default; - - AABB_indexed_bbox_primitive(Iterator it) - : m_it(it) - {} - - Id id() const - { - return m_it->index; - } - - const Datum& datum() const - { - return m_it->bbox; - } - - private: - Iterator m_it; - }; -} - /*! * \ingroup PMP_intersection_grp * diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index dd383115dc19..8cab052f0a38 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -400,7 +400,6 @@ class Listing_intersecting_faces_two_trees_traits constexpr bool go_further() const { return true; } - // node coming from the same tree, always alternate is a good choice template bool prefer_A_for_next_step(const Node_A&, const Node_B&, const std::size_t&, const std::size_t&) const { return false; From d670930d60888dfe1f7813d4fd792a313a24845e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 17:22:53 +0100 Subject: [PATCH 107/136] missing vpm --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 5e5e226e0363..7f41a9dceb04 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -159,10 +159,10 @@ compute_face_face_intersection(const FaceRange& face_range1, std::vector faces_to_test2; for(face_descriptor f : face_range1) - if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm1), bb)) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm1, parameters::vertex_point_map(vpm1)), bb)) faces_to_test1.emplace_back(f); for(face_descriptor f : face_range2) - if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm2), bb)) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm2, parameters::vertex_point_map(vpm2)), bb)) faces_to_test2.emplace_back(f); Tree_1 tree1; @@ -282,7 +282,7 @@ compute_face_polyline_intersection(const FaceRange& face_range, std::vector faces_to_test; for(face_descriptor f : face_range) - if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm), bb)) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm, parameters::vertex_point_map(vpm)), bb)) faces_to_test.emplace_back(f); AABB_tree_helper helper; @@ -424,7 +424,7 @@ compute_face_polylines_intersection(const FaceRange& face_range, std::vector faces_to_test; for(face_descriptor f : face_range) - if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm), bb)) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm, parameters::vertex_point_map(vpm)), bb)) faces_to_test.emplace_back(f); AABB_tree_helper helper; From 8d610b7c547d7ac6a868c4764a3964aa745ecaa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Mon, 9 Nov 2026 17:30:16 +0100 Subject: [PATCH 108/136] Complete missing commentaries --- .../internal/Corefinement/intersection_impl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 6f9abb101ca6..134f980cb720 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -408,6 +408,7 @@ class Intersection_of_triangle_meshes else { if (const_mesh_ptr==&tm1) { + // tm1 might feature degenerate features auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ if (get(vpm2, source(h2, tm2)) != get(vpm2, target(h2, tm2))) callback12(h1, h2); @@ -444,7 +445,7 @@ class Intersection_of_triangle_meshes { if (const_mesh_ptr==&tm2) { - // tm2 might feature + // tm2 might feature degenerate features auto filtered_callback_12 = [&](halfedge_descriptor h1, halfedge_descriptor h2){ if(!callback12.is_face_degenerated(h1)) callback12(h1, h2); From a31dbcee3ae507731cc753a41ec21c9243250292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 17:34:17 +0100 Subject: [PATCH 109/136] take a reference so that the output iterator is really updated --- .../CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index b201580812fc..5eb0907ed97b 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -29,9 +29,9 @@ template Date: Mon, 9 Nov 2026 17:41:17 +0100 Subject: [PATCH 110/136] Remove unnecessary copy --- .../include/CGAL/Polygon_mesh_processing/self_intersections.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index 8cab052f0a38..669c84047629 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -556,8 +556,7 @@ self_intersections_impl(const FaceRange& face_range, { std::atomic atomic_counter(counter); std::atomic atomic_flag(false); - Throw_iterator throwing_count(atomic_counter, atomic_flag, maximum_number, std::back_inserter(face_pairs)); - Throw_at_count_reached_output_iterator count_filter(throwing_count); + Throw_iterator count_filter(atomic_counter, atomic_flag, maximum_number, std::back_inserter(face_pairs)); all_pairs_of_intersecting_faces(tree, count_filter); } catch(const CGAL::internal::Throw_at_output_exception&) From 69cbb8a238faeb7dda27c0e4cdefb4c200ca991e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 17:43:30 +0100 Subject: [PATCH 111/136] handle degenerate polylines and missing out it update --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 7f41a9dceb04..3f00497f33f8 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -502,6 +502,7 @@ compute_polylines_polylines_intersection(const PolylineRange& polylines1, for(std::size_t pi = 0; pi < polylines1.size(); ++pi) { const auto& polyline = polylines1[pi]; + if (polyline.size()<2) continue; //skip isolated points polyline_begin1.push_back(segments1.size()); auto pit = std::begin(polyline); @@ -513,6 +514,7 @@ compute_polylines_polylines_intersection(const PolylineRange& polylines1, for(std::size_t pi = 0; pi < polylines2.size(); ++pi) { const auto& polyline = polylines2[pi]; + if (polyline.size()<2) continue; //skip isolated points polyline_begin2.push_back(segments2.size()); auto pit = std::begin(polyline); @@ -602,7 +604,7 @@ compute_polyline_polyline_intersection(const Polyline& polyline1, pair.second.second); }); - compute_polylines_polylines_intersection(polylines1, polylines2, polyline_out, K); + out = compute_polylines_polylines_intersection(polylines1, polylines2, polyline_out, K); return out; } From c8edea5d21f13867fda0273a556ff7083bb32f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 17:49:05 +0100 Subject: [PATCH 112/136] typo: use range size --- .../internal/soup_and_face_graph_tree_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 1bcf6075ffba..ca3962b89aa7 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -100,7 +100,7 @@ struct AABB_tree_graph_helper using Iterator = decltype(face_range.begin()); constexpr bool is_random_access = std::is_base_of_v::iterator_category>; auto parallel_call = [&](const auto& range){ - tbb::parallel_for(std::size_t(0), face_range.size(), [&](std::size_t i){ + tbb::parallel_for(std::size_t(0), range.size(), [&](std::size_t i){ face_descriptor f = *(range.begin() + i); put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm))) ); From 1f088a7eb7fd2a883cd41110b3c8213a56a071ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 18:11:31 +0100 Subject: [PATCH 113/136] no need to update it, taken by ref --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 3f00497f33f8..fe40a0c4bc81 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -604,7 +604,7 @@ compute_polyline_polyline_intersection(const Polyline& polyline1, pair.second.second); }); - out = compute_polylines_polylines_intersection(polylines1, polylines2, polyline_out, K); + compute_polylines_polylines_intersection(polylines1, polylines2, polyline_out, K); return out; } From bd9e2ca996216b4e2fe02db760273ebb89af1cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 18:31:47 +0100 Subject: [PATCH 114/136] idiom for output iterator wrapping --- .../AABB_tree/internal/AABB_two_trees_traversal_traits.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h index 5eb0907ed97b..cf7551a8b492 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal_traits.h @@ -35,15 +35,14 @@ class Wrap_output_iterator Wrap_output_iterator& operator=(Value2 second){ if constexpr(in_order) - *out = std::make_pair(first, second); + *out++ = std::make_pair(first, second); else - *out = std::make_pair(second, first); + *out++ = std::make_pair(second, first); return *this; } Wrap_output_iterator& operator*(){ return *this; } - Wrap_output_iterator& operator++(){ ++out; return *this; } - Wrap_output_iterator operator++(int){ auto tmp = *this; ++out; return tmp; } - Wrap_output_iterator& operator+(int d){ out += d; return *this; } + Wrap_output_iterator& operator++(){ return *this; } + Wrap_output_iterator& operator++(int){ return *this;} }; template From dfe442f8bfd95c87a631024fec1f4cc93fb06b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 18:50:38 +0100 Subject: [PATCH 115/136] even when skipping polylines, index should be registered still compatible with upper_bound that will look for the first larger and then take the one just before --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index fe40a0c4bc81..8440105ce905 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -502,8 +502,8 @@ compute_polylines_polylines_intersection(const PolylineRange& polylines1, for(std::size_t pi = 0; pi < polylines1.size(); ++pi) { const auto& polyline = polylines1[pi]; - if (polyline.size()<2) continue; //skip isolated points polyline_begin1.push_back(segments1.size()); + if (polyline.size()<2) continue; //skip isolated points auto pit = std::begin(polyline); auto prev = pit++; @@ -514,8 +514,8 @@ compute_polylines_polylines_intersection(const PolylineRange& polylines1, for(std::size_t pi = 0; pi < polylines2.size(); ++pi) { const auto& polyline = polylines2[pi]; - if (polyline.size()<2) continue; //skip isolated points polyline_begin2.push_back(segments2.size()); + if (polyline.size()<2) continue; //skip isolated points auto pit = std::begin(polyline); auto prev = pit++; From 526dcd9ca9f7a081382e187d1c37070b0f14878f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 18:54:26 +0100 Subject: [PATCH 116/136] same fix here too --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 8440105ce905..4945f844bf94 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -411,10 +411,8 @@ compute_face_polylines_intersection(const FaceRange& face_range, { const auto& polyline = polyline_range[pi]; - if(polyline.size() < 2) - continue; - polyline_begin.push_back(segments.size()); + if(polyline.size() < 2) continue; auto pit = std::begin(polyline); auto prev = pit++; From 010c70794ee3b8f4801eb88eaa485a0428c1097d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Nov 2026 20:27:26 +0100 Subject: [PATCH 117/136] get rid of internal functions and use AABB_trees::do_intersect() instead the internal function were not compatible with concurrent insertions so instead of an hypothetical use, directly use the AABB-tree function Avoid throwing an exception at the same time --- .../Polygon_mesh_processing/intersection.h | 983 +++++------------- .../pmp_do_intersect_test.cpp | 141 +-- 2 files changed, 269 insertions(+), 855 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 4945f844bf94..2c35ca703aea 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -38,691 +38,6 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace internal { -struct Throw_at_first_output { - class Throw_at_first_output_exception: public std::exception - { }; - - template - void operator()(const T& /* t */) const { - throw Throw_at_first_output_exception(); - } -}; - -// Note this is not officially documented -/* \ingroup PMP_intersection_grp - * - * reports all the pairs of faces intersecting between two triangulated surface meshes. - * - * This function depends on the package \ref PkgBoxIntersectionD. - * - * @pre \link CGAL::is_triangle_mesh `CGAL::is_triangle_mesh(tm1)` \endlink - * @pre \link CGAL::is_triangle_mesh `CGAL::is_triangle_mesh(tm2)` \endlink - * - * \tparam TriangleMesh a model of `FaceListGraph` - * \tparam FaceRange range of `boost::graph_traits::%face_descriptor`, - * model of `RandomAccessRange`. - * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair::%face_descriptor, boost::graph_traits::%face_descriptor>` - * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - * - * \param face_range1 the range of faces of `tm1` to check for intersections. - * \param face_range2 the range of faces of `tm2` to check for intersections. - * \param tm1 the first triangulated surface mesh. - * \param tm2 the second triangulated surface mesh. - * \param out output iterator to be filled with all pairs of faces that intersect. - * First and second element in the pairs correspond to faces of `tm1` and `tm2` respectively - * \param np1 an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below - * \param np2 an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below - * - * \cgalNamedParamsBegin - * \cgalParamNBegin{vertex_point_map} - * \cgalParamDescription{a property map associating points to the vertices of `tm1` (`tm2`)} - * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` - * as key type and `%Point_3` as value type} - * \cgalParamDefault{`boost::get(CGAL::vertex_point, tm1 (tm2))`} - * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` - * should be available for the vertices of `tm1` (`tm2`)} - * \cgalParamExtra{Both vertex point maps must have the same value type} - * \cgalParamNEnd - * - * \cgalParamNBegin{geom_traits} - * \cgalParamDescription{an instance of a geometric traits class} - * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} - * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} - * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} - * \cgalParamExtra{np1 only} - * \cgalParamNEnd - * \cgalNamedParamsEnd - * - * \return `out` - */ -template -OutputIterator -compute_face_face_intersection(const FaceRange& face_range1, - const FaceRange& face_range2, - const TriangleMesh& tm1, - const TriangleMesh& tm2, - OutputIterator out, - const NamedParameters1& np1, - const NamedParameters2& np2) -{ - using parameters::get_parameter; - using parameters::choose_parameter; - - CGAL_precondition(CGAL::is_triangle_mesh(tm1)); - CGAL_precondition(CGAL::is_triangle_mesh(tm2)); - - using Concurrency_tag = typename internal_np::Lookup_named_param_def < - internal_np::concurrency_tag_t, - NamedParameters1, - Sequential_tag - > ::type; - - using GT = typename GetGeomTraits::type; - - using VPM1 = typename GetVertexPointMap::const_type; - using VPM2 = typename GetVertexPointMap::const_type; - - using face_descriptor = typename boost::graph_traits::face_descriptor; - - using AABB_tree_helper_1 = internal::AABB_tree_graph_helper; - using AABB_tree_helper_2 = internal::AABB_tree_graph_helper; - using Tree_1 = typename AABB_tree_helper_1::Tree; - using Tree_2 = typename AABB_tree_helper_2::Tree; - AABB_tree_helper_1 helper_1; - AABB_tree_helper_2 helper_2; - - // compute intersections filtered out by boxes - CGAL::Bbox_3 b1 = CGAL::Polygon_mesh_processing::bbox(tm1, np1), - b2 = CGAL::Polygon_mesh_processing::bbox(tm2, np2); - - if(!CGAL::do_overlap(b1, b2)) - return out; - Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), - (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); - - VPM1 vpm1 = choose_parameter(get_parameter(np1, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, tm1)); - VPM2 vpm2 = choose_parameter(get_parameter(np2, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, tm2)); - static_assert( - (std::is_same< - typename boost::property_traits::value_type, - typename boost::property_traits::value_type - >::value) ); - - std::vector faces_to_test1; - std::vector faces_to_test2; - - for(face_descriptor f : face_range1) - if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm1, parameters::vertex_point_map(vpm1)), bb)) - faces_to_test1.emplace_back(f); - for(face_descriptor f : face_range2) - if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm2, parameters::vertex_point_map(vpm2)), bb)) - faces_to_test2.emplace_back(f); - - Tree_1 tree1; - Tree_2 tree2; - helper_1.template build(faces_to_test1, tree1, tm1, vpm1); - helper_2.template build(faces_to_test2, tree2, tm2, vpm2); - - out = CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, out, parameters::concurrency_tag(Concurrency_tag())); - return out; -} - -// Note this is not officially documented -/* \ingroup PMP_intersection_grp - * - * reports all the pairs of segments and faces intersecting between - * a triangulated surface mesh and a polyline. - * - * This function depends on the package \ref PkgBoxIntersectionD. - * - * \attention If a polyline vertex intersects a face, the intersection will - * be reported twice (or more if it is on a vertex, edge, or point). - * - * @pre \link CGAL::is_triangle_mesh `CGAL::is_triangle_mesh(tm)` \endlink - * - * \tparam TriangleMesh a model of `FaceListGraph` - * \tparam FaceRange range of `boost::graph_traits::%face_descriptor`, - * model of `RandomAccessRange`. - * \tparam Polyline a `RandomAccessRange` of points. The point type of the range must be - * the same as the value type of the vertex point map. - * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair`.This `OutputIterator` will hold the position of the - * elements in their respective range. In the case of the polyline, this position is the index of - * the segment intersecting the face (which is the index of the first point of the - * segment following the range order.) - * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - * - * \param face_range the range of faces of `tm` to check for intersections. - * \param polyline the polyline to check for intersections. - * \param tm the triangulated surface mesh to check for intersections. - * \param out output iterator to be filled with all pairs of face-segment that intersect - * \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below - * - * \cgalNamedParamsBegin - * \cgalParamNBegin{vertex_point_map} - * \cgalParamDescription{a property map associating points to the vertices of `tm`} - * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` as key type and `%Point_3` as value type} - * \cgalParamDefault{`boost::get(CGAL::vertex_point, tm)`} - * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` - * should be available for the vertices of `tm`.} - * \cgalParamNEnd - * - * \cgalParamNBegin{geom_traits} - * \cgalParamDescription{an instance of a geometric traits class} - * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} - * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} - * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} - * \cgalParamNEnd - * \cgalNamedParamsEnd - * - * \return `out` - */ -template -OutputIterator -compute_face_polyline_intersection(const FaceRange& face_range, - const Polyline& polyline, - const TriangleMesh& tm, - OutputIterator out, - const NamedParameters& np) -{ - using parameters::get_parameter; - using parameters::choose_parameter; - - CGAL_precondition(CGAL::is_triangle_mesh(tm)); - - using Concurrency_tag = typename internal_np::Lookup_named_param_def < - internal_np::concurrency_tag_t, - NamedParameters, - Sequential_tag - >::type; - - using GT = typename GetGeomTraits::type; - - using VPM = typename GetVertexPointMap::const_type; - using face_descriptor = typename boost::graph_traits::face_descriptor; - using Segment_3 = typename GT::Segment_3; - - using AABB_tree_helper = internal::AABB_tree_graph_helper; - using Face_tree = typename AABB_tree_helper::Tree; - - using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; - using Segment_traits = CGAL::AABB_traits_3; - using Segment_tree = CGAL::AABB_tree; - - VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, tm)); - - Bbox_3 b1 = Polygon_mesh_processing::bbox(tm, np), - b2 = bbox_3(polyline.begin(), polyline.end()); - - if(!CGAL::do_overlap(b1, b2)) - return out; - Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), - (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); - - std::vector segments; - if(polyline.size() < 2) - return out; - - auto pit = std::begin(polyline); - auto prev = pit++; - for(; pit != std::end(polyline); ++pit, ++prev) - segments.emplace_back(*prev, *pit); - - std::vector faces_to_test; - for(face_descriptor f : face_range) - if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm, parameters::vertex_point_map(vpm)), bb)) - faces_to_test.emplace_back(f); - - AABB_tree_helper helper; - Face_tree face_tree; - - helper.template build(faces_to_test, face_tree, tm, vpm); - Segment_tree segment_tree(segments.begin(), segments.end()); - - auto out_converter = boost::make_function_output_iterator( - [&](const auto& pair) { - *out++ = std::make_pair(pair.first, - static_cast(pair.second - segments.begin())); - }); - CGAL::AABB_trees::all_pairs_of_intersecting_primitives(face_tree, segment_tree, out_converter, parameters::concurrency_tag(Concurrency_tag())); - return out; -} - -// Note this is not officially documented -/* \ingroup PMP_intersection_grp - * - * reports all the pairs of segments and faces intersecting between - * a triangulated surface mesh and a range of polylines. - * - * This function depends on the package \ref PkgBoxIntersectionD. - * - * \attention If a polyline vertex intersects a face, the intersection will - * be reported twice (even more if it is on a vertex, edge, or point). - * - * @pre \link CGAL::is_triangle_mesh `CGAL::is_triangle_mesh(tm)` \endlink - * - * \tparam TriangleMesh a model of `FaceListGraph` - * \tparam FaceRange range of `boost::graph_traits::%face_descriptor`, - * model of `RandomAccessRange`. - * \tparam PolylineRange a `RandomAccessRange` of `RandomAccessRange` of points. The point type of the range must be - * the same as the value type of the vertex point map. - * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair >`. - * Each pair holds the index of the face and a pair containing the index of the polyline in the range and the index of - * the first point of the segment in the polyline. - * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - * - * \param face_range the range of `tm` faces to check for intersections. - * \param polyline_range the range of polylines to check for intersections. - * \param tm the triangulated surface mesh to check for intersections. - * \param out output iterator to be filled with all pairs of face-segment that intersect - * \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below - * - * \cgalNamedParamsBegin - * \cgalParamNBegin{vertex_point_map} - * \cgalParamDescription{a property map associating points to the vertices of `tm`} - * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` - * as key type and `%Point_3` as value type} - * \cgalParamDefault{`boost::get(CGAL::vertex_point, tm)`} - * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` - * should be available for the vertices of `tm`.} - * \cgalParamNEnd - * - * \cgalParamNBegin{geom_traits} - * \cgalParamDescription{an instance of a geometric traits class} - * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} - * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} - * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} - * \cgalParamNEnd - * \cgalNamedParamsEnd - * \return `out` - */ -template -OutputIterator -compute_face_polylines_intersection(const FaceRange& face_range, - const PolylineRange& polyline_range, - const TriangleMesh& tm, - OutputIterator out, - const NamedParameters& np) -{ - if (face_range.empty() || polyline_range.empty()) - return out; - - using parameters::get_parameter; - using parameters::choose_parameter; - - CGAL_precondition(CGAL::is_triangle_mesh(tm)); - - using Concurrency_tag = typename internal_np::Lookup_named_param_def < - internal_np::concurrency_tag_t, - NamedParameters, - Sequential_tag - >::type; - - using GT = typename GetGeomTraits::type; - - using VPM = typename GetVertexPointMap::const_type; - using face_descriptor = typename boost::graph_traits::face_descriptor; - using Segment_3 = typename GT::Segment_3; - - using AABB_tree_helper = internal::AABB_tree_graph_helper; - using Face_tree = typename AABB_tree_helper::Tree; - - using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; - using Segment_traits = CGAL::AABB_traits_3; - using Segment_tree = CGAL::AABB_tree; - - VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, tm)); - - Bbox_3 b1; - for (face_descriptor f : face_range) - b1 += Polygon_mesh_processing::face_bbox(f, tm, np); - auto polyline_it = polyline_range.begin(); - Bbox_3 b2 = bbox_3(polyline_it->begin(), polyline_it->end()); // can deref the polyline_it as we already checked it's not empty - for(++polyline_it; polyline_it != polyline_range.end(); ++polyline_it) - b2 += bbox_3(polyline_it->begin(), polyline_it->end()); - - if(!CGAL::do_overlap(b1, b2)) - return out; - Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), - (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); - - // We store all polylines in one range and we store the offset of the beginning of each polyline - std::vector segments; - std::vector polyline_begin; - for(std::size_t pi = 0; pi < polyline_range.size(); ++pi) - { - const auto& polyline = polyline_range[pi]; - - polyline_begin.push_back(segments.size()); - if(polyline.size() < 2) continue; - - auto pit = std::begin(polyline); - auto prev = pit++; - for(; pit != std::end(polyline); ++pit, ++prev) - segments.emplace_back(*prev, *pit); - } - - std::vector faces_to_test; - for(face_descriptor f : face_range) - if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm, parameters::vertex_point_map(vpm)), bb)) - faces_to_test.emplace_back(f); - - AABB_tree_helper helper; - Face_tree face_tree; - - helper.template build(faces_to_test, face_tree, tm, vpm); - Segment_tree segment_tree(segments.begin(), segments.end()); - - auto out_converter = - boost::make_function_output_iterator( - [&](const auto& pair) - { - std::size_t index = pair.second - segments.begin(); - - // Find the polyline containing this segment. - auto it = std::upper_bound(polyline_begin.begin(), - polyline_begin.end(), - index); - - std::size_t polyline_index = static_cast(it - polyline_begin.begin() - 1); - std::size_t segment_index = index - polyline_begin[polyline_index]; - - *out++ = std::make_pair(pair.first, - std::make_pair(polyline_index, segment_index)); - }); - CGAL::AABB_trees::all_pairs_of_intersecting_primitives(face_tree, segment_tree, out_converter, parameters::concurrency_tag(Concurrency_tag())); - return out; -} - -// Note this is not officially documented -/* \ingroup PMP_intersection_grp - * - * detects and records intersections between two ranges of polylines. - * - * This function depends on the package \ref PkgBoxIntersectionD. - * - * \attention If a polyline vertex intersects another polyline, the intersection will - * be reported twice (even more if it is on a vertex). - * - * \tparam PolylineRange a `RandomAccessRange` of `RandomAccessRange` of points. - * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair, std::pair >`. - * Each pair holds the index of the face and a pair containing the index of the polyline in the range and the index of - * the first point of the segment in the polyline. - * \tparam Kernel a model of `Kernel` - * - * \param polylines1 the first range of polylines to check for intersections. - * \param polylines2 the second range of polylines to check for intersections. - * \param out output iterator to be filled with all pairs of segments that intersect - * \param K an instance of `Kernel` - * - * \return `out` - */ -template < class PolylineRange, - class OutputIterator, - class Kernel> -OutputIterator -compute_polylines_polylines_intersection(const PolylineRange& polylines1, - const PolylineRange& polylines2, - OutputIterator out, - const Kernel& /*K*/) -{ - using parameters::get_parameter; - - using GT = Kernel; - using Segment_3 = typename GT::Segment_3; - - using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; - using Segment_traits = CGAL::AABB_traits_3; - using Segment_tree = CGAL::AABB_tree; - - std::vector segments1, segments2; - std::vector polyline_begin1, polyline_begin2; - - for(std::size_t pi = 0; pi < polylines1.size(); ++pi) - { - const auto& polyline = polylines1[pi]; - polyline_begin1.push_back(segments1.size()); - if (polyline.size()<2) continue; //skip isolated points - - auto pit = std::begin(polyline); - auto prev = pit++; - for(; pit != std::end(polyline); ++pit, ++prev) - segments1.emplace_back(*prev, *pit); - } - - for(std::size_t pi = 0; pi < polylines2.size(); ++pi) - { - const auto& polyline = polylines2[pi]; - polyline_begin2.push_back(segments2.size()); - if (polyline.size()<2) continue; //skip isolated points - - auto pit = std::begin(polyline); - auto prev = pit++; - for(; pit != std::end(polyline); ++pit, ++prev) - segments2.emplace_back(*prev, *pit); - } - - if(segments1.empty() || segments2.empty()) - return out; - - Segment_tree tree1(segments1.begin(), segments1.end()); - Segment_tree tree2(segments2.begin(), segments2.end()); - - auto convert_out = - boost::make_function_output_iterator( - [&](const auto& pair) - { - const std::size_t offset1 = static_cast(pair.first - segments1.cbegin()); - const std::size_t offset2 = static_cast(pair.second - segments2.cbegin()); - - const auto it1 = std::upper_bound(polyline_begin1.begin(), - polyline_begin1.end(), - offset1); - - const auto it2 = std::upper_bound(polyline_begin2.begin(), - polyline_begin2.end(), - offset2); - - const std::size_t pi1 = static_cast(it1 - polyline_begin1.begin() - 1); - const std::size_t pi2 = static_cast(it2 - polyline_begin2.begin() - 1); - - *out++ = std::make_pair( - std::make_pair(pi1, offset1 - polyline_begin1[pi1]), - std::make_pair(pi2, offset2 - polyline_begin2[pi2])); - }); - - CGAL::AABB_trees::all_pairs_of_intersecting_primitives( - tree1, - tree2, - convert_out); - - return out; -} - -// Note this is not officially documented -/* \ingroup PMP_intersection_grp - * - * detects and records intersections between two polylines. - * - * This function depends on the package \ref PkgBoxIntersectionD. - * - * \attention If a polyline vertex intersects another polyline, the intersection will - * be reported twice (even more if it is on a vertex). - * - * \tparam Polyline a `RandomAccessRange` of points. - * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair`. This OutputIterator will hold the position of the - * elements in their respective range. This position is the index of the segment that holds the - * intersection, so it is the index of the first point of the segment following the range order. - * \tparam Kernel a model of `Kernel` - * - * \param polyline1 the first polyline to check for intersections. - * \param polyline2 the second polyline to check for intersections. - * \param out output iterator to be filled with all pairs of segments that intersect - * \param K an instance of `Kernel` - * - * \return `out` - */ -template < class Polyline, - class OutputIterator, - class Kernel> -OutputIterator -compute_polyline_polyline_intersection(const Polyline& polyline1, - const Polyline& polyline2, - OutputIterator out, - const Kernel& K) -{ - std::array polylines1{{polyline1}}; - std::array polylines2{{polyline2}}; - - auto polyline_out = - boost::make_function_output_iterator( - [&](const auto& pair) - { - *out++ = std::make_pair(pair.first.second, - pair.second.second); - }); - - compute_polylines_polylines_intersection(polylines1, polylines2, polyline_out, K); - return out; -} - -// Note this is not officially documented -/* \ingroup PMP_intersection_grp - * - * reports all the pairs of faces intersecting between two triangulated surface meshes. - * - * This function depends on the package \ref PkgBoxIntersectionD. - * - * @pre \link CGAL::is_triangle_mesh `CGAL::is_triangle_mesh(tm1)` \endlink - * @pre \link CGAL::is_triangle_mesh `CGAL::is_triangle_mesh(tm2)` \endlink - * - * \tparam TriangleMesh a model of `FaceListGraph` - * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair::%face_descriptor, boost::graph_traits::%face_descriptor>` - * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - * - * \param tm1 the first triangulated surface mesh to check for intersections - * \param tm2 the second triangulated surface mesh to check for intersections - * \param out output iterator to be filled with all pairs of faces that intersect - * \param np1 an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below - * \param np2 an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below - * - * \cgalNamedParamsBegin - * \cgalParamNBegin{vertex_point_map} - * \cgalParamDescription{a property map associating points to the vertices of `tm1` (`tm2`)} - * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` - * as key type and `%Point_3` as value type} - * \cgalParamDefault{`boost::get(CGAL::vertex_point, tm1 (tm2))`} - * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` - * should be available for the vertices of `tm1` (`tm2`)} - * \cgalParamNEnd - * - * \cgalParamNBegin{geom_traits} - * \cgalParamDescription{an instance of a geometric traits class} - * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} - * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} - * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} - * \cgalParamExtra{np1 only} - * \cgalParamNEnd - * \cgalNamedParamsEnd - * - * \return `out` - */ -template -OutputIterator -compute_face_face_intersection(const TriangleMesh& tm1, - const TriangleMesh& tm2, - OutputIterator out, - const NamedParameters1& np1, - const NamedParameters2& np2) -{ - return compute_face_face_intersection(faces(tm1), faces(tm2), - tm1, tm2, out, np1, np2); -} - -// Note this is not officially documented -/* \ingroup PMP_intersection_grp - * - * detects and records intersections between a triangulated surface mesh and a polyline. - * - * This function depends on the package \ref PkgBoxIntersectionD. - * - * \attention If a polyline vertex intersects a face or another polyline, the intersection will - * be reported twice (even more if it is on a vertex, edge, or point). - * - * @pre \link CGAL::is_triangle_mesh `CGAL::is_triangle_mesh(tm)` \endlink - * - * \tparam TriangleMesh a model of `FaceListGraph` - * \tparam Polyline a `RandomAccessRange` of points. The point type of the range must be the - * same as the value type of the vertex point map. - * \cgalDescribePolylineType - * \tparam OutputIterator a model of `OutputIterator` holding objects of type - * `std::pair`. This OutputIterator will hold the position of the - * elements in their respective range. In the case of the polyline, this position is the index - * of the segment that holds the intersection, so it is the index of the first point of the - * segment following the range order. - * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - * - * \param tm the triangulated surface mesh to check for intersections. - * \param polyline the polyline to check for intersections. - * \param out output iterator to be filled with all pairs of face-segment that intersect - * \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below - * - * \cgalNamedParamsBegin - * \cgalParamNBegin{vertex_point_map} - * \cgalParamDescription{a property map associating points to the vertices of `tm`} - * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` as key type and `%Point_3` as value type} - * \cgalParamDefault{`boost::get(CGAL::vertex_point, tm)`} - * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` - * should be available for the vertices of `tm`.} - * \cgalParamNEnd - * - * \cgalParamNBegin{geom_traits} - * \cgalParamDescription{an instance of a geometric traits class} - * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} - * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} - * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} - * \cgalParamNEnd - * \cgalNamedParamsEnd - * - * \return `out` - */ -template -OutputIterator -compute_face_polyline_intersection(const TriangleMesh& tm, - const Polyline& polyline, - OutputIterator out, - const NamedParameters& np) -{ - return compute_face_polyline_intersection(faces(tm), polyline, tm, out, np); -} - // functions to check for overlap of meshes template void get_one_point_per_cc(TriangleMesh& tm, @@ -809,14 +124,26 @@ bool is_mesh2_in_mesh1(const TriangleMesh& tm1, * \tparam PolylineRange a `RandomAccessRange` of `RandomAccessRange` of points. * The point type must be from a 3D point from a \cgal Kernel. * \cgalDescribePolylineType + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" for the algorithm * * @param polylines1 the first range of polylines to check for intersections. * @param polylines2 the second range of polylines to check for intersections. + * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd + * \cgalNamedParamsEnd * */ -template +template bool do_intersect(const PolylineRange& polylines1, - const PolylineRange& polylines2 + const PolylineRange& polylines2, + const NamedParameters& np = parameters::default_values() #ifndef DOXYGEN_RUNNING , const std::enable_if_t< boost::has_range_iterator< @@ -829,18 +156,63 @@ bool do_intersect(const PolylineRange& polylines1, #endif ) { - typedef typename boost::range_value::type Polyline; - typedef typename boost::range_value::type Point; - typedef typename CGAL::Kernel_traits::Kernel K; - try + CGAL_USE(np); + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + > ::type; + + using Polyline = typename boost::range_value::type; + using Point = typename boost::range_value::type; + using GT = typename CGAL::Kernel_traits::Kernel; + using Segment_3 = typename GT::Segment_3; + + using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; + using Segment_traits = CGAL::AABB_traits_3; + using Segment_tree = CGAL::AABB_tree; + + Bbox_3 b1; + for(const auto& polyline : polylines1) + b1 += bbox_3(polyline.begin(), polyline.end()); + Bbox_3 b2; + for(const auto& polyline : polylines2) + b2 += bbox_3(polyline.begin(), polyline.end()); + + if(!CGAL::do_overlap(b1, b2)) + return false; + + Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), + (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); + + // We store all polylines in one filtered range + std::vector segments1; + for (const auto& polyline : polylines1) + { + if(polyline.size() < 2) continue; + + auto pit = std::begin(polyline); + auto prev = pit++; + for(; pit != std::end(polyline); ++pit, ++prev) + if (do_overlap(bb, prev->bbox()+pit->bbox())) + segments1.emplace_back(*prev, *pit); + } + std::vector segments2; + for (const auto& polyline : polylines2) { - typedef boost::function_output_iterator OutputIterator; - internal::compute_polylines_polylines_intersection(polylines1, polylines2, OutputIterator(), K()); + if(polyline.size() < 2) continue; + + auto pit = std::begin(polyline); + auto prev = pit++; + for(; pit != std::end(polyline); ++pit, ++prev) + if (do_overlap(bb, prev->bbox()+pit->bbox())) + segments2.emplace_back(*prev, *pit); } - catch( internal::Throw_at_first_output::Throw_at_first_output_exception& ) - { return true; } - return false; + Segment_tree tree1(segments1.begin(), segments1.end()); + Segment_tree tree2(segments2.begin(), segments2.end()); + + return AABB_trees::do_intersect(tree1, tree2, parameters::concurrency_tag(Concurrency_tag())); } /** @@ -854,14 +226,26 @@ bool do_intersect(const PolylineRange& polylines1, * \tparam Polyline a `RandomAccessRange` of points. * The point type must be from a 3D point type from \cgal Kernel. * \cgalDescribePolylineType + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" for the algorithm * * @param polyline1 the first polyline to check for intersections. * @param polyline2 the second polyline to check for intersections. + * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd + * \cgalNamedParamsEnd * */ -template +template bool do_intersect(const Polyline& polyline1, - const Polyline& polyline2 + const Polyline& polyline2, + const NamedParameters& np = parameters::default_values() #ifndef DOXYGEN_RUNNING , const std::enable_if_t< boost::has_range_const_iterator::value @@ -878,17 +262,10 @@ bool do_intersect(const Polyline& polyline1, #endif ) { - typedef typename boost::range_value::type Point; - typedef typename CGAL::Kernel_traits::Kernel K; - try - { - typedef boost::function_output_iterator OutputIterator; - internal::compute_polyline_polyline_intersection(polyline1, polyline2, OutputIterator(), K()); - } - catch( internal::Throw_at_first_output::Throw_at_first_output_exception& ) - { return true; } + std::array polylines1{{polyline1}}; + std::array polylines2{{polyline2}}; - return false; + return do_intersect(polylines1, polylines2, np); } /** @@ -916,6 +293,12 @@ bool do_intersect(const Polyline& polyline1, * @param np2 an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm1` (`tm2`)} * \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -925,7 +308,6 @@ bool do_intersect(const Polyline& polyline1, * should be available for the vertices of `tm1` (`tm2`)} * \cgalParamExtra{Both vertex point maps must have the same value type} * \cgalParamNEnd - * * \cgalParamNBegin{geom_traits} * \cgalParamDescription{an instance of a geometric traits class} * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} @@ -933,7 +315,6 @@ bool do_intersect(const Polyline& polyline1, * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} * \cgalParamExtra{np1 only} * \cgalParamNEnd - * * \cgalParamNBegin{do_overlap_test_of_bounded_sides} * \cgalParamDescription{If `true`, also tests the overlap of the bounded sides of `tm1` and `tm2`. * If `false`, only the intersection of surface triangles is tested.} @@ -958,24 +339,77 @@ bool do_intersect(const TriangleMesh& tm1, #endif ) { + CGAL_precondition(CGAL::is_triangle_mesh(tm1)); + CGAL_precondition(CGAL::is_triangle_mesh(tm2)); + using parameters::choose_parameter; using parameters::get_parameter; bool test_overlap = choose_parameter(get_parameter(np1, internal_np::overlap_test),false) || choose_parameter(get_parameter(np2, internal_np::overlap_test),false); - - CGAL_precondition(CGAL::is_triangle_mesh(tm1)); - CGAL_precondition(CGAL::is_triangle_mesh(tm2)); CGAL_precondition(!test_overlap || CGAL::is_closed(tm1)); CGAL_precondition(!test_overlap || CGAL::is_closed(tm2)); - try - { - typedef boost::function_output_iterator OutputIterator; - internal::compute_face_face_intersection(tm1,tm2, OutputIterator(), np1, np2); - } - catch( internal::Throw_at_first_output::Throw_at_first_output_exception& ) - { return true; } + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + CGAL_NP_CLASS_1, + Sequential_tag + > ::type; + + using GT = typename GetGeomTraits::type; + + using VPM1 = typename GetVertexPointMap::const_type; + using VPM2 = typename GetVertexPointMap::const_type; + + using face_descriptor = typename boost::graph_traits::face_descriptor; + + using AABB_tree_helper_1 = internal::AABB_tree_graph_helper; + using AABB_tree_helper_2 = internal::AABB_tree_graph_helper; + using Tree_1 = typename AABB_tree_helper_1::Tree; + using Tree_2 = typename AABB_tree_helper_2::Tree; + AABB_tree_helper_1 helper_1; + AABB_tree_helper_2 helper_2; + + // compute intersections filtered out by boxes + CGAL::Bbox_3 b1 = CGAL::Polygon_mesh_processing::bbox(tm1, np1), + b2 = CGAL::Polygon_mesh_processing::bbox(tm2, np2); + + if(!CGAL::do_overlap(b1, b2)) + return false; + + Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), + (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); + + VPM1 vpm1 = choose_parameter(get_parameter(np1, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, tm1)); + VPM2 vpm2 = choose_parameter(get_parameter(np2, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, tm2)); + static_assert( + (std::is_same< + typename boost::property_traits::value_type, + typename boost::property_traits::value_type + >::value) ); + +// TODO: can be done in parallel + std::vector faces_to_test1; + std::vector faces_to_test2; + + for(face_descriptor f : faces(tm1)) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm1, parameters::vertex_point_map(vpm1)), bb)) + faces_to_test1.emplace_back(f); + for(face_descriptor f : faces(tm2) ) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm2, parameters::vertex_point_map(vpm2)), bb)) + faces_to_test2.emplace_back(f); +//--- + + Tree_1 tree1; + Tree_2 tree2; + helper_1.template build(faces_to_test1, tree1, tm1, vpm1); + helper_2.template build(faces_to_test2, tree2, tm2, vpm2); + + bool inter = AABB_trees::do_intersect(tree1, tree2, parameters::concurrency_tag(Concurrency_tag())); + + if (inter) return true; if (test_overlap) { @@ -1015,6 +449,12 @@ bool do_intersect(const TriangleMesh& tm1, * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm`} * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` as key type and `%Point_3` as value type} @@ -1022,7 +462,6 @@ bool do_intersect(const TriangleMesh& tm1, * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` * should be available for the vertices of `tm`.} * \cgalParamNEnd - * * \cgalParamNBegin{geom_traits} * \cgalParamDescription{an instance of a geometric traits class} * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} @@ -1051,16 +490,74 @@ bool do_intersect(const TriangleMesh& tm, #endif ) { + if (faces(tm).size()==0 || polylines.empty()) + return false; + + using parameters::get_parameter; + using parameters::choose_parameter; + CGAL_precondition(CGAL::is_triangle_mesh(tm)); - try + + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + >::type; + + using GT = typename GetGeomTraits::type; + + using VPM = typename GetVertexPointMap::const_type; + using face_descriptor = typename boost::graph_traits::face_descriptor; + using Segment_3 = typename GT::Segment_3; + + using AABB_tree_helper = internal::AABB_tree_graph_helper; + using Face_tree = typename AABB_tree_helper::Tree; + + using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; + using Segment_traits = CGAL::AABB_traits_3; + using Segment_tree = CGAL::AABB_tree; + + VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, tm)); + + Bbox_3 b1; + for (face_descriptor f : faces(tm)) + b1 += Polygon_mesh_processing::face_bbox(f, tm, np); + Bbox_3 b2; + for(const auto& polyline : polylines) + b2 += bbox_3(polyline.begin(), polyline.end()); + + if(!CGAL::do_overlap(b1, b2)) + return false; + + Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), + (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); + + // We store all polylines in one filtered range + std::vector segments; + for (const auto& polyline : polylines) { - typedef boost::function_output_iterator OutputIterator; - internal::compute_face_polylines_intersection(faces(tm), polylines, tm, OutputIterator(), np); + if(polyline.size() < 2) continue; + + auto pit = std::begin(polyline); + auto prev = pit++; + for(; pit != std::end(polyline); ++pit, ++prev) + if (do_overlap(bb, prev->bbox()+pit->bbox())) + segments.emplace_back(*prev, *pit); } - catch( internal::Throw_at_first_output::Throw_at_first_output_exception& ) - { return true; } - return false; + std::vector faces_to_test; + for(face_descriptor f : faces(tm)) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm, parameters::vertex_point_map(vpm)), bb)) + faces_to_test.emplace_back(f); + + AABB_tree_helper helper; + Face_tree face_tree; + + helper.template build(faces_to_test, face_tree, tm, vpm); + Segment_tree segment_tree(segments.begin(), segments.end()); + + return CGAL::AABB_trees::do_intersect(face_tree, segment_tree, parameters::concurrency_tag(Concurrency_tag())); } /** @@ -1083,6 +580,12 @@ bool do_intersect(const TriangleMesh& tm, * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd * \cgalParamNBegin{vertex_point_map} * \cgalParamDescription{a property map associating points to the vertices of `tm`} * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` as key type and `%Point_3` as value type} @@ -1090,7 +593,6 @@ bool do_intersect(const TriangleMesh& tm, * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` * should be available for the vertices of `tm`.} * \cgalParamNEnd - * * \cgalParamNBegin{geom_traits} * \cgalParamDescription{an instance of a geometric traits class} * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} @@ -1121,16 +623,8 @@ bool do_intersect(const TriangleMesh& tm, #endif ) { - CGAL_precondition(CGAL::is_triangle_mesh(tm)); - try - { - typedef boost::function_output_iterator OutputIterator; - internal::compute_face_polyline_intersection(tm,polyline, OutputIterator(), np); - } - catch( internal::Throw_at_first_output::Throw_at_first_output_exception& ) - { return true; } - - return false; + std::array polylines{{polyline}}; + return do_intersect(tm, polylines, np); } namespace internal { @@ -1187,13 +681,12 @@ namespace internal { * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`, * where `Point` is the value type of the vertex point map of the meshes} * \cgalParamNEnd - * \cgalParamNBegin{concurrency_tag} - * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} - * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} - * \cgalParamDefault{`CGAL::Sequential_tag`} - * \cgalParamExtra{`np1` only} - * \cgalParamNEnd - * + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd * \cgalParamNBegin{do_overlap_test_of_bounded_sides} * \cgalParamDescription{If `true`, reports also overlap of bounded sides of meshes. * If `false`, only the intersection of surface triangles are tested.} diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_do_intersect_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_do_intersect_test.cpp index 31391bdaa1ba..b8b59c15a0b6 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_do_intersect_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_do_intersect_test.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -66,7 +66,6 @@ test_faces_intersections(const std::filesystem::path& filename1, const bool expected) { typedef CGAL::Surface_mesh Mesh; - typedef typename boost::graph_traits::face_descriptor face_descriptor; std::ifstream input1(filename1); std::ifstream input2(filename2); @@ -83,30 +82,16 @@ test_faces_intersections(const std::filesystem::path& filename1, std::cout << "Reading files: " << filename1 <<", "<< filename2 << std::endl; - CGAL::Timer timer; + CGAL::Real_timer timer; timer.start(); - - std::vector > intersected_tris; - CGAL::Polygon_mesh_processing::internal::compute_face_face_intersection( - m1, m2, - std::back_inserter(intersected_tris), - CGAL::parameters::default_values(), - CGAL::parameters::default_values()); - - bool intersecting_1 = !intersected_tris.empty(); - - std::cout << "intersections test took " << timer.time() << " sec." << std::endl; - std::cout << intersected_tris.size() << " pairs of triangles are intersecting." << std::endl; - - timer.reset(); - bool intersecting_2 = CGAL::Polygon_mesh_processing::do_intersect(m1, m2); + bool intersecting = CGAL::Polygon_mesh_processing::do_intersect(m1, m2); + timer.stop(); std::cout << "does_intersect test took " << timer.time() << " sec." << std::endl; - std::cout << (intersecting_2 ? "There are intersections." : - "There are no intersections.") << std::endl; + std::cout << (intersecting ? "There are intersections." : + "There are no intersections.") << std::endl; - assert(intersecting_1 == intersecting_2); - assert(intersecting_1 == expected); + assert(intersecting == expected); std::cout << filename1 << "and " < > intersected_tris; - CGAL::Polygon_mesh_processing::internal::compute_face_polyline_intersection( - m, points, - std::back_inserter(intersected_tris), - CGAL::parameters::default_values()); - - bool intersecting_1 = !intersected_tris.empty(); - - std::cout << "intersections test took " << timer.time() << " sec." << std::endl; - std::cout << intersected_tris.size() << " intersections." << std::endl; - - timer.reset(); - bool intersecting_2 = CGAL::Polygon_mesh_processing::do_intersect(m,points); + bool intersecting = CGAL::Polygon_mesh_processing::do_intersect(m,points); + timer.stop(); std::cout << "does_intersect test took " << timer.time() << " sec." << std::endl; - std::cout << (intersecting_2 ? "There are intersections." : - "There are no intersections.") << std::endl; + std::cout << (intersecting ? "There are intersections." : + "There are no intersections.") << std::endl; - assert(intersecting_1 == intersecting_2); - assert(intersecting_1 == expected); + assert(intersecting == expected); std::cout << filename1 << "and " < > > intersected_tris; - - CGAL::Polygon_mesh_processing::internal::compute_face_polylines_intersection( - faces(m), - points, - m, - std::back_inserter(intersected_tris), - CGAL::parameters::default_values()); - - bool intersecting_1 = !intersected_tris.empty(); - - std::cout << "intersections test took " << timer.time() << " sec." << std::endl; - std::cout << intersected_tris.size() << " intersections." << std::endl; - - timer.reset(); - bool intersecting_2 = CGAL::Polygon_mesh_processing::do_intersect(m,points); + bool intersecting = CGAL::Polygon_mesh_processing::do_intersect(m,points); + timer.stop(); std::cout << "does_intersect test took " << timer.time() << " sec." << std::endl; - std::cout << (intersecting_2 ? "There are intersections." : - "There are no intersections.") << std::endl; + std::cout << (intersecting ? "There are intersections." : + "There are no intersections.") << std::endl; - assert(intersecting_1 == intersecting_2); - assert(intersecting_1 == expected); + assert(intersecting == expected); std::cout << filename1 << "and " <, - std::pair - > - > intersected_segs; - - CGAL::Polygon_mesh_processing::internal::compute_polylines_polylines_intersection( - polys1, - polys2, - std::back_inserter(intersected_segs), - K()); - - bool intersecting_1 = !intersected_segs.empty(); - - std::cout << "intersections test took " << timer.time() << " sec." << std::endl; - std::cout << intersected_segs.size() << " intersections." << std::endl; - - timer.reset(); - bool intersecting_2 = CGAL::Polygon_mesh_processing::do_intersect(polys1, polys2); + bool intersecting = CGAL::Polygon_mesh_processing::do_intersect(polys1, polys2); + timer.stop(); std::cout << "does_intersect test took " << timer.time() << " sec." << std::endl; - std::cout << (intersecting_2 ? "There are intersections." : - "There are no intersections.") << std::endl; + std::cout << (intersecting ? "There are intersections." : + "There are no intersections.") << std::endl; - assert(intersecting_1 == intersecting_2); - assert(intersecting_1 == expected); + assert(intersecting == expected); std::cout << filename1 << "and " < > intersected_polys; - CGAL::Polygon_mesh_processing::internal::compute_polyline_polyline_intersection( - points1, points2, - std::back_inserter(intersected_polys), - K()); - - bool intersecting_1 = !intersected_polys.empty(); - - std::cout << "intersections test took " << timer.time() << " sec." << std::endl; - std::cout << intersected_polys.size() << " intersections." << std::endl; - - timer.reset(); - - bool intersecting_2 = CGAL::Polygon_mesh_processing::do_intersect(points1, points2); + bool intersecting = CGAL::Polygon_mesh_processing::do_intersect(points1, points2); + timer.stop(); std::cout << "does_intersect test took " << timer.time() << " sec." << std::endl; - std::cout << (intersecting_2 ? "There are intersections." : - "There are no intersections.") << std::endl; + std::cout << (intersecting ? "There are intersections." : + "There are no intersections.") << std::endl; - assert(intersecting_1 == intersecting_2); - assert(intersecting_1 == expected); + assert(intersecting == expected); std::cout << filename1 << "and " < Date: Tue, 10 Nov 2026 11:22:33 +0100 Subject: [PATCH 118/136] avoid a copy --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 2c35ca703aea..d56201f64e22 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -262,8 +262,8 @@ bool do_intersect(const Polyline& polyline1, #endif ) { - std::array polylines1{{polyline1}}; - std::array polylines2{{polyline2}}; + auto polylines1 = make_range(&polyline1,&polyline1+1); + auto polylines2 = make_range(&polyline2,&polyline2+1); return do_intersect(polylines1, polylines2, np); } @@ -623,7 +623,7 @@ bool do_intersect(const TriangleMesh& tm, #endif ) { - std::array polylines{{polyline}}; + auto polylines = make_range(&polyline,&polyline+1); return do_intersect(tm, polylines, np); } From aa60b1372289713a4801a9f5e4e3f28314107e96 Mon Sep 17 00:00:00 2001 From: lvalque <131978677+LeoValque@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:38:01 +0100 Subject: [PATCH 119/136] Apply batched suggestions from code review Co-authored-by: Sebastien Loriot --- .../include/CGAL/Cartesian/function_objects.h | 12 ------------ .../include/CGAL/Homogeneous/function_objects.h | 12 ------------ Installation/CHANGES.md | 2 +- .../internal/soup_and_face_graph_tree_helper.h | 3 --- 4 files changed, 1 insertion(+), 28 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index 01eb9d1f22d2..14f795d2e837 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -1893,12 +1893,6 @@ namespace CartesianKernelFunctors { return b; } - Bbox_2& - operator()(Bbox_2& b) const - { - return b; - } - Bbox_2 operator()(const Point_2& p) const { @@ -1977,12 +1971,6 @@ namespace CartesianKernelFunctors { return b; } - Bbox_3& - operator()(Bbox_3& b) const - { - return b; - } - Bbox_3 operator()(const Point_3& p) const { diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index deca99b0ac4c..90683d416ec2 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -1895,12 +1895,6 @@ namespace HomogeneousKernelFunctors { return b; } - Bbox_2& - operator()(Bbox_2& b) const - { - return b; - } - Bbox_2 operator()( const Point_2& p) const { @@ -1971,12 +1965,6 @@ namespace HomogeneousKernelFunctors { return b; } - Bbox_3& - operator()(Bbox_3& b) const - { - return b; - } - Bbox_3 operator()(const Point_3& p) const { diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index ae9c69805436..e8f78b04be60 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -72,7 +72,7 @@ Release date: December 2026 handle cases when some identical faces are shared between the input meshes. This leads to a significant speed up in those cases. - `corefine()` and its variants now have a named parameter `concurrency_tag`, specifying whether the task should be performed using a single or multiple threads. -- The running time of `corefine()`, `autorefine()` and their variants has been improved. +- The running times of `corefine()`, `autorefine()` and their variants have been improved. - Added new multithreading compatible functions operating directly on triangle soups, enabling the handling of non-manifold input and output volumes: `CGAL::Polygon_mesh_processing::compute_union()`, `CGAL::Polygon_mesh_processing::compute_intersection()`, and `CGAL::Polygon_mesh_processing::compute_difference()`. diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 3e9e9507f08d..60942f2d5e5d 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -25,9 +25,6 @@ #include #include -#include -#include -#include #include namespace CGAL { From 8b09b1bc5677aa2ae0f32a8a355568e3adfda578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 10 Nov 2026 12:38:47 +0100 Subject: [PATCH 120/136] Move an assertion to CGAL_expensive_assertion() --- Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h b/Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h index b9c444c43205..80db1d6d8785 100644 --- a/Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h +++ b/Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h @@ -264,7 +264,7 @@ class Side_of_triangle_mesh */ Bounded_side operator()(const Point& point) const { - CGAL_assertion(tm_ptr == nullptr || CGAL::is_closed(*tm_ptr)); + CGAL_expensive_assertion(tm_ptr == nullptr || CGAL::is_closed(*tm_ptr)); if(point.x() < box.xmin() || point.x() > box.xmax() From 7966565495e6775f79b8ff92deba01d2a6c61252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 10 Nov 2026 13:24:11 +0100 Subject: [PATCH 121/136] Apply suggestions from the review --- .../Polygon_mesh_processing/autorefinement.h | 2 - .../internal/Corefinement/intersection_impl.h | 92 ++++++++----------- .../self_intersections.h | 8 +- 3 files changed, 40 insertions(+), 62 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h index 547b232cbebe..eaf53038719e 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h @@ -24,8 +24,6 @@ #include #include -#include - #ifdef CGAL_AUTOREF_USE_PROGRESS_DISPLAY #include #endif diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index a0b3650ca37f..3b413721d813 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -495,7 +495,8 @@ class Intersection_of_triangle_meshes void filter_intersections(const TriangleMesh& tm, const VPM& vpm) { - using GT = typename GetGeomTraits::type; + using Point = typename boost::property_traits::value_type; + using GT = typename CGAL::Kernel_traits::Kernel; using AABB_tree_helper = CGAL::Polygon_mesh_processing::internal::AABB_tree_graph_helper; using Tree = typename AABB_tree_helper::Tree; AABB_tree_helper helper; @@ -507,69 +508,48 @@ class Intersection_of_triangle_meshes TriangleMesh, VPM, Edge_to_faces, Coplanar_face_set>; Callback callback(tm, vpm, stm_edge_to_ltm_faces, coplanar_faces); - #ifdef CGAL_LINKED_WITH_TBB +#ifdef CGAL_LINKED_WITH_TBB + using Intersections = std::conditional_t>, + std::vector>>; +#else + using Intersections = std::vector>; +#endif + Intersections inter; +#ifdef CGAL_LINKED_WITH_TBB if constexpr(ConcurrencyTag::is_parallel) { - tbb::concurrent_vector> inter; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(inter)); - - // tbb::parallel_for(std::size_t(0), inter.size(), [&](std::size_t i){ - for(std::size_t i=0; i> inter; CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(inter)); - - for(const auto& [f_1, f_2]: inter){ - halfedge_descriptor h0_f1 = halfedge(f_1, tm); - halfedge_descriptor h1_f1 = next(h0_f1, tm); - halfedge_descriptor h2_f1 = next(h1_f1, tm); - - halfedge_descriptor h0_f2 = halfedge(f_2, tm); - halfedge_descriptor h1_f2 = next(h0_f2, tm); - halfedge_descriptor h2_f2 = next(h1_f2, tm); - - if (is_border_edge(h0_f1, tm) || h0_f1 < opposite(h0_f1, tm)) - callback(h0_f2, h0_f1); - if (is_border_edge(h1_f1, tm) || h1_f1 < opposite(h1_f1, tm)) - callback(h0_f2, h1_f1); - if (is_border_edge(h2_f1, tm) || h2_f1 < opposite(h2_f1, tm)) - callback(h0_f2, h2_f1); - - if (is_border_edge(h0_f2, tm) || h0_f2 < opposite(h0_f2, tm)) - callback(h0_f1, h0_f2); - if (is_border_edge(h1_f2, tm) || h1_f2 < opposite(h1_f2, tm)) - callback(h0_f1, h1_f2); - if (is_border_edge(h2_f2, tm) || h2_f2 < opposite(h2_f2, tm)) - callback(h0_f1, h2_f2); - } + } + for(std::size_t i=0; i; public: - Listing_distinct_intersecting_faces_traits(OutputIterator out_it, const GT& gt, const AABBTraits& traits, const TriangleMesh &tm, const VertexPointMap &vpm) + Listing_distinct_intersecting_faces_traits(OutputIterator& out_it, const GT& gt, const AABBTraits& traits, const TriangleMesh &tm, const VertexPointMap &vpm) : m_out_it(out_it), m_gt(gt), m_traits(traits), m_tm(tm), m_vpm(vpm) {} constexpr bool go_further() const { return true; } @@ -377,7 +377,7 @@ class Listing_distinct_intersecting_faces_traits } private: - OutputIterator m_out_it; + OutputIterator& m_out_it; const GT& m_gt; const AABBTraits& m_traits; const TriangleMesh& m_tm; @@ -393,7 +393,7 @@ class Listing_intersecting_faces_two_trees_traits public: Listing_intersecting_faces_two_trees_traits(const AABBTraits& traits, const GT& gt, - OutputIterator out_, + OutputIterator& out_, const TriangleMesh& tm, const VertexPointMap& vpm) : m_traits(traits), m_gt(gt), out(out_), m_tm(tm), m_vpm(vpm) {} @@ -436,7 +436,7 @@ class Listing_intersecting_faces_two_trees_traits private: const AABBTraits& m_traits; const GT& m_gt; - OutputIterator out; + OutputIterator& out; const TriangleMesh& m_tm; const VertexPointMap& m_vpm; }; From a4bf70827fb061371929c4aa0e15cf652795c4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 10 Nov 2026 15:53:50 +0100 Subject: [PATCH 122/136] Apply suggestions from the review --- .../internal/AABB_two_trees_traversal.h | 34 ++++++----- .../CGAL/Surface_mesh/Surface_mesh_fwd.h | 4 +- .../internal/Corefinement/intersection_impl.h | 4 +- .../refine_with_plane.h | 2 +- .../soup_and_face_graph_tree_helper.h | 21 +++---- .../self_intersections.h | 22 +++---- .../include/CGAL/Surface_mesh/Surface_mesh.h | 39 ------------ .../CGAL/Surface_mesh/print_surface_mesh.h | 61 +++++++++++++++++++ 8 files changed, 105 insertions(+), 82 deletions(-) create mode 100644 Surface_mesh/include/CGAL/Surface_mesh/print_surface_mesh.h diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h index ec6f853b639f..61244dcb0123 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_two_trees_traversal.h @@ -26,20 +26,22 @@ namespace CGAL { namespace internal { namespace AABB_tree { +struct Two_trees_traversal_parallel_cutoff +{ + static constexpr std::size_t value = 3000; +}; + template void two_trees_traversal(const ::CGAL::AABB_node& node_A, - const ::CGAL::AABB_node& node_B, - const std::size_t nb_primitives_A, - const std::size_t nb_primitives_B, - TwoTreeTraversalTraits& traversal_traits) + const ::CGAL::AABB_node& node_B, + const std::size_t nb_primitives_A, + const std::size_t nb_primitives_B, + TwoTreeTraversalTraits& traversal_traits) { -#if CGAL_LINKED_WITH_TBB - const std::size_t cutoff_parallel_call = 3000; -#endif auto recursive_call = [](const auto &node_A, const auto &node_B, const std::size_t nb_primitives_A, const std::size_t nb_primitives_B, auto &traversal_traits){ if(traversal_traits.prefer_A_for_next_step(node_A, node_B, nb_primitives_A, nb_primitives_B)) two_trees_traversal< in_order, ConcurrencyTag>(node_A, node_B, nb_primitives_A, nb_primitives_B, traversal_traits); @@ -88,7 +90,10 @@ void two_trees_traversal(const ::CGAL::AABB_node& node_A, #if CGAL_LINKED_WITH_TBB if constexpr(ConcurrencyTag::is_parallel) { - if(do_intersect_left && do_intersect_right && nb_primitives_A > cutoff_parallel_call && nb_primitives_B > cutoff_parallel_call) + if(do_intersect_left && + do_intersect_right && + nb_primitives_A > Two_trees_traversal_parallel_cutoff::value && + nb_primitives_B > Two_trees_traversal_parallel_cutoff::value) { oneapi::tbb::task_group tg; tg.run([&]{ @@ -145,9 +150,6 @@ void one_tree_traversal(const ::CGAL::AABB_node& node, const std::size_t nb_primitives, TwoTreeTraversalTraits& traversal_traits) { -#if CGAL_LINKED_WITH_TBB - const std::size_t cutoff_parallel_call = 3000; -#endif switch(nb_primitives) { case 2: @@ -166,7 +168,7 @@ void one_tree_traversal(const ::CGAL::AABB_node& node, #if CGAL_LINKED_WITH_TBB if constexpr(ConcurrencyTag::is_parallel) { - if(nb_primitives > cutoff_parallel_call) + if(nb_primitives > Two_trees_traversal_parallel_cutoff::value) { oneapi::tbb::task_group tg; if(traversal_traits.do_intersect(node.left_child(), node.right_child())){ @@ -225,9 +227,6 @@ void two_trees_partial_traversal(const ::CGAL::AABB_node& node_A, const std::size_t cutoff, TwoTreeTraversalTraits& traversal_traits) { -#if CGAL_LINKED_WITH_TBB - const std::size_t cutoff_parallel_call = 3000; -#endif auto recursive_call = [&](const auto &node_A, const auto &node_B, const std::size_t nb_primitives_A, const std::size_t nb_primitives_B, auto &traversal_traits){ if(traversal_traits.prefer_A_for_next_step(node_A, node_B, nb_primitives_A, nb_primitives_B)) two_trees_partial_traversal< in_order, ConcurrencyTag>(node_A, node_B, nb_primitives_A, nb_primitives_B, cutoff, traversal_traits); @@ -258,7 +257,10 @@ void two_trees_partial_traversal(const ::CGAL::AABB_node& node_A, #if CGAL_LINKED_WITH_TBB if constexpr(ConcurrencyTag::is_parallel) { - if(do_intersect_left && do_intersect_right && nb_primitives_A > cutoff_parallel_call && nb_primitives_B > cutoff_parallel_call) + if(do_intersect_left && + do_intersect_right && + nb_primitives_A > Two_trees_traversal_parallel_cutoff::value && + nb_primitives_B > Two_trees_traversal_parallel_cutoff::value) { oneapi::tbb::task_group tg; tg.run([&]{ diff --git a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h index 0b0aa3f63c01..012de41f6d8d 100644 --- a/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h +++ b/Installation/include/CGAL/Surface_mesh/Surface_mesh_fwd.h @@ -26,10 +26,10 @@ template class Surface_mesh; template -struct is_surface_mesh : std::false_type {}; +struct Is_base_of_surface_mesh : std::false_type {}; template -struct is_surface_mesh::value>>: std::is_base_of< CGAL::Surface_mesh, T> +struct Is_base_of_surface_mesh::value>>: std::is_base_of< CGAL::Surface_mesh, T> {}; diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 3b413721d813..f0ff1fcf4e10 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -272,8 +272,8 @@ class Intersection_of_triangle_meshes std::vector tm1_faces_intersecting_bb; std::vector tm2_faces_intersecting_bb; - tm1_faces_intersecting_bb.reserve(num_faces(tm1)); - tm2_faces_intersecting_bb.reserve(num_faces(tm2)); + tm1_faces_intersecting_bb.reserve(std::min(faces(tm1).size(), faces(tm2).size())); + tm2_faces_intersecting_bb.reserve(std::min(faces(tm1).size(), faces(tm2).size())); for(face_descriptor f: faces(tm1)) if( !get(is_shared_face_map_1, f) && diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h index e43600a1e945..d2bf3327022b 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h @@ -452,7 +452,7 @@ void refine_with_plane(PolygonMesh& pm, std::sort(test_faces.begin(), test_faces.end()); auto last = std::unique(test_faces.begin(), test_faces.end()); test_faces.erase(last, test_faces.end()); - if (does_self_intersect(test_faces, pm, parameters::vertex_point_map(vpm).concurrency_tag(Concurrency_tag()))) + if (does_self_intersect(test_faces, pm, np)) throw Corefinement::Self_intersection_exception(); } diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 60942f2d5e5d..a6a288536943 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -79,6 +79,7 @@ struct AABB_tree_graph_helper template void build(const FaceRange &face_range, Tree& tree, const TriangleMesh& tm, VertexPointMap& vpm){ using Face_bbox_tag = typename CGAL::dynamic_face_property_t; + // Reference point do not need to be exact, so we use Epick for them using Face_ref_point_tag = typename CGAL::dynamic_face_property_t; using Bbox_map = typename boost::property_map::const_type; using Ref_point_map = typename boost::property_map::const_type; @@ -96,15 +97,13 @@ struct AABB_tree_graph_helper tbb::blocked_range(0, face_range.size()), [&](const tbb::blocked_range& block) { - auto it = std::next(std::begin(face_range), block.begin()); - - for (std::size_t i = block.begin(); i != block.end(); ++i, ++it) - { - face_descriptor f = *it; - - put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); - put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm)))); - } + auto it = std::next(std::begin(face_range), block.begin()); + for (std::size_t i = block.begin(); i != block.end(); ++i, ++it) + { + face_descriptor f = *it; + put(bb_map, f, face_bbox(f, tm, parameters::vertex_point_map(vpm))); + put(rp_map, f, to_input(get(vpm, target(halfedge(f, tm), tm)))); + } }); } else @@ -186,8 +185,8 @@ struct AABB_tree_soup_helper CGAL::Bbox_3 operator()(ConstPrimitiveIterator first, ConstPrimitiveIterator beyond) const { - CGAL::Bbox_3 bbox = get(bpm, first->id()); - for(++first; first != beyond; ++first) + CGAL::Bbox_3 bbox; + for(; first != beyond; ++first) bbox += get(bpm, first->id()); return bbox; } diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index 876a1c6ed2a2..56ced242f8dd 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -344,7 +344,7 @@ bool do_faces_intersect(typename Triangle_mesh_and_triangle_soup_wrapper -class Listing_distinct_intersecting_faces_traits +class Listing_self_intersecting_faces_traversal_traits { using FT = typename AABBTraits::FT; using Point = typename AABBTraits::Point; @@ -356,7 +356,7 @@ class Listing_distinct_intersecting_faces_traits using Node = ::CGAL::AABB_node; public: - Listing_distinct_intersecting_faces_traits(OutputIterator& out_it, const GT& gt, const AABBTraits& traits, const TriangleMesh &tm, const VertexPointMap &vpm) + Listing_self_intersecting_faces_traversal_traits(OutputIterator& out_it, const GT& gt, const AABBTraits& traits, const TriangleMesh &tm, const VertexPointMap &vpm) : m_out_it(out_it), m_gt(gt), m_traits(traits), m_tm(tm), m_vpm(vpm) {} constexpr bool go_further() const { return true; } @@ -385,17 +385,17 @@ class Listing_distinct_intersecting_faces_traits }; template -class Listing_intersecting_faces_two_trees_traits +class Listing_self_intersecting_faces_one_tree_traversal_traits { using Primitive = typename AABBTraits::Primitive; using Node = ::CGAL::AABB_node; public: - Listing_intersecting_faces_two_trees_traits(const AABBTraits& traits, - const GT& gt, - OutputIterator& out_, - const TriangleMesh& tm, - const VertexPointMap& vpm) + Listing_self_intersecting_faces_one_tree_traversal_traits(const AABBTraits& traits, + const GT& gt, + OutputIterator& out_, + const TriangleMesh& tm, + const VertexPointMap& vpm) : m_traits(traits), m_gt(gt), out(out_), m_tm(tm), m_vpm(vpm) {} constexpr bool go_further() const { return true; } @@ -418,13 +418,13 @@ class Listing_intersecting_faces_two_trees_traits void intersection(const Primitive& primitive1, const Node& node2, std::size_t nb_primitives_2) { - Listing_distinct_intersecting_faces_traits traits(out, m_gt, m_traits, m_tm, m_vpm); + Listing_self_intersecting_faces_traversal_traits traits(out, m_gt, m_traits, m_tm, m_vpm); node2.traversal( primitive1, traits, nb_primitives_2); } void intersection(const Node& node1, std::size_t nb_primitives_1, const Primitive& primitive2) { - Listing_distinct_intersecting_faces_traits traits(out, m_gt, m_traits, m_tm, m_vpm); + Listing_self_intersecting_faces_traversal_traits traits(out, m_gt, m_traits, m_tm, m_vpm); node1.traversal( primitive2, traits, nb_primitives_1); } @@ -531,7 +531,7 @@ self_intersections_impl(const FaceRange& face_range, Wrapper::template build_tree(faces_not_degenerated, tree, tmesh, vpmap); const auto all_pairs_of_intersecting_faces = [&](const AABB_tree& tree, auto out){ - Listing_intersecting_faces_two_trees_traits + Listing_self_intersecting_faces_one_tree_traversal_traits traversal_traits(tree.traits(), gt, out, tmesh, vpmap); CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); }; diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index a4783421b5e6..e9283007c231 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -2885,45 +2885,6 @@ namespace boost { } // namespace boost -namespace CGAL { - -/// Print all mesh elements and their connectivity to an output stream. -template -void print_surface_mesh(const Surface_mesh

& mesh, - std::ostream& out = std::cout) -{ - typedef Surface_mesh

Mesh; - typedef typename Mesh::Vertex_index Vertex_index; - typedef typename Mesh::Halfedge_index Halfedge_index; - typedef typename Mesh::Face_index Face_index; - - out << "Points:\n"; - for (Vertex_index v : mesh.vertices()) - out << " " << v << ": point=" << mesh.point(v) << '\n'; - - out << "Vertices:\n"; - for (Vertex_index v : mesh.vertices()) - out << " " << v << ": halfedge=" << mesh.halfedge(v) << '\n'; - - out << "Halfedges:\n"; - for (Halfedge_index h : mesh.halfedges()) - { - out << " " << h << ": target=" << mesh.target(h) - << " face=" << mesh.face(h) - << " next=" << mesh.next(h) << '\n'; - } - - out << "Faces:\n"; - for (Face_index f : mesh.faces()) - { - out << " " << f << ": halfedge=" << mesh.halfedge(f) << '\n'; - } -} - -} // namespace CGAL - - - #endif // DOXYGEN_RUNNING #include diff --git a/Surface_mesh/include/CGAL/Surface_mesh/print_surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/print_surface_mesh.h new file mode 100644 index 000000000000..bdc18c514792 --- /dev/null +++ b/Surface_mesh/include/CGAL/Surface_mesh/print_surface_mesh.h @@ -0,0 +1,61 @@ +// Copyright (c) 2026 GeometryFactory (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Leo Valque +#ifndef CGAL_DEBUG_PRINT_SURFACE_MESH_H +#define CGAL_DEBUG_PRINT_SURFACE_MESH_H + +#include + +#include +#include +#include + +#ifndef DOXYGEN_RUNNING + +namespace CGAL { + +/// Print all mesh elements and their connectivity to an output stream. +template +void print_surface_mesh(const Surface_mesh

& mesh, + std::ostream& out = std::cout) +{ + typedef Surface_mesh

Mesh; + typedef typename Mesh::Vertex_index Vertex_index; + typedef typename Mesh::Halfedge_index Halfedge_index; + typedef typename Mesh::Face_index Face_index; + + out << "Points:\n"; + for (Vertex_index v : mesh.vertices()) + out << " " << v << ": point=" << mesh.point(v) << '\n'; + + out << "Vertices:\n"; + for (Vertex_index v : mesh.vertices()) + out << " " << v << ": halfedge=" << mesh.halfedge(v) << '\n'; + + out << "Halfedges:\n"; + for (Halfedge_index h : mesh.halfedges()) + { + out << " " << h << ": target=" << mesh.target(h) + << " face=" << mesh.face(h) + << " next=" << mesh.next(h) + << " prev=" << mesh.prev(h) << '\n'; + } + + out << "Faces:\n"; + for (Face_index f : mesh.faces()) + { + out << " " << f << ": halfedge=" << mesh.halfedge(f) << '\n'; + } +} + +} // namespace CGAL +#endif + +#endif /* CGAL_DEBUG_PRINT_SURFACE_MESH_H */ From a2fab023bd5f367cf21024561bd5b1860ef10921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 10 Nov 2026 16:33:10 +0100 Subject: [PATCH 123/136] Reintroduce necessary include --- .../include/CGAL/Polygon_mesh_processing/autorefinement.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h index eaf53038719e..4762aceac510 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/autorefinement.h @@ -28,6 +28,8 @@ #include #endif +#include + // output #include #include From f9511010d725cba12f147bbf0b87a548051ff022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 10 Nov 2026 16:39:40 +0100 Subject: [PATCH 124/136] () for std::min --- .../internal/Corefinement/intersection_impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index f0ff1fcf4e10..7c972f709293 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -272,8 +272,8 @@ class Intersection_of_triangle_meshes std::vector tm1_faces_intersecting_bb; std::vector tm2_faces_intersecting_bb; - tm1_faces_intersecting_bb.reserve(std::min(faces(tm1).size(), faces(tm2).size())); - tm2_faces_intersecting_bb.reserve(std::min(faces(tm1).size(), faces(tm2).size())); + tm1_faces_intersecting_bb.reserve((std::min)(faces(tm1).size(), faces(tm2).size())); + tm2_faces_intersecting_bb.reserve((std::min)(faces(tm1).size(), faces(tm2).size())); for(face_descriptor f: faces(tm1)) if( !get(is_shared_face_map_1, f) && From fb0a691a07aef8856a37f4d0cbf5117c6b35e1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 10 Nov 2026 17:12:53 +0100 Subject: [PATCH 125/136] leftover --- .../test/PMP_Boolean_operations/test_corefinement_bool_op.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp index 2c4343b734ab..306969d5645f 100644 --- a/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp +++ b/PMP_Boolean_operations/test/PMP_Boolean_operations/test_corefinement_bool_op.cpp @@ -277,7 +277,7 @@ void run(char* P_fname, char* Q_fname, int k, int main(int argc,char** argv) { // Check if DerivedMesh is correctly identified - static_assert( CGAL::is_surface_mesh::value ); + static_assert( CGAL::Is_base_of_surface_mesh::value ); if (argc<3){ std::cerr << "Usage "<< argv[0] << " file1.off file2.off [scenario_id/ALL] [0/1 0/1 0/1 0/1 (expected valid operations U I P-Q Q-P)]\n"; From bb629dff36055f76191ed878f48666724a576c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 12 Nov 2026 12:07:28 +0100 Subject: [PATCH 126/136] auto in a lambda in not in c++17 --- .../self_intersections.h | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index 56ced242f8dd..4b794b43e298 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -478,7 +478,6 @@ self_intersections_impl(const FaceRange& face_range, using vertex_descriptor = typename Wrapper::vertex_descriptor; using AABB_tree = typename Wrapper::Tree; - using AABB_traits = typename AABB_tree::AABB_traits; CGAL_precondition(Wrapper::is_pure_triangle(tmesh)); @@ -530,11 +529,6 @@ self_intersections_impl(const FaceRange& face_range, AABB_tree tree; Wrapper::template build_tree(faces_not_degenerated, tree, tmesh, vpmap); - const auto all_pairs_of_intersecting_faces = [&](const AABB_tree& tree, auto out){ - Listing_self_intersecting_faces_one_tree_traversal_traits - traversal_traits(tree.traits(), gt, out, tmesh, vpmap); - CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); - }; #if !defined(CGAL_LINKED_WITH_TBB) static_assert (!(std::is_convertible::value), "Parallel_tag is enabled but TBB is unavailable."); @@ -549,7 +543,10 @@ self_intersections_impl(const FaceRange& face_range, Face_pairs face_pairs; if(throw_on_SI) - all_pairs_of_intersecting_faces(tree, throwing_filter); + { + Listing_self_intersecting_faces_one_tree_traversal_traits traversal_traits(tree.traits(), gt, throwing_filter, tmesh, vpmap); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); + } else if(do_limit) { try @@ -557,7 +554,8 @@ self_intersections_impl(const FaceRange& face_range, std::atomic atomic_counter(counter); std::atomic atomic_flag(false); Throw_iterator count_filter(atomic_counter, atomic_flag, maximum_number, std::back_inserter(face_pairs)); - all_pairs_of_intersecting_faces(tree, count_filter); + Listing_self_intersecting_faces_one_tree_traversal_traits traversal_traits(tree.traits(), gt, count_filter, tmesh, vpmap); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); } catch(const CGAL::internal::Throw_at_output_exception&) { @@ -569,7 +567,9 @@ self_intersections_impl(const FaceRange& face_range, } else { - all_pairs_of_intersecting_faces(tree, std::back_inserter(face_pairs)); + auto l_out = std::back_inserter(face_pairs); + Listing_self_intersecting_faces_one_tree_traversal_traits traversal_traits(tree.traits(), gt, l_out, tmesh, vpmap); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); } // Sequentially write into the output iterator @@ -582,7 +582,10 @@ self_intersections_impl(const FaceRange& face_range, // Sequential version of the code if(throw_on_SI) - all_pairs_of_intersecting_faces(tree, throwing_filter); + { + Listing_self_intersecting_faces_one_tree_traversal_traits traversal_traits(tree.traits(), gt, throwing_filter, tmesh, vpmap); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); + } else if(do_limit) { using Count_and_throw_filter = std::function&) >; @@ -596,7 +599,9 @@ self_intersections_impl(const FaceRange& face_range, try { - all_pairs_of_intersecting_faces(tree, boost::make_function_output_iterator(max_inter_counter)); + auto l_out = boost::make_function_output_iterator(max_inter_counter); + Listing_self_intersecting_faces_one_tree_traversal_traits traversal_traits(tree.traits(), gt, l_out, tmesh, vpmap); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); } catch (const CGAL::internal::Throw_at_output_exception&) { @@ -604,7 +609,10 @@ self_intersections_impl(const FaceRange& face_range, } } else - all_pairs_of_intersecting_faces(tree, out); + { + Listing_self_intersecting_faces_one_tree_traversal_traits traversal_traits(tree.traits(), gt, out, tmesh, vpmap); + CGAL::internal::AABB_tree::one_tree_traversal(tree, traversal_traits); + } return out; } From 01a7bad66e1cddf3e602416464892386698c746b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 12 Nov 2026 15:02:32 +0100 Subject: [PATCH 127/136] fix concurrency issue --- .../CGAL/Polygon_mesh_processing/intersection.h | 12 ++++++++++++ .../test/Polygon_mesh_processing/CMakeLists.txt | 1 + .../pmp_do_intersect_test.cpp | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 0966b2fa166d..4a5aa0dc6f91 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -28,6 +28,10 @@ #include #include +#ifdef CGAL_LINKED_WITH_TBB +#include +#endif + #include #include #include @@ -757,9 +761,17 @@ intersecting_meshes(const TriangleMeshRange& range, Tree tree(indexed_bboxes.begin(), indexed_bboxes.end()); +#ifdef CGAL_LINKED_WITH_TBB + std::conditional_t>, + std::vector>> candidates; +#else std::vector> candidates; +#endif + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(candidates)); + // TODO: we could also do that in parallel, depending on candidates.size() for(const auto& p : candidates) { const TriangleMesh &mesh1 = range[p.first]; diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt index cc2549482590..8067726fa069 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt @@ -57,6 +57,7 @@ if(TARGET CGAL::TBB_support) target_link_libraries(test_hausdorff_bounded_error_distance PRIVATE CGAL::TBB_support) target_link_libraries(test_pmp_distance PRIVATE CGAL::TBB_support) target_link_libraries(self_intersection_surface_mesh_test PRIVATE CGAL::TBB_support) + target_link_libraries(pmp_do_intersect_test PRIVATE CGAL::TBB_support) else() message(STATUS "NOTICE: Intel TBB was not found. Tests will use sequential code.") endif() diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_do_intersect_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_do_intersect_test.cpp index b8b59c15a0b6..1a9bd7e25c6b 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_do_intersect_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_do_intersect_test.cpp @@ -296,6 +296,14 @@ int test_inter_in_range(const std::vector& filenames, std std::cout << output.size() <<" pairs."< Date: Thu, 12 Nov 2026 16:04:03 +0100 Subject: [PATCH 128/136] no need to change the halfedge, let the filter below pick the right one with the old code the risk was to never consider a nm edge if it's halfedge is not the small one --- .../internal/Corefinement/intersection_impl.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h index 7c972f709293..26fa76805d0f 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_impl.h @@ -323,12 +323,8 @@ class Intersection_of_triangle_meshes std::size_t eid = non_manifold_feature_map_2.non_manifold_edges.empty() ? NM_NID : get(non_manifold_feature_map_2.e_nm_id, ed); - if (eid!=NM_NID){ - if (non_manifold_feature_map_2.non_manifold_edges[eid].front()!=ed) continue; - else - // make sure the halfedge used is consistent with stored one - h = halfedge(non_manifold_feature_map_2.non_manifold_edges[eid].front(), tm2); - } + if (eid!=NM_NID && non_manifold_feature_map_2.non_manifold_edges[eid].front()!=ed) continue; + if( !get(is_shared_edge_map_2, ed) && (is_border_edge(h, tm2) || h < opposite(h, tm2))) callback12(hf1[0], h); } @@ -337,12 +333,8 @@ class Intersection_of_triangle_meshes std::size_t eid = non_manifold_feature_map_1.non_manifold_edges.empty() ? NM_NID : get(non_manifold_feature_map_1.e_nm_id, ed); - if (eid!=NM_NID){ - if (non_manifold_feature_map_1.non_manifold_edges[eid].front()!=ed) continue; - else - // make sure the halfedge used is consistent with stored one - h = halfedge(non_manifold_feature_map_1.non_manifold_edges[eid].front(), tm1); - } + if (eid!=NM_NID && non_manifold_feature_map_1.non_manifold_edges[eid].front()!=ed) continue; + if( !get(is_shared_edge_map_1, ed) && (is_border_edge(h, tm1) || h < opposite(h, tm1))) callback21(hf2[0], h); } From 7e8c4e1ae0896e7e142fa7b6b20fe16864fc516d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 12 Nov 2026 16:55:42 +0100 Subject: [PATCH 129/136] init to map to avoid concurrent insert issues --- .../internal/soup_and_face_graph_tree_helper.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index a6a288536943..4df53dedbe5f 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -87,8 +87,10 @@ struct AABB_tree_graph_helper using VPM_kernel = typename Kernel_traits::value_type>::Kernel; CGAL::Cartesian_converter to_input; - Bbox_map bb_map = get(Face_bbox_tag(), tm); - Ref_point_map rp_map = get(Face_ref_point_tag(), tm); + // we put a default value for case the property vector is not fully allocated. + // For exampe maps using a unordered map would have an issue with the concurrent insertion + Bbox_map bb_map = get(Face_bbox_tag(), tm, Bbox_3()); + Ref_point_map rp_map = get(Face_ref_point_tag(), tm, Epick::Point_3(0.,0.,0.)); #ifdef CGAL_LINKED_WITH_TBB if constexpr(Concurrency_tag::is_parallel) From c2c64ac035cbae437c55e38fc54c8165a4038e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 12 Nov 2026 17:09:57 +0100 Subject: [PATCH 130/136] one more TODO --- .../include/CGAL/Polygon_mesh_processing/intersection.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 4a5aa0dc6f91..500ddc1857a9 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -772,6 +772,7 @@ intersecting_meshes(const TriangleMeshRange& range, CGAL::AABB_trees::all_pairs_of_intersecting_primitives(tree, std::back_inserter(candidates)); // TODO: we could also do that in parallel, depending on candidates.size() + // TODO: tree caching could be added for(const auto& p : candidates) { const TriangleMesh &mesh1 = range[p.first]; From 0055d389a292a67cdccb7df4d8350a34791bfc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 13 Nov 2026 15:43:38 +0100 Subject: [PATCH 131/136] In troduces intersections for polylines and repair CGAL Lab --- .../PMP/Surface_intersection_plugin.cpp | 11 +- .../Polygon_mesh_processing/intersection.h | 274 ++++++++++++++++++ 2 files changed, 279 insertions(+), 6 deletions(-) diff --git a/Lab/demo/Lab/Plugins/PMP/Surface_intersection_plugin.cpp b/Lab/demo/Lab/Plugins/PMP/Surface_intersection_plugin.cpp index c8a57ea630de..4521b84a4262 100644 --- a/Lab/demo/Lab/Plugins/PMP/Surface_intersection_plugin.cpp +++ b/Lab/demo/Lab/Plugins/PMP/Surface_intersection_plugin.cpp @@ -208,7 +208,7 @@ void CGAL_Lab_intersection_plugin::intersectionPolylines() } std::vector poly_intersections; - PMP::internal::compute_polylines_polylines_intersection(polyA, polyB,std::back_inserter(poly_intersections) , Kernel()); + PMP::intersections(polyA, polyB, std::back_inserter(poly_intersections)); for(const Poly_intersection& inter : poly_intersections) { @@ -309,11 +309,10 @@ void CGAL_Lab_intersection_plugin::intersectionSurfacePolyline() polylines.push_back(pol); } std::vector poly_intersections; - PMP::internal::compute_face_polylines_intersection(faces(*itemA->face_graph()), - polylines, - *itemA->face_graph(), - std::back_inserter(poly_intersections), - CGAL::parameters::default_values()); + PMP::intersections(*itemA->face_graph(), + polylines, + std::back_inserter(poly_intersections), + CGAL::parameters::default_values()); for(const Poly_intersection& inter : poly_intersections) { diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 0966b2fa166d..fa78800ef5e1 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -113,6 +113,132 @@ bool is_mesh2_in_mesh1(const TriangleMesh& tm1, }// namespace internal +#ifndef DOXYGEN_RUNNING // Not documented yet, used by CGAL Lab +/** + * \ingroup PMP_intersection_grp + * + * detects and records intersections between two polylines. + * + * \attention If a polyline vertex intersects another polyline, the intersection will + * be reported twice (even more if it is on a vertex). + * + * \tparam PolylineRange a `RandomAccessRange` of `RandomAccessRange` of points. + * The point type must be from a 3D point from a \cgal Kernel. + * \cgalDescribePolylineType + * \tparam OutputIterator a model of `OutputIterator` holding objects of type + * `std::pair, std::pair >`. + * Each pair holds the index of the face and a pair containing the index of the polyline in the range and the index of + * the first point of the segment in the polyline. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" for the algorithm + * + * @param polylines1 the first range of polylines to check for intersections. + * @param polylines2 the second range of polylines to check for intersections. + * @param out output iterator to be filled with all pairs of segments that intersect + * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd + * \cgalNamedParamsEnd + * + */ +template +OutputIterator intersections(const PolylineRange& polylines1, + const PolylineRange& polylines2, + OutputIterator out, + const NamedParameters& np = parameters::default_values() +#ifndef DOXYGEN_RUNNING + , const std::enable_if_t< + boost::has_range_iterator< + typename boost::mpl::eval_if< + boost::has_range_iterator, + boost::range_value, + std::false_type >::type + >::value + >* = 0//end enable_if +#endif + ) +{ + CGAL_USE(np); + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + > ::type; + + using Polyline = typename boost::range_value::type; + using Point = typename boost::range_value::type; + using GT = typename CGAL::Kernel_traits::Kernel; + using Segment_3 = typename GT::Segment_3; + + using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; + using Segment_traits = CGAL::AABB_traits_3; + using Segment_tree = CGAL::AABB_tree; + + Bbox_3 b1; + for(const auto& polyline : polylines1) + b1 += bbox_3(polyline.begin(), polyline.end()); + Bbox_3 b2; + for(const auto& polyline : polylines2) + b2 += bbox_3(polyline.begin(), polyline.end()); + + if(!CGAL::do_overlap(b1, b2)) + return out; + + Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), + (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); + + // Store filtered segments and their original indices. + std::vector segments1, segments2; + std::vector> segment_indices1, segment_indices2; + + auto collect_segments = [&](const PolylineRange& polylines, + std::vector& segments, + std::vector>& segment_indices) + { + std::size_t polyline_index = 0; + for(const auto& polyline : polylines) + { + if(polyline.size() >= 2) + { + auto pit = std::begin(polyline); + auto prev = ++pit; + + for(; pit != std::end(polyline); ++pit, ++prev) + { + if(do_overlap(bb, prev->bbox()+pit->bbox())){ + segments.emplace_back(*prev, *pit); + segment_indices.emplace_back(polyline_index, std::size_t(prev - std::begin(polyline))); + } + } + } + ++polyline_index; + } + }; + + collect_segments(polylines1, segments1, segment_indices1); + collect_segments(polylines2, segments2, segment_indices2); + + Segment_tree tree1(segments1.begin(), segments1.end()); + Segment_tree tree2(segments2.begin(), segments2.end()); + + auto output = boost::make_function_output_iterator( + [&](const std::pair& ids) + { + const std::size_t index1 = std::size_t(ids.first - segments1.cbegin()); + const std::size_t index2 = std::size_t(ids.second - segments2.cbegin()); + + *out++ = std::make_pair( segment_indices1[index1], segment_indices2[index2]); + }); + AABB_trees::all_pairs_of_intersecting_primitives(tree1, tree2, output, parameters::concurrency_tag(Concurrency_tag())); + return out; +} +#endif + /** * \ingroup PMP_intersection_grp * @@ -428,6 +554,154 @@ bool do_intersect(const TriangleMesh& tm1, return false; } +#ifndef DOXYEGN_RUNNING // Not documented yet, used by Lab +/** + * \ingroup PMP_intersection_grp + * + * detects and reports all intersections between a face of `tm` and a segment of a polyline of `polylines`. + * + * @pre \link CGAL::is_triangle_mesh `CGAL::is_triangle_mesh(tm)` \endlink + * + * \tparam TriangleMesh a model of `FaceListGraph` + * \tparam PolylineRange a `RandomAccessRange` of `RandomAccessRange` of points. The point type of the range must be the + * same as the value type of the vertex point map. + * \cgalDescribePolylineType + * \tparam NamedParameters a sequence of \ref bgl_namedparameters + * + * @param tm the triangulated surface mesh to check for intersections + * @param polylines the range of polylines to check for intersections. + * @param out output iterator receiving pairs consisting of an intersecting face descriptor and a pair containing the + * index of the polyline and the index of the first point of the intersecting segment in that polyline + * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + * + * \cgalNamedParamsBegin + * \cgalParamNBegin{concurrency_tag} + * \cgalParamDescription{a tag indicating if the task should be done using one or several threads.} + * \cgalParamType{Either `CGAL::Sequential_tag`, or `CGAL::Parallel_tag`, or `CGAL::Parallel_if_available_tag`} + * \cgalParamDefault{`CGAL::Sequential_tag`} + * \cgalParamExtra{`np1` only} + * \cgalParamNEnd + * \cgalParamNBegin{vertex_point_map} + * \cgalParamDescription{a property map associating points to the vertices of `tm`} + * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%vertex_descriptor` as key type and `%Point_3` as value type} + * \cgalParamDefault{`boost::get(CGAL::vertex_point, tm)`} + * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` + * should be available for the vertices of `tm`.} + * \cgalParamNEnd + * \cgalParamNBegin{geom_traits} + * \cgalParamDescription{an instance of a geometric traits class} + * \cgalParamType{a class model of `PMPSelfIntersectionTraits`} + * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} + * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} + * \cgalParamNEnd + * \cgalNamedParamsEnd + * + */ +template +OutputIterator intersections(const TriangleMesh& tm, + const PolylineRange& polylines, + OutputIterator out, + const NamedParameters& np = parameters::default_values() +#ifndef DOXYGEN_RUNNING + , const std::enable_if_t< + boost::has_range_iterator< + typename boost::mpl::eval_if< + boost::has_range_iterator, + boost::range_value, + std::false_type + >::type + >::value + >* = 0//end enable_if +#endif + ) +{ + if (faces(tm).size()==0 || polylines.empty()) + return out; + + using parameters::get_parameter; + using parameters::choose_parameter; + + CGAL_precondition(CGAL::is_triangle_mesh(tm)); + + using Concurrency_tag = typename internal_np::Lookup_named_param_def < + internal_np::concurrency_tag_t, + NamedParameters, + Sequential_tag + >::type; + + using GT = typename GetGeomTraits::type; + + using VPM = typename GetVertexPointMap::const_type; + using face_descriptor = typename boost::graph_traits::face_descriptor; + using Segment_3 = typename GT::Segment_3; + + using AABB_tree_helper = internal::AABB_tree_graph_helper; + using Face_tree = typename AABB_tree_helper::Tree; + + using Segment_primitive = CGAL::AABB_segment_primitive_3::const_iterator>; + using Segment_traits = CGAL::AABB_traits_3; + using Segment_tree = CGAL::AABB_tree; + + VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, tm)); + + Bbox_3 b1; + for (face_descriptor f : faces(tm)) + b1 += Polygon_mesh_processing::face_bbox(f, tm, np); + Bbox_3 b2; + for(const auto& polyline : polylines) + b2 += bbox_3(polyline.begin(), polyline.end()); + + if(!CGAL::do_overlap(b1, b2)) + return out; + + Bbox_3 bb((std::max)(b1.xmin(),b2.xmin()), (std::max)(b1.ymin(),b2.ymin()), (std::max)(b1.zmin(),b2.zmin()), + (std::min)(b1.xmax(),b2.xmax()), (std::min)(b1.ymax(),b2.ymax()), (std::min)(b1.zmax(),b2.zmax())); + + // Store filtered segments and their original indices. + std::vector segments; + std::vector > segment_indices; + std::size_t polyline_index = 0; + for (const auto& polyline : polylines) + { + if(polyline.size() >= 2) + { + auto pit = std::begin(polyline); + auto prev = pit++; + for(; pit != std::end(polyline); ++pit, ++prev) + if (do_overlap(bb, prev->bbox()+pit->bbox())) + { + segments.emplace_back(*prev, *pit); + segment_indices.emplace_back(polyline_index, std::size_t(std::begin(polyline) - prev)); + } + } + ++polyline_index; + } + + std::vector faces_to_test; + for(face_descriptor f : faces(tm)) + if(do_overlap(Polygon_mesh_processing::face_bbox(f, tm, parameters::vertex_point_map(vpm)), bb)) + faces_to_test.emplace_back(f); + + AABB_tree_helper helper; + Face_tree face_tree; + + helper.template build(faces_to_test, face_tree, tm, vpm); + Segment_tree segment_tree(segments.begin(), segments.end()); + + auto output = boost::make_function_output_iterator( + [&](const auto& ids) + { + *out++ = std::make_pair(ids.first, segment_indices[std::size_t(ids.second - segments.cbegin())]); + }); + CGAL::AABB_trees::all_pairs_of_intersecting_primitives(face_tree, segment_tree, output, parameters::concurrency_tag(Concurrency_tag())); + return out; +} +#endif + /** * \ingroup PMP_intersection_grp * From 200054ca44a788fd624cc5557d3b1df9ea02f966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 13 Nov 2026 15:44:28 +0100 Subject: [PATCH 132/136] Replace EPICK per Simple_cartesian for reference point --- .../internal/soup_and_face_graph_tree_helper.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index a6a288536943..9f12918db1f6 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -15,7 +15,7 @@ #include -#include +#include #include #include @@ -79,13 +79,14 @@ struct AABB_tree_graph_helper template void build(const FaceRange &face_range, Tree& tree, const TriangleMesh& tm, VertexPointMap& vpm){ using Face_bbox_tag = typename CGAL::dynamic_face_property_t; - // Reference point do not need to be exact, so we use Epick for them - using Face_ref_point_tag = typename CGAL::dynamic_face_property_t; + // Reference point do not need to be exact, so we use Simple_cartesian for them + using FloatK = Simple_cartesian; + using Face_ref_point_tag = typename CGAL::dynamic_face_property_t; using Bbox_map = typename boost::property_map::const_type; using Ref_point_map = typename boost::property_map::const_type; using VPM_kernel = typename Kernel_traits::value_type>::Kernel; - CGAL::Cartesian_converter to_input; + CGAL::Cartesian_converter to_input; Bbox_map bb_map = get(Face_bbox_tag(), tm); Ref_point_map rp_map = get(Face_ref_point_tag(), tm); @@ -196,15 +197,16 @@ struct AABB_tree_soup_helper template void build(const FaceRange &face_range, Tree& tree, const PointRange& pts, const TriangleRange& triangles, VPM vpm){ using PM_kernel = typename Kernel_traits::value_type>::Kernel; + using FloatK = Simple_cartesian; using Bbox_map = Pointer_property_map::type; - using Ref_point_map = Pointer_property_map::type; + using Ref_point_map = Pointer_property_map::type; - CGAL::Cartesian_converter to_input; + CGAL::Cartesian_converter to_input; tree.insert(face_range.begin(), face_range.end(), pts, triangles, vpm.vpm); std::vector bb_vector(triangles.size(), Bbox_3()); - std::vector rp_vector(triangles.size(), Epick::Point_3()); + std::vector rp_vector(triangles.size(), FloatK::Point_3()); Bbox_map bb_map = make_property_map(bb_vector); Ref_point_map rp_map = make_property_map(rp_vector); From 9c42394366a220028cb8c8d3636261c88a0fb632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 13 Nov 2026 16:12:28 +0100 Subject: [PATCH 133/136] Missing change from EPick to cartesian --- .../internal/soup_and_face_graph_tree_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 9bda336ac8bd..694d9f1cc82d 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -91,7 +91,7 @@ struct AABB_tree_graph_helper // we put a default value for case the property vector is not fully allocated. // For exampe maps using a unordered map would have an issue with the concurrent insertion Bbox_map bb_map = get(Face_bbox_tag(), tm, Bbox_3()); - Ref_point_map rp_map = get(Face_ref_point_tag(), tm, Epick::Point_3(0.,0.,0.)); + Ref_point_map rp_map = get(Face_ref_point_tag(), tm, FloatK::Point_3(0.,0.,0.)); #ifdef CGAL_LINKED_WITH_TBB if constexpr(Concurrency_tag::is_parallel) From 00c63fb500ec2a8d3e500ad52d5aba9fe092c5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Fri, 13 Nov 2026 16:26:49 +0100 Subject: [PATCH 134/136] Update CHANGES.md --- Installation/CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 0508ae449706..b386c5884396 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -60,6 +60,11 @@ Release date: December 2026 - **Breaking change** Removed the member function `vertices_in_conflict()` of the Delaunay and the regular triangulation which were deprecated since CGAL-3.8 - Removed the concept `WeightedPoint` +### [Polygon Mesh Processing](https://doc.cgal.org/6.3/Manual/packages.html#PkgPolygonMeshProcessing) +- `CGAL::Polygon_mesh_processing::do_intersect()` and `CGAL::Polygon_mesh_processing::self_intersections()` functions now have a named parameter `concurrency_tag`, + specifying whether the task should be performed using a single or multiple threads. +- The running times of the functions above have been improved. + ### [Polygon Mesh Processing - Mesh Repair](https://doc.cgal.org/6.3/Manual/packages.html#PkgPMPMeshRepair) - **Breaking change**: Removed the function `CGAL::Polygon_mesh_processing::smooth_mesh()` which was deprecated since CGAL-5.5. - **Breaking change**: Removed the overload of the functions `CGAL::Polygon_mesh_processing::triangulate_hole()`, `CGAL::Polygon_mesh_processing::triangulate_and_refine_hole()`, and `CGAL::Polygon_mesh_processing::triangulate_refine_and_fair_hole()` having output iterators for vertices and faces as parameter, which were deprecated since CGAL-6.0. From 6ae21d66de102d6570f298bc9a609e185092e487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 17 Nov 2026 09:18:24 +0100 Subject: [PATCH 135/136] avoid conversion warning --- .../internal/soup_and_face_graph_tree_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h index 694d9f1cc82d..56574b4b219e 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/soup_and_face_graph_tree_helper.h @@ -91,7 +91,7 @@ struct AABB_tree_graph_helper // we put a default value for case the property vector is not fully allocated. // For exampe maps using a unordered map would have an issue with the concurrent insertion Bbox_map bb_map = get(Face_bbox_tag(), tm, Bbox_3()); - Ref_point_map rp_map = get(Face_ref_point_tag(), tm, FloatK::Point_3(0.,0.,0.)); + Ref_point_map rp_map = get(Face_ref_point_tag(), tm, FloatK::Point_3(0.f,0.f,0.f)); #ifdef CGAL_LINKED_WITH_TBB if constexpr(Concurrency_tag::is_parallel) From 6dac706c4a939dcbd22db0c5accbcee21775f6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valque=20L=C3=A9o?= Date: Tue, 17 Nov 2026 17:36:45 +0100 Subject: [PATCH 136/136] Add missing operator for Orthogonal_cut_plane_traits be compatible with AABB_tree --- .../refine_with_plane.h | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h index d2bf3327022b..97e597311890 100644 --- a/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h +++ b/PMP_Boolean_operations/include/CGAL/Polygon_mesh_processing/refine_with_plane.h @@ -150,16 +150,41 @@ struct Orthogonal_cut_plane_traits Construct_direction_3 construct_direction_3_object() const { return Construct_direction_3(); } Compare_projection_along_direction_3 compare_projection_along_direction_3_object() const { return Compare_projection_along_direction_3(); } -#ifndef CGAL_PLANE_CLIP_DO_NOT_USE_BOX_INTERSECTION_D -// for does self-intersect +#ifndef CGAL_PLANE_CLIP_DO_NOT_USE_AABB_TREE using Segment_3 = typename Kernel::Segment_3; using Triangle_3 = typename Kernel::Triangle_3; using Construct_segment_3 = typename Kernel::Construct_segment_3; using Construct_triangle_3 =typename Kernel::Construct_triangle_3; using Do_intersect_3 = typename Kernel::Do_intersect_3; + using Construct_sphere_3 = typename Kernel::Construct_sphere_3; + using Sphere_3 = typename Kernel::Sphere_3; + using Iso_cuboid_3 = typename Kernel::Iso_cuboid_3; + using Cartesian_const_iterator_3 = typename Kernel::Cartesian_const_iterator_3; + using Construct_cartesian_const_iterator_3 = typename Kernel::Construct_cartesian_const_iterator_3; + using Construct_min_vertex_3 = typename Kernel::Construct_min_vertex_3; + using Construct_max_vertex_3 = typename Kernel::Construct_max_vertex_3; + using Construct_center_3 = typename Kernel::Construct_center_3; + using Compute_squared_radius_3 = typename Kernel::Compute_squared_radius_3; + using Construct_iso_cuboid_3 = typename Kernel::Construct_iso_cuboid_3; + using Equal_3 = typename Kernel::Equal_3; + using Less_x_3 = typename Kernel::Less_x_3; + using Less_y_3 = typename Kernel::Less_y_3; + using Less_z_3 = typename Kernel::Less_z_3; + + Construct_sphere_3 construct_sphere_3_object() const { return Construct_sphere_3(); } Construct_segment_3 construct_segment_3_object() const { return Construct_segment_3(); } Construct_triangle_3 construct_triangle_3_object() const { return Construct_triangle_3(); } Do_intersect_3 do_intersect_3_object() const { return Do_intersect_3(); } + Construct_cartesian_const_iterator_3 construct_cartesian_const_iterator_3_object() const { return Construct_cartesian_const_iterator_3(); } + Construct_min_vertex_3 construct_min_vertex_3_object() const { return Construct_min_vertex_3(); } + Construct_max_vertex_3 construct_max_vertex_3_object() const { return Construct_max_vertex_3(); } + Construct_center_3 construct_center_3_object() const { return Construct_center_3(); } + Compute_squared_radius_3 compute_squared_radius_3_object() const { return Compute_squared_radius_3(); } + Construct_iso_cuboid_3 construct_iso_cuboid_3_object() const { return Construct_iso_cuboid_3(); } + Equal_3 equal_3_object() const { return Equal_3(); } + Less_x_3 less_x_3_object() const { return Less_x_3(); } + Less_y_3 less_y_3_object() const { return Less_y_3(); } + Less_z_3 less_z_3_object() const { return Less_z_3(); } #endif }; #endif