Skip to content

Commit

Permalink
Merge pull request #1050 from Geode-solutions/feat/replace_component_…
Browse files Browse the repository at this point in the history
…meshes_by_others

feat(replace_components_meshes_by_others): Added function to replace …
  • Loading branch information
MelchiorSchuh authored Nov 28, 2024
2 parents 185dbab + df869d9 commit 82001bd
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 10 deletions.
3 changes: 3 additions & 0 deletions include/geode/model/mixin/builder/blocks_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ namespace geode
[[nodiscard]] SolidMesh< dimension >& modifiable_block_mesh(
const uuid& id );

[[nodiscard]] std::unique_ptr< SolidMesh< dimension > >
steal_block_mesh( const uuid& id );

private:
Blocks< dimension >& blocks_;
};
Expand Down
3 changes: 3 additions & 0 deletions include/geode/model/mixin/builder/corners_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ namespace geode
[[nodiscard]] PointSet< dimension >& modifiable_corner_mesh(
const uuid& id );

[[nodiscard]] std::unique_ptr< PointSet< dimension > >
steal_corner_mesh( const uuid& id );

private:
Corners< dimension >& corners_;
};
Expand Down
3 changes: 3 additions & 0 deletions include/geode/model/mixin/builder/lines_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ namespace geode
[[nodiscard]] EdgedCurve< dimension >& modifiable_line_mesh(
const uuid& id );

[[nodiscard]] std::unique_ptr< EdgedCurve< dimension > >
steal_line_mesh( const uuid& id );

private:
Lines< dimension >& lines_;
};
Expand Down
3 changes: 3 additions & 0 deletions include/geode/model/mixin/builder/surfaces_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ namespace geode
[[nodiscard]] SurfaceMesh< dimension >& modifiable_surface_mesh(
const uuid& id );

[[nodiscard]] std::unique_ptr< SurfaceMesh< dimension > >
steal_surface_mesh( const uuid& id );

private:
Surfaces< dimension >& surfaces_;
};
Expand Down
15 changes: 9 additions & 6 deletions include/geode/model/mixin/core/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ namespace geode

[[nodiscard]] const MeshImpl& mesh_type() const;

template < typename TypedMesh = Mesh >
[[nodiscard]] TypedMesh& modifiable_mesh( BlocksKey /*unused*/ )
{
return dynamic_cast< TypedMesh& >( get_modifiable_mesh() );
}

public:
explicit Block( BlocksKey key );

Expand All @@ -100,6 +94,12 @@ namespace geode

void set_mesh( std::unique_ptr< Mesh > mesh, BlocksBuilderKey key );

template < typename TypedMesh = Mesh >
[[nodiscard]] TypedMesh& modifiable_mesh( BlocksKey /*unused*/ )
{
return dynamic_cast< TypedMesh& >( get_modifiable_mesh() );
}

template < typename TypedMesh = Mesh >
[[nodiscard]] TypedMesh& modifiable_mesh( BlocksBuilderKey /*unused*/ )
{
Expand All @@ -108,6 +108,9 @@ namespace geode

void set_block_name( std::string_view name, BlocksBuilderKey key );

[[nodiscard]] std::unique_ptr< Mesh > steal_mesh(
BlocksBuilderKey key );

private:
Block();

Expand Down
7 changes: 5 additions & 2 deletions include/geode/model/mixin/core/corner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ namespace geode

[[nodiscard]] const Mesh& mesh() const;

[[nodiscard]] Mesh& modifiable_mesh( CornersKey key );

[[nodiscard]] const MeshImpl& mesh_type() const;

public:
Expand All @@ -94,8 +92,13 @@ namespace geode

void set_corner_name( std::string_view name, CornersBuilderKey key );

[[nodiscard]] Mesh& modifiable_mesh( CornersKey key );

[[nodiscard]] Mesh& modifiable_mesh( CornersBuilderKey key );

[[nodiscard]] std::unique_ptr< Mesh > steal_mesh(
CornersBuilderKey key );

private:
Corner();

Expand Down
5 changes: 5 additions & 0 deletions include/geode/model/mixin/core/detail/mesh_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ namespace geode
return *mesh_;
}

[[nodiscard]] std::unique_ptr< Mesh > steal_mesh()
{
return std::move( mesh_ );
}

[[nodiscard]] const MeshImpl& mesh_type() const
{
return mesh_type_;
Expand Down
6 changes: 4 additions & 2 deletions include/geode/model/mixin/core/line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ namespace geode

[[nodiscard]] const MeshImpl& mesh_type() const;

[[nodiscard]] Mesh& modifiable_mesh( LinesKey key );

public:
explicit Line( LinesKey key );

Expand All @@ -93,8 +91,12 @@ namespace geode

void set_line_name( std::string_view name, LinesBuilderKey key );

[[nodiscard]] Mesh& modifiable_mesh( LinesKey key );

[[nodiscard]] Mesh& modifiable_mesh( LinesBuilderKey key );

[[nodiscard]] std::unique_ptr< Mesh > steal_mesh( LinesBuilderKey key );

private:
Line();

Expand Down
3 changes: 3 additions & 0 deletions include/geode/model/mixin/core/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ namespace geode
return dynamic_cast< TypedMesh& >( get_modifiable_mesh() );
}

[[nodiscard]] std::unique_ptr< Mesh > steal_mesh(
SurfacesBuilderKey key );

private:
Surface();

Expand Down
3 changes: 3 additions & 0 deletions include/geode/model/representation/builder/brep_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ namespace geode

ModelCopyMapping copy( const BRep& brep );

void replace_components_meshes_by_others(
BRep&& other, const ModelCopyMapping& mapping );

ModelCopyMapping copy_components( const BRep& brep );

void copy_components( ModelCopyMapping& mapping, const BRep& brep );
Expand Down
8 changes: 8 additions & 0 deletions src/geode/model/mixin/builder/blocks_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,13 @@ namespace geode
typename Block< dimension >::BlocksBuilderKey{} );
}

template < index_t dimension >
std::unique_ptr< SolidMesh< dimension > >
BlocksBuilder< dimension >::steal_block_mesh( const uuid& id )
{
return blocks_.modifiable_block( id, {} ).steal_mesh(
typename Block< dimension >::BlocksBuilderKey{} );
}

template class opengeode_model_api BlocksBuilder< 3 >;
} // namespace geode
8 changes: 8 additions & 0 deletions src/geode/model/mixin/builder/corners_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ namespace geode
typename Corner< dimension >::CornersBuilderKey{} );
}

template < index_t dimension >
std::unique_ptr< PointSet< dimension > >
CornersBuilder< dimension >::steal_corner_mesh( const uuid& id )
{
return corners_.modifiable_corner( id, {} ).steal_mesh(
typename Corner< dimension >::CornersBuilderKey{} );
}

template class opengeode_model_api CornersBuilder< 2 >;
template class opengeode_model_api CornersBuilder< 3 >;
} // namespace geode
8 changes: 8 additions & 0 deletions src/geode/model/mixin/builder/lines_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ namespace geode
typename Line< dimension >::LinesBuilderKey{} );
}

template < index_t dimension >
std::unique_ptr< EdgedCurve< dimension > >
LinesBuilder< dimension >::steal_line_mesh( const uuid& id )
{
return lines_.modifiable_line( id, {} ).steal_mesh(
typename Line< dimension >::LinesBuilderKey{} );
}

template class opengeode_model_api LinesBuilder< 2 >;
template class opengeode_model_api LinesBuilder< 3 >;
} // namespace geode
8 changes: 8 additions & 0 deletions src/geode/model/mixin/builder/surfaces_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ namespace geode
typename Surface< dimension >::SurfacesBuilderKey{} );
}

template < index_t dimension >
std::unique_ptr< SurfaceMesh< dimension > >
SurfacesBuilder< dimension >::steal_surface_mesh( const uuid& id )
{
return surfaces_.modifiable_surface( id, {} ).steal_mesh(
typename Surface< dimension >::SurfacesBuilderKey{} );
}

template class opengeode_model_api SurfacesBuilder< 2 >;
template class opengeode_model_api SurfacesBuilder< 3 >;
} // namespace geode
7 changes: 7 additions & 0 deletions src/geode/model/mixin/core/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ namespace geode
this->set_name( name );
}

template < index_t dimension >
auto Block< dimension >::steal_mesh(
BlocksBuilderKey /*unused*/ ) -> std::unique_ptr< Mesh >
{
return impl_->steal_mesh();
}

template class opengeode_model_api Block< 3 >;

SERIALIZE_BITSERY_ARCHIVE( opengeode_model_api, Block< 3 > );
Expand Down
7 changes: 7 additions & 0 deletions src/geode/model/mixin/core/corner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ namespace geode
impl_->set_mesh( this->id(), std::move( mesh ) );
}

template < index_t dimension >
auto Corner< dimension >::steal_mesh(
CornersBuilderKey /*unused*/ ) -> std::unique_ptr< Mesh >
{
return impl_->steal_mesh();
}

template class opengeode_model_api Corner< 2 >;
template class opengeode_model_api Corner< 3 >;

Expand Down
7 changes: 7 additions & 0 deletions src/geode/model/mixin/core/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ namespace geode
return modifiable_mesh();
}

template < index_t dimension >
auto Line< dimension >::steal_mesh(
LinesBuilderKey /*unused*/ ) -> std::unique_ptr< Mesh >
{
return impl_->steal_mesh();
}

template class opengeode_model_api Line< 2 >;
template class opengeode_model_api Line< 3 >;

Expand Down
7 changes: 7 additions & 0 deletions src/geode/model/mixin/core/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ namespace geode
this->set_name( name );
}

template < index_t dimension >
auto Surface< dimension >::steal_mesh(
SurfacesBuilderKey /*unused*/ ) -> std::unique_ptr< Mesh >
{
return impl_->steal_mesh();
}

template class opengeode_model_api Surface< 2 >;
template class opengeode_model_api Surface< 3 >;

Expand Down
39 changes: 39 additions & 0 deletions src/geode/model/representation/builder/brep_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,45 @@ namespace geode
return mapping;
}

void BRepBuilder::replace_components_meshes_by_others(
BRep&& other, const ModelCopyMapping& mapping )
{
BRepBuilder other_builder{ other };
for( const auto& in2out :
mapping.at( Corner3D::component_type_static() ).in2out_map() )
{
this->update_corner_mesh( brep_.corner( in2out.first ),
other_builder.steal_corner_mesh( in2out.second ) );
this->corner_mesh_builder( in2out.first )->set_id( in2out.first );
}
for( const auto& in2out :
mapping.at( Line3D::component_type_static() ).in2out_map() )
{
this->update_line_mesh( brep_.line( in2out.first ),
other_builder.steal_line_mesh( in2out.second ) );
this->line_mesh_builder( in2out.first )->set_id( in2out.first );
}
for( const auto& in2out :
mapping.at( Surface3D::component_type_static() ).in2out_map() )
{
this->update_surface_mesh( brep_.surface( in2out.first ),
other_builder.steal_surface_mesh( in2out.second ) );
this->surface_mesh_builder( in2out.first )->set_id( in2out.first );
}
for( const auto& in2out :
mapping.at( Block3D::component_type_static() ).in2out_map() )
{
this->update_block_mesh( brep_.block( in2out.first ),
other_builder.steal_block_mesh( in2out.second ) );
this->block_mesh_builder( in2out.first )->set_id( in2out.first );
}
this->delete_isolated_vertices();
const auto first_new_unique_vertex_id =
create_unique_vertices( other.nb_unique_vertices() );
detail::copy_vertex_identifier_components(
other, *this, first_new_unique_vertex_id, mapping );
}

ModelCopyMapping BRepBuilder::copy_components( const BRep& brep )
{
ModelCopyMapping mappings;
Expand Down
17 changes: 17 additions & 0 deletions tests/model/test-brep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,22 @@ void test_components_filter()
"[Test] Wrong number of components with relations" );
}

std::tuple< geode::BRep, geode::ModelCopyMapping > copy_model(
geode::BRep& brep )
{
geode::BRep other;
geode::BRepBuilder other_builder{ other };
auto mapping = other_builder.copy( brep );
return { std::move( other ), std::move( mapping ) };
}

void test_steal_mesh( geode::BRep& brep )
{
auto [other, mapping] = copy_model( brep );
geode::BRepBuilder builder{ brep };
builder.replace_components_meshes_by_others( std::move( other ), mapping );
}

void test()
{
geode::OpenGeodeModelLibrary::initialize();
Expand Down Expand Up @@ -1391,6 +1407,7 @@ void test()
model, surface_uuids, surface_collection_uuids );
test_block_collection_ranges( model, block_uuid, block_collection_uuid );
test_clone( model );
test_steal_mesh( model );

const auto file_io = absl::StrCat( "test.", model.native_extension() );
geode::save_brep( model, file_io );
Expand Down

0 comments on commit 82001bd

Please sign in to comment.