mod_geo-tp/src/main_window.cpp

66 lines
1.8 KiB
C++
Raw Normal View History

2021-09-20 20:36:29 +02:00
#include "main_window.h"
2021-09-30 17:20:25 +02:00
#include "mesh_processing.h"
2021-09-20 20:36:29 +02:00
#include <QApplication>
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent),
mesh_viewer(this),
toolbar(this) {
connect(&mesh_viewer, &MeshViewer::initialized, this, &MainWindow::meshViewerInitialized);
setCentralWidget(&mesh_viewer);
addToolBar(Qt::RightToolBarArea, &toolbar);
open_action = toolbar.addAction("Ouvrir…", [&](){
open(QFileDialog::getOpenFileName(this, "Ouvrir un fichier OBJ"));
});
// toolbar_actions.append(toolbar.addAction("Fractionner", [&](){
// QVector<QPair<MyMesh::Point, MyMesh>> fragments = shatter(mesh);
// mesh_viewer.removeOpenGLMesh(glm);
// for (auto &[pos, fragment] : fragments) {
// fragment.triangulate();
// QMatrix4x4 mat;
// float scale = 1.2;
// mat.translate(pos[0] * scale, pos[1] * scale, pos[2] * scale);
// mesh_viewer.addOpenGLMeshFromOpenMesh(&fragment, mat);
// }
// }));
open_action->setEnabled(false);
for (QAction *a : toolbar_actions) {
a->setEnabled(false);
}
}
void MainWindow::open(const QString &path) {
2021-09-30 17:20:25 +02:00
OpenMesh::IO::Options options;
options.set(OpenMesh::IO::Options::VertexColor);
if (!OpenMesh::IO::read_mesh(mesh, path.toUtf8().constData(), options)) {
2021-09-20 20:36:29 +02:00
qWarning() << "Failed to read" << path;
return;
}
for (const VertexHandle &vh : mesh.vertices()) {
2021-09-30 17:20:25 +02:00
mesh.set_color(vh, MyMesh::Color(0, 0, 0));
2021-09-20 20:36:29 +02:00
}
2021-10-02 12:03:46 +02:00
for (HalfedgeHandle border : findBorders(mesh)) {
2021-10-01 10:07:54 +02:00
setBorderColor(mesh, border, {1, 0, 0});
2021-10-02 12:03:46 +02:00
fillHoleDumb(mesh, border);
2021-10-01 10:07:54 +02:00
}
2021-10-02 12:03:46 +02:00
if (glm != nullptr) mesh_viewer.removeOpenGLMesh(glm);
2021-09-20 20:36:29 +02:00
glm = mesh_viewer.addOpenGLMeshFromOpenMesh(&mesh);
for (QAction *a : toolbar_actions) {
a->setEnabled(true);
}
}
void MainWindow::meshViewerInitialized() {
if (qApp->arguments().size() == 2) {
open(qApp->arguments().at(1));
}
open_action->setEnabled(true);
}