From 81513fc8604df9c9e2cdfdf8d38b993324c38f18 Mon Sep 17 00:00:00 2001 From: Dmitry Anisimov Date: Fri, 16 Apr 2021 18:15:07 +0200 Subject: [PATCH] face descriptor is now stored in the candidate triangle to remember the realizing triangle --- .../CGAL/Polygon_mesh_processing/distance.h | 19 ++++++---- ...traversal_traits_with_Hausdorff_distance.h | 35 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h index 02b50c33973..8a28f607bcb 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h @@ -1345,6 +1345,7 @@ double bounded_error_Hausdorff_impl( typedef typename Kernel::Triangle_3 Triangle_3; typedef typename boost::graph_traits::face_descriptor face_descriptor; + using Candidate = Candidate_triangle; typename Kernel::Compute_squared_distance_3 squared_distance; @@ -1400,13 +1401,15 @@ double bounded_error_Hausdorff_impl( // Can already build a sorted structure while collecting the candidates auto& candidate_triangles = traversal_traits_tm1.get_candidate_triangles(); auto global_bounds = traversal_traits_tm1.get_global_bounds(); - // std::cout << candidate_triangles.size() << std::endl; + + // std::cout << "number of candidate triangles 1: " << + // candidate_triangles.size() << std::endl; const FT squared_error_bound = error_bound * error_bound; while ( (global_bounds.second - global_bounds.first > error_bound) && !candidate_triangles.empty() ) { // Get the first triangle and its Hausdorff bounds from the candidate set - const Candidate_triangle triangle_and_bound = candidate_triangles.top(); + const Candidate triangle_and_bound = candidate_triangles.top(); // Remove it from the candidate set as it will be processed now candidate_triangles.pop(); @@ -1414,11 +1417,11 @@ double bounded_error_Hausdorff_impl( // i.e. if its Upper Bound is higher than the currently known best lower bound // and the difference between the bounds to be obtained is larger than the // user given error. - const auto& triangle_bounds = triangle_and_bound.m_bounds; + const auto& triangle_bounds = triangle_and_bound.bounds; if ( (triangle_bounds.second > global_bounds.first) && (triangle_bounds.second - triangle_bounds.first > error_bound) ) { // Get the triangle that is to be subdivided and read its vertices - const Triangle_3& triangle_for_subdivision = triangle_and_bound.m_triangle; + const Triangle_3& triangle_for_subdivision = triangle_and_bound.triangle; const Point_3 v0 = triangle_for_subdivision.vertex(0); const Point_3 v1 = triangle_for_subdivision.vertex(1); const Point_3 v2 = triangle_for_subdivision.vertex(2); @@ -1479,16 +1482,18 @@ double bounded_error_Hausdorff_impl( // TODO Additionally store the face descriptor of the parent from TM1 in the Candidate_triangle. // Add the subtriangle to the candidate list candidate_triangles.push( - Candidate_triangle(sub_triangles[i], local_bounds) - ); + Candidate(sub_triangles[i], local_bounds, triangle_and_bound.face) ); } // Update global upper Hausdorff bound after subdivision - const FT current_max = candidate_triangles.top().m_bounds.second; + const FT current_max = candidate_triangles.top().bounds.second; global_bounds.second = std::max(current_max, global_bounds.first); } } + // std::cout << "number of candidate triangles 2: " << + // candidate_triangles.size() << std::endl; + // Return linear interpolation between found lower and upper bound return CGAL::to_double((global_bounds.first + global_bounds.second) / FT(2)); diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_Hausdorff_distance.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_Hausdorff_distance.h index eaf710daf53..e0095823213 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_Hausdorff_distance.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_Hausdorff_distance.h @@ -29,21 +29,25 @@ namespace CGAL { return FT(1000000000000); } - /** - * @struct Candidate_triangle - */ - template + // Candidate triangle. + template struct Candidate_triangle { using FT = typename Kernel::FT; - typedef typename Kernel::Triangle_3 Triangle_3; + using Triangle_3 = typename Kernel::Triangle_3; - Candidate_triangle(const Triangle_3& triangle, const std::pair& bounds) - : m_triangle(triangle), m_bounds(bounds) {} + Candidate_triangle( + const Triangle_3& triangle, + const std::pair& bounds, + const FaceDescriptor& face) : + triangle(triangle), bounds(bounds), face(face) + { } - Triangle_3 m_triangle; - std::pair m_bounds; - bool operator>(const Candidate_triangle& other) const { return m_bounds.second < other.m_bounds.second; } - bool operator<(const Candidate_triangle& other) const { return m_bounds.second > other.m_bounds.second; } + Triangle_3 triangle; + std::pair bounds; + FaceDescriptor face; + + bool operator>(const Candidate_triangle& other) const { return bounds.second < other.bounds.second; } + bool operator<(const Candidate_triangle& other) const { return bounds.second > other.bounds.second; } }; /** @@ -229,7 +233,8 @@ namespace CGAL { typedef AABB_tree< AABB_traits > TM2_tree; typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef std::priority_queue< Candidate_triangle > Heap_type; + using Candidate = Candidate_triangle; + typedef std::priority_queue Heap_type; public: typedef FT Priority; @@ -255,7 +260,7 @@ namespace CGAL { { // Map to transform faces of TM1 to actual triangles const Triangle_from_face_descriptor_map m_face_to_triangle_map( &m_tm1, m_vpm1 ); - const Triangle_3 candidate_triangle = get(m_face_to_triangle_map, primitive.id()); + const Triangle_3 triangle = get(m_face_to_triangle_map, primitive.id()); // TODO Can we initialize the bounds here, s.t. we don't start with infty? // Can we initialize the bounds depending on the closest points in tm2 @@ -271,7 +276,7 @@ namespace CGAL { infinity_value(), infinity_value() ); - m_tm2_tree.traversal_with_priority(candidate_triangle, traversal_traits_tm2); + m_tm2_tree.traversal_with_priority(triangle, traversal_traits_tm2); // Update global Hausdorff bounds according to the obtained local bounds const auto local_bounds = traversal_traits_tm2.get_local_bounds(); @@ -286,7 +291,7 @@ namespace CGAL { // Store the triangle given as primitive here as candidate triangle // together with the local bounds it obtained to sind it to subdivision // later - m_candidiate_triangles.push( Candidate_triangle(candidate_triangle, local_bounds) ); + m_candidiate_triangles.push( Candidate(triangle, local_bounds, primitive.id()) ); } // Determine whether child nodes will still contribute to a larger