From 03bed4bc4a639a135227edc39a9c6a98dff6e46a Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Thu, 2 Jan 2025 15:57:08 +0100 Subject: [PATCH 1/2] fix(SurfaceMesh): create Segment from PolygonEdge --- .../geode/geometry/basic_objects/triangle.hpp | 1 + include/geode/mesh/core/surface_mesh.hpp | 4 ++++ src/geode/geometry/basic_objects/triangle.cpp | 21 +++++++++++++++++++ src/geode/mesh/core/surface_mesh.cpp | 14 +++++++++---- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/geode/geometry/basic_objects/triangle.hpp b/include/geode/geometry/basic_objects/triangle.hpp index 39e8359cf..8a96a6561 100644 --- a/include/geode/geometry/basic_objects/triangle.hpp +++ b/include/geode/geometry/basic_objects/triangle.hpp @@ -84,6 +84,7 @@ namespace geode [[nodiscard]] const std::array< PointType, 3 >& vertices() const; [[nodiscard]] BoundingBox< dimension > bounding_box() const; [[nodiscard]] local_index_t longest_edge_index() const; + [[nodiscard]] local_index_t smallest_edge_index() const; [[nodiscard]] double minimum_height() const; [[nodiscard]] bool is_degenerated() const; [[nodiscard]] std::string string() const; diff --git a/include/geode/mesh/core/surface_mesh.hpp b/include/geode/mesh/core/surface_mesh.hpp index 28de91f6f..ec14342aa 100644 --- a/include/geode/mesh/core/surface_mesh.hpp +++ b/include/geode/mesh/core/surface_mesh.hpp @@ -40,6 +40,7 @@ namespace geode FORWARD_DECLARATION_DIMENSION_CLASS( Polygon ); FORWARD_DECLARATION_DIMENSION_CLASS( Vector ); FORWARD_DECLARATION_DIMENSION_CLASS( BoundingBox ); + FORWARD_DECLARATION_DIMENSION_CLASS( Segment ); FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceEdges ); FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMeshBuilder ); @@ -404,6 +405,9 @@ namespace geode [[nodiscard]] std::optional< PolygonEdge > polygon_edge_from_vertices( index_t from_vertex_id, index_t to_vertex_id ) const; + [[nodiscard]] Segment< dimension > segment( + const PolygonEdge& polygon_edge ) const; + /*! * Find the polygon edges corresponding to a pair of vertex indices. * @return Local indices of the edges found diff --git a/src/geode/geometry/basic_objects/triangle.cpp b/src/geode/geometry/basic_objects/triangle.cpp index 7eb4f5365..bfa5da980 100644 --- a/src/geode/geometry/basic_objects/triangle.cpp +++ b/src/geode/geometry/basic_objects/triangle.cpp @@ -256,6 +256,27 @@ namespace geode return max_length_edge_id; } + template < typename PointType, index_t dimension > + local_index_t + GenericTriangle< PointType, dimension >::smallest_edge_index() const + { + local_index_t min_length_edge_id{ NO_LID }; + auto edge_min_length = std::numeric_limits< double >::max(); + for( const auto edge_id : LRange{ 3 } ) + { + const auto next_vertex = edge_id == 2 ? 0 : edge_id + 1; + const Point< dimension >& point0 = vertices_.at( edge_id ); + const Point< dimension >& point1 = vertices_.at( next_vertex ); + const auto edge_length = point_point_distance( point0, point1 ); + if( edge_length < edge_min_length ) + { + min_length_edge_id = edge_id; + edge_min_length = edge_length; + } + } + return min_length_edge_id; + } + template < typename PointType, index_t dimension > double GenericTriangle< PointType, dimension >::minimum_height() const { diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index c33eae82a..50d832ce1 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -274,13 +274,11 @@ namespace geode public: Impl( SurfaceMesh& surface ) - : polygon_around_vertex_( - surface.vertex_attribute_manager() + : polygon_around_vertex_( surface.vertex_attribute_manager() .template find_or_create_attribute< VariableAttribute, PolygonVertex >( "polygon_around_vertex", PolygonVertex{} ) ), - polygons_around_vertex_( - surface.vertex_attribute_manager() + polygons_around_vertex_( surface.vertex_attribute_manager() .template find_or_create_attribute< VariableAttribute, CachedPolygons >( POLYGONS_AROUND_VERTEX_NAME, CachedPolygons{} ) ) @@ -911,6 +909,14 @@ namespace geode return std::nullopt; } + template < index_t dimension > + Segment< dimension > SurfaceMesh< dimension >::segment( + const PolygonEdge& polygon_edge ) const + { + const auto vertices = polygon_edge_vertices( polygon_edge ); + return { this->point( vertices[0] ), this->point( vertices[1] ) }; + } + template < index_t dimension > PolygonsAroundEdge SurfaceMesh< dimension >::polygons_from_edge_vertices( absl::Span< const index_t > edge_vertices ) const From 000b0c18d797d64810b2896c97df56c4718dcb36 Mon Sep 17 00:00:00 2001 From: BotellaA Date: Thu, 2 Jan 2025 14:58:08 +0000 Subject: [PATCH 2/2] Apply prepare changes --- src/geode/mesh/core/surface_mesh.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 50d832ce1..20a5f7a3b 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -274,11 +274,13 @@ namespace geode public: Impl( SurfaceMesh& surface ) - : polygon_around_vertex_( surface.vertex_attribute_manager() + : polygon_around_vertex_( + surface.vertex_attribute_manager() .template find_or_create_attribute< VariableAttribute, PolygonVertex >( "polygon_around_vertex", PolygonVertex{} ) ), - polygons_around_vertex_( surface.vertex_attribute_manager() + polygons_around_vertex_( + surface.vertex_attribute_manager() .template find_or_create_attribute< VariableAttribute, CachedPolygons >( POLYGONS_AROUND_VERTEX_NAME, CachedPolygons{} ) )