Skip to content

Commit b04c5e6

Browse files
committed
fix(ModelMappings): intermediate refactoring using more templated structs
1 parent df0db87 commit b04c5e6

File tree

4 files changed

+98
-33
lines changed

4 files changed

+98
-33
lines changed

include/geode/model/helpers/detail/mappings_merger.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ namespace geode
4141
[[nodiscard]] ModelGenericMapping opengeode_model_api
4242
copy_to_generic_mappings( const ModelCopyMapping& mappings2 );
4343

44-
[[nodiscard]] ModelMappings opengeode_model_api merge_mappings(
45-
const ModelMappings& mappings1, const ModelMappings& mappings2 );
44+
[[nodiscard]] SectionMappings opengeode_model_api merge_mappings(
45+
const SectionMappings& mappings1,
46+
const SectionMappings& mappings2 );
47+
48+
[[nodiscard]] BRepMappings opengeode_model_api merge_mappings(
49+
const BRepMappings& mappings1, const BRepMappings& mappings2 );
4650
} // namespace detail
4751
} // namespace geode

include/geode/model/representation/core/mapping.hpp

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
#include <geode/model/mixin/core/component_mesh_element.hpp>
3535
#include <geode/model/mixin/core/vertex_identifier.hpp>
3636

37+
namespace geode
38+
{
39+
class Section;
40+
class BRep;
41+
} // namespace geode
42+
3743
namespace geode
3844
{
3945
template < typename MappingType >
@@ -126,6 +132,23 @@ namespace geode
126132
MeshElementMapping blocks;
127133
};
128134

135+
template < typename Model >
136+
struct TypedModelMeshesElementMapping
137+
{
138+
};
139+
140+
template <>
141+
struct TypedModelMeshesElementMapping< Section >
142+
{
143+
using type = SectionMeshesElementMapping;
144+
};
145+
146+
template <>
147+
struct TypedModelMeshesElementMapping< BRep >
148+
{
149+
using type = BRepMeshesElementMapping;
150+
};
151+
129152
struct ModelMeshesVertexMapping
130153
{
131154
MeshVertexMapping corners;
@@ -142,19 +165,62 @@ namespace geode
142165
MeshVertexMapping blocks;
143166
};
144167

145-
struct ModelMappings
168+
template < typename Model >
169+
struct TypedModelMeshesVertexMapping
170+
{
171+
};
172+
173+
template <>
174+
struct TypedModelMeshesVertexMapping< Section >
175+
{
176+
using type = SectionMeshesVertexMapping;
177+
};
178+
179+
template <>
180+
struct TypedModelMeshesVertexMapping< BRep >
181+
{
182+
using type = BRepMeshesVertexMapping;
183+
};
184+
185+
struct ModelComponentMappings
146186
{
147187
ModelGenericMapping component_mapping;
148188
ModelAddedComponentMapping added_components;
149189
ModelUnchangedComponentMapping unchanged_components;
190+
};
191+
192+
struct [[deprecated]] ModelMappings : public ModelComponentMappings
193+
{
150194
ModelMeshesElementMapping mesh_element_mapping;
151195
ModelMeshesVertexMapping mesh_vertices_mapping;
152196
};
153197

154-
struct BRepMappings
198+
struct SectionMappings : public ModelComponentMappings
199+
{
200+
ModelMeshesElementMapping mesh_element_mapping;
201+
ModelMeshesVertexMapping mesh_vertices_mapping;
202+
};
203+
204+
struct BRepMappings : public ModelComponentMappings
155205
{
156-
ModelGenericMapping component_mapping;
157206
BRepMeshesElementMapping mesh_element_mapping;
158207
BRepMeshesVertexMapping mesh_vertices_mapping;
159208
};
209+
210+
template < typename Model >
211+
struct TypedModelMappings
212+
{
213+
};
214+
215+
template <>
216+
struct TypedModelMappings< Section >
217+
{
218+
using type = SectionMappings;
219+
};
220+
221+
template <>
222+
struct TypedModelMappings< BRep >
223+
{
224+
using type = BRepMappings;
225+
};
160226
} // namespace geode

src/geode/model/helpers/component_mesh_polygons.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,6 @@ namespace
477477
const geode::Line< dimension >& line,
478478
geode::index_t edge_id )
479479
{
480-
OPENGEODE_EXCEPTION( model.is_boundary( line, surface )
481-
|| model.is_internal( line, surface ),
482-
"[helpers::surface_vertices_from_line_edge] The given line "
483-
"is neither boundary nor internal to the given surface in the "
484-
"given model." );
485480
const auto edge_unique_vertices =
486481
geode::edge_unique_vertices( model, line, edge_id );
487482
const auto edges_surface_and_unique_vertices =
@@ -499,11 +494,6 @@ namespace
499494
const geode::Line< dimension >& line,
500495
geode::index_t edge_id )
501496
{
502-
OPENGEODE_EXCEPTION( model.is_boundary( line, surface )
503-
|| model.is_internal( line, surface ),
504-
"[helpers::oriented_surface_vertices_from_line_edge] The given "
505-
"line is neither boundary nor internal to the given surface in the "
506-
"given model." );
507497
const auto edge_unique_vertices =
508498
geode::edge_unique_vertices( model, line, edge_id );
509499
const auto output =
@@ -753,11 +743,6 @@ namespace geode
753743
const Surface3D& surface,
754744
index_t polygon_id )
755745
{
756-
OPENGEODE_EXCEPTION( model.is_boundary( surface, block )
757-
|| model.is_internal( surface, block ),
758-
"[helpers::block_vertices_from_surface_polygon] The given surface "
759-
"is neither boundary nor internal to the given block in the given "
760-
"model." );
761746
return block_mesh_polyhedra_from_unique_vertices_facet( model, block,
762747
polygon_unique_vertices( model, surface, polygon_id ) );
763748
}
@@ -768,11 +753,6 @@ namespace geode
768753
const Surface3D& surface,
769754
index_t polygon_id )
770755
{
771-
OPENGEODE_EXCEPTION( model.is_boundary( surface, block )
772-
|| model.is_internal( surface, block ),
773-
"[helpers::block_vertices_from_surface_polygon] The given surface "
774-
"is neither boundary nor internal to the given block in the given "
775-
"model." );
776756
const auto polygon_vertices =
777757
polygon_unique_vertices( model, surface, polygon_id );
778758
const auto facets_block_and_unique_vertices =
@@ -789,11 +769,6 @@ namespace geode
789769
const Surface3D& surface,
790770
index_t polygon_id )
791771
{
792-
OPENGEODE_EXCEPTION( model.is_boundary( surface, block )
793-
|| model.is_internal( surface, block ),
794-
"[helpers::block_vertices_from_surface_polygon] The given surface "
795-
"is neither boundary nor internal to the given block in the given "
796-
"model." );
797772
const auto polygon_vertices =
798773
polygon_unique_vertices( model, surface, polygon_id );
799774
const auto output = oriented_polygon_vertices_to_block_facets_vertices(

src/geode/model/helpers/detail/mappings_merger.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,11 @@ namespace geode
250250
return transferer.transfer();
251251
}
252252

253-
ModelMappings merge_mappings(
254-
const ModelMappings& mappings1, const ModelMappings& mappings2 )
253+
template < typename ModelMappingType >
254+
ModelMappingType base_merge_mappings( const ModelMappingType& mappings1,
255+
const ModelMappingType& mappings2 )
255256
{
256-
ModelMappings result;
257+
ModelMappingType result;
257258
result.component_mapping = merge_mappings(
258259
mappings1.component_mapping, mappings2.component_mapping );
259260
result.mesh_element_mapping.corners =
@@ -276,5 +277,24 @@ namespace geode
276277
mappings2.mesh_vertices_mapping.surfaces );
277278
return result;
278279
}
280+
281+
SectionMappings merge_mappings(
282+
const SectionMappings& mappings1, const SectionMappings& mappings2 )
283+
{
284+
return base_merge_mappings( mappings1, mappings2 );
285+
}
286+
287+
BRepMappings merge_mappings(
288+
const BRepMappings& mappings1, const BRepMappings& mappings2 )
289+
{
290+
auto result = base_merge_mappings( mappings1, mappings2 );
291+
result.mesh_element_mapping.blocks =
292+
merge_element_mappings( mappings1.mesh_element_mapping.blocks,
293+
mappings2.mesh_element_mapping.blocks );
294+
result.mesh_vertices_mapping.blocks =
295+
merge_vertex_mappings( mappings1.mesh_vertices_mapping.blocks,
296+
mappings2.mesh_vertices_mapping.blocks );
297+
return result;
298+
}
279299
} // namespace detail
280300
} // namespace geode

0 commit comments

Comments
 (0)