diff --git a/include/geode/geometry/information.hpp b/include/geode/geometry/information.hpp index 4a23b237a..76ff6f1ef 100644 --- a/include/geode/geometry/information.hpp +++ b/include/geode/geometry/information.hpp @@ -71,5 +71,8 @@ namespace geode { [[nodiscard]] local_index_t opengeode_geometry_api position_to_index( POSITION position ); + + [[nodiscard]] std::string opengeode_geometry_api position_to_string( + POSITION position ); } // namespace detail } // namespace geode diff --git a/include/geode/geometry/internal/predicates.hpp b/include/geode/geometry/internal/predicates.hpp index f1ee18632..546cf6bf8 100644 --- a/include/geode/geometry/internal/predicates.hpp +++ b/include/geode/geometry/internal/predicates.hpp @@ -429,7 +429,6 @@ namespace GEO enum SIGN { - negative = -1, zero = 0, diff --git a/include/geode/model/representation/core/detail/transfer_collections.hpp b/include/geode/model/representation/core/detail/transfer_collections.hpp index 58ce7b032..767d5a218 100644 --- a/include/geode/model/representation/core/detail/transfer_collections.hpp +++ b/include/geode/model/representation/core/detail/transfer_collections.hpp @@ -44,10 +44,22 @@ namespace geode BRepBuilder& new_brep_builder, const ModelGenericMapping& component_mapping ); + void opengeode_model_api transfer_brep_collections( + const BRep& old_brep, + const BRep& new_brep, + BRepBuilder& new_brep_builder, + const ModelUnchangedComponentMapping& unchanged_components ); + void opengeode_model_api transfer_section_collections( const Section& old_section, const Section& new_section, SectionBuilder& new_brep_builder, const ModelGenericMapping& component_mapping ); + + void opengeode_model_api transfer_section_collections( + const Section& old_section, + const Section& new_section, + SectionBuilder& new_brep_builder, + const ModelUnchangedComponentMapping& unchanged_components ); } // namespace detail } // namespace geode diff --git a/src/geode/geometry/information.cpp b/src/geode/geometry/information.cpp index 9027cb03c..75ca6bf74 100644 --- a/src/geode/geometry/information.cpp +++ b/src/geode/geometry/information.cpp @@ -57,5 +57,34 @@ namespace geode } return index_it->second; } + + std::string position_to_string( POSITION position ) + { + static const absl::flat_hash_map< POSITION, std::string > map = { + { POSITION::vertex0, "vertex0" }, + { POSITION::vertex1, "vertex1" }, + { POSITION::vertex2, "vertex2" }, + { POSITION::vertex3, "vertex3" }, + { POSITION::edge0, "edge0" }, + { POSITION::edge1, "edge1" }, + { POSITION::edge2, "edge2" }, + { POSITION::facet0, "facet0" }, + { POSITION::facet1, "facet1" }, + { POSITION::facet2, "facet2" }, + { POSITION::facet3, "facet3" }, + { POSITION::edge01, "edge01" }, + { POSITION::edge02, "edge02" }, + { POSITION::edge03, "edge03" }, + { POSITION::edge12, "edge12" }, + { POSITION::edge13, "edge13" }, + { POSITION::edge23, "edge23" }, + }; + const auto index_it = map.find( position ); + if( index_it == map.end() ) + { + return "NO_LID"; + } + return index_it->second; + } } // namespace detail } // namespace geode diff --git a/src/geode/model/representation/core/detail/transfer_collections.cpp b/src/geode/model/representation/core/detail/transfer_collections.cpp index d5c3e9cdb..b5b411e8b 100644 --- a/src/geode/model/representation/core/detail/transfer_collections.cpp +++ b/src/geode/model/representation/core/detail/transfer_collections.cpp @@ -69,9 +69,12 @@ namespace { continue; } - new_model_builder.add_corner_collection( collection_in.id() ); - new_model_builder.set_corner_collection_name( - collection_in.id(), collection_in.name() ); + if( !new_model.has_corner_collection( collection_in.id() ) ) + { + new_model_builder.add_corner_collection( collection_in.id() ); + new_model_builder.set_corner_collection_name( + collection_in.id(), collection_in.name() ); + } const auto& new_collection = new_model.corner_collection( collection_in.id() ); for( const auto& corner_in_collection : @@ -97,6 +100,51 @@ namespace } } + template < typename Model > + void transfer_corner_collections( const Model& old_model, + const Model& new_model, + typename Model::Builder& new_model_builder, + const geode::ModelUnchangedComponentMapping& unchanged_components ) + { + if( !unchanged_components.has_mapping_type( + geode::Corner< Model::dim >::component_type_static() ) ) + { + return; + } + const auto& unchanged_corners = unchanged_components.at( + geode::Corner< Model::dim >::component_type_static() ); + for( const auto& collection_in : old_model.corner_collections() ) + { + std::vector< geode::uuid > corners_to_add; + for( const auto& corner_in_collection : + old_model.corner_collection_items( collection_in ) ) + { + if( absl::c_contains( + unchanged_corners, corner_in_collection.id() ) ) + { + corners_to_add.push_back( corner_in_collection.id() ); + } + } + if( corners_to_add.empty() ) + { + continue; + } + if( !new_model.has_corner_collection( collection_in.id() ) ) + { + new_model_builder.add_corner_collection( collection_in.id() ); + new_model_builder.set_corner_collection_name( + collection_in.id(), collection_in.name() ); + } + const auto& new_collection = + new_model.corner_collection( collection_in.id() ); + for( const auto& corner_id : corners_to_add ) + { + new_model_builder.add_corner_in_corner_collection( + new_model.corner( corner_id ), new_collection ); + } + } + } + template < typename Model > void transfer_line_collections( const Model& old_model, const Model& new_model, @@ -126,9 +174,12 @@ namespace { continue; } - new_model_builder.add_line_collection( collection_in.id() ); - new_model_builder.set_line_collection_name( - collection_in.id(), collection_in.name() ); + if( !new_model.has_line_collection( collection_in.id() ) ) + { + new_model_builder.add_line_collection( collection_in.id() ); + new_model_builder.set_line_collection_name( + collection_in.id(), collection_in.name() ); + } const auto& new_collection = new_model.line_collection( collection_in.id() ); for( const auto& line_in_collection : @@ -152,6 +203,50 @@ namespace } } } + template < typename Model > + void transfer_line_collections( const Model& old_model, + const Model& new_model, + typename Model::Builder& new_model_builder, + const geode::ModelUnchangedComponentMapping& unchanged_components ) + { + if( !unchanged_components.has_mapping_type( + geode::Line< Model::dim >::component_type_static() ) ) + { + return; + } + const auto& unchanged_lines = unchanged_components.at( + geode::Line< Model::dim >::component_type_static() ); + for( const auto& collection_in : old_model.line_collections() ) + { + std::vector< geode::uuid > lines_to_add; + for( const auto& line_in_collection : + old_model.line_collection_items( collection_in ) ) + { + if( absl::c_contains( + unchanged_lines, line_in_collection.id() ) ) + { + lines_to_add.push_back( line_in_collection.id() ); + } + } + if( lines_to_add.empty() ) + { + continue; + } + if( !new_model.has_line_collection( collection_in.id() ) ) + { + new_model_builder.add_line_collection( collection_in.id() ); + new_model_builder.set_line_collection_name( + collection_in.id(), collection_in.name() ); + } + const auto& new_collection = + new_model.line_collection( collection_in.id() ); + for( const auto& line_id : lines_to_add ) + { + new_model_builder.add_line_in_line_collection( + new_model.line( line_id ), new_collection ); + } + } + } template < typename Model > void transfer_surface_collections( const Model& old_model, @@ -183,9 +278,12 @@ namespace { continue; } - new_model_builder.add_surface_collection( collection_in.id() ); - new_model_builder.set_surface_collection_name( - collection_in.id(), collection_in.name() ); + if( !new_model.has_surface_collection( collection_in.id() ) ) + { + new_model_builder.add_surface_collection( collection_in.id() ); + new_model_builder.set_surface_collection_name( + collection_in.id(), collection_in.name() ); + } const auto& new_collection = new_model.surface_collection( collection_in.id() ); for( const auto& surface_in_collection : @@ -212,6 +310,51 @@ namespace } } + template < typename Model > + void transfer_surface_collections( const Model& old_model, + const Model& new_model, + typename Model::Builder& new_model_builder, + const geode::ModelUnchangedComponentMapping& unchanged_components ) + { + if( !unchanged_components.has_mapping_type( + geode::Surface< Model::dim >::component_type_static() ) ) + { + return; + } + const auto& unchanged_surfaces = unchanged_components.at( + geode::Surface< Model::dim >::component_type_static() ); + for( const auto& collection_in : old_model.surface_collections() ) + { + std::vector< geode::uuid > surfaces_to_add; + for( const auto& surface_in_collection : + old_model.surface_collection_items( collection_in ) ) + { + if( absl::c_contains( + unchanged_surfaces, surface_in_collection.id() ) ) + { + surfaces_to_add.push_back( surface_in_collection.id() ); + } + } + if( surfaces_to_add.empty() ) + { + continue; + } + if( !new_model.has_surface_collection( collection_in.id() ) ) + { + new_model_builder.add_surface_collection( collection_in.id() ); + new_model_builder.set_surface_collection_name( + collection_in.id(), collection_in.name() ); + } + const auto& new_collection = + new_model.surface_collection( collection_in.id() ); + for( const auto& surface_id : surfaces_to_add ) + { + new_model_builder.add_surface_in_surface_collection( + new_model.surface( surface_id ), new_collection ); + } + } + } + void transfer_block_collections( const geode::BRep& old_model, const geode::BRep& new_model, typename geode::BRepBuilder& new_model_builder, @@ -241,9 +384,12 @@ namespace { continue; } - new_model_builder.add_block_collection( collection_in.id() ); - new_model_builder.set_block_collection_name( - collection_in.id(), collection_in.name() ); + if( !new_model.has_block_collection( collection_in.id() ) ) + { + new_model_builder.add_block_collection( collection_in.id() ); + new_model_builder.set_block_collection_name( + collection_in.id(), collection_in.name() ); + } const auto& new_collection = new_model.block_collection( collection_in.id() ); for( const auto& block_in_collection : @@ -268,6 +414,50 @@ namespace } } + void transfer_block_collections( const geode::BRep& old_model, + const geode::BRep& new_model, + typename geode::BRepBuilder& new_model_builder, + const geode::ModelUnchangedComponentMapping& unchanged_components ) + { + if( !unchanged_components.has_mapping_type( + geode::Block3D::component_type_static() ) ) + { + return; + } + const auto& unchanged_blocks = + unchanged_components.at( geode::Block3D::component_type_static() ); + for( const auto& collection_in : old_model.block_collections() ) + { + std::vector< geode::uuid > blocks_to_add; + for( const auto& block_in_collection : + old_model.block_collection_items( collection_in ) ) + { + if( absl::c_contains( + unchanged_blocks, block_in_collection.id() ) ) + { + blocks_to_add.push_back( block_in_collection.id() ); + } + } + if( blocks_to_add.empty() ) + { + continue; + } + if( !new_model.has_block_collection( collection_in.id() ) ) + { + new_model_builder.add_block_collection( collection_in.id() ); + new_model_builder.set_block_collection_name( + collection_in.id(), collection_in.name() ); + } + const auto& new_collection = + new_model.block_collection( collection_in.id() ); + for( const auto& block_id : blocks_to_add ) + { + new_model_builder.add_block_in_block_collection( + new_model.block( block_id ), new_collection ); + } + } + } + void transfer_brep_model_boundaries( const geode::BRep& old_model, const geode::BRep& new_model, typename geode::BRepBuilder& new_model_builder, @@ -297,9 +487,12 @@ namespace { continue; } - new_model_builder.add_model_boundary( collection_in.id() ); - new_model_builder.set_model_boundary_name( - collection_in.id(), collection_in.name() ); + if( !new_model.has_model_boundary( collection_in.id() ) ) + { + new_model_builder.add_model_boundary( collection_in.id() ); + new_model_builder.set_model_boundary_name( + collection_in.id(), collection_in.name() ); + } const auto& new_collection = new_model.model_boundary( collection_in.id() ); for( const auto& surface_in_collection : @@ -326,6 +519,50 @@ namespace } } + void transfer_brep_model_boundaries( const geode::BRep& old_model, + const geode::BRep& new_model, + typename geode::BRepBuilder& new_model_builder, + const geode::ModelUnchangedComponentMapping& unchanged_components ) + { + if( !unchanged_components.has_mapping_type( + geode::Surface3D::component_type_static() ) ) + { + return; + } + const auto& unchanged_surfaces = unchanged_components.at( + geode::Surface3D::component_type_static() ); + for( const auto& model_bdry : old_model.model_boundaries() ) + { + std::vector< geode::uuid > surfaces_to_add; + for( const auto& surface_in_bdry : + old_model.model_boundary_items( model_bdry ) ) + { + if( absl::c_contains( + unchanged_surfaces, surface_in_bdry.id() ) ) + { + surfaces_to_add.push_back( surface_in_bdry.id() ); + } + } + if( surfaces_to_add.empty() ) + { + continue; + } + if( !new_model.has_model_boundary( model_bdry.id() ) ) + { + new_model_builder.add_model_boundary( model_bdry.id() ); + new_model_builder.set_model_boundary_name( + model_bdry.id(), model_bdry.name() ); + } + const auto& new_model_bdry = + new_model.model_boundary( model_bdry.id() ); + for( const auto& surface_id : surfaces_to_add ) + { + new_model_builder.add_surface_in_model_boundary( + new_model.surface( surface_id ), new_model_bdry ); + } + } + } + void transfer_section_model_boundaries( const geode::Section& old_model, const geode::Section& new_model, typename geode::SectionBuilder& new_model_builder, @@ -355,9 +592,12 @@ namespace { continue; } - new_model_builder.add_model_boundary( collection_in.id() ); - new_model_builder.set_model_boundary_name( - collection_in.id(), collection_in.name() ); + if( !new_model.has_model_boundary( collection_in.id() ) ) + { + new_model_builder.add_model_boundary( collection_in.id() ); + new_model_builder.set_model_boundary_name( + collection_in.id(), collection_in.name() ); + } const auto& new_collection = new_model.model_boundary( collection_in.id() ); for( const auto& line_in_collection : @@ -381,6 +621,49 @@ namespace } } } + + void transfer_section_model_boundaries( const geode::Section& old_model, + const geode::Section& new_model, + typename geode::SectionBuilder& new_model_builder, + const geode::ModelUnchangedComponentMapping& unchanged_components ) + { + if( !unchanged_components.has_mapping_type( + geode::Line2D::component_type_static() ) ) + { + return; + } + const auto& unchanged_lines = + unchanged_components.at( geode::Line2D::component_type_static() ); + for( const auto& model_bdry : old_model.model_boundaries() ) + { + std::vector< geode::uuid > lines_to_add; + for( const auto& line_in_bdry : + old_model.model_boundary_items( model_bdry ) ) + { + if( absl::c_contains( unchanged_lines, line_in_bdry.id() ) ) + { + lines_to_add.push_back( line_in_bdry.id() ); + } + } + if( lines_to_add.empty() ) + { + continue; + } + if( !new_model.has_model_boundary( model_bdry.id() ) ) + { + new_model_builder.add_model_boundary( model_bdry.id() ); + new_model_builder.set_model_boundary_name( + model_bdry.id(), model_bdry.name() ); + } + const auto& new_model_bdry = + new_model.model_boundary( model_bdry.id() ); + for( const auto& line_id : lines_to_add ) + { + new_model_builder.add_line_in_model_boundary( + new_model.line( line_id ), new_model_bdry ); + } + } + } } // namespace namespace geode @@ -405,6 +688,24 @@ namespace geode old_brep, new_brep, new_brep_builder, component_mapping ); } + void opengeode_model_api transfer_brep_collections( + const BRep& old_brep, + const BRep& new_brep, + BRepBuilder& new_brep_builder, + const ModelUnchangedComponentMapping& unchanged_components ) + { + transfer_corner_collections( + old_brep, new_brep, new_brep_builder, unchanged_components ); + transfer_line_collections( + old_brep, new_brep, new_brep_builder, unchanged_components ); + transfer_surface_collections( + old_brep, new_brep, new_brep_builder, unchanged_components ); + transfer_block_collections( + old_brep, new_brep, new_brep_builder, unchanged_components ); + transfer_brep_model_boundaries( + old_brep, new_brep, new_brep_builder, unchanged_components ); + } + void opengeode_model_api transfer_section_collections( const Section& old_section, const Section& new_section, @@ -420,5 +721,21 @@ namespace geode transfer_section_model_boundaries( old_section, new_section, new_section_builder, component_mapping ); } + + void opengeode_model_api transfer_section_collections( + const Section& old_section, + const Section& new_section, + SectionBuilder& new_brep_builder, + const ModelUnchangedComponentMapping& unchanged_components ) + { + transfer_corner_collections( old_section, new_section, + new_brep_builder, unchanged_components ); + transfer_line_collections( old_section, new_section, + new_brep_builder, unchanged_components ); + transfer_surface_collections( old_section, new_section, + new_brep_builder, unchanged_components ); + transfer_section_model_boundaries( old_section, new_section, + new_brep_builder, unchanged_components ); + } } // namespace detail } // namespace geode