Wildmeshing Toolkit
Loading...
Searching...
No Matches
Accessor.hpp
Go to the documentation of this file.
1#pragma once
2#include <algorithm>
7
8namespace wmtk {
9class HDF5Reader;
10}
11namespace wmtk::tests {
12class DEBUG_PointMesh;
13class DEBUG_EdgeMesh;
14class DEBUG_TriMesh;
15} // namespace wmtk::tests
16namespace wmtk::tests_3d {
17class DEBUG_TetMesh;
18}
19
20namespace wmtk::attribute {
22
23template <typename MeshType>
25
38template <
39 typename T,
40 typename MeshType = Mesh,
41 typename AttributeType_ = CachingAttribute<T>,
42 int Dim = Eigen::Dynamic>
44{
45public:
46 friend class wmtk::Mesh;
51 friend class IndexFlagAccessor<MeshType>;
52 friend class wmtk::HDF5Reader;
53
54 using Scalar = T;
55
56 using AttributeType = AttributeType_; // CachingAttribute<T>;
57
58 // Even though the attribute dimension is specified above by the Dim parameter, we still allow
59 // users to specify the dimension of the attributes they extract - this lets Dim=Eigen::Dynamic
60 // accessors be passed around with internal logic specifying the appropriate dimension
61 // Eigen::Map<Vector<T,D>>
62 template <int D = Dim>
63 using MapResult = typename AttributeType::template MapResult<D>;
64 // Eigen::Map<const Vector<T,D>>
65 template <int D = Dim>
66 using ConstMapResult = typename AttributeType::template ConstMapResult<D>;
67
68
69 Accessor(MeshType& m, const TypedAttributeHandle<T>& handle);
70 Accessor(const MeshType& m, const TypedAttributeHandle<T>& handle);
71
72 template <typename OMType, typename OAT, int D>
74
75 // dimension of the attribute (the return types are a dimensino-vector)
76 auto dimension() const -> int64_t;
77 // the number of (vector-)values that can be written to. Note this is can be larger than the
78 // size of the mesh
79 auto reserved_size() const -> int64_t;
80 // the default value assigned to new values of this attribute (for vector valued attributes
81 // every dimension holds is this)
82 auto default_value() const -> const Scalar&;
83
84
85 // =============
86 // Access methods
87 // =============
88 // NOTE: If any compilation warnings occur check that there is an overload for an index method
89
90
91 // Access to a vector-valued attribute
98 template <int D = Dim, typename ArgType = wmtk::Tuple>
99 MapResult<std::max(D, Dim)> vector_attribute(const ArgType& t);
106 template <int D = Dim, typename ArgType = wmtk::Tuple>
107 ConstMapResult<std::max(D, Dim)> const_vector_attribute(const ArgType& t) const;
108
117 template <typename ArgType>
118 Scalar& scalar_attribute(const ArgType& t);
127 template <typename ArgType>
128 const Scalar& const_scalar_attribute(const ArgType& t) const;
129
130 // For topological attributes we want to select teh value (global_id) by its (local_id) index,
131 // for whichever local index this attribute lies on For instance, to get the global index of a
132 // vertex from a FV matrix we want to access const_vector_attribute(global_id)(local_vid). This
133 // function lets us use the primitive type to identify which local id we want.
134 const T& const_topological_scalar_attribute(const Tuple& t, PrimitiveType pt) const;
135
136
137 MeshType& mesh();
138 const MeshType& mesh() const;
139
140 int64_t transaction_depth() const;
141
142protected:
151 int64_t index(const Tuple& t) const;
152 // Simplex's primitive type must match this attribute, should assert failure if not
161 int64_t index(const simplex::Simplex& t) const;
165 int64_t index(const simplex::IdSimplex& t) const;
166
167 int64_t index(const int64_t t) const;
168
169 // The underlying attribute object.
171 // The underlying attribute object
172 const AttributeType& attribute() const;
173
174public:
176 const TypedAttributeHandle<T>& typed_handle() const;
178
179private:
181 MeshType& m_mesh;
183};
184} // namespace wmtk::attribute
185#include "Accessor.hxx"
The Tuple is the basic navigation tool in our mesh data structure.
Definition Tuple.hpp:19
An Accessor that uses tuples for accessing attributes instead of indices.
Definition Accessor.hpp:44
friend class wmtk::tests_3d::DEBUG_TetMesh
Definition Accessor.hpp:50
int64_t transaction_depth() const
Definition Accessor.hxx:135
AttributeType_ AttributeType
Definition Accessor.hpp:56
typename AttributeType::template MapResult< D > MapResult
Definition Accessor.hpp:63
typename AttributeType::template ConstMapResult< D > ConstMapResult
Definition Accessor.hpp:66
const TypedAttributeHandle< T > & typed_handle() const
Definition Accessor.hxx:169
MapResult< std::max(D, Dim)> vector_attribute(const ArgType &t)
Access function for a vector attribute.
int64_t index(const Tuple &t) const
Retrieve the global ID of the given simplex.
Definition Accessor.hxx:32
const Scalar & const_scalar_attribute(const ArgType &t) const
Constant access function for a scalar attribute.
MeshAttributeHandle handle() const
Definition Accessor.hxx:175
friend class wmtk::tests::DEBUG_EdgeMesh
Definition Accessor.hpp:48
AttributeType & m_attribute
Definition Accessor.hpp:182
const T & const_topological_scalar_attribute(const Tuple &t, PrimitiveType pt) const
Definition Accessor.hxx:103
friend class wmtk::tests::DEBUG_PointMesh
Definition Accessor.hpp:47
auto default_value() const -> const Scalar &
Definition Accessor.hxx:153
auto reserved_size() const -> int64_t
Definition Accessor.hxx:141
AttributeType & attribute()
Definition Accessor.hxx:159
ConstMapResult< std::max(D, Dim)> const_vector_attribute(const ArgType &t) const
Constant access function for a vector attribute.
Scalar & scalar_attribute(const ArgType &t)
Access function for a scalar attribute.
TypedAttributeHandle< T > m_handle
Definition Accessor.hpp:180
auto dimension() const -> int64_t
Definition Accessor.hxx:147
PrimitiveType primitive_type() const
Definition Accessor.hxx:181
friend class wmtk::tests::DEBUG_TriMesh
Definition Accessor.hpp:49
Handle that represents attributes for some mesh.