Compare commits
3 Commits
1772005c1b
...
6310c2c551
Author | SHA1 | Date | |
---|---|---|---|
6310c2c551 | |||
e7caf40445 | |||
c17e01d366 |
54
src/main.cpp
54
src/main.cpp
@ -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) {
|
||||
@ -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[]) {
|
||||
using namespace std;
|
||||
|
||||
if (argc != 2) {
|
||||
cerr << "Utilisation : " << argv[0] << " [fichier.obj]" << endl;
|
||||
if (argc != 2 && argc != 3) {
|
||||
cerr << "Utilisation : " << argv[0] << " fichier.obj [surface|valence|deviation]" << endl;
|
||||
return 1;
|
||||
}
|
||||
MyMesh mesh;
|
||||
@ -110,8 +141,21 @@ int main(int argc, char *argv[]) {
|
||||
cerr << "Les arêtes sont sur une face : "
|
||||
<< (check_edges_arent_lonely(argv[1]) ? "oui" : "non")
|
||||
<< endl;
|
||||
cerr << "Aire totale : " << total_area(mesh) << endl;
|
||||
// stats_to_csv(stats_surface_area(mesh));
|
||||
stats_surface_area(mesh);
|
||||
float area = total_area(mesh);
|
||||
cerr << "Aire totale : " << area << endl;
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user