Lagrange
Loading...
Searching...
No Matches
find_attribute_utils.h
1/*
2 * Copyright 2022 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/SurfaceMesh.h>
15#include <lagrange/utils/BitField.h>
16#include <lagrange/utils/span.h>
17
18#include <string>
19#include <string_view>
20
21namespace lagrange::internal {
22
24enum class ResetToDefault { Yes, No };
25
27enum class ShouldBeWritable { Yes, No };
28
31{
32 bool success = true;
33 std::string msg;
34};
35
53template <typename ExpectedValueType, typename Scalar, typename Index>
56 AttributeId id,
57 BitField<AttributeElement> expected_element,
58 AttributeUsage expected_usage,
59 size_t expected_channels,
60 ShouldBeWritable expected_writable = ShouldBeWritable::No);
61
80template <typename ExpectedValueType, typename Scalar, typename Index>
83 std::string_view name,
84 BitField<AttributeElement> expected_element,
85 AttributeUsage expected_usage,
86 size_t expected_channels);
87
107template <typename ExpectedValueType, typename Scalar, typename Index>
109 const SurfaceMesh<Scalar, Index>& mesh,
110 span<const AttributeId> selected_ids,
111 BitField<AttributeElement> expected_element,
112 AttributeUsage expected_usage,
113 size_t expected_channels);
114
131template <typename ExpectedValueType, typename Scalar, typename Index>
133 const SurfaceMesh<Scalar, Index>& mesh,
134 std::string_view name,
135 BitField<AttributeElement> expected_element,
136 AttributeUsage expected_usage,
137 size_t expected_channels);
138
157template <typename ExpectedValueType, typename Scalar, typename Index>
160 std::string_view name,
161 AttributeElement expected_element,
162 AttributeUsage expected_usage,
163 size_t expected_channels,
164 ResetToDefault reset_tag);
165
166} // namespace lagrange::internal
Bit field utility class.
Definition BitField.h:33
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:66
uint32_t AttributeId
Identified to be used to access an attribute.
Definition AttributeFwd.h:73
AttributeUsage
Usage tag indicating how the attribute should behave under mesh transformations.
Definition AttributeFwd.h:54
AttributeElement
Type of element to which the attribute is attached.
Definition AttributeFwd.h:26
::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
CheckAttributeResult check_attribute(const SurfaceMesh< Scalar, Index > &mesh, AttributeId id, BitField< AttributeElement > expected_element, AttributeUsage expected_usage, size_t expected_channels, ShouldBeWritable expected_writable=ShouldBeWritable::No)
Check that an attribute matches the expected value type, element type, usage and number of channels.
Definition find_attribute_utils.cpp:38
AttributeId find_attribute(const SurfaceMesh< Scalar, Index > &mesh, std::string_view name, BitField< AttributeElement > expected_element, AttributeUsage expected_usage, size_t expected_channels)
Find an attribute with a given name, ensuring the usage and element type match an expected target.
Definition find_attribute_utils.cpp:152
ShouldBeWritable
Whether the attribute should be writable.
Definition find_attribute_utils.h:27
AttributeId find_matching_attribute(const SurfaceMesh< Scalar, Index > &mesh, std::string_view name, BitField< AttributeElement > expected_element, AttributeUsage expected_usage, size_t expected_channels)
Find an attribute with a given name, ensuring the usage and element type match an expected target.
Definition find_attribute_utils.cpp:89
ResetToDefault
Whether to reset the attribute values to default when an existing attribute is found.
Definition find_attribute_utils.h:24
AttributeId find_or_create_attribute(SurfaceMesh< Scalar, Index > &mesh, std::string_view name, AttributeElement expected_element, AttributeUsage expected_usage, size_t expected_channels, ResetToDefault reset_tag)
Either retrieve or create an attribute with a prescribed name, element type and usage.
Definition find_attribute_utils.cpp:177
Result of a check_attribute call.
Definition find_attribute_utils.h:31
std::string msg
Error message if the check failed.
Definition find_attribute_utils.h:33
bool success
Whether the check passed.
Definition find_attribute_utils.h:32