14#include <lagrange/Edge.h>
15#include <lagrange/Logger.h>
16#include <lagrange/Mesh.h>
17#include <lagrange/MeshTrait.h>
18#include <lagrange/attributes/eval_as_attribute.h>
19#include <lagrange/compute_triangle_normal.h>
20#include <lagrange/legacy/inline.h>
21#include <lagrange/utils/geometry3d.h>
36template <
typename MeshType>
39 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
41 if (mesh.get_dim() != 3) {
42 throw std::runtime_error(
"Input mesh is not 3D.");
45 using Index =
typename MeshType::Index;
46 using Scalar =
typename MeshType::Scalar;
48 mesh.initialize_edge_data();
50 if (!mesh.has_facet_attribute(
"normal")) {
51 compute_triangle_normal(mesh);
54 const auto& facet_normals = mesh.get_facet_attribute(
"normal");
55 bool non_manifold =
false;
56 eval_as_edge_attribute_new(mesh,
"dihedral_angle", [&](Index i) -> Scalar {
57 const auto num_adj_facets = mesh.get_num_facets_around_edge(i);
58 if (num_adj_facets > 2) {
62 if (num_adj_facets <= 1) {
64 }
else if (num_adj_facets == 2) {
65 Eigen::Matrix<Scalar, 2, 3, Eigen::RowMajor> normals(num_adj_facets, 3);
67 mesh.foreach_facets_around_edge(i, [&](Index fid) {
68 normals.row(index) = facet_normals.row(fid);
72 const Eigen::Matrix<Scalar, 1, 3>& n1 = normals.row(0);
73 const Eigen::Matrix<Scalar, 1, 3>& n2 = normals.row(1);
82 lagrange::logger().warn(
"Computing dihedral angles on a non-manifold mesh!");
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:40
AttributeId compute_dihedral_angles(SurfaceMesh< Scalar, Index > &mesh, const DihedralAngleOptions &options={})
Computes dihedral angles for each edge in the mesh.
Definition: compute_dihedral_angles.cpp:32
Main namespace for Lagrange.
Definition: AABBIGL.h:30
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