Skip to content

Commit

Permalink
feat(Geometry): adding new tetrahedron quality metric (volume to edge…
Browse files Browse the repository at this point in the history
… ratio).
  • Loading branch information
benoit2776 committed Dec 12, 2024
1 parent 52b9616 commit 5aed18e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/geode/geometry/quality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <limits>

#include <geode/geometry/basic_objects/tetrahedron.hpp>
#include <geode/geometry/mensuration.hpp>
#include <geode/geometry/vector.hpp>

namespace geode
Expand Down Expand Up @@ -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
8 changes: 3 additions & 5 deletions src/geode/mesh/core/solid_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{} ) )
Expand Down Expand Up @@ -1260,7 +1258,7 @@ namespace geode
{
facet_vertices.push_back(
vertices[polyhedron_facet_vertex_id( { facet, v } )
.vertex_id] );
.vertex_id] );
}
}
return facets_vertices;
Expand Down

0 comments on commit 5aed18e

Please sign in to comment.