Skip to content

Commit

Permalink
perf(TetrahedralSolidBuilder): improve the creation of edges and face…
Browse files Browse the repository at this point in the history
…ts at tetrahedron creation
  • Loading branch information
panquez authored Apr 17, 2020
1 parent bf9e892 commit fd92a54
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 35 deletions.
6 changes: 6 additions & 0 deletions include/geode/mesh/builder/tetrahedral_solid_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ namespace geode
*/
index_t create_tetrahedra( index_t nb );

/*!
* Reserve storage for new tetrahedra without creating them.
* @param[in] nb Number of tetrahedra to reserve
*/
void reserve_tetrahedra( index_t nb );

void copy(
const TetrahedralSolid< dimension >& tetrahedral_solid, BuilderKey )
{
Expand Down
6 changes: 6 additions & 0 deletions include/geode/mesh/builder/triangulated_surface_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ namespace geode
*/
index_t create_triangles( index_t nb );

/*!
* Reserve storage for new triangles without creating them.
* @param[in] nb Number of triangles to reserve
*/
void reserve_triangles( index_t nb );

void copy( const TriangulatedSurface< dimension >& triangulated_surface,
BuilderKey )
{
Expand Down
20 changes: 10 additions & 10 deletions src/geode/mesh/builder/geode_tetrahedral_solid_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ namespace geode
void OpenGeodeTetrahedralSolidBuilder< dimension >::do_create_facets(
const std::array< index_t, 4 >& vertices )
{
for( auto&& facet_vertices :
get_tetrahedron_facet_vertices( vertices ) )
{
this->find_or_create_facet( facet_vertices );
}
this->find_or_create_facet( { vertices[1], vertices[3], vertices[2] } );
this->find_or_create_facet( { vertices[0], vertices[2], vertices[3] } );
this->find_or_create_facet( { vertices[3], vertices[1], vertices[0] } );
this->find_or_create_facet( { vertices[0], vertices[1], vertices[2] } );
}

template < index_t dimension >
void OpenGeodeTetrahedralSolidBuilder< dimension >::do_create_edges(
const std::array< index_t, 4 >& vertices )
{
for( auto&& edge_vertices :
this->get_tetrahedron_edge_vertices( vertices ) )
{
this->find_or_create_edge( edge_vertices );
}
this->find_or_create_edge( { vertices[0], vertices[1] } );
this->find_or_create_edge( { vertices[0], vertices[2] } );
this->find_or_create_edge( { vertices[0], vertices[3] } );
this->find_or_create_edge( { vertices[1], vertices[2] } );
this->find_or_create_edge( { vertices[1], vertices[3] } );
this->find_or_create_edge( { vertices[2], vertices[3] } );
}

template < index_t dimension >
Expand Down
5 changes: 4 additions & 1 deletion src/geode/mesh/builder/polyhedral_solid_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ namespace geode
for( auto&& edge_vertices :
get_polyhedron_edge_vertices( vertices, facets ) )
{
this->find_or_create_edge( edge_vertices );
if( edge_vertices[0] < edge_vertices[1] )
{
this->find_or_create_edge( edge_vertices );
}
}
}

Expand Down
31 changes: 12 additions & 19 deletions src/geode/mesh/builder/tetrahedral_solid_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ namespace geode
"tetrahedra are handled" );
std::array< index_t, 4 > tetra_vertices;
absl::c_copy_n( vertices, 4, tetra_vertices.begin() );
// sort !!!
absl::c_sort( tetra_vertices );
do_create_edges( tetra_vertices );
}

Expand Down Expand Up @@ -109,26 +107,21 @@ namespace geode
{ added_tetra, vertex_id++ }, vertex );
}
do_create_tetrahedron( vertices );
for( const auto f : Range{ 4 } )
{
PolyhedronFacet facet{ added_tetra, f };
PolyhedronFacetVertices facet_vertices( 3 );
for( const auto v : Range{ 3 } )
{
facet_vertices[v] =
tetrahedral_solid_.polyhedron_facet_vertex( { facet, v } );
std::array< index_t, 2 > edge_vertices{
tetrahedral_solid_.polyhedron_facet_vertex( { facet, v } ),
tetrahedral_solid_.polyhedron_facet_vertex(
{ facet, ( v + 1 ) % 3 } )
};
this->find_or_create_edge( std::move( edge_vertices ) );
}
this->find_or_create_facet( std::move( facet_vertices ) );
}
do_create_facets( vertices );
do_create_edges( vertices );
return added_tetra;
}

template < index_t dimension >
void TetrahedralSolidBuilder< dimension >::reserve_tetrahedra( index_t nb )
{
const auto nb_tet = tetrahedral_solid_.nb_polyhedra();
tetrahedral_solid_.polyhedron_attribute_manager().reserve(
nb_tet + nb );
tetrahedral_solid_.facet_attribute_manager().reserve( nb_tet + 4 * nb );
tetrahedral_solid_.edge_attribute_manager().reserve( nb_tet + 6 * nb );
}

template < index_t dimension >
index_t TetrahedralSolidBuilder< dimension >::create_tetrahedra(
index_t nb )
Expand Down
9 changes: 9 additions & 0 deletions src/geode/mesh/builder/triangulated_surface_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ namespace geode
return added_triangle;
}

template < index_t dimension >
void TriangulatedSurfaceBuilder< dimension >::reserve_triangles(
index_t nb )
{
const auto nb_triangles = triangulated_surface_.nb_polygons();
triangulated_surface_.polygon_attribute_manager().reserve(
nb_triangles + nb );
}

template < index_t dimension >
void TriangulatedSurfaceBuilder< dimension >::copy(
const TriangulatedSurface< dimension >& triangulated_surface )
Expand Down
6 changes: 1 addition & 5 deletions src/geode/mesh/core/polyhedral_solid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ namespace geode

index_t find_or_create_edge( std::array< index_t, 2 > edge_vertices )
{
if( edge_vertices[0] < edge_vertices[1] )
{
return Edges::add_facet( std::move( edge_vertices ) );
}
return find_edge( edge_vertices );
return Edges::add_facet( std::move( edge_vertices ) );
}

const PolyhedronFacetVertices& get_facet_vertices(
Expand Down
3 changes: 3 additions & 0 deletions tests/mesh/test-tetrahedral-solid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void test_create_vertices( const geode::TetrahedralSolid3D& solid,
void test_create_tetrahedra( const geode::TetrahedralSolid3D& solid,
geode::TetrahedralSolidBuilder3D& builder )
{
builder.reserve_tetrahedra( 3 );
OPENGEODE_EXCEPTION( solid.nb_polyhedra() == 0,
"[Test] TetrahedralSolid should have no tetrahedron" );
builder.create_tetrahedra( 1 );
builder.create_tetrahedron( { 1, 2, 3, 4 } );
builder.create_polyhedron( { 1, 4, 3, 5 },
Expand Down

0 comments on commit fd92a54

Please sign in to comment.