Lagrange
check_flipped_uv.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/ExactPredicates.h>
15#include <lagrange/legacy/inline.h>
16#include <lagrange/utils/range.h>
17
18#include <Eigen/Core>
19
20namespace lagrange {
21LAGRANGE_LEGACY_INLINE
22namespace legacy {
23
34template <typename UVArray, typename UVIndices, typename T = void>
35size_t check_flipped_uv(
36 const Eigen::PlainObjectBase<UVArray>& uv,
37 const Eigen::PlainObjectBase<UVIndices>& uv_indices,
38 T* flipped = nullptr)
39{
40 const auto num_facets = uv_indices.rows();
41 const auto predicates = ExactPredicates::create("shewchuk");
42 size_t num_flipped = 0;
43 double uv0[2], uv1[2], uv2[2];
44 for (auto i : range(num_facets)) {
45 // Explicit cast needed for orientation check.
46 uv0[0] = static_cast<double>(uv(uv_indices(i, 0), 0));
47 uv0[1] = static_cast<double>(uv(uv_indices(i, 0), 1));
48 uv1[0] = static_cast<double>(uv(uv_indices(i, 1), 0));
49 uv1[1] = static_cast<double>(uv(uv_indices(i, 1), 1));
50 uv2[0] = static_cast<double>(uv(uv_indices(i, 2), 0));
51 uv2[1] = static_cast<double>(uv(uv_indices(i, 2), 1));
52 auto r = predicates->orient2D(uv0, uv1, uv2);
53 if (r <= 0) num_flipped++;
54 if (flipped) flipped[i] = r <= 0;
55 }
56
57 return num_flipped;
58}
59
60} // namespace legacy
61} // namespace lagrange
static std::unique_ptr< ExactPredicates > create(const std::string &engine)
Factory method to create an exact predicate engine.
Definition: ExactPredicates.cpp:20
internal::Range< Index > range(Index end)
Returns an iterable object representing the range [0, end).
Definition: range.h:176
Main namespace for Lagrange.
Definition: AABBIGL.h:30