Wildmeshing Toolkit
tuple_map_attribute_io.cpp
Go to the documentation of this file.
3 
4 #include <wmtk/EdgeMesh.hpp>
5 #include <wmtk/Mesh.hpp>
6 #include <wmtk/TetMesh.hpp>
7 #include <wmtk/TriMesh.hpp>
8 #include <wmtk/Types.hpp>
10 
11 #include <wmtk/utils/Logger.hpp>
12 
13 namespace wmtk::multimesh::utils {
14 
15 
16 namespace {
17 using Vec84 = Vector<int8_t, 4>;
18 }
20 {
21  Vector<int64_t, 2> v = Vector<int64_t, 2>::ConstMapType(reinterpret_cast<const int64_t*>(&t));
22  return v;
23 }
24 
25 Tuple vector2_to_tuple(const Eigen::Ref<const Vector2l>& v)
26 {
27  const Tuple* data = reinterpret_cast<const Tuple*>(v.data());
28  return *data;
29 }
31 {
37  return v;
38 }
39 
40 Tuple vector5_to_tuple(const Eigen::Ref<const Vector5l>& v)
41 {
42  return Tuple(v(0), v(1), v(2), v(3));
43 }
44 
46 {
47 #if defined WMTK_DISABLE_COMPRESSED_MULTIMESH_TUPLE
48  return tuple_to_vector5(t);
49 #else
50  return tuple_to_vector2(t);
51 #endif
52 }
53 Tuple vector_to_tuple(const Eigen::Ref<const TupleVector>& v)
54 {
55 #if defined WMTK_DISABLE_COMPRESSED_MULTIMESH_TUPLE
56  return vector5_to_tuple(v);
57 #else
58  return vector2_to_tuple(v);
59 #endif
60 }
61 
62 std::tuple<Tuple, Tuple> vectors_to_tuples(const Eigen::Ref<const TwoTupleVector>& v)
63 {
64  return std::make_tuple(
65  vector_to_tuple(v.head<TUPLE_SIZE>()),
66  vector_to_tuple(v.tail<TUPLE_SIZE>()));
67 }
69 {
71  t.head<TUPLE_SIZE>() = tuple_to_vector(a);
72  t.tail<TUPLE_SIZE>() = tuple_to_vector(b);
73  return t;
74 }
75 
76 
77 template <typename MeshType>
78 std::tuple<Tuple, Tuple> read_tuple_map_attribute(
80  const Tuple& source_tuple)
81 {
82 #if !defined(NDEBUG)
83  // check t hat the global ids are either -1 or positive
84  auto v = accessor.const_vector_attribute(source_tuple);
85  assert(v(0) >= -1);
86  assert(v(2) >= -1);
87 #endif
88  assert(accessor.dimension() == 4);
89 
90  const wmtk::attribute::TupleAccessor<MeshType> acc(accessor);
91  assert(acc.dimension() == 2);
92  auto map = acc.const_vector_attribute(source_tuple);
93  return std::tie(map(0), map(1));
94 }
95 
96 
97 template std::tuple<Tuple, Tuple> read_tuple_map_attribute(
99  const Tuple& source_tuple);
100 template std::tuple<Tuple, Tuple> read_tuple_map_attribute(
102  const Tuple& source_tuple);
103 template std::tuple<Tuple, Tuple> read_tuple_map_attribute(
105  const Tuple& source_tuple);
106 template std::tuple<Tuple, Tuple> read_tuple_map_attribute(
108  const Tuple& source_tuple);
109 
110 
111 template <typename MeshType>
114  const Tuple& source_tuple,
115  const Tuple& target_tuple)
116 {
117  assert(map_accessor.dimension() == 4);
119  assert(acc.dimension() == 2);
120  auto map = acc.vector_attribute(source_tuple);
121  map(0) = source_tuple;
122  map(1) = target_tuple;
123 #if !defined(NDEBUG)
124  // check t hat the global ids are either -1 or positive
125  auto v = map_accessor.const_vector_attribute(source_tuple);
126  assert(v(0) >= -1);
127  assert(v(2) >= -1);
128 #endif
129 }
130 
133  const Tuple& source_tuple,
134  const Tuple& target_tuple);
137  const Tuple& source_tuple,
138  const Tuple& target_tuple);
141  const Tuple& source_tuple,
142  const Tuple& target_tuple);
145  const Tuple& source_tuple,
146  const Tuple& target_tuple);
147 
148 
150  Mesh& source_mesh,
152  const Tuple& source_tuple,
153  const Tuple& target_tuple)
154 {
155  auto map_accessor = source_mesh.create_accessor(map_handle);
156  write_tuple_map_attribute(map_accessor, source_tuple, target_tuple);
157 }
158 std::tuple<Tuple, Tuple> read_tuple_map_attribute_slow(
159  const Mesh& source_mesh,
161  const Tuple& source_tuple)
162 {
163  auto acc = source_mesh.create_const_accessor(map_handle);
164  return read_tuple_map_attribute(acc, source_tuple);
165 }
166 } // namespace wmtk::multimesh::utils
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
int64_t dimension() const
ConstMapResult< D > const_vector_attribute(const ArgType &t) const
ConstMapResult< D > const_vector_attribute(const Tuple &t) const
MapResult< D > vector_attribute(const Tuple &t)
Eigen::Index dimension() const
Handle that represents attributes for some mesh.
static int8_t local_eid(const Tuple &t)
static int64_t global_cid(const Tuple &t)
static int8_t local_vid(const Tuple &t)
static int8_t local_fid(const Tuple &t)
Vector< int64_t, TUPLE_SIZE > tuple_to_vector(const Tuple &t)
Tuple vector5_to_tuple(const Eigen::Ref< const Vector5l > &v)
Tuple vector2_to_tuple(const Eigen::Ref< const Vector2l > &v)
Vector< int64_t, 2 > tuple_to_vector2(const Tuple &t)
std::tuple< Tuple, Tuple > vectors_to_tuples(const Eigen::Ref< const TwoTupleVector > &v)
std::tuple< Tuple, Tuple > read_tuple_map_attribute(const wmtk::attribute::Accessor< int64_t, MeshType > &accessor, const Tuple &source_tuple)
Vector< int64_t, 4 > tuple_to_vector5(const Tuple &t)
TwoTupleVector tuples_to_vectors(const Tuple &a, const Tuple &b)
void write_tuple_map_attribute(wmtk::attribute::Accessor< int64_t, MeshType > &map_accessor, const Tuple &source_tuple, const Tuple &target_tuple)
void write_tuple_map_attribute_slow(Mesh &source_mesh, TypedAttributeHandle< int64_t > map_handle, const Tuple &source_tuple, const Tuple &target_tuple)
Vector< int64_t, TWO_TUPLE_SIZE > TwoTupleVector
std::tuple< Tuple, Tuple > read_tuple_map_attribute_slow(const Mesh &source_mesh, TypedAttributeHandle< int64_t > map_handle, const Tuple &source_tuple)
Tuple vector_to_tuple(const Eigen::Ref< const TupleVector > &v)
Eigen::Matrix< T, R, 1 > Vector
Definition: Types.hpp:17