Lagrange
Loading...
Searching...
No Matches
delaunay_split.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/internal/constants.h>
15#include <lagrange/utils/geometry3d.h>
16
17#include <array>
18#include <cstdint>
19
20namespace lagrange::internal {
21
22template <typename Derived>
23std::array<std::array<uint8_t, 3>, 2> delaunay_split(
24 const Eigen::DenseBase<Derived>& p0,
25 const Eigen::DenseBase<Derived>& p1,
26 const Eigen::DenseBase<Derived>& p2,
27 const Eigen::DenseBase<Derived>& p3)
28{
29 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
30 // Choose split that maximizes the minimum angle
31 using Scalar = typename Derived::Scalar;
32 using Vector3s = Eigen::Vector3<Scalar>;
33 auto angle1 =
34 angle_between(Vector3s(p0.derived() - p1.derived()), Vector3s(p2.derived() - p1.derived()));
35 auto angle2 =
36 angle_between(Vector3s(p0.derived() - p3.derived()), Vector3s(p2.derived() - p3.derived()));
37 if (angle1 + angle2 <= lagrange::internal::pi) {
38 return {{{0, 1, 2}, {0, 2, 3}}};
39 } else {
40 return {{{0, 1, 3}, {1, 2, 3}}};
41 }
42}
43
44} // namespace lagrange::internal
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition attribute_string_utils.h:21
Scalar angle_between(const Eigen::Matrix< Scalar, _Rows, _Cols > &v1, const Eigen::Matrix< Scalar, _Rows, _Cols > &v2)
Returns the angle between two 3d vectors.
Definition geometry3d.h:38