diff --git a/README b/README index 0e654c8..3f171d7 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ -Pour compiler la première fois : `mkdir build && make' -Pour recompiler les fois suivantes : `make' +Pour compiler la première fois : `mkdir build && cd build && qmake .. && make' +Pour recompiler les fois suivantes : `cd build && make' Pour nettoyer les fichiers de compilation : `make clean' -Pour exécuter le programme : `LD_LIBRARY_PATH=libs/OpenMesh/liblinux/ ./build/tp1 ' -Pour faire un bel histogramme coloré : LD_LIBRARY_PATH=libs/OpenMesh/liblinux/ build/tp1 | util/plot.py [nombre de classes, 10 par défaut] [min] [max] +Pour exécuter le programme : `./build/tp1 ' +Pour faire un bel histogramme coloré : LD_LIBRARY_PATH=libs/OpenMesh/liblinux/ build/tp1 | util/plot.py [nombre de classes, 10 par défaut] [min] [max] diff --git a/libs/OpenMesh/liblinux/libOpenMeshCore.a b/libs/OpenMesh/liblinux/libOpenMeshCore.a new file mode 100644 index 0000000..29578ff Binary files /dev/null and b/libs/OpenMesh/liblinux/libOpenMeshCore.a differ diff --git a/libs/OpenMesh/liblinux/libOpenMeshCore.so b/libs/OpenMesh/liblinux/libOpenMeshCore.so deleted file mode 100755 index 45ca36a..0000000 Binary files a/libs/OpenMesh/liblinux/libOpenMeshCore.so and /dev/null differ diff --git a/libs/OpenMesh/liblinux/libOpenMeshCore.so.7.1 b/libs/OpenMesh/liblinux/libOpenMeshCore.so.7.1 deleted file mode 100755 index 45ca36a..0000000 Binary files a/libs/OpenMesh/liblinux/libOpenMeshCore.so.7.1 and /dev/null differ diff --git a/libs/OpenMesh/libwin/OpenMeshCore.lib b/libs/OpenMesh/libwin/OpenMeshCore.lib new file mode 100644 index 0000000..1521cdd Binary files /dev/null and b/libs/OpenMesh/libwin/OpenMeshCore.lib differ diff --git a/src/analysis.cpp b/src/analysis.cpp new file mode 100644 index 0000000..093766e --- /dev/null +++ b/src/analysis.cpp @@ -0,0 +1,142 @@ +#include "analysis.h" +#include +#include +#include + +#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) { + size_t n_edges = 0; + for (auto fe_it = mesh.fe_iter(*f_it); fe_it.is_valid(); ++fe_it) { + n_edges++; + } + if (n_edges != 3) { + return false; + } + } + return true; +} + + +bool check_faces_arent_lonely(MyMesh &mesh) { + for (auto f_it = mesh.faces_begin(); f_it != mesh.faces_end(); ++f_it) { + auto ff_it = mesh.ff_iter(*f_it); + if (!ff_it.is_valid()) { + return false; + } + } + return true; +} + + +bool check_vertices_arent_lonely(MyMesh &mesh) { + for (auto v_it = mesh.vertices_begin(); v_it != mesh.vertices_end(); ++v_it) { + auto ve_it = mesh.ve_iter(*v_it); + if (!ve_it.is_valid()) { + return false; + } + } + return true; +} + + +bool check_edges_arent_lonely(const char *path) { + using namespace std; + ifstream f(path); + string line; + while (getline(f, line)) { + istringstream iss(line); + char first; + iss >> first; + if (first == 'l') return false; + } + return true; +} + + +float face_area(MyMesh &mesh, const MyMesh::FaceHandle &face) { + MyMesh::Point p0, p1, p2; + auto fv_it = mesh.fv_iter(face); + p0 = mesh.point(*fv_it++); + p1 = mesh.point(*fv_it++); + p2 = mesh.point(*fv_it); + return ((p1 - p0) % (p2 - p0)).norm() / 2; +} + + +float total_area(MyMesh &mesh) { + if (!check_faces_are_triangles(mesh)) { + std::cerr << "Le calcul de l’aire ne peu se faire que sur un maillage triangulaire." << std::endl; + return -1; + } + float ret = 0; + for (const MyMesh::FaceHandle &face : mesh.faces()) { + ret += face_area(mesh, face); + } + return ret; +} + + +void stats_surface_area(MyMesh &mesh) { + if (!check_faces_are_triangles(mesh)) { + std::cerr << "Le calcul de l’aire ne peu se faire que sur un maillage triangulaire." << std::endl; + return; + } + for (const MyMesh::FaceHandle &face : mesh.faces()) { + std::cout << face_area(mesh, face) << " "; + } + std::cout << std::endl; +} + + +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; +} + + +#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); + 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; + } + 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; +} + + +void stats_dihedral_angles(MyMesh &mesh) { + mesh.update_normals(); + for (size_t i = 0; i < mesh.n_halfedges(); i++) { + MyMesh::HalfedgeHandle heh = mesh.halfedge_handle(i); + std::cout << mesh.calc_dihedral_angle_fast(heh) * 180.0 / PI + 180 << " "; + } + std::cout << std::endl; +} diff --git a/src/analysis.h b/src/analysis.h new file mode 100644 index 0000000..1e14218 --- /dev/null +++ b/src/analysis.h @@ -0,0 +1,17 @@ +#ifndef ANALYSIS_H +#define ANALYSIS_H + +#include "my_mesh.h" + +bool check_faces_are_triangles(MyMesh &mesh); +bool check_faces_arent_lonely(MyMesh &mesh); +bool check_vertices_arent_lonely(MyMesh &mesh); +bool check_edges_arent_lonely(const char *path); +float face_area(MyMesh &mesh, const MyMesh::FaceHandle &face); +float total_area(MyMesh &mesh); +void stats_surface_area(MyMesh &mesh); +void stats_n_neighbors(MyMesh &mesh); +void stats_normal_deviation(MyMesh &mesh); +void stats_dihedral_angles(MyMesh &mesh); + +#endif diff --git a/src/main.cpp b/src/main.cpp index b5e5649..339b423 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,146 +1,5 @@ -#include "my_mesh.h" - -#include +#include "analysis.h" #include -#include - -#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) { - size_t n_edges = 0; - for (auto fe_it = mesh.fe_iter(*f_it); fe_it.is_valid(); ++fe_it) { - n_edges++; - } - if (n_edges != 3) { - return false; - } - } - return true; -} - - -bool check_faces_arent_lonely(MyMesh &mesh) { - for (auto f_it = mesh.faces_begin(); f_it != mesh.faces_end(); ++f_it) { - auto ff_it = mesh.ff_iter(*f_it); - if (!ff_it.is_valid()) { - return false; - } - } - return true; -} - - -bool check_vertices_arent_lonely(MyMesh &mesh) { - for (auto v_it = mesh.vertices_begin(); v_it != mesh.vertices_end(); ++v_it) { - auto ve_it = mesh.ve_iter(*v_it); - if (!ve_it.is_valid()) { - return false; - } - } - return true; -} - - -bool check_edges_arent_lonely(const char *path) { - using namespace std; - ifstream f(path); - string line; - while (getline(f, line)) { - istringstream iss(line); - char first; - iss >> first; - if (first == 'l') return false; - } - return true; -} - - -float face_area(MyMesh &mesh, const MyMesh::FaceHandle &face) { - MyMesh::Point p0, p1, p2; - auto fv_it = mesh.fv_iter(face); - p0 = mesh.point(*fv_it++); - p1 = mesh.point(*fv_it++); - p2 = mesh.point(*fv_it); - return ((p1 - p0) % (p2 - p0)).norm() / 2; -} - - -float total_area(MyMesh &mesh) { - if (!check_faces_are_triangles(mesh)) { - std::cerr << "Le calcul de l’aire ne peu se faire que sur un maillage triangulaire." << std::endl; - return -1; - } - float ret = 0; - for (const MyMesh::FaceHandle &face : mesh.faces()) { - ret += face_area(mesh, face); - } - return ret; -} - - -void stats_surface_area(MyMesh &mesh) { - if (!check_faces_are_triangles(mesh)) { - std::cerr << "Le calcul de l’aire ne peu se faire que sur un maillage triangulaire." << std::endl; - return; - } - for (const MyMesh::FaceHandle &face : mesh.faces()) { - std::cout << face_area(mesh, face) << " "; - } - std::cout << std::endl; -} - - -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; -} - - -#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); - 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; - } - 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; -} - - -void stats_dihedral_angles(MyMesh &mesh) { - mesh.update_normals(); - for (size_t i = 0; i < mesh.n_halfedges(); i++) { - MyMesh::HalfedgeHandle heh = mesh.halfedge_handle(i); - std::cout << mesh.calc_dihedral_angle_fast(heh) * 180.0 / PI + 180 << " "; - } - std::cout << std::endl; -} int main(int argc, char *argv[]) { diff --git a/tp1.pro b/tp1.pro index ed1a385..f8c72fb 100644 --- a/tp1.pro +++ b/tp1.pro @@ -1,32 +1,23 @@ +QT += core gui widgets TARGET = tp1 TEMPLATE = app - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which has been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - +CONFIG += DEBUG +INCLUDEPATH += $$PWD/libs/OpenMesh/inc/ +DEFINES += OM_STATIC_BUILD unix:!macx { LIBS += -L$$PWD/libs/OpenMesh/liblinux/ -lOpenMeshCore - INCLUDEPATH += $$PWD/libs/OpenMesh/inc/ - DEPENDPATH += $$PWD/libs/OpenMesh/inc/ - DEPENDPATH += $$PWD/libs/OpenMesh/liblinux/ } - -macx: { - INCLUDEPATH += $$PWD/libs/OpenMesh/inc/ +macx { LIBS += -L$$PWD/libs/OpenMesh/libosx/ -lOpenMeshCore } +win32 { + LIBS += $$PWD/libs/OpenMesh/libwin/OpenMeshCore.lib +} -SOURCES += \ - src/main.cpp +HEADERS += src/analysis.h +HEADERS += src/my_mesh.h -HEADERS += \ - src/my_mesh.h +SOURCES += src/main.cpp +SOURCES += src/analysis.cpp