14#include <lagrange/Mesh.h>
15#include <lagrange/MeshTrait.h>
16#include <lagrange/common.h>
17#include <lagrange/legacy/inline.h>
18#include <lagrange/utils/safe_cast.h>
19#include <tbb/parallel_for.h>
25template <
typename MeshType>
28 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
31 using AttributeArray =
typename MeshType::AttributeArray;
32 using IndexArray =
typename MeshType::IndexArray;
34 const auto names = from.get_indexed_attribute_names();
38 for (
const auto& name : names) {
39 std::tie(attr, indices) = from.get_indexed_attribute(name);
40 to.add_indexed_attribute(name);
41 to.import_indexed_attribute(name, attr, indices);
45template <
typename MeshType>
46void map_indexed_attributes(
49 const std::vector<typename MeshType::Index>& facet_map)
51 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
53 using Index =
typename MeshType::Index;
54 using AttributeArray =
typename MeshType::AttributeArray;
55 using IndexArray =
typename MeshType::IndexArray;
57 const auto num_out_facets = to.get_num_facets();
58 const auto vertex_per_facet = to.get_vertex_per_facet();
59 const auto names = from.get_indexed_attribute_names();
62 IndexArray from_indices, to_indices;
63 for (
const auto& name : names) {
64 std::tie(attr, from_indices) = from.get_indexed_attribute(name);
65 assert(safe_cast<Index>(from_indices.rows()) == from.get_num_facets());
66 to_indices.resize(num_out_facets, vertex_per_facet);
67 to_indices.setConstant(invalid<Index>());
68 tbb::parallel_for(Index(0), num_out_facets, [&](Index i) {
69 to_indices.row(i) = from_indices.row(facet_map[i]);
71 assert((to_indices.array() != invalid<Index>()).all());
72 to.add_indexed_attribute(name);
73 to.import_indexed_attribute(name, attr, to_indices);
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
Main namespace for Lagrange.
Definition: AABBIGL.h:30