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
6 changes: 3 additions & 3 deletions include/geode/model/mixin/builder/blocks_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace geode

void set_block_active( const uuid& id, bool active );

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

protected:
explicit BlocksBuilder( Blocks< dimension >& blocks )
: blocks_( blocks )
Expand All @@ -88,9 +91,6 @@ 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
6 changes: 3 additions & 3 deletions include/geode/model/mixin/builder/corners_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ namespace geode

void set_corner_active( const uuid& id, bool active );

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

protected:
explicit CornersBuilder( Corners< dimension >& corners )
: corners_( corners )
Expand All @@ -80,9 +83,6 @@ 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
6 changes: 3 additions & 3 deletions include/geode/model/mixin/builder/lines_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ namespace geode

void set_line_active( const uuid& id, bool active );

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

protected:
explicit LinesBuilder( Lines< dimension >& lines ) : lines_( lines ) {}

Expand All @@ -77,9 +80,6 @@ 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
6 changes: 3 additions & 3 deletions include/geode/model/mixin/builder/surfaces_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace geode

void set_surface_active( const uuid& id, bool active );

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

protected:
explicit SurfacesBuilder( Surfaces< dimension >& surfaces )
: surfaces_( surfaces )
Expand All @@ -88,9 +91,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ namespace geode

ModelCopyMapping copy( const Section& section );

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

ModelCopyMapping copy_components( const Section& section );

void copy_components(
Expand Down
52 changes: 52 additions & 0 deletions include/geode/model/representation/core/detail/transfer_meshes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <geode/model/common.hpp>
#include <geode/model/representation/core/mapping.hpp>

namespace geode
{
class Section;
class SectionBuilder;
class BRep;
class BRepBuilder;
} // namespace geode

namespace geode
{
namespace detail
{
void opengeode_model_api transfer_brep_meshes( const BRep& brep,
BRepBuilder& brep_builder,
BRep&& other,
const ModelCopyMapping& component_mapping );

void opengeode_model_api transfer_section_meshes(
const Section& section,
SectionBuilder& section_builder,
Section&& other,
const ModelCopyMapping& component_mapping );
} // namespace detail
} // namespace geode
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace geode

void opengeode_model_api transfer_section_metadata(
const Section& old_section,
SectionBuilder& new_brep_builder,
SectionBuilder& new_section_builder,
const ModelGenericMapping& component_mapping );

template < typename ModelBuilder >
Expand Down
2 changes: 2 additions & 0 deletions src/geode/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ add_geode_library(
"representation/builder/section_builder.cpp"
"representation/core/detail/clone.cpp"
"representation/core/detail/transfer_collections.cpp"
"representation/core/detail/transfer_meshes.cpp"
"representation/core/detail/transfer_metadata.cpp"
"representation/core/brep.cpp"
"representation/core/section.cpp"
Expand Down Expand Up @@ -188,6 +189,7 @@ add_geode_library(
"representation/core/detail/clone.hpp"
"representation/core/detail/model_component.hpp"
"representation/core/detail/transfer_collections.hpp"
"representation/core/detail/transfer_meshes.hpp"
"representation/core/detail/transfer_metadata.hpp"
INTERNAL_HEADERS
"helpers/internal/simplicial_model_creator.hpp"
Expand Down
125 changes: 3 additions & 122 deletions src/geode/model/representation/builder/brep_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,71 +47,7 @@
#include <geode/model/representation/builder/detail/copy.hpp>
#include <geode/model/representation/builder/detail/register.hpp>
#include <geode/model/representation/core/brep.hpp>

namespace
{
void remove_component_meshes_in_mapping( const geode::BRep& brep,
geode::BRepBuilder& builder,
const geode::ModelCopyMapping& mapping )
{
for( const auto& in2out :
mapping.at( geode::Corner3D::component_type_static() )
.in2out_map() )
{
builder.update_corner_mesh(
brep.corner( in2out.first ), geode::PointSet3D::create() );
}
for( const auto& in2out :
mapping.at( geode::Line3D::component_type_static() ).in2out_map() )
{
builder.update_line_mesh(
brep.line( in2out.first ), geode::EdgedCurve3D::create() );
}
for( const auto& in2out :
mapping.at( geode::Surface3D::component_type_static() )
.in2out_map() )
{
builder.update_surface_mesh(
brep.surface( in2out.first ), geode::SurfaceMesh3D::create() );
}
for( const auto& in2out :
mapping.at( geode::Block3D::component_type_static() ).in2out_map() )
{
builder.update_block_mesh(
brep.block( in2out.first ), geode::SolidMesh3D::create() );
}
}

template < typename Mesh >
absl::FixedArray< geode::index_t > save_mesh_unique_vertices(
const geode::BRep& model,
const Mesh& mesh,
const geode::ComponentID& component_id )
{
const auto nb_vertices = mesh.nb_vertices();
absl::FixedArray< geode::index_t > unique_vertices( nb_vertices );
for( const auto v : geode::Range{ nb_vertices } )
{
unique_vertices[v] = model.unique_vertex( { component_id, v } );
}
return unique_vertices;
}

void set_mesh_unique_vertices( geode::BRepBuilder& builder,
absl::Span< const geode::index_t > unique_vertices,
const geode::ComponentID& component_id,
geode::index_t first_new_unique_vertex )
{
for( const auto v : geode::Indices{ unique_vertices } )
{
if( unique_vertices[v] != geode::NO_ID )
{
builder.set_unique_vertex( { component_id, v },
first_new_unique_vertex + unique_vertices[v] );
}
}
}
} // namespace
#include <geode/model/representation/core/detail/transfer_meshes.hpp>

namespace geode
{
Expand Down Expand Up @@ -150,63 +86,8 @@ namespace geode
void BRepBuilder::replace_components_meshes_by_others(
BRep&& other, const ModelCopyMapping& mapping )
{
BRepBuilder other_builder{ other };
remove_component_meshes_in_mapping( brep_, *this, mapping );
this->delete_isolated_vertices();
const auto first_new_unique_vertex_id =
create_unique_vertices( other.nb_unique_vertices() );
for( const auto& in2out :
mapping.at( Corner3D::component_type_static() ).in2out_map() )
{
const auto corner_unique_vertices = save_mesh_unique_vertices(
other, other.corner( in2out.second ).mesh(),
other.corner( in2out.second ).component_id() );
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 );
set_mesh_unique_vertices( *this, corner_unique_vertices,
brep_.corner( in2out.first ).component_id(),
first_new_unique_vertex_id );
}
for( const auto& in2out :
mapping.at( Line3D::component_type_static() ).in2out_map() )
{
const auto line_unique_vertices = save_mesh_unique_vertices( other,
other.line( in2out.second ).mesh(),
other.line( in2out.second ).component_id() );
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 );
set_mesh_unique_vertices( *this, line_unique_vertices,
brep_.line( in2out.first ).component_id(),
first_new_unique_vertex_id );
}
for( const auto& in2out :
mapping.at( Surface3D::component_type_static() ).in2out_map() )
{
const auto surface_unique_vertices = save_mesh_unique_vertices(
other, other.surface( in2out.second ).mesh(),
other.surface( in2out.second ).component_id() );
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 );
set_mesh_unique_vertices( *this, surface_unique_vertices,
brep_.surface( in2out.first ).component_id(),
first_new_unique_vertex_id );
}
for( const auto& in2out :
mapping.at( Block3D::component_type_static() ).in2out_map() )
{
const auto block_unique_vertices = save_mesh_unique_vertices( other,
other.block( in2out.second ).mesh(),
other.block( in2out.second ).component_id() );
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 );
set_mesh_unique_vertices( *this, block_unique_vertices,
brep_.block( in2out.first ).component_id(),
first_new_unique_vertex_id );
}
detail::transfer_brep_meshes(
brep_, *this, std::move( other ), mapping );
}

ModelCopyMapping BRepBuilder::copy_components( const BRep& brep )
Expand Down
8 changes: 8 additions & 0 deletions src/geode/model/representation/builder/section_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <geode/model/mixin/core/surface_collection.hpp>
#include <geode/model/representation/builder/detail/copy.hpp>
#include <geode/model/representation/builder/detail/register.hpp>
#include <geode/model/representation/core/detail/transfer_meshes.hpp>
#include <geode/model/representation/core/section.hpp>

namespace geode
Expand Down Expand Up @@ -76,6 +77,13 @@ namespace geode
return mapping;
}

void SectionBuilder::replace_components_meshes_by_others(
Section&& other, const ModelCopyMapping& mapping )
{
detail::transfer_section_meshes(
section_, *this, std::move( other ), mapping );
}

ModelCopyMapping SectionBuilder::copy_components( const Section& section )
{
ModelCopyMapping mappings;
Expand Down
Loading