14#include "PyAttribute.h"
16#include <lagrange/Attribute.h>
17#include <lagrange/IndexedAttribute.h>
18#include <lagrange/SurfaceMeshTypes.h>
19#include <lagrange/internal/weak_ptr.h>
20#include <lagrange/utils/Error.h>
24namespace lagrange::python {
26class PyIndexedAttribute
38 auto attr = m_attr.lock();
39 if (attr ==
nullptr)
throw Error(
"Indexed attribute is no longer valid!");
43 template <
typename CallBack>
44 auto process(CallBack&& cb)
46 auto attr = m_attr.lock();
47 if (attr ==
nullptr)
throw Error(
"Indexed attribute is no longer valid!");
48 if (attr->get_element_type() !=
Indexed)
49 throw Error(
"Attribute is not an indexed attribute");
51#define LA_X_process(Index, ValueType) \
53 auto indexed_attr = dynamic_cast<IndexedAttribute<ValueType, Index>*>(attr.get()); \
54 if (indexed_attr != nullptr) { \
55 return cb(*indexed_attr); \
58#define LA_X_process_index(_, Index) LA_ATTRIBUTE_X(process, Index)
60#undef LA_X_process_index
62 throw Error(
"Cannot process indexed attribute with unsupported types!");
67 return process([&](
auto& indexed_attr) {
68 auto attr = m_attr.lock();
70 auto& value_attr = indexed_attr.values();
78 return process([&](
auto& indexed_attr) {
79 auto attr = m_attr.lock();
81 auto& index_attr = indexed_attr.indices();
NOT implemented: custom allocator support.
Definition shared_ptr.h:111
Definition PyAttribute.h:24
@ Indexed
Indexed mesh attributes.
Definition AttributeFwd.h:45
#define LA_SURFACE_MESH_INDEX_X(mode, data)
X Macro arguments to iterate over index types available for the SurfaceMesh<> class.
Definition SurfaceMeshTypes.h:71
#define la_debug_assert(...)
Debug assertion check.
Definition assert.h:194
@ Error
Throw an error if collision is detected.
Definition MappingPolicy.h:24