Lagrange
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/utils/geometry3d.h>
15
16#include <array>
17#include <cstdint>
18
19namespace lagrange::internal {
20
21template <typename Derived>
22std::array<std::array<uint8_t, 3>, 2> delaunay_split(
23 const Eigen::DenseBase<Derived>& p0,
24 const Eigen::DenseBase<Derived>& p1,
25 const Eigen::DenseBase<Derived>& p2,
26 const Eigen::DenseBase<Derived>& p3)
27{
28 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
29 // Choose split that maximizes the minimum angle
30 using Scalar = typename Derived::Scalar;
31 using Vector3s = Eigen::Vector3<Scalar>;
32 auto angle1 = angle_between(Vector3s(p0.derived() - p1.derived()), Vector3s(p2.derived() - p1.derived()));
33 auto angle2 = angle_between(Vector3s(p0.derived() - p3.derived()), Vector3s(p2.derived() - p3.derived()));
34 if (angle1 + angle2 <= M_PI) {
35 return {{{0, 1, 2}, {0, 2, 3}}};
36 } else {
37 return {{{0, 1, 3}, {1, 2, 3}}};
38 }
39}
40
41} // namespace lagrange::internal
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:36