cleanup initialization

This commit is contained in:
papush! 2021-11-18 14:55:03 +01:00
parent 6fdca63aee
commit 54470644f1
4 changed files with 24 additions and 22 deletions

View File

@ -18,31 +18,17 @@ int main(int argc, char *argv[]) {
MeshProcessor *mesh_processor = nullptr;
MainWindow main_window;
MeshViewer *mesh_viewer = &main_window.mesh_viewer;
QObject::connect(mesh_viewer, &MeshViewer::initialized,
[&]() {
if (mesh_processor) {
mesh_viewer->addMesh(mesh_processor->mesh);
}
});
if (argc > 2) {
qWarning("Utilisation: %s [MAILLAGE]", argv[0]);
return 1;
} else if (argc == 2) {
mesh_processor = new MeshProcessor(argv[1], *mesh_viewer);
QObject::connect(mesh_viewer, &MeshViewer::clicked,
mesh_processor, &MeshProcessor::click);
}
QObject::connect(&main_window, &MainWindow::open,
[&](const QString &path) {
if (mesh_processor) {
mesh_viewer->removeMesh(mesh_processor->mesh);
delete mesh_processor;
}
mesh_processor = new MeshProcessor(path, *mesh_viewer);
mesh_viewer->addMesh(mesh_processor->mesh);
QObject::connect(mesh_viewer, &MeshViewer::clicked,
mesh_processor, &MeshProcessor::click);
if (mesh_processor) delete mesh_processor;
mesh_processor = new MeshProcessor(path,
*mesh_viewer);
});
main_window.show();
return app.exec();

View File

@ -35,16 +35,29 @@ MeshProcessor::MeshProcessor(const QString &path, MeshViewer &mesh_viewer)
return;
}
mesh.update_normals();
courbure = new Courbures(mesh);
courbure->compute_KH();
courbure->set_K_colors();
// mesh.holes = findHoles(mesh);
// fillHoles();
// courbure = new Courbures(mesh);
// courbure->compute_KH();
// courbure->set_K_colors();
mesh.holes = findHoles(mesh);
fillHoles();
// smooth(mesh);
if (mesh_viewer.isInitialized()) {
mesh_viewer.addMesh(mesh);
} else {
connect(&mesh_viewer, &MeshViewer::initialized,
[&]() { mesh_viewer.addMesh(mesh); });
}
connect(&mesh_viewer, &MeshViewer::clicked, this, &MeshProcessor::click);
}
MeshProcessor::~MeshProcessor() {
if (mesh_viewer.isInitialized()) {
mesh_viewer.removeMesh(mesh);
} else {
connect(&mesh_viewer, &MeshViewer::initialized,
[&]() { mesh_viewer.removeMesh(mesh); });
}
if (courbure) delete courbure;
}

View File

@ -64,6 +64,7 @@ void MeshViewer::initializeGL() {
glf->glEnable(GL_MULTISAMPLE);
qDebug("MeshViewer: initialization complete");
is_initialized = true;
emit initialized();
}

View File

@ -35,6 +35,7 @@ class MeshViewer : public QOpenGLWidget {
QMatrix4x4 view = trans * rot;
QPoint mouse_pos;
void updateViewMatrix();
bool is_initialized = false;
public:
MeshViewer(QWidget *parent=nullptr);
@ -42,6 +43,7 @@ public:
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
constexpr bool isInitialized() { return is_initialized; }
public slots:
void addMesh(const MyMesh &mesh);