Compare commits
2 Commits
c86240455d
...
c564671b93
Author | SHA1 | Date | |
---|---|---|---|
c564671b93 | |||
8d253a3c91 |
29
src/main.cpp
29
src/main.cpp
@ -1,6 +1,6 @@
|
||||
#include "my_mesh.h"
|
||||
|
||||
#include <ctgmath>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#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) {
|
||||
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;
|
||||
|
@ -10,17 +10,10 @@ using namespace OpenMesh;
|
||||
using namespace OpenMesh::Attributes;
|
||||
|
||||
struct MyTraits : public OpenMesh::DefaultTraits {
|
||||
// use vertex normals and vertex colors
|
||||
VertexAttributes( OpenMesh::Attributes::Normal | OpenMesh::Attributes::Color );
|
||||
// store the previous halfedge
|
||||
HalfedgeAttributes( OpenMesh::Attributes::PrevHalfedge );
|
||||
// use face normals face colors
|
||||
FaceAttributes( OpenMesh::Attributes::Normal | OpenMesh::Attributes::Color );
|
||||
EdgeAttributes( OpenMesh::Attributes::Color );
|
||||
// vertex thickness
|
||||
VertexTraits{float thickness; float value; Color faceShadingColor;};
|
||||
// edge thickness
|
||||
EdgeTraits{float thickness;};
|
||||
VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Color);
|
||||
HalfedgeAttributes(OpenMesh::Attributes::PrevHalfedge);
|
||||
FaceAttributes(OpenMesh::Attributes::Normal);
|
||||
EdgeAttributes(OpenMesh::Attributes::Color);
|
||||
};
|
||||
typedef OpenMesh::PolyMesh_ArrayKernelT<MyTraits> MyMesh;
|
||||
|
||||
|
Reference in New Issue
Block a user