Compare commits

...

3 Commits

View File

@ -1,8 +1,11 @@
#include "my_mesh.h" #include "my_mesh.h"
#include <ctgmath>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#define PI 3.14159265
bool check_faces_are_triangles(MyMesh &mesh) { bool check_faces_are_triangles(MyMesh &mesh) {
for (auto f_it = mesh.faces_begin(); f_it != mesh.faces_end(); ++f_it) { for (auto f_it = mesh.faces_begin(); f_it != mesh.faces_end(); ++f_it) {
@ -89,11 +92,39 @@ void stats_surface_area(MyMesh &mesh) {
} }
void stats_n_neighbors(MyMesh &mesh) {
for (const VertexHandle &vh : mesh.vertices()) {
unsigned count = 0;
for (auto vv_it = mesh.vv_iter(vh); vv_it.is_valid(); ++vv_it) {
count++;
}
std::cout << count << " ";
}
std::cout << std::endl;
}
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[]) { int main(int argc, char *argv[]) {
using namespace std; using namespace std;
if (argc != 2) { if (argc != 2 && argc != 3) {
cerr << "Utilisation: " << argv[0] << " [fichier.obj]" << endl; cerr << "Utilisation: " << argv[0] << " fichier.obj [surface|valence|deviation]" << endl;
return 1; return 1;
} }
MyMesh mesh; MyMesh mesh;
@ -110,8 +141,21 @@ int main(int argc, char *argv[]) {
cerr << "Les arêtes sont sur une face : " cerr << "Les arêtes sont sur une face : "
<< (check_edges_arent_lonely(argv[1]) ? "oui" : "non") << (check_edges_arent_lonely(argv[1]) ? "oui" : "non")
<< endl; << endl;
cerr << "Aire totale : " << total_area(mesh) << endl; float area = total_area(mesh);
// stats_to_csv(stats_surface_area(mesh)); cerr << "Aire totale : " << area << endl;
stats_surface_area(mesh); cerr << "Aire moyenne : " << area / mesh.n_faces() << endl;
if (argc == 3) {
string cmd = argv[2];
if (cmd == "surface")
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; return 0;
} }