Lagrange
compute_edge_lengths.h
1/*
2 * Copyright 2019 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 <memory>
15
16#include <lagrange/Edge.h>
17#include <lagrange/Mesh.h>
18#include <lagrange/MeshTrait.h>
19#include <lagrange/attributes/eval_as_attribute.h>
20#include <lagrange/legacy/inline.h>
21
22namespace lagrange {
23LAGRANGE_LEGACY_INLINE
24namespace legacy {
25/*
26Fills the edge attribute "length" with edge lengths.
27
28Initializes the mesh edge data map if needed.
29*/
30template <typename MeshType>
32{
33 static_assert(MeshTrait<MeshType>::is_mesh(), "Input type is not Mesh");
34
35 using Index = typename MeshType::Index;
36
37 mesh.initialize_edge_data();
38
39 const auto& vertices = mesh.get_vertices();
40
41 eval_as_edge_attribute_new(mesh, "length", [&](Index e_idx) {
42 auto v = mesh.get_edge_vertices(e_idx);
43 auto p0 = vertices.row(v[0]);
44 auto p1 = vertices.row(v[1]);
45 return (p0 - p1).norm();
46 });
47}
48} // namespace legacy
49} // namespace lagrange
Definition: Mesh.h:48
AttributeId compute_edge_lengths(SurfaceMesh< Scalar, Index > &mesh, const EdgeLengthOptions &options={})
Computes edge lengths attribute.
Definition: compute_edge_lengths.cpp:28
Main namespace for Lagrange.
Definition: AABBIGL.h:30