diff --git a/src/mesh_processor.cpp b/src/mesh_processor.cpp index 4cf75fb..adc59e0 100644 --- a/src/mesh_processor.cpp +++ b/src/mesh_processor.cpp @@ -32,6 +32,7 @@ MeshProcessor::MeshProcessor(const QString &path, MeshViewer &mesh_viewer, qWarning() << "Curvature computation failed"; } connect(&mesh_viewer, &MeshViewer::clicked, this, &MeshProcessor::click); + updateView(); } @@ -44,7 +45,7 @@ MeshProcessor::~MeshProcessor() { } -void MeshProcessor::updateView() const { +void MeshProcessor::updateView() { if (mesh_viewer.isInitialized()) { mesh_viewer.removeMesh(mesh); mesh_viewer.addMesh(mesh); diff --git a/src/mesh_processor.h b/src/mesh_processor.h index 95210a6..4dbf233 100644 --- a/src/mesh_processor.h +++ b/src/mesh_processor.h @@ -18,7 +18,7 @@ class MeshProcessor : public QObject { double implicit_hole_filling_discr; std::vector fillings; - void updateView() const; + void updateView(); public: MyMesh mesh; diff --git a/src/mesh_viewer.cpp b/src/mesh_viewer.cpp index 45bb717..0c64ba3 100644 --- a/src/mesh_viewer.cpp +++ b/src/mesh_viewer.cpp @@ -89,9 +89,10 @@ void MeshViewer::paintGL() { } -void MeshViewer::addMesh(const MyMesh &mesh) { +void MeshViewer::addMesh(MyMesh &mesh) { Q_ASSERT(isValid()); makeCurrent(); + mesh.viewer_id = meshes.size(); meshes.emplace_back(mesh, program); doneCurrent(); update(); @@ -100,9 +101,14 @@ void MeshViewer::addMesh(const MyMesh &mesh) { void MeshViewer::removeMesh(const MyMesh &mesh) { makeCurrent(); - meshes.remove_if([&](const MeshView &mv) { - return &mv.mesh == &mesh; - }); + size_t i = 0; + for (auto it = meshes.begin(); it != meshes.end(); ++it) { + if (i == mesh.viewer_id) { + meshes.erase(it); + break; + } + i++; + } doneCurrent(); update(); } diff --git a/src/mesh_viewer.h b/src/mesh_viewer.h index d00139c..6602d3a 100644 --- a/src/mesh_viewer.h +++ b/src/mesh_viewer.h @@ -46,7 +46,7 @@ public: constexpr bool isInitialized() { return is_initialized; } public slots: - void addMesh(const MyMesh &mesh); + void addMesh(MyMesh &mesh); void removeMesh(const MyMesh &mesh); void updateForReal(); diff --git a/src/my_mesh.h b/src/my_mesh.h index 931e353..1e78a81 100644 --- a/src/my_mesh.h +++ b/src/my_mesh.h @@ -25,6 +25,7 @@ class MyMesh : public OpenMesh::TriMesh_ArrayKernelT { public: Color default_color {.5, .5, .5}; QMatrix4x4 transform; + size_t viewer_id; std::vector> holes; };