From b6ff43682441e1be97151e9aaa39a9ae357e3def Mon Sep 17 00:00:00 2001 From: Yoann Le Montagner Date: Mon, 18 Mar 2024 09:54:45 +0100 Subject: [PATCH 1/2] feat(SolidMesh): add polyhedron_facet_area Added a method on SolidMesh to compute the area of a polyhedron facet. Implementation similar to SurfaceMesh3D::polygon_area. --- include/geode/mesh/core/solid_mesh.h | 7 +++++++ src/geode/mesh/core/solid_mesh.cpp | 22 ++++++++++++++++++++++ tests/mesh/test-tetrahedral-solid.cpp | 17 +++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/include/geode/mesh/core/solid_mesh.h b/include/geode/mesh/core/solid_mesh.h index 38bd71299..018018a15 100644 --- a/include/geode/mesh/core/solid_mesh.h +++ b/include/geode/mesh/core/solid_mesh.h @@ -425,6 +425,13 @@ namespace geode Vector3D OPENGEODE_MESH_DEPRECATED polyhedron_facet_normal( const PolyhedronFacet& polyhedron_facet ) const; + /*! + * Return the area of a given PolyhedronFacet. + * @param[in] polyhedron_facet Local index of facet in polyhedron. + */ + double polyhedron_facet_area( + const PolyhedronFacet& polyhedron_facet ) const; + /*! * Return the normal of a given PolyhedronFacet. * @param[in] polyhedron_facet Local index of facet in polyhedron. diff --git a/src/geode/mesh/core/solid_mesh.cpp b/src/geode/mesh/core/solid_mesh.cpp index 643fa9aea..262166c71 100644 --- a/src/geode/mesh/core/solid_mesh.cpp +++ b/src/geode/mesh/core/solid_mesh.cpp @@ -800,6 +800,28 @@ namespace geode return volume; } + template < index_t dimension > + double SolidMesh< dimension >::polyhedron_facet_area( + const PolyhedronFacet& polyhedron_facet ) const + { + if( nb_polyhedron_facet_vertices( polyhedron_facet ) < 3 ) + { + return 0; + } + double area{ 0 }; + const auto direction = new_polyhedron_facet_normal( polyhedron_facet ) + .value_or( Vector3D{ { 0, 0, 1 } } ); + const auto vertices = polyhedron_facet_vertices( polyhedron_facet ); + const auto& p1 = this->point( vertices[0] ); + for( const auto i : LRange{ 1, vertices.size() - 1 } ) + { + const auto& p2 = this->point( vertices[i] ); + const auto& p3 = this->point( vertices[i + 1] ); + area += triangle_signed_area( { p1, p2, p3 }, direction ); + } + return area; + } + template < index_t dimension > Vector3D SolidMesh< dimension >::polyhedron_facet_normal( const PolyhedronFacet& polyhedron_facet ) const diff --git a/tests/mesh/test-tetrahedral-solid.cpp b/tests/mesh/test-tetrahedral-solid.cpp index 82b634ed1..8564e5605 100644 --- a/tests/mesh/test-tetrahedral-solid.cpp +++ b/tests/mesh/test-tetrahedral-solid.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -82,6 +83,21 @@ void test_polyhedron_volumes( const geode::TetrahedralSolid3D& solid ) } } +void test_polyhedron_facet_area( const geode::TetrahedralSolid3D& solid ) +{ + for( const auto p : geode::Range{ solid.nb_polyhedra() } ) + { + for( const auto f : geode::LRange{ solid.nb_polyhedron_facets(p) } ) + { + auto actual = std::fabs( solid.polyhedron_facet_area( { p, f } ) ); + auto expected = geode::triangle_area( solid.triangle( { p, f } ) ); + OPENGEODE_EXCEPTION( + std::fabs( actual - expected ) < geode::global_epsilon, + "[Test] Not correct tetrahedron facet area computation" ); + } + } +} + void test_polyhedron_adjacencies( const geode::TetrahedralSolid3D& solid, geode::TetrahedralSolidBuilder3D& builder ) { @@ -369,6 +385,7 @@ void test() test_create_vertices( *solid, *builder ); test_create_tetrahedra( *solid, *builder ); test_polyhedron_volumes( *solid ); + test_polyhedron_facet_area( *solid ); test_polyhedron_adjacencies( *solid, *builder ); test_is_on_border( *solid ); test_io( *solid, absl::StrCat( "test.", solid->native_extension() ) ); From b5a5832bf1d9e5b9e28e82254f6ee4f1c489e41c Mon Sep 17 00:00:00 2001 From: MelchiorSchuh Date: Tue, 26 Mar 2024 13:09:56 +0000 Subject: [PATCH 2/2] Apply prepare changes --- src/geode/mesh/core/solid_mesh.cpp | 2 +- tests/mesh/test-tetrahedral-solid.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geode/mesh/core/solid_mesh.cpp b/src/geode/mesh/core/solid_mesh.cpp index 262166c71..b70b5855a 100644 --- a/src/geode/mesh/core/solid_mesh.cpp +++ b/src/geode/mesh/core/solid_mesh.cpp @@ -810,7 +810,7 @@ namespace geode } double area{ 0 }; const auto direction = new_polyhedron_facet_normal( polyhedron_facet ) - .value_or( Vector3D{ { 0, 0, 1 } } ); + .value_or( Vector3D{ { 0, 0, 1 } } ); const auto vertices = polyhedron_facet_vertices( polyhedron_facet ); const auto& p1 = this->point( vertices[0] ); for( const auto i : LRange{ 1, vertices.size() - 1 } ) diff --git a/tests/mesh/test-tetrahedral-solid.cpp b/tests/mesh/test-tetrahedral-solid.cpp index 8564e5605..3ac6e8bb7 100644 --- a/tests/mesh/test-tetrahedral-solid.cpp +++ b/tests/mesh/test-tetrahedral-solid.cpp @@ -87,7 +87,7 @@ void test_polyhedron_facet_area( const geode::TetrahedralSolid3D& solid ) { for( const auto p : geode::Range{ solid.nb_polyhedra() } ) { - for( const auto f : geode::LRange{ solid.nb_polyhedron_facets(p) } ) + for( const auto f : geode::LRange{ solid.nb_polyhedron_facets( p ) } ) { auto actual = std::fabs( solid.polyhedron_facet_area( { p, f } ) ); auto expected = geode::triangle_area( solid.triangle( { p, f } ) );