Lagrange
compute_vertex_valence.h
1/*
2 * Copyright 2017 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/Mesh.h>
15#include <lagrange/MeshTrait.h>
16#include <lagrange/legacy/inline.h>
17
18namespace lagrange {
19LAGRANGE_LEGACY_INLINE
20namespace legacy {
21template <typename MeshType>
23{
24 static_assert(MeshTrait<MeshType>::is_mesh(), "Input type is not Mesh");
25
26 using Index = typename MeshType::Index;
27
28 const Index num_vertices = mesh.get_num_vertices();
29 const Index num_facets = mesh.get_num_facets();
30 const Index vertex_per_facet = mesh.get_vertex_per_facet();
31 const auto& facets = mesh.get_facets();
32
33 typename MeshType::AttributeArray valence(num_vertices, 1);
34 valence.setZero();
35
36 for (Index i = 0; i < num_facets; i++) {
37 for (Index j = 0; j < vertex_per_facet; j++) {
38 valence(facets(i, j), 0) += 1.0;
39 }
40 }
41
42 mesh.add_vertex_attribute("valence");
43 mesh.import_vertex_attribute("valence", valence);
44}
45} // namespace legacy
46} // namespace lagrange
Definition: Mesh.h:48
AttributeId compute_vertex_valence(SurfaceMesh< Scalar, Index > &mesh, VertexValenceOptions options={})
Compute vertex valence.
Definition: compute_vertex_valence.cpp:25
Main namespace for Lagrange.
Definition: AABBIGL.h:30