Wildmeshing Toolkit
Loading...
Searching...
No Matches
Attribute.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <vector>
6#include "MapTypes.hpp"
7
8namespace wmtk {
9class MeshWriter;
10
11namespace attribute {
12
13
20template <typename T>
22{
23public:
24 using Scalar = T;
25 // typedefs
26 template <int D = Eigen::Dynamic>
28 template <int D = Eigen::Dynamic>
30
31
32 // attribute directly hashes its "children" components so it overrides "child_hashes"
33 std::map<std::string, size_t> child_hashes() const override;
34
35
36 void serialize(int dim, MeshWriter& writer) const;
37
48 Attribute(const std::string& name, int64_t dimension, T default_value = T(0), int64_t size = 0);
49
52
53 Attribute(const Attribute& o) = delete;
54 Attribute& operator=(const Attribute&& o) = delete;
55
56 ~Attribute() override;
57
59 template <int D = Eigen::Dynamic>
62 template <int D = Eigen::Dynamic>
64
66 const T& const_scalar_attribute(int64_t index) const;
68 T& scalar_attribute(int64_t index);
70 template <int D = Eigen::Dynamic>
71 const T& const_vector_single_value(int64_t index, int8_t vector_index) const;
73 template <int D = Eigen::Dynamic>
74 T& vector_single_value(int64_t index, int8_t vector_index);
75
79 void set(std::vector<T> val);
80
86 int64_t reserved_size() const;
87
91 int64_t dimension() const;
92 void reserve(int64_t size);
93
97 const T& default_value() const;
98
99 bool operator==(const Attribute<T>& o) const;
100
101
102
107 void consolidate(const std::vector<int64_t>& new2old);
108
113 void index_remap(const std::vector<T>& old2new);
114 void index_remap(const std::vector<T>& old2new, const std::vector<Eigen::Index>& cols);
115
121 template <int D = Eigen::Dynamic>
122 ConstMapResult<D> const_vector_attribute(int64_t index, const std::vector<T>& data) const;
123
129 template <int D = Eigen::Dynamic>
131 int64_t index,
132 const std::vector<T>& data) const;
137 template <int D = Eigen::Dynamic>
138 MapResult<D> vector_attribute(int64_t index, std::vector<T>& data) const;
139
145 template <int D = Eigen::Dynamic>
146 MapResult<D> vector_attribute_without_stride(int64_t index, std::vector<T>& data) const;
152 const T& const_scalar_attribute(int64_t index, const std::vector<T>& data) const;
157 T& scalar_attribute(int64_t index, std::vector<T>& data) const;
158
164 template <int D = Eigen::Dynamic>
166 int64_t index,
167 int8_t vector_index,
168 const std::vector<T>& data) const;
174 template <int D = Eigen::Dynamic>
176 int64_t index,
177 int8_t vector_index,
178 std::vector<T>& data) const;
179
180 // computes the "reserved size" but using the passed in data
181 int64_t reserved_size(const std::vector<T>& data) const;
182
183 const std::string& name() const;
184 void set_name(const std::string& name) { m_name = name; }
185
186protected:
187 std::vector<T> m_data;
188 int64_t m_dimension = -1;
190
191 std::string m_name;
192
193public:
194};
195
196
197} // namespace attribute
198} // namespace wmtk
199#if !defined(WMTK_ENABLED_DEV_MODE)
200#include "Attribute.hxx"
201#endif
This class stores data of type T in a vector.
Definition Attribute.hpp:22
Attribute & operator=(Attribute &&o)
T & vector_single_value(int64_t index, int8_t vector_index)
Access to a single a single value of a scalr attribute.
void index_remap(const std::vector< T > &old2new)
Applies the scalar old2new map to the indices in the attribute This is commonly used after a consolid...
ConstMapResult< D > const_vector_attribute(int64_t index, const std::vector< T > &data) const
Accesses the attribute using the specified vector as the underlying data This is internally used by t...
void set_name(const std::string &name)
ConstMapResult< D > const_vector_attribute(int64_t index) const
Access the value of an attribute at a particular index. If the dimension of the attribute is known at...
const std::string & name() const
Definition Attribute.cpp:79
const T & const_scalar_attribute(int64_t index) const
Access the value of a scalar attribute.
MapResult< T, D > MapResult
Definition Attribute.hpp:27
bool operator==(const Attribute< T > &o) const
Definition Attribute.cpp:53
void serialize(int dim, MeshWriter &writer) const
Definition Attribute.cpp:11
Attribute & operator=(const Attribute &&o)=delete
ConstMapResult< D > const_vector_attribute_without_stride(int64_t index, const std::vector< T > &data) const
Accesses the attribute using the specified vector as the underlying data This is internally used by t...
ConstMapResult< T, D > ConstMapResult
Definition Attribute.hpp:29
MapResult< D > vector_attribute_without_stride(int64_t index, std::vector< T > &data) const
Accesses the attribute using the specified vector as the underlying data This is internally used by t...
void reserve(int64_t size)
Definition Attribute.cpp:61
T & vector_single_value(int64_t index, int8_t vector_index, std::vector< T > &data) const
Accesses the attribute using the specified scalar as the underlying data This is internally used by t...
int64_t dimension() const
The number of values for each index.
void consolidate(const std::vector< int64_t > &new2old)
Consolidate the vector, using the new2old map m provided and resizing the vector to m....
Definition Attribute.cpp:93
int64_t reserved_size() const
The total number of elements in a vector.
Definition Attribute.cpp:68
const T & const_vector_single_value(int64_t index, int8_t vector_index) const
Access a single entry in a vector attribute. TODO: this might not actually be more performant than.
T & scalar_attribute(int64_t index)
Access the value of a scalar attribute. Assignment to the returned value will change the value.
std::vector< T > m_data
MapResult< D > vector_attribute(int64_t index)
Access the value of an attribute at a particular index. If the dimension of the attribute is known at...
const T & default_value() const
returns the default value of this attribute
void set(std::vector< T > val)
Replace the internal data with val.
Definition Attribute.cpp:86
Attribute(const Attribute &o)=delete
MapResult< D > vector_attribute(int64_t index, std::vector< T > &data) const
Accesses the attribute using the specified vector as the underlying data This is internally used by t...
std::map< std::string, size_t > child_hashes() const override
Definition Attribute.cpp:31
const T & const_vector_single_value(int64_t index, int8_t vector_index, const std::vector< T > &data) const
Accesses the attribute using the specified scalar as the underlying data This is internally used by t...