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; MeshProcessor *mesh_processor = nullptr;
MainWindow main_window; MainWindow main_window;
MeshViewer *mesh_viewer = &main_window.mesh_viewer; 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) { if (argc > 2) {
qWarning("Utilisation: %s [MAILLAGE]", argv[0]); qWarning("Utilisation: %s [MAILLAGE]", argv[0]);
return 1; return 1;
} else if (argc == 2) { } else if (argc == 2) {
mesh_processor = new MeshProcessor(argv[1], *mesh_viewer); mesh_processor = new MeshProcessor(argv[1], *mesh_viewer);
QObject::connect(mesh_viewer, &MeshViewer::clicked,
mesh_processor, &MeshProcessor::click);
} }
QObject::connect(&main_window, &MainWindow::open, QObject::connect(&main_window, &MainWindow::open,
[&](const QString &path) { [&](const QString &path) {
if (mesh_processor) { if (mesh_processor) delete mesh_processor;
mesh_viewer->removeMesh(mesh_processor->mesh); mesh_processor = new MeshProcessor(path,
delete mesh_processor; *mesh_viewer);
}
mesh_processor = new MeshProcessor(path, *mesh_viewer);
mesh_viewer->addMesh(mesh_processor->mesh);
QObject::connect(mesh_viewer, &MeshViewer::clicked,
mesh_processor, &MeshProcessor::click);
}); });
main_window.show(); main_window.show();
return app.exec(); return app.exec();

View File

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

View File

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

View File

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