From a9082f85754d0129179938b0d4867b2b88d319c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 26 Mar 2025 22:47:09 +0100 Subject: [PATCH] Factorize MC/TMC vertex interpolation functions --- .../internal/marching_cubes_functors.h | 21 ++++++++++--------- ...ogically_correct_marching_cubes_functors.h | 15 +++---------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/marching_cubes_functors.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/marching_cubes_functors.h index c9489890bc1..448fbee6a34 100644 --- a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/marching_cubes_functors.h +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/marching_cubes_functors.h @@ -64,12 +64,13 @@ namespace internal { // Interpolate linearly between two vertex locations v0, v1 with values d0 and d1 according to the isovalue template -typename GeomTraits::Point_3 vertex_interpolation(const typename GeomTraits::Point_3& p0, - const typename GeomTraits::Point_3& p1, - const typename GeomTraits::FT d0, - const typename GeomTraits::FT d1, - const typename GeomTraits::FT isovalue, - const GeomTraits& gt) +std::pair +vertex_interpolation(const typename GeomTraits::Point_3& p0, + const typename GeomTraits::Point_3& p1, + const typename GeomTraits::FT d0, + const typename GeomTraits::FT d1, + const typename GeomTraits::FT isovalue, + const GeomTraits& gt) { using FT = typename GeomTraits::FT; @@ -88,9 +89,9 @@ typename GeomTraits::Point_3 vertex_interpolation(const typename GeomTraits::Poi mu = std::clamp(mu, FT(0), FT(1)); // linear interpolation - return point((FT(1) - mu) * x_coord(p0) + mu * x_coord(p1), - (FT(1) - mu) * y_coord(p0) + mu * y_coord(p1), - (FT(1) - mu) * z_coord(p0) + mu * z_coord(p1)); + return { point((FT(1) - mu) * x_coord(p0) + mu * x_coord(p1), + (FT(1) - mu) * y_coord(p0) + mu * y_coord(p1), + (FT(1) - mu) * z_coord(p0) + mu * z_coord(p1)), mu }; } // retrieves the values of a cell and return the lookup index @@ -173,7 +174,7 @@ void MC_construct_vertices(const typename Domain::cell_descriptor& cell, vertices[e_id] = vertex_interpolation(corners[v0], corners[v1], values[v0], values[v1], - isovalue, domain.geom_traits()); + isovalue, domain.geom_traits()).first; } flag <<= 1; diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/topologically_correct_marching_cubes_functors.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/topologically_correct_marching_cubes_functors.h index d4e0e30d887..1b6449edca3 100644 --- a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/topologically_correct_marching_cubes_functors.h +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/topologically_correct_marching_cubes_functors.h @@ -399,18 +399,9 @@ private: unsigned int v0, v1; get_edge_vertex(eg, v0, v1, l_edges_); - // @todo use the domain's interpolation scheme? - const FT den = values[v1] - values[v0]; - FT l = is_zero(den) ? FT(1) / FT(2) : (i0 - values[v0]) / den; - l = std::clamp(l, FT(0), FT(1)); - - ecoord[eg] = l; - - const FT px = (FT(1) - l) * x_coord(corners[v0]) + l * x_coord(corners[v1]); - const FT py = (FT(1) - l) * y_coord(corners[v0]) + l * y_coord(corners[v1]); - const FT pz = (FT(1) - l) * z_coord(corners[v0]) + l * z_coord(corners[v1]); - - vertices[eg] = point(px, py, pz); + std::tie(vertices[eg], ecoord[eg]) = vertex_interpolation(corners[v0], corners[v1], + values[v0], values[v1], + i0, m_domain.geom_traits()); } // next edge