From df4f83417f9510319aca3e4db4d6724ab28e69fc Mon Sep 17 00:00:00 2001 From: MelchiorSchuh Date: Wed, 15 Apr 2026 16:13:57 +0200 Subject: [PATCH 1/3] feat(SurfaceMeshHelpers): Added the computation of surface mesh statistics to know current mesh metrics --- .../geode/mesh/helpers/mesh_statistics.hpp | 47 +++++++++++++ src/geode/mesh/CMakeLists.txt | 2 + src/geode/mesh/helpers/mesh_statistics.cpp | 70 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 include/geode/mesh/helpers/mesh_statistics.hpp create mode 100644 src/geode/mesh/helpers/mesh_statistics.cpp diff --git a/include/geode/mesh/helpers/mesh_statistics.hpp b/include/geode/mesh/helpers/mesh_statistics.hpp new file mode 100644 index 000000000..7484642c1 --- /dev/null +++ b/include/geode/mesh/helpers/mesh_statistics.hpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#pragma once + +#include + +namespace geode +{ + FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMesh ); + ALIAS_2D_AND_3D( SurfaceMesh ); + class Tetrahedron; +} // namespace geode + +namespace geode +{ + struct MeshMetric + { + double min_mesh_size{ std::numeric_limits< double >::max() }; + double mean_mesh_size{ 0. }; + double max_mesh_size{ std::numeric_limits< double >::min() }; + }; + + template < index_t dimension > + [[nodiscard]] MeshMetric compute_surface_metrics( + const SurfaceMesh< dimension >& mesh ); +} // namespace geode diff --git a/src/geode/mesh/CMakeLists.txt b/src/geode/mesh/CMakeLists.txt index 6567f01e6..8b7b1d9db 100644 --- a/src/geode/mesh/CMakeLists.txt +++ b/src/geode/mesh/CMakeLists.txt @@ -110,6 +110,7 @@ add_geode_library( "helpers/euclidean_distance_transform.cpp" "helpers/gradient_computation.cpp" "helpers/hausdorff_distance.cpp" + "helpers/mesh_statistics.cpp" "helpers/rasterize.cpp" "helpers/ray_tracing.cpp" "helpers/grid_point_function.cpp" @@ -252,6 +253,7 @@ add_geode_library( "helpers/generic_edged_curve_accessor.hpp" "helpers/hausdorff_distance.hpp" "helpers/nnsearch_mesh.hpp" + "helpers/mesh_statistics.hpp" "helpers/rasterize.hpp" "helpers/ray_tracing.hpp" "helpers/grid_point_function.hpp" diff --git a/src/geode/mesh/helpers/mesh_statistics.cpp b/src/geode/mesh/helpers/mesh_statistics.cpp new file mode 100644 index 000000000..1985e8ce2 --- /dev/null +++ b/src/geode/mesh/helpers/mesh_statistics.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#include + +#include + +namespace +{ +} // namespace + +namespace geode +{ + template < index_t dimension > + [[nodiscard]] MeshMetric compute_surface_metrics( + const SurfaceMesh< dimension >& mesh ) + { + MeshMetric result; + index_t nb_edges{ 0 }; + for( const auto polygon_id : Range{ mesh.nb_polygons() } ) + { + for( const auto edge_id : + LRange{ mesh.nb_polygon_edges( polygon_id ) } ) + { + const PolygonEdge polygon_edge{ polygon_id, edge_id }; + if( const auto adjacent = + mesh.polygon_adjacent( polygon_edge ) ) + { + if( adjacent.value() < polygon_id ) + { + continue; + } + } + const auto length = mesh.edge_length( polygon_edge ); + result.max_mesh_size = std::max( result.max_mesh_size, length ); + result.min_mesh_size = std::min( result.min_mesh_size, length ); + result.mean_mesh_size += length; + nb_edges++; + } + } + if( nb_edges != 0 ) + { + result.mean_mesh_size /= nb_edges; + } + return result; + } + + template MeshMetric compute_surface_metrics< 2 >( const SurfaceMesh< 2 >& ); + template MeshMetric compute_surface_metrics< 3 >( const SurfaceMesh< 3 >& ); +} // namespace geode From 870ebd90f8221f48297f8d86b78ef73fefaf22e8 Mon Sep 17 00:00:00 2001 From: MelchiorSchuh Date: Wed, 15 Apr 2026 16:59:52 +0200 Subject: [PATCH 2/3] Piere comments --- include/geode/mesh/helpers/mesh_statistics.hpp | 11 +++++------ src/geode/mesh/helpers/mesh_statistics.cpp | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/geode/mesh/helpers/mesh_statistics.hpp b/include/geode/mesh/helpers/mesh_statistics.hpp index 7484642c1..9d68edbf9 100644 --- a/include/geode/mesh/helpers/mesh_statistics.hpp +++ b/include/geode/mesh/helpers/mesh_statistics.hpp @@ -29,19 +29,18 @@ namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMesh ); ALIAS_2D_AND_3D( SurfaceMesh ); - class Tetrahedron; } // namespace geode namespace geode { - struct MeshMetric + struct MeshStatistics { - double min_mesh_size{ std::numeric_limits< double >::max() }; - double mean_mesh_size{ 0. }; - double max_mesh_size{ std::numeric_limits< double >::min() }; + double min_edge_size{ std::numeric_limits< double >::max() }; + double mean_edge_size{ 0. }; + double max_edge_size{ std::numeric_limits< double >::min() }; }; template < index_t dimension > - [[nodiscard]] MeshMetric compute_surface_metrics( + [[nodiscard]] MeshStatistics compute_surface_metrics( const SurfaceMesh< dimension >& mesh ); } // namespace geode diff --git a/src/geode/mesh/helpers/mesh_statistics.cpp b/src/geode/mesh/helpers/mesh_statistics.cpp index 1985e8ce2..b8522a615 100644 --- a/src/geode/mesh/helpers/mesh_statistics.cpp +++ b/src/geode/mesh/helpers/mesh_statistics.cpp @@ -32,10 +32,10 @@ namespace namespace geode { template < index_t dimension > - [[nodiscard]] MeshMetric compute_surface_metrics( + [[nodiscard]] MeshStatistics compute_surface_metrics( const SurfaceMesh< dimension >& mesh ) { - MeshMetric result; + MeshStatistics result; index_t nb_edges{ 0 }; for( const auto polygon_id : Range{ mesh.nb_polygons() } ) { @@ -52,19 +52,21 @@ namespace geode } } const auto length = mesh.edge_length( polygon_edge ); - result.max_mesh_size = std::max( result.max_mesh_size, length ); - result.min_mesh_size = std::min( result.min_mesh_size, length ); - result.mean_mesh_size += length; + result.max_edge_size = std::max( result.max_edge_size, length ); + result.min_edge_size = std::min( result.min_edge_size, length ); + result.mean_edge_size += length; nb_edges++; } } if( nb_edges != 0 ) { - result.mean_mesh_size /= nb_edges; + result.mean_edge_size /= nb_edges; } return result; } - template MeshMetric compute_surface_metrics< 2 >( const SurfaceMesh< 2 >& ); - template MeshMetric compute_surface_metrics< 3 >( const SurfaceMesh< 3 >& ); + template MeshStatistics compute_surface_metrics< 2 >( + const SurfaceMesh< 2 >& ); + template MeshStatistics compute_surface_metrics< 3 >( + const SurfaceMesh< 3 >& ); } // namespace geode From 55141d39f0e4721d0c4d604f498fa8d37902b416 Mon Sep 17 00:00:00 2001 From: MelchiorSchuh Date: Wed, 15 Apr 2026 17:01:00 +0200 Subject: [PATCH 3/3] fix tidy --- src/geode/mesh/helpers/mesh_statistics.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/geode/mesh/helpers/mesh_statistics.cpp b/src/geode/mesh/helpers/mesh_statistics.cpp index b8522a615..e466595c6 100644 --- a/src/geode/mesh/helpers/mesh_statistics.cpp +++ b/src/geode/mesh/helpers/mesh_statistics.cpp @@ -23,6 +23,8 @@ #include +#include + #include namespace