13 writer.
write(m_name, dim, dimension(), m_data, m_default_value);
19 : m_dimension(dimension)
20 , m_default_value(default_value)
33 std::map<std::string, size_t> hashes;
34 hashes[
"dimension"] = m_dimension;
35 if constexpr (std::is_same_v<T, Rational>) {
36 constexpr static std::hash<std::string> h;
37 hashes[
"default_value"] = h(m_default_value.serialize());
39 hashes[
"default_value"] = m_default_value;
63 if (size >= 0 && size > reserved_size()) {
64 m_data.resize(m_dimension * size, m_default_value);
70 return reserved_size(m_data);
75 return data.size() / m_dimension;
89 assert(val.size() % m_dimension == 0);
90 m_data = std::move(val);
95 for (int64_t i = 0; i < new2old.size(); ++i) {
96 vector_attribute(i) = vector_attribute(new2old[i]);
99 m_data.resize(new2old.size() * m_dimension);
102#if defined(__GNUG__) && !defined(__clang__)
103#pragma GCC diagnostic push
104#pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
109 std::vector<Eigen::Index> indices(dimension());
110 std::iota(indices.begin(), indices.end(), Eigen::Index(0));
111 index_remap(old2new, indices);
117 if constexpr (std::is_same_v<T, int64_t>) {
118 for (int64_t i = 0; i < reserved_size(); ++i) {
119 auto vec = vector_attribute(i);
120 for (Eigen::Index idx : cols) {
121 int64_t& v = vec(idx);
127 throw std::runtime_error(
"Only int64_t attributes can be index remapped.");
130#if defined(__GNUG__) && !defined(__clang__)
131#pragma GCC diagnostic pop
139#if defined(WMTK_ENABLED_DEV_MODE)
143#define VECTOR_DEC(TYPE, D) \
144 template auto Attribute<TYPE>::const_vector_single_value<D>( \
146 int8_t single_index) const -> const TYPE&; \
147 template auto Attribute<TYPE>::vector_single_value<D>( \
149 int8_t single_index) -> TYPE&; \
150 template auto Attribute<TYPE>::const_vector_attribute<D>(int64_t index) const \
151 -> ConstMapResult<D>; \
152 template auto Attribute<TYPE>::vector_attribute<D>(int64_t index) -> MapResult<D>;\
153 template auto Attribute<TYPE>::const_vector_attribute<D>(int64_t index, const std::vector<TYPE>&) const \
154 -> ConstMapResult<D>; \
155 template auto Attribute<TYPE>::vector_attribute<D>(int64_t index, std::vector<TYPE>&) const -> MapResult<D>;
157#define SCALAR_DEC(TYPE) \
158 template auto Attribute<TYPE>::const_scalar_attribute(int64_t index) const \
160 template auto Attribute<TYPE>::scalar_attribute(int64_t index) -> TYPE&;\
161 template auto Attribute<TYPE>::const_scalar_attribute(int64_t index, const std::vector<TYPE>& ) const \
163 template auto Attribute<TYPE>::scalar_attribute(int64_t index, std::vector<TYPE>&) const-> TYPE&;
168 VECTOR_DEC(TYPE, -1) \
169 VECTOR_DEC(TYPE, 1) \
170 VECTOR_DEC(TYPE, 2) \
171 VECTOR_DEC(TYPE, 3) \
172 VECTOR_DEC(TYPE, 4) \
173 VECTOR_DEC(TYPE, 5) \
virtual bool write(const int dim)=0
This class stores data of type T in a vector.
Attribute & operator=(Attribute &&o)
Attribute(const std::string &name, int64_t dimension, T default_value=T(0), int64_t size=0)
Initialize the 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...
const std::string & name() const
bool operator==(const Attribute< T > &o) const
void serialize(int dim, MeshWriter &writer) const
void reserve(int64_t size)
void consolidate(const std::vector< int64_t > &new2old)
Consolidate the vector, using the new2old map m provided and resizing the vector to m....
int64_t reserved_size() const
The total number of elements in a vector.
void set(std::vector< T > val)
Replace the internal data with val.
std::map< std::string, size_t > child_hashes() const override
std::size_t vector_hash(const std::vector< size_t > &data)