From 06db9ccad8ebfabcac9d435975c2c1f7ee2301e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 2 Aug 2023 17:25:58 +0200 Subject: [PATCH] reproject barycenter to avoid boundary shrinking --- .../tangential_relaxation.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/tangential_relaxation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/tangential_relaxation.h index 2c67b83005fb..85431955cf7a 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/tangential_relaxation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/tangential_relaxation.h @@ -218,6 +218,7 @@ void tangential_relaxation(const VertexRange& vertices, typedef std::tuple VNP; std::vector< VNP > barycenters; auto gt_barycenter = gt.construct_barycenter_3_object(); + auto gt_project = gt.construct_projected_point_3_object(); // at each vertex, compute vertex normal std::unordered_map vnormals; @@ -269,8 +270,19 @@ void tangential_relaxation(const VertexRange& vertices, //check squared cosine is < 0.25 (~120 degrees) if (0.25 < dot*dot / ( squared_distance(get(vpm,ph0), get(vpm, v)) * squared_distance(get(vpm,ph1), get(vpm, v))) ) - barycenters.emplace_back(v, vn, - gt_barycenter(get(vpm, ph0), 0.25, get(vpm, ph1), 0.25, get(vpm, v), 0.5)); + { + typename GT::Point_3 bary = gt_barycenter(get(vpm, ph0), 0.25, get(vpm, ph1), 0.25, get(vpm, v), 0.5); + // to avoid shrinking of borders, we project back onto the incident segments + typename GT::Segment_3 s1(get(vpm, ph0), get(vpm,v)), + s2(get(vpm, ph1), get(vpm,v)); + + typename GT::Point_3 p1 = gt_project(s1, bary), p2 = gt_project(s2, bary); + + bary = squared_distance(p1, bary)