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>
48 assert(t.primitive_type() == primitive_type());
49 return this->mesh().id(t);
51
52template <typename T, typename MeshType, typename AttributeType, int Dim>
53template <int D, typename ArgType>
55 -> ConstMapResult<std::max(D, Dim)>
57 const int64_t idx = this->index(t);
58 return m_attribute.template const_vector_attribute<std::max(D, Dim)>(idx);
60
61template <typename T, typename MeshType, typename AttributeType, int Dim>
62template <int D, typename ArgType>
64 -> MapResult<std::max(D, Dim)>
65{
66 const int64_t idx = this->index(t);
67 return m_attribute.template vector_attribute<std::max(D, Dim)>(idx);
68}
69
70template <typename T, typename MeshType, typename AttributeType, int Dim>
71template <typename ArgType>
73{
74 const int64_t idx = this->index(t);
75 return m_attribute.scalar_attribute(idx);
76}
77
78template <typename T, typename MeshType, typename AttributeType, int Dim>
79template <typename ArgType>
81 -> const Scalar&
82{
83 const int64_t idx = this->index(t);
84 return m_attribute.const_scalar_attribute(idx);
85}
86// template <typename T, typename MeshType, typename AttributeType, int Dim>
87// template <typename ArgType>
88// auto Accessor<T, MeshType, AttributeType, Dim>::topological_scalar_attribute(const ArgType& t) ->
89// Scalar&
90//{
91// const int64_t idx = this->index(t);
92// return m_attribute.topological_scalar_attribute<Dim>(idx);
93// }
94
96template <typename T, typename MeshType, typename AttributeType, int Dim>
98 const Tuple& t,
99 PrimitiveType pt) const
100{
101 assert(mesh().top_simplex_type() == m_handle.primitive_type());
102 switch (pt) {
104 return m_attribute.const_vector_single_value(t.global_cid(), t.local_vid());
106 return m_attribute.const_vector_single_value(t.global_cid(), t.local_eid());
108 return m_attribute.const_vector_single_value(t.global_cid(), t.local_fid());
109 case PrimitiveType::Tetrahedron: [[fallthrough]];
110 default: {
111 const static T x(0);
112 return x;
113 }
114 }
115}
116
117template <typename T, typename MeshType, typename AttributeType, int Dim>
119{
120 return m_mesh;
121}
122template <typename T, typename MeshType, typename AttributeType, int Dim>
124{
125 return m_mesh;
126}
127
128template <typename T, typename MeshType, typename AttributeType, int Dim>
130{
131 return attribute().reserved_size();
132}
133
134template <typename T, typename MeshType, typename AttributeType, int Dim>
136{
137 return attribute().dimension();
138}
139
140template <typename T, typename MeshType, typename AttributeType, int Dim>
142{
143 return attribute().default_value();
144}
145
146template <typename T, typename MeshType, typename AttributeType, int Dim>
148{
149 return m_attribute;
150}
151template <typename T, typename MeshType, typename AttributeType, int Dim>
153{
154 return m_attribute;
155}
156template <typename T, typename MeshType, typename AttributeType, int Dim>
159{
160 return m_handle;
161}
162template <typename T, typename MeshType, typename AttributeType, int Dim>
167
168template <typename T, typename MeshType, typename AttributeType, int Dim>
170{
171 return handle().primitive_type();
172}
173// template class Accessor<char>;
174// template class Accessor<int64_t>;
175// template class Accessor<double>;
176// template class Accessor<Rational>;
177} // 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:28
AttributeType_ AttributeType
Definition Accessor.hpp:33
typename AttributeType::template MapResult< D > MapResult
Definition Accessor.hpp:40
typename AttributeType::template ConstMapResult< D > ConstMapResult
Definition Accessor.hpp:43
const TypedAttributeHandle< T > & typed_handle() const
Definition Accessor.hxx:157
MapResult< std::max(D, Dim)> vector_attribute(const ArgType &t)
int64_t index(const Tuple &t) const
Definition Accessor.hxx:32
const Scalar & const_scalar_attribute(const ArgType &t) const
MeshAttributeHandle handle() const
Definition Accessor.hxx:163
const T & const_topological_scalar_attribute(const Tuple &t, PrimitiveType pt) const
Definition Accessor.hxx:97
auto default_value() const -> const Scalar &
Definition Accessor.hxx:141
auto reserved_size() const -> int64_t
Definition Accessor.hxx:129
AttributeType & attribute()
Definition Accessor.hxx:147
ConstMapResult< std::max(D, Dim)> const_vector_attribute(const ArgType &t) const
Scalar & scalar_attribute(const ArgType &t)
auto dimension() const -> int64_t
Definition Accessor.hxx:135
PrimitiveType primitive_type() const
Definition Accessor.hxx:169
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