implements statistics computation on normal deviation

This commit is contained in:
ccolin 2020-10-02 13:07:51 +02:00
parent e7caf40445
commit 6310c2c551

View File

@ -1,8 +1,11 @@
#include "my_mesh.h"
#include <ctgmath>
#include <iostream>
#include <fstream>
#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;
}