From 6310c2c551f9eb41397b588e2891a5bae477c160 Mon Sep 17 00:00:00 2001 From: ccolin Date: Fri, 2 Oct 2020 13:07:51 +0200 Subject: [PATCH] implements statistics computation on normal deviation --- src/main.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a5be378..c668feb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,11 @@ #include "my_mesh.h" +#include #include #include +#define PI 3.14159265 + bool check_faces_are_triangles(MyMesh &mesh) { for (auto f_it = mesh.faces_begin(); f_it != mesh.faces_end(); ++f_it) { @@ -101,11 +104,27 @@ void stats_n_neighbors(MyMesh &mesh) { } +void stats_normal_deviation(MyMesh &mesh) { + mesh.update_normals(); + for (const VertexHandle &vh : mesh.vertices()) { + MyMesh::Normal normal = mesh.normal(vh); + float max = 0; + for (auto vf_it = mesh.vf_iter(vh); vf_it.is_valid(); ++vf_it) { + float angle = acos(OpenMesh::dot(mesh.normal(*vf_it), normal)) * 180.0 / PI; + if (angle > max) + max = angle; + } + std::cout << max << " "; + } + std::cout << std::endl; +} + + int main(int argc, char *argv[]) { using namespace std; if (argc != 2 && argc != 3) { - cerr << "Utilisation : " << argv[0] << " fichier.obj [surface|valence]" << endl; + cerr << "Utilisation : " << argv[0] << " fichier.obj [surface|valence|deviation]" << endl; return 1; } MyMesh mesh; @@ -131,6 +150,12 @@ int main(int argc, char *argv[]) { stats_surface_area(mesh); else if (cmd == "valence") stats_n_neighbors(mesh); + else if (cmd == "deviation") + stats_normal_deviation(mesh); + else { + cerr << "Commande inconnue : " << cmd << endl; + return 1; + } } return 0; }