Wildmeshing Toolkit
Loading...
Searching...
No Matches
Accessor.hxx
Go to the documentation of this file.
1#pragma once
3#include "Accessor.hpp"
5
6namespace wmtk::attribute {
7
8template <typename T, typename MeshType, typename AttributeType, int Dim>
10 MeshType& m,
11 const TypedAttributeHandle<T>& handle)
12 : m_handle(handle)
13 , m_mesh(m)
14 , m_attribute(mesh().m_attribute_manager.get(m_handle).attribute(m_handle.m_base_handle))
15{}
16template <typename T, typename MeshType, typename AttributeType, int Dim>
18 const MeshType& m,
19 const TypedAttributeHandle<T>& handle)
20 : Accessor(const_cast<MeshType&>(m), handle)
21{}
22template <typename T, typename MeshType, typename AttributeType, int Dim>
23template <typename OMType, typename OAT, int D>
25 : Accessor(static_cast<const MeshType&>(o.mesh()), o.handle())
26{
27 static_assert(Dim == Eigen::Dynamic || D == Eigen::Dynamic || Dim == D);
28}
29
30
31template <typename T, typename MeshType, typename AttributeType, int Dim>
33{
34 assert(mesh().is_valid(t));
35 return this->mesh().id(t, typed_handle().primitive_type());
36}
37
38template <typename T, typename MeshType, typename AttributeType, int Dim>
40{
41 assert(t.primitive_type() == primitive_type());
42 return this->index(t.tuple());
43}
44
45template <typename T, typename MeshType, typename AttributeType, int Dim>
47{
48 assert(t.primitive_type() == primitive_type());
49 return this->mesh().id(t);
50}
51
52template <typename T, typename MeshType, typename AttributeType_, int Dim>
53inline int64_t Accessor<T, MeshType, AttributeType_, Dim>::index(const int64_t t) const
54{
55 return t;
56}
57
58template <typename T, typename MeshType, typename AttributeType, int Dim>
59template <int D, typename ArgType>
61 -> ConstMapResult<std::max(D, Dim)>
62{
63 const int64_t idx = this->index(t);
64 return m_attribute.template const_vector_attribute<std::max(D, Dim)>(idx);
65}
66
67template <typename T, typename MeshType, typename AttributeType, int Dim>
68template <int D, typename ArgType>
70 -> MapResult<std::max(D, Dim)>
71{
72 const int64_t idx = this->index(t);
73 return m_attribute.template vector_attribute<std::max(D, Dim)>(idx);
74}
75
76template <typename T, typename MeshType, typename AttributeType, int Dim>
77template <typename ArgType>
80 const int64_t idx = this->index(t);
81 return m_attribute.scalar_attribute(idx);
83
84template <typename T, typename MeshType, typename AttributeType, int Dim>
85template <typename ArgType>
87 -> const Scalar&
88{
89 const int64_t idx = this->index(t);
90 return m_attribute.const_scalar_attribute(idx);
91}
92// template <typename T, typename MeshType, typename AttributeType, int Dim>
93// template <typename ArgType>
94// auto Accessor<T, MeshType, AttributeType, Dim>::topological_scalar_attribute(const ArgType& t) ->
95// Scalar&
96//{
97// const int64_t idx = this->index(t);
98// return m_attribute.topological_scalar_attribute<Dim>(idx);
99// }
100
101
102template <typename T, typename MeshType, typename AttributeType, int Dim>
104 const Tuple& t,
105 PrimitiveType pt) const
106{
107 assert(mesh().top_simplex_type() == m_handle.primitive_type());
108 switch (pt) {
110 return m_attribute.const_vector_single_value(t.global_cid(), t.local_vid());
112 return m_attribute.const_vector_single_value(t.global_cid(), t.local_eid());
114 return m_attribute.const_vector_single_value(t.global_cid(), t.local_fid());
115 case PrimitiveType::Tetrahedron: [[fallthrough]];
116 default: {
117 const static T x(0);
118 return x;
119 }
120 }
121}
122
123template <typename T, typename MeshType, typename AttributeType, int Dim>
125{
126 return m_mesh;
127}
128template <typename T, typename MeshType, typename AttributeType, int Dim>
130{
131 return m_mesh;
132}
133
134template <typename T, typename MeshType, typename AttributeType_, int Dim>
136{
137 return attribute().transaction_depth();
139
140template <typename T, typename MeshType, typename AttributeType, int Dim>
142{
143 return attribute().reserved_size();
144}
145
146template <typename T, typename MeshType, typename AttributeType, int Dim>
148{
149 return attribute().dimension();
150}
152template <typename T, typename MeshType, typename AttributeType, int Dim>
154{
155 return attribute().default_value();
156}
157
158template <typename T, typename MeshType, typename AttributeType, int Dim>
160{
161 return m_attribute;
162}
163template <typename T, typename MeshType, typename AttributeType, int Dim>
166 return m_attribute;
168template <typename T, typename MeshType, typename AttributeType, int Dim>
171{
172 return m_handle;
173}
174template <typename T, typename MeshType, typename AttributeType, int Dim>
177 return MeshAttributeHandle(m_mesh, m_handle);
178}
179
180template <typename T, typename MeshType, typename AttributeType, int Dim>
182{
183 return handle().primitive_type();
184}
185// template class Accessor<char>;
186// template class Accessor<int64_t>;
187// template class Accessor<double>;
188// template class Accessor<Rational>;
189} // namespace wmtk::attribute
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
An Accessor that uses tuples for accessing attributes instead of indices.
Definition Accessor.hpp:44
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
const T & const_topological_scalar_attribute(const Tuple &t, PrimitiveType pt) const
Definition Accessor.hxx:103
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.
auto dimension() const -> int64_t
Definition Accessor.hxx:147
PrimitiveType primitive_type() const
Definition Accessor.hxx:181
Accessor(MeshType &m, const TypedAttributeHandle< T > &handle)
Definition Accessor.hxx:9
Handle that represents attributes for some mesh.
PrimitiveType primitive_type() const
Definition IdSimplex.hpp:23
const Tuple & tuple() const
Definition Simplex.hpp:53
PrimitiveType primitive_type() const
Definition Simplex.hpp:51