From a01838d9f7b45892a5f77602191a2c2608ff725d Mon Sep 17 00:00:00 2001 From: Sven Oesau Date: Wed, 10 Dec 2025 14:56:12 +0100 Subject: [PATCH] adding check for collinear segments in case of strict parameters --- .../Polygon_mesh/Plane_face_region.h | 5 +- .../Segment_set/Line_segment_region.h | 59 ++++++++++--------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Plane_face_region.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Plane_face_region.h index 0ce82957af8..2bb084d0755 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Plane_face_region.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Polygon_mesh/Plane_face_region.h @@ -232,7 +232,7 @@ public: const Item query, const Region&) const { - if (m_cos_value_threshold==1 || m_distance_threshold == 0) + if (m_cos_value_threshold == 1 || m_distance_threshold == 0) { halfedge_descriptor h = halfedge(query, m_pmesh); for (vertex_descriptor v : vertices_around_face(h, m_pmesh)) @@ -250,9 +250,6 @@ public: if (typename GeomTraits::Compare_squared_distance_3()(m_p, m_q, m_r,get(m_vpm, v), m_squared_distance_threshold) != SMALLER) return false; - if (m_cos_value_threshold == 1) - return true; - const typename GeomTraits::Point_3& p2=get(m_vpm,source(h, m_pmesh)); const typename GeomTraits::Point_3& q2=get(m_vpm,target(h, m_pmesh)); typename GeomTraits::Point_3 r2; diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Segment_set/Line_segment_region.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Segment_set/Line_segment_region.h index 06addbbb618..6206f160fb8 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/Segment_set/Line_segment_region.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/Segment_set/Line_segment_region.h @@ -211,40 +211,41 @@ public: const auto& seg = get(m_segment_map, query); const Point& s = seg.source(); const Point& t = seg.target(); + const auto& seed_seg = get(m_segment_map, m_seed); + const Point& seed_s = seed_seg.source(); + const Point& seed_t = seed_seg.target(); - const Vector dir(s, t); - if (m_distance_threshold > FT(0)) { - const auto& seed_seg = get(m_segment_map, m_seed); - const Point& seed_s = seed_seg.source(); - const Point& seed_t = seed_seg.target(); - Line seed_line(seed_s, seed_t); - if (m_compare_squared_distance(s, seed_line, m_squared_distance_threshold) != SMALLER || + if (m_distance_threshold == 0 || m_cos_value_threshold == 1) + return collinear(seed_s, seed_t, s) && collinear(seed_s, seed_t, t); + else + { + if (m_distance_threshold > FT(0)) { + Line seed_line(seed_s, seed_t); + if (m_compare_squared_distance(s, seed_line, m_squared_distance_threshold) != SMALLER || m_compare_squared_distance(t, seed_line, m_squared_distance_threshold) != SMALLER) - return false; - } + return false; + } + + if (s == t) + return true; + + if (m_cos_value_threshold < FT(1)) { + typename GeomTraits::Compute_scalar_product_3 scalar_product = m_traits.compute_scalar_product_3_object(); + typename GeomTraits::Construct_vector_3 vector = m_traits.construct_vector_3_object(); + typename GeomTraits::Compute_squared_length_3 sq_length = m_traits.compute_squared_length_3_object(); + + const Vector_3 seed_dir = vector(seed_s, seed_t); + const Vector_3 query_dir = vector(s, t); + + typename GeomTraits::FT sc_prod = scalar_product(seed_dir, query_dir); + + return CGAL::compare(CGAL::square(m_cos_value_threshold) + * sq_length(seed_dir) * sq_length(query_dir), + CGAL::square(sc_prod)) == SMALLER; + } - if (s == t) return true; - - if (m_cos_value_threshold < FT(1)) { - const auto& seed_seg = get(m_segment_map, m_seed); - const Point& seed_s = seed_seg.source(); - const Point& seed_t = seed_seg.target(); - - typename GeomTraits::Compute_scalar_product_3 scalar_product = m_traits.compute_scalar_product_3_object(); - typename GeomTraits::Construct_vector_3 vector = m_traits.construct_vector_3_object(); - typename GeomTraits::Compute_squared_length_3 sq_length = m_traits.compute_squared_length_3_object(); - - const Vector_3 seed_dir = vector(seed_s, seed_t); - const Vector_3 query_dir = vector(s, t); - - typename GeomTraits::FT sc_prod = scalar_product(seed_dir, query_dir); - - return CGAL::compare(CGAL::square(m_cos_value_threshold) - * sq_length(seed_dir) * sq_length(query_dir), - CGAL::square(sc_prod)) == SMALLER; } - return true; } /*!