Lagrange
Loading...
Searching...
No Matches
interpolate_attribute_row.h
1/*
2 * Copyright 2026 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/utils/assert.h>
15
16#include <Eigen/Dense>
17
18#include <type_traits>
19
20namespace lagrange::internal {
21
37template <typename Derived, typename Scalar, typename Index>
39 Eigen::MatrixBase<Derived>& data,
40 Index row_to,
41 Index row_from_1,
42 Index row_from_2,
43 Scalar t)
44{
45 la_debug_assert(row_to < static_cast<Index>(data.rows()));
46 la_debug_assert(row_from_1 < static_cast<Index>(data.rows()));
47 la_debug_assert(row_from_2 < static_cast<Index>(data.rows()));
48 using ValueType = typename Derived::Scalar;
49
50 if constexpr (std::is_integral_v<ValueType>) {
51 data.row(row_to) = (data.row(row_from_1).template cast<Scalar>() * (1 - t) +
52 data.row(row_from_2).template cast<Scalar>() * t)
53 .array()
54 .round()
55 .template cast<ValueType>()
56 .eval();
57 } else {
58 data.row(row_to) = data.row(row_from_1) * (1 - t) + data.row(row_from_2) * t;
59 }
60}
61
62} // namespace lagrange::internal
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56
SurfaceMesh< ToScalar, ToIndex > cast(const SurfaceMesh< FromScalar, FromIndex > &source_mesh, const AttributeFilter &convertible_attributes={}, std::vector< std::string > *converted_attributes_names=nullptr)
Cast a mesh to a mesh of different scalar and/or index type.
#define la_debug_assert(...)
Debug assertion check.
Definition assert.h:197
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition attribute_string_utils.h:21
void interpolate_attribute_row(Eigen::MatrixBase< Derived > &data, Index row_to, Index row_from_1, Index row_from_2, Scalar t)
Linearly interpolate row row_to from rows row_from_1 and row_from_2 of an attribute matrix: data....
Definition interpolate_attribute_row.h:38