14#include <lagrange/AttributeFwd.h>
15#include <lagrange/utils/SharedSpan.h>
16#include <lagrange/utils/span.h>
151template <
typename ValueType_>
165 std::is_same_v<ValueType, int8_t> || std::is_same_v<ValueType, int16_t> ||
166 std::is_same_v<ValueType, int32_t> || std::is_same_v<ValueType, int64_t> ||
167 std::is_same_v<ValueType, uint8_t> || std::is_same_v<ValueType, uint16_t> ||
168 std::is_same_v<ValueType, uint32_t> || std::is_same_v<ValueType, uint64_t> ||
169 std::is_same_v<ValueType, float> || std::is_same_v<ValueType, double>,
170 "Attribute's ValueType template parameter can only be float, double, or a fixed size integer type.");
234 template <
typename OtherValue>
248 template <
typename OtherValue>
650 void growth_check(
size_t new_cap);
Base handle for attributes.
Definition: Attribute.h:41
size_t m_num_channels
Number of channel for each value.
Definition: Attribute.h:143
void unsafe_set_element_type(AttributeElement element)
Sets the attribute element type.
Definition: Attribute.h:133
void unsafe_set_usage(AttributeUsage usage)
Sets the attribute usage tag.
Definition: Attribute.h:124
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:32
virtual ~AttributeBase()
Destroys the object.
AttributeUsage get_usage() const
Gets the attribute usage tag.
Definition: Attribute.h:108
AttributeUsage m_usage
Attribute usage tag.
Definition: Attribute.h:140
AttributeElement get_element_type() const
Gets the attribute element type.
Definition: Attribute.h:101
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:137
size_t get_num_channels() const
Gets the number of channels for the attribute.
Definition: Attribute.h:115
Derived attribute class that stores the actual information.
Definition: Attribute.h:153
bool is_managed() const
Checks whether the attribute is managing the lifetime of the underlying buffer.
Definition: Attribute.h:489
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:523
ValueType get_default_value() const
Gets the default value to use when growing the attribute.
Definition: Attribute.h:335
lagrange::span< const ValueType > get_all() const
Returns a read-only view of the buffer spanning num elements x num channels.
Definition: Attribute.cpp:486
lagrange::span< ValueType > m_view
Writable pointer to the buffer storing the attribute data.
Definition: Attribute.h:684
AttributeCopyPolicy get_copy_policy() const
Get the copy policy for external buffers.
Definition: Attribute.h:391
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:539
bool m_is_external
Flag to determine whether an attribute is using an external or internal buffer.
Definition: Attribute.h:704
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:517
void reserve_entries(size_t new_cap)
Reserve enough memory for new_cap entries.
Definition: Attribute.cpp:388
AttributeGrowthPolicy m_growth_policy
Growth policy for external buffers.
Definition: Attribute.h:691
static constexpr bool IsIndexed
Whether this attribute type is indexed.
Definition: Attribute.h:159
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:505
ValueType_ ValueType
Attribute value type.
Definition: Attribute.h:156
~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:499
void wrap_const(span< const ValueType > buffer, size_t num_elements)
Wraps a const external buffer into the attribute.
Definition: Attribute.cpp:296
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:531
void shrink_to_fit()
Shrink attribute buffer to fit the current number of entries.
Definition: Attribute.cpp:355
bool empty() const
Test whether the attribute is empty (its size is 0).
Definition: Attribute.h:465
void create_internal_copy()
Creates an internal copy of the attribute data.
Definition: Attribute.cpp:327
bool is_read_only() const
Checks whether the attribute is external and pointing to a const buffer.
Definition: Attribute.h:497
void set_write_policy(AttributeWritePolicy policy)
Sets the write policy for read-only external buffers.
Definition: Attribute.h:370
bool m_is_read_only
Flag to determine whether an external attribute is read-only or writable.
Definition: Attribute.h:709
void wrap(span< ValueType > buffer, size_t num_elements)
Wraps an external buffer into the attribute.
Definition: Attribute.cpp:271
AttributeWritePolicy m_write_policy
Policy for write access to read-only external buffers.
Definition: Attribute.h:697
AttributeShrinkPolicy m_shrink_policy
Shrink policy for external buffers.
Definition: Attribute.h:694
std::shared_ptr< const ValueType > m_owner
Optional aliased ptr to extend the lifetime of memory owner object of external buffer.
Definition: Attribute.h:676
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:545
size_t get_num_elements() const
Gets the number of elements.
Definition: Attribute.h:472
bool is_external() const
Checks whether an attribute buffer is external or internally managed.
Definition: Attribute.h:480
void set_copy_policy(AttributeCopyPolicy policy)
Set copy policy for external buffers.
Definition: Attribute.h:384
void set_growth_policy(AttributeGrowthPolicy policy)
Sets the growth policy for external buffers.
Definition: Attribute.h:342
AttributeShrinkPolicy get_shrink_policy() const
Gets the shrink policy for external buffers.
Definition: Attribute.h:363
ValueType get(size_t i, size_t c) const
Gets an entry for element i, at channel p.
Definition: Attribute.cpp:458
std::vector< ValueType > m_data
Internal buffer storing the data (when the attribute is not external).
Definition: Attribute.h:672
void clear()
Clears the attribute buffer (new number of elements is 0).
Definition: Attribute.cpp:343
Attribute(Attribute &&other) noexcept
Move constructor.
ValueType m_default_value
Default values used to populate buffer when the attribute grows.
Definition: Attribute.h:679
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:511
size_t m_num_elements
Number of elements associated with the attribute.
Definition: Attribute.h:712
void set_default_value(ValueType value)
Sets the default value to use when growing the attribute.
Definition: Attribute.h:330
void resize_elements(size_t num_elements)
Resize the buffer to contain num_elements elements.
Definition: Attribute.cpp:398
lagrange::span< ValueType > ref_all()
Returns a writable view of the buffer spanning num elements x num channels.
Definition: Attribute.cpp:492
AttributeWritePolicy get_write_policy() const
Gets the write policy for read-only external buffers.
Definition: Attribute.h:377
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:688
void set_shrink_policy(AttributeShrinkPolicy policy)
Sets the shrink policy for external buffers.
Definition: Attribute.h:356
AttributeCopyPolicy m_copy_policy
Copy policy for external buffers.
Definition: Attribute.h:700
Attribute(AttributeElement element, AttributeUsage usage, size_t num_channels)
Constructs a new instance.
Definition: Attribute.cpp:64
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:464
void insert_elements(span< const ValueType > values)
Inserts values for new elements.
Definition: Attribute.cpp:416
AttributeGrowthPolicy get_growth_policy() const
Gets the growth policy for external buffers.
Definition: Attribute.h:349
Shared span with ownership tracking.
Definition: SharedSpan.h:36
AttributeWritePolicy
Policy for attempting to write to read-only external buffers.
Definition: AttributeFwd.h:123
AttributeCopyPolicy
Policy for copying attribute that are views onto external buffers.
Definition: AttributeFwd.h:146
AttributeUsage
Usage tag indicating how the attribute should behave under mesh transformations.
Definition: AttributeFwd.h:54
AttributeShrinkPolicy
Policy for shrinking external attribute buffers.
Definition: AttributeFwd.h:110
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
AttributeGrowthPolicy
Policy for growing external attribute buffers.
Definition: AttributeFwd.h:96
@ ErrorIfReadOnly
Throws an exception when trying to write to a read-only buffer.
@ CopyIfExternal
Copy the buffer during copy if the attribute points to an external buffer.
@ ErrorIfExternal
Throws an exception when trying to shrink an external buffer (even if the new size is.
@ ErrorIfExternal
Throws an exception when trying to grow an external buffer (even if the new size is.
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition: span.h:27
Main namespace for Lagrange.
Definition: AABBIGL.h:30