From 5aed18e8c0fdbf6e79d899c3a79ad685dc28b7c4 Mon Sep 17 00:00:00 2001 From: benoitTHEBAULT Date: Thu, 12 Dec 2024 10:28:48 +0100 Subject: [PATCH] feat(Geometry): adding new tetrahedron quality metric (volume to edge ratio). --- src/geode/geometry/quality.cpp | 23 +++++++++++++++++++++++ src/geode/mesh/core/solid_mesh.cpp | 8 +++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/geode/geometry/quality.cpp b/src/geode/geometry/quality.cpp index 69ffc7876..2c4ca524d 100644 --- a/src/geode/geometry/quality.cpp +++ b/src/geode/geometry/quality.cpp @@ -28,6 +28,7 @@ #include #include +#include #include namespace geode @@ -64,4 +65,26 @@ namespace geode constant * longest_edge_length * total_area2 / absolute_det; return aspect_ratio; } + + double tetrahedron_volume_to_edge_ratio( const Tetrahedron& tetra ) + { + const auto signed_volume = geode::tetrahedron_signed_volume( tetra ); + double sq_len{ 0 }; + const auto& vertices = tetra.vertices(); + for( const auto v0 : geode::LRange{ 3 } ) + { + const auto& point0 = vertices[v0].get(); + for( const auto v1 : geode::LRange{ v0, 4 } ) + { + const auto& point1 = vertices[v1].get(); + for( const auto d : geode::LRange{ 3 } ) + { + const auto diff = point0.value( d ) - point1.value( d ); + sq_len += diff * diff; + } + } + } + const auto l_rms = std::sqrt( sq_len / 6 ); + return 6 * std::sqrt( 2 ) * signed_volume / ( l_rms * l_rms * l_rms ); + } } // namespace geode diff --git a/src/geode/mesh/core/solid_mesh.cpp b/src/geode/mesh/core/solid_mesh.cpp index e4f4b7fdd..2b17e6c16 100644 --- a/src/geode/mesh/core/solid_mesh.cpp +++ b/src/geode/mesh/core/solid_mesh.cpp @@ -412,13 +412,11 @@ namespace geode public: explicit Impl( SolidMesh& solid ) - : polyhedron_around_vertex_( - solid.vertex_attribute_manager() + : polyhedron_around_vertex_( solid.vertex_attribute_manager() .template find_or_create_attribute< VariableAttribute, PolyhedronVertex >( "polyhedron_around_vertex", PolyhedronVertex{} ) ), - polyhedra_around_vertex_( - solid.vertex_attribute_manager() + polyhedra_around_vertex_( solid.vertex_attribute_manager() .template find_or_create_attribute< VariableAttribute, CachedPolyhedra >( POLYHEDRA_AROUND_VERTEX_NAME, CachedPolyhedra{} ) ) @@ -1260,7 +1258,7 @@ namespace geode { facet_vertices.push_back( vertices[polyhedron_facet_vertex_id( { facet, v } ) - .vertex_id] ); + .vertex_id] ); } } return facets_vertices;