Lagrange
recompute_facet_normal_if_needed.h
1/*
2 * Copyright 2023 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/SurfaceMesh.h>
15#include <lagrange/compute_facet_normal.h>
16#include <lagrange/internal/find_attribute_utils.h>
17
18namespace lagrange::internal {
19
32template <typename Scalar, typename Index>
35 std::string_view facet_normal_attribute_name,
36 bool recompute_facet_normals)
37{
38 AttributeId facet_normal_id;
39 bool had_facet_normals = mesh.has_attribute(facet_normal_attribute_name);
40 if (recompute_facet_normals || !had_facet_normals) {
41 FacetNormalOptions facet_normal_options;
42 facet_normal_options.output_attribute_name = facet_normal_attribute_name;
43 facet_normal_id = compute_facet_normal(mesh, facet_normal_options);
44 } else {
45 facet_normal_id = internal::find_attribute<Scalar>(
46 mesh,
47 facet_normal_attribute_name,
48 Facet,
50 3);
51 }
52 return std::make_pair(facet_normal_id, had_facet_normals);
53}
54
55} // namespace lagrange::internal
uint32_t AttributeId
Identified to be used to access an attribute.
Definition: AttributeFwd.h:73
@ Normal
Mesh attribute can have dim or dim + 1 channels.
@ Facet
Per-facet mesh attributes.
Definition: AttributeFwd.h:31
AttributeId compute_facet_normal(SurfaceMesh< Scalar, Index > &mesh, FacetNormalOptions options={})
Compute facet normals.
Definition: compute_facet_normal.cpp:34
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition: attribute_string_utils.h:21
auto recompute_facet_normal_if_needed(SurfaceMesh< Scalar, Index > &mesh, std::string_view facet_normal_attribute_name, bool recompute_facet_normals)
Compute facet normal attribute if necessary or as requested.
Definition: recompute_facet_normal_if_needed.h:33
Option struct for computing per-facet mesh normals.
Definition: compute_facet_normal.h:33
std::string_view output_attribute_name
Output normal attribute name.
Definition: compute_facet_normal.h:35