Wildmeshing Toolkit
Loading...
Searching...
No Matches
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>
9
10#include <wmtk/utils/Logger.hpp>
11
12namespace wmtk::multimesh::utils {
13
14
15namespace {
16using Vec84 = Vector<int8_t, 4>;
17}
19{
20 Vector<int64_t, 2> v = Vector<int64_t, 2>::ConstMapType(reinterpret_cast<const int64_t*>(&t));
21 return v;
22}
23
24Tuple vector2_to_tuple(const Eigen::Ref<const Vector2l>& v)
25{
26 const Tuple* data = reinterpret_cast<const Tuple*>(v.data());
27 return *data;
28}
30{
32 v(0) = t.local_vid();
33 v(1) = t.local_eid();
34 v(2) = t.local_fid();
35 v(3) = t.global_cid();
36 return v;
37}
38
39Tuple vector5_to_tuple(const Eigen::Ref<const Vector5l>& v)
40{
41 return Tuple(v(0), v(1), v(2), v(3));
42}
43
45{
46#if defined WMTK_DISABLE_COMPRESSED_MULTIMESH_TUPLE
47 return tuple_to_vector5(t);
48#else
49 return tuple_to_vector2(t);
50#endif
51}
52Tuple vector_to_tuple(const Eigen::Ref<const TupleVector>& v)
53{
54#if defined WMTK_DISABLE_COMPRESSED_MULTIMESH_TUPLE
55 return vector5_to_tuple(v);
56#else
57 return vector2_to_tuple(v);
58#endif
59}
60
61std::tuple<Tuple, Tuple> vectors_to_tuples(const Eigen::Ref<const TwoTupleVector>& v)
62{
63 return std::make_tuple(
64 vector_to_tuple(v.head<TUPLE_SIZE>()),
65 vector_to_tuple(v.tail<TUPLE_SIZE>()));
66}
68{
70 t.head<TUPLE_SIZE>() = tuple_to_vector(a);
71 t.tail<TUPLE_SIZE>() = tuple_to_vector(b);
72 return t;
73}
74
75
76template <typename MeshType>
77std::tuple<Tuple, Tuple> read_tuple_map_attribute(
79 const Tuple& source_tuple)
80{
81#if !defined(NDEBUG)
82 // check t hat the global ids are either -1 or positive
83 auto v = accessor.const_vector_attribute(source_tuple);
84 assert(v(0) >= -1);
85 assert(v(2) >= -1);
86#endif
87 assert(accessor.dimension() == 4);
88
90 assert(acc.dimension() == 2);
91 auto map = acc.const_vector_attribute(source_tuple);
92 return std::tie(map(0), map(1));
93}
94
95
96template std::tuple<Tuple, Tuple> read_tuple_map_attribute(
98 const Tuple& source_tuple);
99template std::tuple<Tuple, Tuple> read_tuple_map_attribute(
101 const Tuple& source_tuple);
102template std::tuple<Tuple, Tuple> read_tuple_map_attribute(
104 const Tuple& source_tuple);
105template std::tuple<Tuple, Tuple> read_tuple_map_attribute(
107 const Tuple& source_tuple);
108
109
110template <typename MeshType>
113 const Tuple& source_tuple,
114 const Tuple& target_tuple)
115{
116 assert(map_accessor.dimension() == 4);
118 assert(acc.dimension() == 2);
119 auto map = acc.vector_attribute(source_tuple);
120 map(0) = source_tuple;
121 map(1) = target_tuple;
122#if !defined(NDEBUG)
123 // check t hat the global ids are either -1 or positive
124 auto v = map_accessor.const_vector_attribute(source_tuple);
125 assert(v(0) >= -1);
126 assert(v(2) >= -1);
127#endif
128}
129
132 const Tuple& source_tuple,
133 const Tuple& target_tuple);
136 const Tuple& source_tuple,
137 const Tuple& target_tuple);
140 const Tuple& source_tuple,
141 const Tuple& target_tuple);
144 const Tuple& source_tuple,
145 const Tuple& target_tuple);
146
147
149 Mesh& source_mesh,
151 const Tuple& source_tuple,
152 const Tuple& target_tuple)
153{
154 auto map_accessor = source_mesh.create_accessor(map_handle);
155 write_tuple_map_attribute(map_accessor, source_tuple, target_tuple);
156}
157std::tuple<Tuple, Tuple> read_tuple_map_attribute_slow(
158 const Mesh& source_mesh,
160 const Tuple& source_tuple)
161{
162 auto acc = source_mesh.create_const_accessor(map_handle);
163 return read_tuple_map_attribute(acc, source_tuple);
164}
165} // 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)
The Tuple is the basic navigation tool in our mesh data structure.
Definition Tuple.hpp:19
int8_t local_vid() const
Definition Tuple.hxx:52
int8_t local_fid() const
Definition Tuple.hxx:62
int8_t local_eid() const
Definition Tuple.hxx:57
int64_t global_cid() const
Definition Tuple.hxx:47
A CachingAccessor that uses tuples for accessing attributes instead of indices.
Definition Accessor.hpp:28
ConstMapResult< D > const_vector_attribute(const ArgType &t) const
Eigen::Index dimension() const
MapResult< D > vector_attribute(const Tuple &t)
ConstMapResult< D > const_vector_attribute(const Tuple &t) const
Handle that represents attributes for some mesh.
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)
std::tuple< Tuple, Tuple > read_tuple_map_attribute_slow(const Mesh &source_mesh, TypedAttributeHandle< int64_t > map_handle, const Tuple &source_tuple)
Vector< int64_t, 2 > tuple_to_vector2(const Tuple &t)
Vector< int64_t, 4 > tuple_to_vector5(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)
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
Tuple vector_to_tuple(const Eigen::Ref< const TupleVector > &v)
Eigen::Matrix< T, R, 1 > Vector
Definition Types.hpp:17