16#include <lagrange/Mesh.h>
17#include <lagrange/MeshTrait.h>
18#include <lagrange/attributes/map_corner_attributes.h>
19#include <lagrange/attributes/map_facet_attributes.h>
20#include <lagrange/attributes/map_indexed_attributes.h>
21#include <lagrange/attributes/map_vertex_attributes.h>
22#include <lagrange/common.h>
23#include <lagrange/legacy/inline.h>
24#include <lagrange/utils/range.h>
40template <
typename Index>
41std::vector<Index>
invert_mapping(
const std::vector<Index>& map, Index target_count)
47 std::vector<Index> ret(target_count, invalid<Index>());
48 for (
auto i :
range((Index)map.size())) {
50 if (value != invalid<Index>()) {
72template <
typename MeshType>
75 using Index =
typename MeshType::Index;
76 std::vector<Index> vertex;
77 std::vector<Index> facet;
83template <
typename MeshType>
91template <
typename MeshType>
97template <
typename MeshType>
102 map2.vertex = invert_mapping(map1.vertex, target_mesh.get_num_vertices());
103 map2.facet = invert_mapping(map1.facet, target_mesh.get_num_facets());
107template <
typename MeshType>
108void map_attributes(
const MeshType& from,
MeshType& to,
const BackwardMeshMapping<MeshType>& map)
111 map_vertex_attributes(from, to, map.vertex);
112 map_facet_attributes(from, to, map.facet);
113 map_corner_attributes(from, to);
114 map_indexed_attributes(from, to);
117template <
typename MeshType>
118void map_attributes(
const MeshType& from,
MeshType& to,
const ForwardMeshMapping<MeshType>& map)
120 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
121 map_attributes(from, to, invert_mapping(map, to));
124template <
typename MeshType>
128 const std::vector<typename MeshType::Index>& backward_vertex_mapping = {},
129 const std::vector<typename MeshType::Index>& backward_facet_mapping = {})
131 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
132 map_vertex_attributes(from, to, backward_vertex_mapping);
133 map_facet_attributes(from, to, backward_facet_mapping);
134 if (backward_facet_mapping.empty() && to.get_num_facets() != 0) {
135 map_corner_attributes(from, to);
136 map_indexed_attributes(from, to);
138 map_corner_attributes(from, to, backward_facet_mapping);
139 map_indexed_attributes(from, to, backward_facet_mapping);
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
internal::Range< Index > range(Index end)
Returns an iterable object representing the range [0, end).
Definition: range.h:176
void map_attributes(const SurfaceMesh< Scalar, Index > &source_mesh, SurfaceMesh< Scalar, Index > &target_mesh, span< const Index > mapping_data, span< const Index > mapping_offsets={}, const MapAttributesOptions &options={})
Map attributes from the source mesh to the target mesh.
Definition: map_attributes.cpp:26
InverseMapping< Index > invert_mapping(Index num_source_elements, Function old_to_new, Index num_target_elements=invalid< Index >())
Compute the target-to-source (i.e.
Definition: invert_mapping.h:61
Main namespace for Lagrange.
Definition: AABBIGL.h:30
MeshTrait class provide compiler check for different mesh types.
Definition: MeshTrait.h:108
Definition: map_attributes.h:93
Definition: map_attributes.h:85
Definition: map_attributes.h:74