Lagrange
internal_angles.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/utils/assert.h>
15
16// clang-format off
17#include <lagrange/utils/warnoff.h>
18#include <tbb/parallel_for.h>
19#include <lagrange/utils/warnon.h>
20// clang-format on
21
22#include <Eigen/Dense>
23
24namespace lagrange::internal {
25
38template <typename DerivedV, typename DerivedF, typename DerivedK>
40 const Eigen::MatrixBase<DerivedV>& vertices,
41 const Eigen::MatrixBase<DerivedF>& facets,
42 Eigen::PlainObjectBase<DerivedK>& angles)
43{
44 la_runtime_assert(facets.cols() == 3);
45 // Computing Cross-Products and Rotations in 2- and 3-Dimensional Euclidean Spaces [Kahan 2016]
46 // Formula can be found in ยง13 (page 15)
47 using Scalar = typename DerivedV::Scalar;
48 using Index = typename DerivedF::Index;
49 const Index m = facets.rows();
50 angles.resize(m, 3);
51 tbb::parallel_for(Index(0), m, [&](const Index f) {
52 for (size_t d = 0; d < 3; d++) {
53 auto v1 = vertices.row(facets(f, d)) - vertices.row(facets(f, (d + 1) % 3));
54 auto v2 = vertices.row(facets(f, d)) - vertices.row(facets(f, (d + 2) % 3));
55 angles(f, d) = Scalar(2) * std::atan2(
56 (v1.stableNormalized() - v2.stableNormalized()).norm(),
57 (v1.stableNormalized() + v2.stableNormalized()).norm());
58 }
59 });
60}
61
62} // namespace lagrange::internal
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition: attribute_string_utils.h:21
void internal_angles(const Eigen::MatrixBase< DerivedV > &vertices, const Eigen::MatrixBase< DerivedF > &facets, Eigen::PlainObjectBase< DerivedK > &angles)
Compute internal angles for a triangle mesh.
Definition: internal_angles.h:39