Lagrange
Loading...
Searching...
No Matches
get_uv_attribute.h
1/*
2 * Copyright 2025 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/Error.h>
16#include <lagrange/utils/fmt/format.h>
17#include <lagrange/uv_mesh.h>
18#include <lagrange/views.h>
19
20#include <string_view>
21#include <tuple>
22#include <type_traits>
23
24namespace lagrange::internal {
25
31
48template <typename Scalar, typename Index, typename UVScalar = Scalar>
51 std::string_view uv_attribute_name = "",
54
68template <typename Scalar, typename Index, typename UVScalar = Scalar>
69std::tuple<ConstRowMatrixView<UVScalar>, ConstVectorView<Index>> get_uv_attribute(
71 std::string_view uv_attribute_name = "");
72
86template <typename Scalar, typename Index, typename UVScalar = Scalar>
87std::tuple<RowMatrixView<UVScalar>, VectorView<Index>> ref_uv_attribute(
89 std::string_view uv_attribute_name = "");
90
93template <typename T>
95{
96 using type = T;
97};
98
119template <typename Scalar, typename Index, typename F>
122 const UVMeshOptions& options,
123 std::string_view caller,
124 F&& visitor)
125{
126 using OtherScalar = std::conditional_t<std::is_same_v<Scalar, float>, double, float>;
127 if (auto id = uv_attribute_id<Scalar, Index, Scalar>(mesh, options)) {
128 return visitor(UVScalarTag<Scalar>{}, *id);
129 }
130 if (auto id = uv_attribute_id<Scalar, Index, OtherScalar>(mesh, options)) {
131 return visitor(UVScalarTag<OtherScalar>{}, *id);
132 }
133 throw Error(format("{}: no suitable UV attribute found.", caller));
134}
135
136} // namespace lagrange::internal
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:73
uint32_t AttributeId
Identified to be used to access an attribute.
Definition AttributeFwd.h:73
std::optional< AttributeId > uv_attribute_id(const SurfaceMesh< Scalar, Index > &mesh, const UVMeshOptions &options={})
Check whether a UV attribute of a given scalar type exists on a mesh.
Definition uv_mesh.cpp:132
Eigen::Map< Vector< Scalar >, Eigen::Unaligned > VectorView
Type alias for row-major vector view.
Definition views.h:83
const Eigen::Map< const Vector< Scalar >, Eigen::Unaligned > ConstVectorView
Type alias for row-major const vector view.
Definition views.h:87
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition attribute_string_utils.h:21
AttributeId get_uv_id(const SurfaceMesh< Scalar, Index > &mesh, std::string_view uv_attribute_name="", UVMeshOptions::ElementTypes element_types=UVMeshOptions::ElementTypes::IndexedOrVertex, TypeMismatchPolicy type_mismatch=TypeMismatchPolicy::Assert)
Get the ID of the UV attribute of a mesh.
Definition get_uv_attribute.cpp:26
auto dispatch_uv_scalar_type(SurfaceMesh< Scalar, Index > &mesh, const UVMeshOptions &options, std::string_view caller, F &&visitor)
Dispatch on the scalar type of a UV attribute.
Definition get_uv_attribute.h:120
std::tuple< RowMatrixView< UVScalar >, VectorView< Index > > ref_uv_attribute(SurfaceMesh< Scalar, Index > &mesh, std::string_view uv_attribute_name="")
Get the modifiable UV attribute buffers of a mesh.
Definition get_uv_attribute.cpp:127
std::tuple< ConstRowMatrixView< UVScalar >, ConstVectorView< Index > > get_uv_attribute(const SurfaceMesh< Scalar, Index > &mesh, std::string_view uv_attribute_name="")
Get the constant UV attribute buffers of a mesh.
Definition get_uv_attribute.cpp:103
TypeMismatchPolicy
Behavior when a named UV attribute has a mismatched scalar type.
Definition get_uv_attribute.h:27
@ Graceful
Return invalid_attribute_id() on type mismatch (for dual-dispatch probing).
Definition get_uv_attribute.h:29
@ Assert
Assert on type mismatch (default, for strict callers).
Definition get_uv_attribute.h:28
@ Error
Throw an error if collision is detected.
Definition MappingPolicy.h:24
Definition uv_mesh.h:27
ElementTypes
Supported element types for UV mesh extraction.
Definition uv_mesh.h:29
@ IndexedOrVertex
Only indexed/vertex attributes (zero-copy, no allocation).
Definition uv_mesh.h:30
Tag carrying a UV scalar type, used to disambiguate the type passed back to dispatch_uv_scalar_type c...
Definition get_uv_attribute.h:95