Skip to content

Commit 7b6b493

Browse files
authored
fix(Mesh): add in SolidMesh a method to get local indices of edge vertices (#529)
1 parent f4dc7b0 commit 7b6b493

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

bindings/python/src/mesh/core/solid_mesh.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@
105105
.def( "polyhedron_attribute_manager", \
106106
&SolidMesh##dimension##D::polyhedron_attribute_manager, \
107107
pybind11::return_value_policy::reference ) \
108-
.def( "bounding_box", &SolidMesh##dimension##D::bounding_box )
108+
.def( "bounding_box", &SolidMesh##dimension##D::bounding_box ) \
109+
.def( "edge_vertices_in_polyhedron", \
110+
&SolidMesh##dimension##D::edge_vertices_in_polyhedron )
109111

110112
namespace geode
111113
{

include/geode/mesh/core/solid_mesh.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,17 @@ namespace geode
492492
PolyhedraAroundFacet polyhedra_from_facet_vertices(
493493
PolyhedronFacetVertices facet_vertices ) const;
494494

495+
/*!
496+
* Get the local indices in the polyhedra of both edge vertices.
497+
* @param[in] polyhedron_id Index of polyhedron.
498+
* @param[in] edge_vertices Global indices of the two edge vertices.
499+
* @details If the vertices are not in the polyhedron, NO_LID is
500+
* returned.
501+
*/
502+
std::array< local_index_t, 2 > edge_vertices_in_polyhedron(
503+
index_t polyhedron_id,
504+
const std::array< index_t, 2 >& edge_vertices ) const;
505+
495506
bool are_edges_enabled() const;
496507

497508
void enable_edges() const;

src/geode/mesh/core/solid_mesh.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,29 @@ namespace geode
12441244
return borders;
12451245
}
12461246

1247+
template < index_t dimension >
1248+
std::array< local_index_t, 2 >
1249+
SolidMesh< dimension >::edge_vertices_in_polyhedron(
1250+
index_t polyhedron_id,
1251+
const std::array< index_t, 2 >& edge_vertices ) const
1252+
{
1253+
std::array< local_index_t, 2 > result{ { NO_LID, NO_LID } };
1254+
1255+
const auto vertices = polyhedron_vertices( polyhedron_id );
1256+
for( const auto v : LRange{ nb_polyhedron_vertices( polyhedron_id ) } )
1257+
{
1258+
if( vertices[v] == edge_vertices[0] && result[0] == NO_LID )
1259+
{
1260+
result[0] = v;
1261+
}
1262+
else if( vertices[v] == edge_vertices[1] && result[1] == NO_LID )
1263+
{
1264+
result[1] = v;
1265+
}
1266+
}
1267+
return result;
1268+
}
1269+
12471270
template < index_t dimension >
12481271
AttributeManager&
12491272
SolidMesh< dimension >::polyhedron_attribute_manager() const

0 commit comments

Comments
 (0)