adds export of normal derivation-colored mesh
This commit is contained in:
parent
8d253a3c91
commit
c564671b93
29
src/main.cpp
29
src/main.cpp
@ -1,6 +1,6 @@
|
|||||||
#include "my_mesh.h"
|
#include "my_mesh.h"
|
||||||
|
|
||||||
#include <ctgmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
@ -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) {
|
void stats_normal_deviation(MyMesh &mesh) {
|
||||||
|
const float s = 1, v = 1, min_h = 50, max_h = 0;
|
||||||
mesh.update_normals();
|
mesh.update_normals();
|
||||||
for (const VertexHandle &vh : mesh.vertices()) {
|
for (const VertexHandle &vh : mesh.vertices()) {
|
||||||
MyMesh::Normal normal = mesh.normal(vh);
|
MyMesh::Normal normal = mesh.normal(vh);
|
||||||
@ -114,6 +126,7 @@ void stats_normal_deviation(MyMesh &mesh) {
|
|||||||
if (angle > max)
|
if (angle > max)
|
||||||
max = angle;
|
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 << max << " ";
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
@ -156,14 +169,20 @@ int main(int argc, char *argv[]) {
|
|||||||
cerr << "Aire moyenne : " << area / mesh.n_faces() << endl;
|
cerr << "Aire moyenne : " << area / mesh.n_faces() << endl;
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
string cmd = argv[2];
|
string cmd = argv[2];
|
||||||
if (cmd == "surface")
|
if (cmd == "surface") {
|
||||||
stats_surface_area(mesh);
|
stats_surface_area(mesh);
|
||||||
else if (cmd == "valence")
|
}
|
||||||
|
else if (cmd == "valence") {
|
||||||
stats_n_neighbors(mesh);
|
stats_n_neighbors(mesh);
|
||||||
else if (cmd == "deviation")
|
}
|
||||||
|
else if (cmd == "deviation") {
|
||||||
stats_normal_deviation(mesh);
|
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);
|
stats_dihedral_angles(mesh);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
cerr << "Commande inconnue : " << cmd << endl;
|
cerr << "Commande inconnue : " << cmd << endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user