diff --git a/src/main.cpp b/src/main.cpp index 2f4bad2..b5e5649 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include "my_mesh.h" -#include +#include #include #include @@ -104,7 +104,19 @@ void stats_n_neighbors(MyMesh &mesh) { } +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +static float f(int n, float h, float s, float v) { + float k = fmod(n + h / 60, 6); + return v - v * s * MAX(0, MIN(k, MIN(4 - k, 1))); +} + +static OpenMesh::Vec3uc hsv_to_rgb(float h, float s, float v) { + return OpenMesh::Vec3uc {f(5, h, s, v) * 255, f(3, h, s, v) * 255, f(1, h, s, v) * 255}; +} + void stats_normal_deviation(MyMesh &mesh) { + const float s = 1, v = 1, min_h = 50, max_h = 0; mesh.update_normals(); for (const VertexHandle &vh : mesh.vertices()) { MyMesh::Normal normal = mesh.normal(vh); @@ -114,6 +126,7 @@ void stats_normal_deviation(MyMesh &mesh) { if (angle > max) max = angle; } + mesh.set_color(vh, (MyMesh::Color) hsv_to_rgb(fmod(max * 360 / (max_h - min_h) + max_h, 360), s, v)); std::cout << max << " "; } std::cout << std::endl; @@ -156,14 +169,20 @@ int main(int argc, char *argv[]) { cerr << "Aire moyenne : " << area / mesh.n_faces() << endl; if (argc == 3) { string cmd = argv[2]; - if (cmd == "surface") + if (cmd == "surface") { stats_surface_area(mesh); - else if (cmd == "valence") + } + else if (cmd == "valence") { stats_n_neighbors(mesh); - else if (cmd == "deviation") + } + else if (cmd == "deviation") { stats_normal_deviation(mesh); - else if (cmd == "dièdre") + OpenMesh::IO::write_mesh(mesh, "out.ply", + OpenMesh::IO::Options(OpenMesh::IO::Options::VertexColor)); + } + else if (cmd == "dièdre") { stats_dihedral_angles(mesh); + } else { cerr << "Commande inconnue : " << cmd << endl; return 1;