Skip to content

fix(ModelMappings): intermediate refactoring using more templated str… #1157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions include/geode/model/helpers/detail/mappings_merger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ namespace geode
[[nodiscard]] ModelGenericMapping opengeode_model_api
copy_to_generic_mappings( const ModelCopyMapping& mappings2 );

[[nodiscard]] ModelMappings opengeode_model_api merge_mappings(
const ModelMappings& mappings1, const ModelMappings& mappings2 );
[[nodiscard]] SectionMappings opengeode_model_api merge_mappings(
const SectionMappings& mappings1,
const SectionMappings& mappings2 );

[[nodiscard]] BRepMappings opengeode_model_api merge_mappings(
const BRepMappings& mappings1, const BRepMappings& mappings2 );
} // namespace detail
} // namespace geode
72 changes: 69 additions & 3 deletions include/geode/model/representation/core/mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#include <geode/model/mixin/core/component_mesh_element.hpp>
#include <geode/model/mixin/core/vertex_identifier.hpp>

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

namespace geode
{
template < typename MappingType >
Expand Down Expand Up @@ -126,6 +132,23 @@ namespace geode
MeshElementMapping blocks;
};

template < typename Model >
struct TypedModelMeshesElementMapping
{
};

template <>
struct TypedModelMeshesElementMapping< Section >
{
using type = SectionMeshesElementMapping;
};

template <>
struct TypedModelMeshesElementMapping< BRep >
{
using type = BRepMeshesElementMapping;
};

struct ModelMeshesVertexMapping
{
MeshVertexMapping corners;
Expand All @@ -142,19 +165,62 @@ namespace geode
MeshVertexMapping blocks;
};

struct ModelMappings
template < typename Model >
struct TypedModelMeshesVertexMapping
{
};

template <>
struct TypedModelMeshesVertexMapping< Section >
{
using type = SectionMeshesVertexMapping;
};

template <>
struct TypedModelMeshesVertexMapping< BRep >
{
using type = BRepMeshesVertexMapping;
};

struct ModelComponentMappings
{
ModelGenericMapping component_mapping;
ModelAddedComponentMapping added_components;
ModelUnchangedComponentMapping unchanged_components;
};

struct [[deprecated]] ModelMappings : public ModelComponentMappings
{
ModelMeshesElementMapping mesh_element_mapping;
ModelMeshesVertexMapping mesh_vertices_mapping;
};

struct BRepMappings
struct SectionMappings : public ModelComponentMappings
{
ModelMeshesElementMapping mesh_element_mapping;
ModelMeshesVertexMapping mesh_vertices_mapping;
};

struct BRepMappings : public ModelComponentMappings
{
ModelGenericMapping component_mapping;
BRepMeshesElementMapping mesh_element_mapping;
BRepMeshesVertexMapping mesh_vertices_mapping;
};

template < typename Model >
struct TypedModelMappings
{
};

template <>
struct TypedModelMappings< Section >
{
using type = SectionMappings;
};

template <>
struct TypedModelMappings< BRep >
{
using type = BRepMappings;
};
} // namespace geode
25 changes: 0 additions & 25 deletions src/geode/model/helpers/component_mesh_polygons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,6 @@ namespace
const geode::Line< dimension >& line,
geode::index_t edge_id )
{
OPENGEODE_EXCEPTION( model.is_boundary( line, surface )
|| model.is_internal( line, surface ),
"[helpers::surface_vertices_from_line_edge] The given line "
"is neither boundary nor internal to the given surface in the "
"given model." );
const auto edge_unique_vertices =
geode::edge_unique_vertices( model, line, edge_id );
const auto edges_surface_and_unique_vertices =
Expand All @@ -499,11 +494,6 @@ namespace
const geode::Line< dimension >& line,
geode::index_t edge_id )
{
OPENGEODE_EXCEPTION( model.is_boundary( line, surface )
|| model.is_internal( line, surface ),
"[helpers::oriented_surface_vertices_from_line_edge] The given "
"line is neither boundary nor internal to the given surface in the "
"given model." );
const auto edge_unique_vertices =
geode::edge_unique_vertices( model, line, edge_id );
const auto output =
Expand Down Expand Up @@ -753,11 +743,6 @@ namespace geode
const Surface3D& surface,
index_t polygon_id )
{
OPENGEODE_EXCEPTION( model.is_boundary( surface, block )
|| model.is_internal( surface, block ),
"[helpers::block_vertices_from_surface_polygon] The given surface "
"is neither boundary nor internal to the given block in the given "
"model." );
return block_mesh_polyhedra_from_unique_vertices_facet( model, block,
polygon_unique_vertices( model, surface, polygon_id ) );
}
Expand All @@ -768,11 +753,6 @@ namespace geode
const Surface3D& surface,
index_t polygon_id )
{
OPENGEODE_EXCEPTION( model.is_boundary( surface, block )
|| model.is_internal( surface, block ),
"[helpers::block_vertices_from_surface_polygon] The given surface "
"is neither boundary nor internal to the given block in the given "
"model." );
const auto polygon_vertices =
polygon_unique_vertices( model, surface, polygon_id );
const auto facets_block_and_unique_vertices =
Expand All @@ -789,11 +769,6 @@ namespace geode
const Surface3D& surface,
index_t polygon_id )
{
OPENGEODE_EXCEPTION( model.is_boundary( surface, block )
|| model.is_internal( surface, block ),
"[helpers::block_vertices_from_surface_polygon] The given surface "
"is neither boundary nor internal to the given block in the given "
"model." );
const auto polygon_vertices =
polygon_unique_vertices( model, surface, polygon_id );
const auto output = oriented_polygon_vertices_to_block_facets_vertices(
Expand Down
26 changes: 23 additions & 3 deletions src/geode/model/helpers/detail/mappings_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ namespace geode
return transferer.transfer();
}

ModelMappings merge_mappings(
const ModelMappings& mappings1, const ModelMappings& mappings2 )
template < typename ModelMappingType >
ModelMappingType base_merge_mappings( const ModelMappingType& mappings1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To move in anonymous namespace?

const ModelMappingType& mappings2 )
{
ModelMappings result;
ModelMappingType result;
result.component_mapping = merge_mappings(
mappings1.component_mapping, mappings2.component_mapping );
result.mesh_element_mapping.corners =
Expand All @@ -276,5 +277,24 @@ namespace geode
mappings2.mesh_vertices_mapping.surfaces );
return result;
}

SectionMappings merge_mappings(
const SectionMappings& mappings1, const SectionMappings& mappings2 )
{
return base_merge_mappings( mappings1, mappings2 );
}

BRepMappings merge_mappings(
const BRepMappings& mappings1, const BRepMappings& mappings2 )
{
auto result = base_merge_mappings( mappings1, mappings2 );
result.mesh_element_mapping.blocks =
merge_element_mappings( mappings1.mesh_element_mapping.blocks,
mappings2.mesh_element_mapping.blocks );
result.mesh_vertices_mapping.blocks =
merge_vertex_mappings( mappings1.mesh_vertices_mapping.blocks,
mappings2.mesh_vertices_mapping.blocks );
return result;
}
} // namespace detail
} // namespace geode