Lagrange
visit_attribute.h
1/*
2 * Copyright 2024 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/Attribute.h>
15#include <lagrange/AttributeTypes.h>
16#include <lagrange/AttributeValueType.h>
17#include <lagrange/IndexedAttribute.h>
18#include <lagrange/SurfaceMesh.h>
19
20namespace lagrange::internal {
21
38template <typename Func, typename Scalar, typename Index>
40{
41 const auto& attr = mesh.get_attribute_base(id);
42 auto type = attr.get_value_type();
43 bool is_indexed = (attr.get_element_type() == AttributeElement::Indexed);
44 switch (type) {
45#define LA_X_visit(_, ValueType) \
46 case make_attribute_value_type<ValueType>(): { \
47 if (is_indexed) { \
48 func(static_cast<const IndexedAttribute<ValueType, Index>&>(attr)); \
49 } else { \
50 func(static_cast<const Attribute<ValueType>&>(attr)); \
51 } \
52 break; \
53 }
54 LA_ATTRIBUTE_X(visit, 0)
55#undef LA_X_visit
56 }
57}
58
75template <typename Func, typename Scalar, typename Index>
77{
78 const auto& attr = mesh.get_attribute_base(id);
79 auto type = attr.get_value_type();
80 bool is_indexed = (attr.get_element_type() == AttributeElement::Indexed);
81 switch (type) {
82#define LA_X_visit(_, ValueType) \
83 case make_attribute_value_type<ValueType>(): { \
84 if (is_indexed) { \
85 func(mesh.template ref_indexed_attribute<ValueType>(id)); \
86 } else { \
87 func(mesh.template ref_attribute<ValueType>(id)); \
88 } \
89 break; \
90 }
91 LA_ATTRIBUTE_X(visit, 0)
92#undef LA_X_visit
93 }
94}
95
96} // namespace lagrange::internal
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
@ Indexed
Indexed mesh attributes.
Definition: AttributeFwd.h:45
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition: attribute_string_utils.h:21
void visit_attribute_write(SurfaceMesh< Scalar, Index > &mesh, AttributeId id, Func &&func)
Apply a function to a writeable mesh attribute.
Definition: visit_attribute.h:76
void visit_attribute_read(const SurfaceMesh< Scalar, Index > &mesh, AttributeId id, Func &&func)
Apply a function to a read-only mesh attribute.
Definition: visit_attribute.h:39