Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/geode/mesh/builder/solid_edges_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#pragma once

#include <geode/basic/mapping.hpp>

#include <geode/mesh/common.hpp>
#include <geode/mesh/core/solid_mesh.hpp>

Expand Down Expand Up @@ -59,7 +61,8 @@ namespace geode

void remove_edge( std::array< index_t, 2 > edge_vertices );

void update_edge_vertex( std::array< index_t, 2 > edge_vertices,
geode::BijectiveMapping< index_t > update_edge_vertex(
std::array< index_t, 2 > edge_vertices,
index_t edge_vertex_id,
index_t new_vertex_id );

Expand Down
5 changes: 4 additions & 1 deletion include/geode/mesh/builder/solid_facets_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#pragma once

#include <geode/basic/mapping.hpp>

#include <geode/mesh/common.hpp>
#include <geode/mesh/core/solid_mesh.hpp>

Expand Down Expand Up @@ -59,7 +61,8 @@ namespace geode

void remove_facet( PolyhedronFacetVertices facet_vertices );

void update_facet_vertex( PolyhedronFacetVertices facet_vertices,
geode::BijectiveMapping< index_t > update_facet_vertex(
PolyhedronFacetVertices facet_vertices,
index_t facet_vertex_id,
index_t new_vertex_id );

Expand Down
10 changes: 9 additions & 1 deletion include/geode/mesh/builder/solid_mesh_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ namespace geode
/*!
* Interface class to represent the builder of a SolidMesh
*/

struct ReplaceVertexInfo
{
geode::BijectiveMapping< index_t > edge_mapping;
geode::BijectiveMapping< index_t > facet_mapping;
};

template < index_t dimension >
class SolidMeshBuilder
: public VertexSetBuilder,
Expand Down Expand Up @@ -102,7 +109,8 @@ namespace geode
* @warning This function supposes that the mesh is manifold
* around old vertex
*/
void replace_vertex( index_t old_vertex_id, index_t new_vertex_id );
ReplaceVertexInfo replace_vertex(
index_t old_vertex_id, index_t new_vertex_id );

/*!
* Replace old polyhedron vertices from given vertices to another ones.
Expand Down
5 changes: 4 additions & 1 deletion include/geode/mesh/builder/surface_edges_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <absl/types/span.h>

#include <geode/basic/mapping.hpp>

#include <geode/mesh/builder/vertex_set_builder.hpp>
#include <geode/mesh/common.hpp>

Expand Down Expand Up @@ -63,7 +65,8 @@ namespace geode

void update_edge_vertices( absl::Span< const index_t > old2new );

void update_edge_vertex( std::array< index_t, 2 > edge_vertices,
geode::BijectiveMapping< index_t > update_edge_vertex(
std::array< index_t, 2 > edge_vertices,
index_t edge_vertex_id,
index_t new_vertex_id );

Expand Down
3 changes: 2 additions & 1 deletion include/geode/mesh/builder/surface_mesh_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ namespace geode
* @warning This function supposes that the mesh is manifold around old
* vertex
*/
void replace_vertex( index_t old_vertex_id, index_t new_vertex_id );
geode::BijectiveMapping< index_t > replace_vertex(
index_t old_vertex_id, index_t new_vertex_id );

/*!
* Replace old polygon vertices from given vertices to another ones.
Expand Down
16 changes: 11 additions & 5 deletions include/geode/mesh/core/detail/facet_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <geode/basic/attribute_manager.hpp>
#include <geode/basic/common.hpp>
#include <geode/basic/detail/mapping_after_deletion.hpp>
#include <geode/basic/mapping.hpp>
#include <geode/basic/range.hpp>
#include <geode/basic/variable_attribute.hpp>

Expand Down Expand Up @@ -104,12 +105,12 @@ namespace geode
return id;
}

void remove_facet( TypedVertexCycle vertices )
index_t remove_facet( TypedVertexCycle vertices )
{
const auto it = facet_indices_.find( vertices );
if( it == facet_indices_.end() )
{
return;
return NO_ID;
}
const auto id = it->second;
OPENGEODE_ASSERT( id != NO_ID,
Expand All @@ -118,6 +119,7 @@ namespace geode
const auto old_count = counter_->value( id );
const auto new_count = std::max( 1u, old_count ) - 1;
counter_->set_value( id, new_count );
return id;
}

std::vector< index_t > clean_facets()
Expand Down Expand Up @@ -155,16 +157,20 @@ namespace geode
return old2new;
}

void update_facet_vertex( VertexContainer facet_vertices,
geode::BijectiveMapping< index_t > update_facet_vertex(
VertexContainer facet_vertices,
const index_t facet_vertex_id,
const index_t new_vertex_id )
{
geode::BijectiveMapping< index_t > mapping;
auto updated_facet_vertices = facet_vertices;
updated_facet_vertices[facet_vertex_id] = new_vertex_id;
this->add_facet(
const auto new_facet_id = this->add_facet(
TypedVertexCycle{ std::move( updated_facet_vertices ) } );
this->remove_facet(
const auto old_facet_id = this->remove_facet(
TypedVertexCycle{ std::move( facet_vertices ) } );
mapping.map( old_facet_id, new_facet_id );
return mapping;
}

std::vector< index_t > update_facet_vertices(
Expand Down
5 changes: 3 additions & 2 deletions include/geode/mesh/core/internal/facet_edges_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ namespace geode
return this->get_facet_vertices( edge_id );
}

void update_edge_vertex( std::array< index_t, 2 > edge_vertices,
BijectiveMapping< index_t > update_edge_vertex(
std::array< index_t, 2 > edge_vertices,
const index_t edge_vertex_id,
const index_t new_vertex_id )
{
this->update_facet_vertex(
return this->update_facet_vertex(
std::move( edge_vertices ), edge_vertex_id, new_vertex_id );
}

Expand Down
4 changes: 3 additions & 1 deletion include/geode/mesh/core/solid_edges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <vector>

#include <geode/basic/mapping.hpp>
#include <geode/basic/passkey.hpp>

#include <geode/mesh/common.hpp>
Expand Down Expand Up @@ -88,7 +89,8 @@ namespace geode
void update_edge_vertices(
absl::Span< const index_t > old2new, SolidEdgesKey );

void update_edge_vertex( std::array< index_t, 2 > edge_vertices,
BijectiveMapping< index_t > update_edge_vertex(
std::array< index_t, 2 > edge_vertices,
index_t edge_vertex_id,
index_t new_vertex_id,
SolidEdgesKey );
Expand Down
3 changes: 2 additions & 1 deletion include/geode/mesh/core/solid_facets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ namespace geode
std::vector< index_t > update_facet_vertices(
absl::Span< const index_t > old2new, SolidFacetsKey );

void update_facet_vertex( PolyhedronFacetVertices facet_vertices,
BijectiveMapping< index_t > update_facet_vertex(
PolyhedronFacetVertices facet_vertices,
index_t facet_vertex_id,
index_t new_vertex_id,
SolidFacetsKey );
Expand Down
4 changes: 3 additions & 1 deletion include/geode/mesh/core/surface_edges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <absl/types/span.h>

#include <geode/basic/mapping.hpp>
#include <geode/basic/passkey.hpp>
#include <geode/basic/pimpl.hpp>

Expand Down Expand Up @@ -86,7 +87,8 @@ namespace geode
void update_edge_vertices(
absl::Span< const index_t > old2new, SurfaceEdgesKey );

void update_edge_vertex( std::array< index_t, 2 > edge_vertices,
BijectiveMapping< index_t > update_edge_vertex(
std::array< index_t, 2 > edge_vertices,
index_t edge_vertex_id,
index_t new_vertex_id,
SurfaceEdgesKey );
Expand Down
11 changes: 6 additions & 5 deletions src/geode/mesh/builder/solid_edges_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ namespace geode
}

template < index_t dimension >
void SolidEdgesBuilder< dimension >::update_edge_vertex(
std::array< index_t, 2 > edge_vertices,
index_t edge_vertex_id,
index_t new_vertex_id )
BijectiveMapping< index_t >
SolidEdgesBuilder< dimension >::update_edge_vertex(
std::array< index_t, 2 > edge_vertices,
index_t edge_vertex_id,
index_t new_vertex_id )
{
edges_->update_edge_vertex(
return edges_->update_edge_vertex(
std::move( edge_vertices ), edge_vertex_id, new_vertex_id, {} );
}

Expand Down
11 changes: 6 additions & 5 deletions src/geode/mesh/builder/solid_facets_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ namespace geode
}

template < index_t dimension >
void SolidFacetsBuilder< dimension >::update_facet_vertex(
PolyhedronFacetVertices facet_vertices,
index_t facet_vertex_id,
index_t new_vertex_id )
BijectiveMapping< index_t >
SolidFacetsBuilder< dimension >::update_facet_vertex(
PolyhedronFacetVertices facet_vertices,
index_t facet_vertex_id,
index_t new_vertex_id )
{
OPENGEODE_ASSERT( facet_vertex_id < facet_vertices.size(),
"[SolidFacetsBuilder::update_facet_vertex] "
"Accessing an invalid vertex in facet" );
facets_->update_facet_vertex(
return facets_->update_facet_vertex(
std::move( facet_vertices ), facet_vertex_id, new_vertex_id, {} );
}

Expand Down
63 changes: 48 additions & 15 deletions src/geode/mesh/builder/solid_mesh_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <geode/basic/attribute_manager.hpp>
#include <geode/basic/detail/mapping_after_deletion.hpp>
#include <geode/basic/mapping.hpp>
#include <geode/basic/permutation.hpp>

#include <geode/geometry/point.hpp>
Expand Down Expand Up @@ -291,11 +292,17 @@ namespace
}

template < geode::index_t dimension >
void update_edge_and_facet( const geode::SolidMesh< dimension >& solid,
geode::SolidMeshBuilder< dimension >& builder,
const geode::PolyhedronVertex& polyhedron_vertex,
geode::index_t new_vertex_id )
{
std::tuple< geode::BijectiveMapping< geode::index_t >,
geode::BijectiveMapping< geode::index_t > >
update_edge_and_facet( const geode::SolidMesh< dimension >& solid,
geode::SolidMeshBuilder< dimension >& builder,
const geode::PolyhedronVertex& polyhedron_vertex,
geode::index_t new_vertex_id )
{
std::tuple< geode::BijectiveMapping< geode::index_t >,
geode::BijectiveMapping< geode::index_t > >
mappings;
auto& [edge_mapping, facet_mapping] = mappings;
for( const auto f : geode::LRange{ solid.nb_polyhedron_facets(
polyhedron_vertex.polyhedron_id ) } )
{
Expand All @@ -322,17 +329,19 @@ namespace
{
facet_vertices_id.emplace_back( solid.polyhedron_vertex( v ) );
}

const auto position = static_cast< geode::index_t >(
std::distance( facet_vertices.begin(), position_it ) );

if( solid.are_facets_enabled() )
{
auto facets = builder.facets_builder();
facets.update_facet_vertex(
const auto maping = facets.update_facet_vertex(
facet_vertices_id, position, new_vertex_id );
for( const auto& [old_facet_id, new_facet_id] :
maping.in2out_map() )
{
facet_mapping.map( old_facet_id, new_facet_id );
}
}

if( solid.are_edges_enabled() )
{
auto edges = builder.edges_builder();
Expand All @@ -343,8 +352,13 @@ namespace
};
if( next_edge_vertices[0] < next_edge_vertices[1] )
{
edges.update_edge_vertex(
const auto mapping = edges.update_edge_vertex(
next_edge_vertices, 0, new_vertex_id );
for( const auto& [old_edge_id, new_edge_id] :
mapping.in2out_map() )
{
edge_mapping.map( old_edge_id, new_edge_id );
}
}
const auto prev =
position == 0 ? nb_facet_vertices - 1 : position - 1;
Expand All @@ -353,11 +367,17 @@ namespace
};
if( previous_edge_vertices[0] < previous_edge_vertices[1] )
{
edges.update_edge_vertex(
const auto mapping = edges.update_edge_vertex(
previous_edge_vertices, 1, new_vertex_id );
for( const auto& [old_edge_id, new_edge_id] :
mapping.in2out_map() )
{
edge_mapping.map( old_edge_id, new_edge_id );
}
}
}
}
return mappings;
}
} // namespace

Expand All @@ -384,12 +404,13 @@ namespace geode
}

template < index_t dimension >
void SolidMeshBuilder< dimension >::replace_vertex(
ReplaceVertexInfo SolidMeshBuilder< dimension >::replace_vertex(
index_t old_vertex_id, index_t new_vertex_id )
{
ReplaceVertexInfo mappings;
if( old_vertex_id == new_vertex_id )
{
return;
return mappings;
}
const auto& polyhedra_around =
solid_mesh_.polyhedra_around_vertex( old_vertex_id );
Expand All @@ -399,12 +420,24 @@ namespace geode
if( solid_mesh_.are_edges_enabled()
|| solid_mesh_.are_facets_enabled() )
{
update_edge_and_facet(
solid_mesh_, *this, polyhedron_around, new_vertex_id );
const auto [local_edge_mapping, local_facet_mapping] =
update_edge_and_facet(
solid_mesh_, *this, polyhedron_around, new_vertex_id );
for( const auto& [old_edge_id, new_edge_id] :
local_edge_mapping.in2out_map() )
{
mappings.edge_mapping.map( old_edge_id, new_edge_id );
}
for( const auto& [old_facet_id, new_facet_id] :
local_facet_mapping.in2out_map() )
{
mappings.facet_mapping.map( old_facet_id, new_facet_id );
}
}
update_polyhedron_vertex( polyhedron_around, new_vertex_id );
}
reset_polyhedra_around_vertex( old_vertex_id );
return mappings;
}

template < index_t dimension >
Expand Down
Loading