14#include <lagrange/AttributeFwd.h>
15#include <lagrange/utils/SharedSpan.h>
16#include <lagrange/utils/span.h>
37template <
typename ValueType>
172template <
typename ValueType_>
186 std::is_same_v<ValueType, int8_t> || std::is_same_v<ValueType, int16_t> ||
187 std::is_same_v<ValueType, int32_t> || std::is_same_v<ValueType, int64_t> ||
188 std::is_same_v<ValueType, uint8_t> || std::is_same_v<ValueType, uint16_t> ||
189 std::is_same_v<ValueType, uint32_t> || std::is_same_v<ValueType, uint64_t> ||
190 std::is_same_v<ValueType, float> || std::is_same_v<ValueType, double>,
191 "Attribute's ValueType template parameter can only be float, double, or a fixed size "
256 template <
typename OtherValue>
270 template <
typename OtherValue>
590 template <
typename V>
691 void growth_check(
size_t new_cap);
size_t m_num_channels
Number of channel for each value.
Definition Attribute.h:164
void unsafe_set_element_type(AttributeElement element)
Sets the attribute element type.
Definition Attribute.h:154
void unsafe_set_usage(AttributeUsage usage)
Sets the attribute usage tag.
Definition Attribute.h:145
AttributeBase & operator=(const AttributeBase &other)=default
Assignment copy operator.
AttributeBase(AttributeElement element, AttributeUsage usage, size_t num_channels)
Constructs a new instance.
Definition Attribute.cpp:46
virtual ~AttributeBase()
Destroys the object.
AttributeUsage get_usage() const
Gets the attribute usage tag.
Definition Attribute.h:129
AttributeUsage m_usage
Attribute usage tag.
Definition Attribute.h:161
AttributeElement get_element_type() const
Gets the attribute element type.
Definition Attribute.h:122
AttributeBase(const AttributeBase &other)=default
Copy constructor.
virtual AttributeValueType get_value_type() const =0
Gets the attribute value type.
AttributeBase & operator=(AttributeBase &&other)=default
Assignment move operator.
AttributeBase(AttributeBase &&other)=default
Move constructor.
AttributeElement m_element
Element type (vertex, facet, indexed, etc.).
Definition Attribute.h:158
size_t get_num_channels() const
Gets the number of channels for the attribute.
Definition Attribute.h:136
Derived attribute class that stores the actual information.
Definition Attribute.h:174
bool is_managed() const
Checks whether the attribute is managing the lifetime of the underlying buffer.
Definition Attribute.h:525
lagrange::span< const ValueType > get_middle(size_t first_element, size_t num_elements) const
Returns a read-only view of the attribute values for the middle elements in the buffer.
Definition Attribute.cpp:583
ValueType get_default_value() const
Gets the default value to use when growing the attribute.
Definition Attribute.h:357
lagrange::span< const ValueType > get_all() const
Returns a read-only view of the buffer spanning num elements x num channels.
Definition Attribute.cpp:525
lagrange::span< ValueType > m_view
Writable pointer to the buffer storing the attribute data.
Definition Attribute.h:725
AttributeCopyPolicy get_copy_policy() const
Gets the copy policy for external buffers.
Definition Attribute.h:413
Attribute & operator=(Attribute &&other) noexcept
Assignment move operator.
AttributeValueType get_value_type() const override
Gets the attribute value type.
lagrange::span< const ValueType > get_row(size_t element) const
Returns a read-only view of the attribute values for the element in the buffer.
Definition Attribute.cpp:599
AttributeCastPolicy get_cast_policy() const
Gets the cast policy.
Definition Attribute.h:427
bool m_is_external
Flag to determine whether an attribute is using an external or internal buffer.
Definition Attribute.h:748
lagrange::span< ValueType > ref_last(size_t num_elements)
Returns a writable view of the attribute values for the last elements in the buffer.
Definition Attribute.cpp:577
void reserve_entries(size_t new_cap)
Reserve enough memory for new_cap entries.
Definition Attribute.cpp:427
AttributeGrowthPolicy m_growth_policy
Growth policy for external buffers.
Definition Attribute.h:732
static constexpr bool IsIndexed
Whether this attribute type is indexed.
Definition Attribute.h:180
lagrange::span< ValueType > ref_first(size_t num_elements)
Returns a writable view of the attribute values for the first elements in the buffer.
Definition Attribute.cpp:565
ValueType_ ValueType
Attribute value type.
Definition Attribute.h:177
~Attribute() override
Destroys the object.
lagrange::span< const ValueType > get_first(size_t num_elements) const
Returns a read-only view of the attribute values for the first elements in the buffer.
Definition Attribute.cpp:559
void wrap_const(span< const ValueType > buffer, size_t num_elements)
Wraps a const external buffer into the attribute.
Definition Attribute.cpp:334
lagrange::span< ValueType > ref_middle(size_t first_element, size_t num_elements)
Returns a writable view of the attribute values for the middle elements in the buffer.
Definition Attribute.cpp:591
AttributeCastPolicy m_cast_policy
Cast policy when converting from this attribute.
Definition Attribute.h:744
void shrink_to_fit()
Shrink attribute buffer to fit the current number of entries.
Definition Attribute.cpp:393
bool empty() const
Test whether the attribute is empty (its size is 0).
Definition Attribute.h:501
void create_internal_copy()
Creates an internal copy of the attribute data.
Definition Attribute.cpp:365
bool is_read_only() const
Checks whether the attribute is external and pointing to a const buffer.
Definition Attribute.h:533
void set_write_policy(AttributeWritePolicy policy)
Sets the write policy for read-only external buffers.
Definition Attribute.h:392
bool m_is_read_only
Flag to determine whether an external attribute is read-only or writable.
Definition Attribute.h:753
void wrap(span< ValueType > buffer, size_t num_elements)
Wraps an external buffer into the attribute.
Definition Attribute.cpp:309
AttributeWritePolicy m_write_policy
Policy for write access to read-only external buffers.
Definition Attribute.h:738
AttributeShrinkPolicy m_shrink_policy
Shrink policy for external buffers.
Definition Attribute.h:735
std::shared_ptr< const ValueType > m_owner
Optional aliased ptr to extend the lifetime of memory owner object of external buffer.
Definition Attribute.h:717
Attribute & operator=(const Attribute &other)
Assignment copy operator.
static Attribute cast_copy(const Attribute< OtherValue > &other)
Cast copy operator.
lagrange::span< ValueType > ref_row(size_t element)
Returns a writable view of the attribute values for the element in the buffer.
Definition Attribute.cpp:605
size_t get_num_elements() const
Gets the number of elements.
Definition Attribute.h:508
bool is_external() const
Checks whether an attribute buffer is external or internally managed.
Definition Attribute.h:516
void set_copy_policy(AttributeCopyPolicy policy)
Sets the copy policy for external buffers.
Definition Attribute.h:406
void set_growth_policy(AttributeGrowthPolicy policy)
Sets the growth policy for external buffers.
Definition Attribute.h:364
AttributeShrinkPolicy get_shrink_policy() const
Gets the shrink policy for external buffers.
Definition Attribute.h:385
ValueType get(size_t i, size_t c) const
Gets an entry for element i, at channel p.
Definition Attribute.cpp:497
std::vector< ValueType > m_data
Internal buffer storing the data (when the attribute is not external).
Definition Attribute.h:713
void clear()
Clears the attribute buffer (new number of elements is 0).
Definition Attribute.cpp:381
Attribute(Attribute &&other) noexcept
Move constructor.
ValueType m_default_value
Default values used to populate buffer when the attribute grows.
Definition Attribute.h:720
lagrange::span< const ValueType > get_last(size_t num_elements) const
Returns a read-only view of the attribute values for the last elements in the buffer.
Definition Attribute.cpp:571
size_t m_num_elements
Number of elements associated with the attribute.
Definition Attribute.h:756
void set_default_value(ValueType value)
Sets the default value to use when growing the attribute.
Definition Attribute.h:352
void resize_elements(size_t num_elements)
Resize the buffer to contain num_elements elements.
Definition Attribute.cpp:437
lagrange::span< ValueType > ref_all()
Returns a writable view of the buffer spanning num elements x num channels.
Definition Attribute.cpp:552
AttributeWritePolicy get_write_policy() const
Gets the write policy for read-only external buffers.
Definition Attribute.h:399
Attribute(const Attribute &other)
Copy constructor.
lagrange::span< const ValueType > m_const_view
Read-only pointer to the buffer storing the attribute data.
Definition Attribute.h:729
void set_shrink_policy(AttributeShrinkPolicy policy)
Sets the shrink policy for external buffers.
Definition Attribute.h:378
void set_cast_policy(AttributeCastPolicy policy)
Sets the cast policy.
Definition Attribute.h:420
AttributeCopyPolicy m_copy_policy
Copy policy for external buffers.
Definition Attribute.h:741
Attribute(AttributeElement element, AttributeUsage usage, size_t num_channels)
Constructs a new instance.
Definition Attribute.cpp:78
Attribute & cast_assign(const Attribute< OtherValue > &other)
Cast assignment operator.
ValueType & ref(size_t i, size_t c)
Gets a writable reference to the entry for element i, at channel p.
Definition Attribute.cpp:503
void insert_elements(span< const ValueType > values)
Inserts values for new elements.
Definition Attribute.cpp:455
AttributeGrowthPolicy get_growth_policy() const
Gets the growth policy for external buffers.
Definition Attribute.h:371
Shared span with ownership tracking.
Definition SharedSpan.h:36
AttributeShrinkPolicy
Policy for shrinking external attribute buffers.
Definition AttributeFwd.h:117
AttributeUsage
Usage tag indicating how the attribute should behave under mesh transformations.
Definition AttributeFwd.h:54
AttributeGrowthPolicy
Policy for growing external attribute buffers.
Definition AttributeFwd.h:96
AttributeCopyPolicy
Policy for copying attribute that are views onto external buffers.
Definition AttributeFwd.h:161
AttributeElement
Type of element to which the attribute is attached.
Definition AttributeFwd.h:26
AttributeValueType
Enum describing at runtime the value type of an attribute.
Definition AttributeValueType.h:25
AttributeWritePolicy
Policy for attempting to write to read-only external buffers.
Definition AttributeFwd.h:138
AttributeCastPolicy
Policy for remapping invalid values when casting to a different value type.
Definition AttributeFwd.h:182
@ ErrorIfExternal
Throws an exception when trying to shrink an external buffer (even if the new size is still within th...
Definition AttributeFwd.h:120
@ ErrorIfExternal
Throws an exception when trying to grow an external buffer (even if the new size is still within the ...
Definition AttributeFwd.h:99
@ CopyIfExternal
Copy the buffer during copy if the attribute points to an external buffer.
Definition AttributeFwd.h:162
@ ErrorIfReadOnly
Throws an exception when trying to write to a read-only buffer.
Definition AttributeFwd.h:139
@ RemapInvalidIndices
Map invalue values only if the AttributeUsage represents indices.
Definition AttributeFwd.h:183
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition span.h:27
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition attribute_string_utils.h:21
Main namespace for Lagrange.