14#include <lagrange/Attribute.h>
15#include <lagrange/AttributeTypes.h>
16#include <lagrange/IndexedAttribute.h>
17#include <lagrange/SurfaceMesh.h>
18#include <lagrange/utils/BitField.h>
58enum class Ordering { Sequential, Parallel };
59enum class Access { Write, Read };
64 std::underlying_type_t<AttributeElement> mask,
69void internal_foreach_named_attribute(
72 span<const AttributeId> ids = {})
74 auto cb = [&](std::string_view name,
AttributeId id) {
75 constexpr auto filter = BitField<AttributeElement>(mask);
76#define LA_X_match_attribute(_, T) \
77 if (mesh.template is_attribute_type<T>(id)) { \
78 if constexpr (filter.test(AttributeElement::Indexed)) { \
79 if (mesh.is_attribute_indexed(id)) { \
80 auto& attr = mesh.template get_indexed_attribute<T>(id); \
81 if (filter.test(attr.get_element_type())) { \
82 if constexpr (access == Access::Write) { \
83 vis(name, mesh.template ref_indexed_attribute<T>(id)); \
90 if constexpr (filter.test_any(~AttributeElement::Indexed)) { \
91 if (!mesh.is_attribute_indexed(id)) { \
92 auto& attr = mesh.template get_attribute<T>(id); \
93 if (filter.test(attr.get_element_type())) { \
94 if constexpr (access == Access::Write) { \
95 vis(name, mesh.template ref_attribute<T>(id)); \
104#undef LA_X_match_attribute
106 if constexpr (ordering == Ordering::Sequential) {
108 mesh.seq_foreach_attribute_id(cb);
110 std::for_each(ids.begin(), ids.end(), [&](
AttributeId id) {
111 cb(mesh.get_attribute_name(id), id);
116 mesh.par_foreach_attribute_id(cb);
118 par_foreach_attribute_id(ids, [&](
AttributeId id) {
119 cb(mesh.get_attribute_name(
id),
id);
126 std::underlying_type_t<AttributeElement> mask,
131void internal_foreach_attribute(
MeshType& mesh, Visitor&& vis, span<const AttributeId> ids = {})
134 constexpr auto filter = BitField<AttributeElement>(mask);
135#define LA_X_match_attribute(_, T) \
136 if (mesh.template is_attribute_type<T>(id)) { \
137 if constexpr (filter.test(AttributeElement::Indexed)) { \
138 if (mesh.is_attribute_indexed(id)) { \
139 auto& attr = mesh.template get_indexed_attribute<T>(id); \
140 if (filter.test(attr.get_element_type())) { \
141 if constexpr (access == Access::Write) { \
142 vis(mesh.template ref_indexed_attribute<T>(id)); \
149 if constexpr (filter.test_any(~AttributeElement::Indexed)) { \
150 if (!mesh.is_attribute_indexed(id)) { \
151 auto& attr = mesh.template get_attribute<T>(id); \
152 if (filter.test(attr.get_element_type())) { \
153 if constexpr (access == Access::Write) { \
154 vis(mesh.template ref_attribute<T>(id)); \
163#undef LA_X_match_attribute
165 if constexpr (ordering == Ordering::Sequential) {
167 mesh.seq_foreach_attribute_id(cb);
169 std::for_each(ids.begin(), ids.end(), cb);
173 mesh.par_foreach_attribute_id(cb);
175 par_foreach_attribute_id(ids, cb);
209 using namespace details;
210 internal_foreach_named_attribute<mask, Ordering::Sequential, Access::Read>(
212 std::forward<Visitor>(vis));
235 using namespace details;
236 internal_foreach_attribute<mask, Ordering::Sequential, Access::Read>(
238 std::forward<Visitor>(vis));
269 using namespace details;
270 internal_foreach_named_attribute<mask, Ordering::Sequential, Access::Write>(
272 std::forward<Visitor>(vis));
296 using namespace details;
297 internal_foreach_attribute<mask, Ordering::Sequential, Access::Write>(
299 std::forward<Visitor>(vis));
329 using namespace details;
330 internal_foreach_named_attribute<mask, Ordering::Parallel, Access::Read>(
332 std::forward<Visitor>(vis));
355 using namespace details;
356 internal_foreach_attribute<mask, Ordering::Parallel, Access::Read>(
358 std::forward<Visitor>(vis));
389 using namespace details;
390 internal_foreach_named_attribute<mask, Ordering::Parallel, Access::Write>(
392 std::forward<Visitor>(vis));
416 using namespace details;
417 internal_foreach_attribute<mask, Ordering::Parallel, Access::Write>(
419 std::forward<Visitor>(vis));
static constexpr BitField all()
Named constructor returning a bitfield set to 1.
Definition: BitField.h:76
uint32_t AttributeId
Identified to be used to access an attribute.
Definition: AttributeFwd.h:73
#define LA_ATTRIBUTE_X(mode, data)
X Macro arguments for the Attribute<> class.
Definition: AttributeTypes.h:48
void par_foreach_named_attribute_write(SurfaceMesh< Scalar, Index > &mesh, Visitor &&vis)
Applies a function in parallel to each attribute of a mesh.
Definition: foreach_attribute.h:387
void par_foreach_attribute_read(const SurfaceMesh< Scalar, Index > &mesh, Visitor &&vis)
Applies a function in parallel to each attribute of a mesh.
Definition: foreach_attribute.h:353
void par_foreach_attribute_write(SurfaceMesh< Scalar, Index > &mesh, Visitor &&vis)
Applies a function in parallel to each attribute of a mesh.
Definition: foreach_attribute.h:414
void seq_foreach_attribute_read(const SurfaceMesh< Scalar, Index > &mesh, Visitor &&vis)
Applies a function to each attribute of a mesh.
Definition: foreach_attribute.h:233
void seq_foreach_named_attribute_write(SurfaceMesh< Scalar, Index > &mesh, Visitor &&vis)
Applies a function to each attribute of a mesh.
Definition: foreach_attribute.h:267
void seq_foreach_named_attribute_read(const SurfaceMesh< Scalar, Index > &mesh, Visitor &&vis)
Applies a function to each attribute of a mesh.
Definition: foreach_attribute.h:207
void par_foreach_named_attribute_read(const SurfaceMesh< Scalar, Index > &mesh, Visitor &&vis)
Applies a function in parallel to each attribute of a mesh.
Definition: foreach_attribute.h:327
void seq_foreach_attribute_write(SurfaceMesh< Scalar, Index > &mesh, Visitor &&vis)
Applies a function to each attribute of a mesh.
Definition: foreach_attribute.h:294
function_ref(R(*)(Args...)) -> function_ref< R(Args...)>
Deduce function_ref type from a function pointer.
Main namespace for Lagrange.
Definition: AABBIGL.h:30