Skip to content

Commit e115d21

Browse files
committed
fix(Model): add transfer model meshes helper
1 parent 3df510d commit e115d21

11 files changed

Lines changed: 371 additions & 135 deletions

File tree

include/geode/model/mixin/builder/blocks_builder.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ namespace geode
6666

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

69+
[[nodiscard]] std::unique_ptr< SolidMesh< dimension > >
70+
steal_block_mesh( const uuid& id );
71+
6972
protected:
7073
explicit BlocksBuilder( Blocks< dimension >& blocks )
7174
: blocks_( blocks )
@@ -88,9 +91,6 @@ namespace geode
8891
[[nodiscard]] SolidMesh< dimension >& modifiable_block_mesh(
8992
const uuid& id );
9093

91-
[[nodiscard]] std::unique_ptr< SolidMesh< dimension > >
92-
steal_block_mesh( const uuid& id );
93-
9494
private:
9595
Blocks< dimension >& blocks_;
9696
};

include/geode/model/mixin/builder/corners_builder.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ namespace geode
5858

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

61+
[[nodiscard]] std::unique_ptr< PointSet< dimension > >
62+
steal_corner_mesh( const uuid& id );
63+
6164
protected:
6265
explicit CornersBuilder( Corners< dimension >& corners )
6366
: corners_( corners )
@@ -80,9 +83,6 @@ namespace geode
8083
[[nodiscard]] PointSet< dimension >& modifiable_corner_mesh(
8184
const uuid& id );
8285

83-
[[nodiscard]] std::unique_ptr< PointSet< dimension > >
84-
steal_corner_mesh( const uuid& id );
85-
8686
private:
8787
Corners< dimension >& corners_;
8888
};

include/geode/model/mixin/builder/lines_builder.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ namespace geode
5858

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

61+
[[nodiscard]] std::unique_ptr< EdgedCurve< dimension > >
62+
steal_line_mesh( const uuid& id );
63+
6164
protected:
6265
explicit LinesBuilder( Lines< dimension >& lines ) : lines_( lines ) {}
6366

@@ -77,9 +80,6 @@ namespace geode
7780
[[nodiscard]] EdgedCurve< dimension >& modifiable_line_mesh(
7881
const uuid& id );
7982

80-
[[nodiscard]] std::unique_ptr< EdgedCurve< dimension > >
81-
steal_line_mesh( const uuid& id );
82-
8383
private:
8484
Lines< dimension >& lines_;
8585
};

include/geode/model/mixin/builder/surfaces_builder.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ namespace geode
6666

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

69+
[[nodiscard]] std::unique_ptr< SurfaceMesh< dimension > >
70+
steal_surface_mesh( const uuid& id );
71+
6972
protected:
7073
explicit SurfacesBuilder( Surfaces< dimension >& surfaces )
7174
: surfaces_( surfaces )
@@ -88,9 +91,6 @@ namespace geode
8891
[[nodiscard]] SurfaceMesh< dimension >& modifiable_surface_mesh(
8992
const uuid& id );
9093

91-
[[nodiscard]] std::unique_ptr< SurfaceMesh< dimension > >
92-
steal_surface_mesh( const uuid& id );
93-
9494
private:
9595
Surfaces< dimension >& surfaces_;
9696
};

include/geode/model/representation/builder/section_builder.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ namespace geode
9999

100100
ModelCopyMapping copy( const Section& section );
101101

102+
void replace_components_meshes_by_others(
103+
Section&& other, const ModelCopyMapping& mapping );
104+
102105
ModelCopyMapping copy_components( const Section& section );
103106

104107
void copy_components(
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2019 - 2026 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
26+
#include <geode/model/common.hpp>
27+
#include <geode/model/representation/core/mapping.hpp>
28+
29+
namespace geode
30+
{
31+
class Section;
32+
class SectionBuilder;
33+
class BRep;
34+
class BRepBuilder;
35+
} // namespace geode
36+
37+
namespace geode
38+
{
39+
namespace detail
40+
{
41+
void opengeode_model_api transfer_brep_meshes( const BRep& brep,
42+
BRepBuilder& brep_builder,
43+
BRep&& other,
44+
const ModelCopyMapping& component_mapping );
45+
46+
void opengeode_model_api transfer_section_meshes(
47+
const Section& section,
48+
SectionBuilder& section_builder,
49+
Section&& other,
50+
const ModelCopyMapping& component_mapping );
51+
} // namespace detail
52+
} // namespace geode

include/geode/model/representation/core/detail/transfer_metadata.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace geode
5353

5454
void opengeode_model_api transfer_section_metadata(
5555
const Section& old_section,
56-
SectionBuilder& new_brep_builder,
56+
SectionBuilder& new_section_builder,
5757
const ModelGenericMapping& component_mapping );
5858

5959
template < typename ModelBuilder >

src/geode/model/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ add_geode_library(
8888
"representation/builder/section_builder.cpp"
8989
"representation/core/detail/clone.cpp"
9090
"representation/core/detail/transfer_collections.cpp"
91+
"representation/core/detail/transfer_meshes.cpp"
9192
"representation/core/detail/transfer_metadata.cpp"
9293
"representation/core/brep.cpp"
9394
"representation/core/section.cpp"
@@ -188,6 +189,7 @@ add_geode_library(
188189
"representation/core/detail/clone.hpp"
189190
"representation/core/detail/model_component.hpp"
190191
"representation/core/detail/transfer_collections.hpp"
192+
"representation/core/detail/transfer_meshes.hpp"
191193
"representation/core/detail/transfer_metadata.hpp"
192194
INTERNAL_HEADERS
193195
"helpers/internal/simplicial_model_creator.hpp"

src/geode/model/representation/builder/brep_builder.cpp

Lines changed: 3 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -47,71 +47,7 @@
4747
#include <geode/model/representation/builder/detail/copy.hpp>
4848
#include <geode/model/representation/builder/detail/register.hpp>
4949
#include <geode/model/representation/core/brep.hpp>
50-
51-
namespace
52-
{
53-
void remove_component_meshes_in_mapping( const geode::BRep& brep,
54-
geode::BRepBuilder& builder,
55-
const geode::ModelCopyMapping& mapping )
56-
{
57-
for( const auto& in2out :
58-
mapping.at( geode::Corner3D::component_type_static() )
59-
.in2out_map() )
60-
{
61-
builder.update_corner_mesh(
62-
brep.corner( in2out.first ), geode::PointSet3D::create() );
63-
}
64-
for( const auto& in2out :
65-
mapping.at( geode::Line3D::component_type_static() ).in2out_map() )
66-
{
67-
builder.update_line_mesh(
68-
brep.line( in2out.first ), geode::EdgedCurve3D::create() );
69-
}
70-
for( const auto& in2out :
71-
mapping.at( geode::Surface3D::component_type_static() )
72-
.in2out_map() )
73-
{
74-
builder.update_surface_mesh(
75-
brep.surface( in2out.first ), geode::SurfaceMesh3D::create() );
76-
}
77-
for( const auto& in2out :
78-
mapping.at( geode::Block3D::component_type_static() ).in2out_map() )
79-
{
80-
builder.update_block_mesh(
81-
brep.block( in2out.first ), geode::SolidMesh3D::create() );
82-
}
83-
}
84-
85-
template < typename Mesh >
86-
absl::FixedArray< geode::index_t > save_mesh_unique_vertices(
87-
const geode::BRep& model,
88-
const Mesh& mesh,
89-
const geode::ComponentID& component_id )
90-
{
91-
const auto nb_vertices = mesh.nb_vertices();
92-
absl::FixedArray< geode::index_t > unique_vertices( nb_vertices );
93-
for( const auto v : geode::Range{ nb_vertices } )
94-
{
95-
unique_vertices[v] = model.unique_vertex( { component_id, v } );
96-
}
97-
return unique_vertices;
98-
}
99-
100-
void set_mesh_unique_vertices( geode::BRepBuilder& builder,
101-
absl::Span< const geode::index_t > unique_vertices,
102-
const geode::ComponentID& component_id,
103-
geode::index_t first_new_unique_vertex )
104-
{
105-
for( const auto v : geode::Indices{ unique_vertices } )
106-
{
107-
if( unique_vertices[v] != geode::NO_ID )
108-
{
109-
builder.set_unique_vertex( { component_id, v },
110-
first_new_unique_vertex + unique_vertices[v] );
111-
}
112-
}
113-
}
114-
} // namespace
50+
#include <geode/model/representation/core/detail/transfer_meshes.hpp>
11551

11652
namespace geode
11753
{
@@ -150,63 +86,8 @@ namespace geode
15086
void BRepBuilder::replace_components_meshes_by_others(
15187
BRep&& other, const ModelCopyMapping& mapping )
15288
{
153-
BRepBuilder other_builder{ other };
154-
remove_component_meshes_in_mapping( brep_, *this, mapping );
155-
this->delete_isolated_vertices();
156-
const auto first_new_unique_vertex_id =
157-
create_unique_vertices( other.nb_unique_vertices() );
158-
for( const auto& in2out :
159-
mapping.at( Corner3D::component_type_static() ).in2out_map() )
160-
{
161-
const auto corner_unique_vertices = save_mesh_unique_vertices(
162-
other, other.corner( in2out.second ).mesh(),
163-
other.corner( in2out.second ).component_id() );
164-
this->update_corner_mesh( brep_.corner( in2out.first ),
165-
other_builder.steal_corner_mesh( in2out.second ) );
166-
this->corner_mesh_builder( in2out.first )->set_id( in2out.first );
167-
set_mesh_unique_vertices( *this, corner_unique_vertices,
168-
brep_.corner( in2out.first ).component_id(),
169-
first_new_unique_vertex_id );
170-
}
171-
for( const auto& in2out :
172-
mapping.at( Line3D::component_type_static() ).in2out_map() )
173-
{
174-
const auto line_unique_vertices = save_mesh_unique_vertices( other,
175-
other.line( in2out.second ).mesh(),
176-
other.line( in2out.second ).component_id() );
177-
this->update_line_mesh( brep_.line( in2out.first ),
178-
other_builder.steal_line_mesh( in2out.second ) );
179-
this->line_mesh_builder( in2out.first )->set_id( in2out.first );
180-
set_mesh_unique_vertices( *this, line_unique_vertices,
181-
brep_.line( in2out.first ).component_id(),
182-
first_new_unique_vertex_id );
183-
}
184-
for( const auto& in2out :
185-
mapping.at( Surface3D::component_type_static() ).in2out_map() )
186-
{
187-
const auto surface_unique_vertices = save_mesh_unique_vertices(
188-
other, other.surface( in2out.second ).mesh(),
189-
other.surface( in2out.second ).component_id() );
190-
this->update_surface_mesh( brep_.surface( in2out.first ),
191-
other_builder.steal_surface_mesh( in2out.second ) );
192-
this->surface_mesh_builder( in2out.first )->set_id( in2out.first );
193-
set_mesh_unique_vertices( *this, surface_unique_vertices,
194-
brep_.surface( in2out.first ).component_id(),
195-
first_new_unique_vertex_id );
196-
}
197-
for( const auto& in2out :
198-
mapping.at( Block3D::component_type_static() ).in2out_map() )
199-
{
200-
const auto block_unique_vertices = save_mesh_unique_vertices( other,
201-
other.block( in2out.second ).mesh(),
202-
other.block( in2out.second ).component_id() );
203-
this->update_block_mesh( brep_.block( in2out.first ),
204-
other_builder.steal_block_mesh( in2out.second ) );
205-
this->block_mesh_builder( in2out.first )->set_id( in2out.first );
206-
set_mesh_unique_vertices( *this, block_unique_vertices,
207-
brep_.block( in2out.first ).component_id(),
208-
first_new_unique_vertex_id );
209-
}
89+
detail::transfer_brep_meshes(
90+
brep_, *this, std::move( other ), mapping );
21091
}
21192

21293
ModelCopyMapping BRepBuilder::copy_components( const BRep& brep )

src/geode/model/representation/builder/section_builder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <geode/model/mixin/core/surface_collection.hpp>
4343
#include <geode/model/representation/builder/detail/copy.hpp>
4444
#include <geode/model/representation/builder/detail/register.hpp>
45+
#include <geode/model/representation/core/detail/transfer_meshes.hpp>
4546
#include <geode/model/representation/core/section.hpp>
4647

4748
namespace geode
@@ -76,6 +77,13 @@ namespace geode
7677
return mapping;
7778
}
7879

80+
void SectionBuilder::replace_components_meshes_by_others(
81+
Section&& other, const ModelCopyMapping& mapping )
82+
{
83+
detail::transfer_section_meshes(
84+
section_, *this, std::move( other ), mapping );
85+
}
86+
7987
ModelCopyMapping SectionBuilder::copy_components( const Section& section )
8088
{
8189
ModelCopyMapping mappings;

0 commit comments

Comments
 (0)