switches to qt build, windows support, static linking of OpenMesh

This commit is contained in:
ccolin 2020-10-03 21:21:35 +02:00
parent c564671b93
commit 905852683b
9 changed files with 176 additions and 167 deletions

8
README
View File

@ -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 <obj>'
Pour faire un bel histogramme coloré : LD_LIBRARY_PATH=libs/OpenMesh/liblinux/ build/tp1 <obj> | util/plot.py [nombre de classes, 10 par défaut] [min] [max]
Pour exécuter le programme : `./build/tp1 <obj> <commande>'
Pour faire un bel histogramme coloré : LD_LIBRARY_PATH=libs/OpenMesh/liblinux/ build/tp1 <obj> <cmd> | util/plot.py [nombre de classes, 10 par défaut] [min] [max]

Binary file not shown.

Binary file not shown.

142
src/analysis.cpp Normal file
View File

@ -0,0 +1,142 @@
#include "analysis.h"
#include <cmath>
#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) {
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 laire 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 laire 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;
}

17
src/analysis.h Normal file
View File

@ -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

View File

@ -1,146 +1,5 @@
#include "my_mesh.h"
#include <cmath>
#include "analysis.h"
#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) {
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 laire 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 laire 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[]) {

33
tp1.pro
View File

@ -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