improve mesh view handling

This commit is contained in:
papush! 2022-01-10 00:13:49 +01:00
parent 940ba1be7f
commit 228096c1a6
5 changed files with 15 additions and 7 deletions

View File

@ -32,6 +32,7 @@ MeshProcessor::MeshProcessor(const QString &path, MeshViewer &mesh_viewer,
qWarning() << "Curvature computation failed"; qWarning() << "Curvature computation failed";
} }
connect(&mesh_viewer, &MeshViewer::clicked, this, &MeshProcessor::click); connect(&mesh_viewer, &MeshViewer::clicked, this, &MeshProcessor::click);
updateView(); updateView();
} }
@ -44,7 +45,7 @@ MeshProcessor::~MeshProcessor() {
} }
void MeshProcessor::updateView() const { void MeshProcessor::updateView() {
if (mesh_viewer.isInitialized()) { if (mesh_viewer.isInitialized()) {
mesh_viewer.removeMesh(mesh); mesh_viewer.removeMesh(mesh);
mesh_viewer.addMesh(mesh); mesh_viewer.addMesh(mesh);

View File

@ -18,7 +18,7 @@ class MeshProcessor : public QObject {
double implicit_hole_filling_discr; double implicit_hole_filling_discr;
std::vector<MyMesh> fillings; std::vector<MyMesh> fillings;
void updateView() const; void updateView();
public: public:
MyMesh mesh; MyMesh mesh;

View File

@ -89,9 +89,10 @@ void MeshViewer::paintGL() {
} }
void MeshViewer::addMesh(const MyMesh &mesh) { void MeshViewer::addMesh(MyMesh &mesh) {
Q_ASSERT(isValid()); Q_ASSERT(isValid());
makeCurrent(); makeCurrent();
mesh.viewer_id = meshes.size();
meshes.emplace_back(mesh, program); meshes.emplace_back(mesh, program);
doneCurrent(); doneCurrent();
update(); update();
@ -100,9 +101,14 @@ void MeshViewer::addMesh(const MyMesh &mesh) {
void MeshViewer::removeMesh(const MyMesh &mesh) { void MeshViewer::removeMesh(const MyMesh &mesh) {
makeCurrent(); makeCurrent();
meshes.remove_if([&](const MeshView &mv) { size_t i = 0;
return &mv.mesh == &mesh; for (auto it = meshes.begin(); it != meshes.end(); ++it) {
}); if (i == mesh.viewer_id) {
meshes.erase(it);
break;
}
i++;
}
doneCurrent(); doneCurrent();
update(); update();
} }

View File

@ -46,7 +46,7 @@ public:
constexpr bool isInitialized() { return is_initialized; } constexpr bool isInitialized() { return is_initialized; }
public slots: public slots:
void addMesh(const MyMesh &mesh); void addMesh(MyMesh &mesh);
void removeMesh(const MyMesh &mesh); void removeMesh(const MyMesh &mesh);
void updateForReal(); void updateForReal();

View File

@ -25,6 +25,7 @@ class MyMesh : public OpenMesh::TriMesh_ArrayKernelT<MyTraits> {
public: public:
Color default_color {.5, .5, .5}; Color default_color {.5, .5, .5};
QMatrix4x4 transform; QMatrix4x4 transform;
size_t viewer_id;
std::vector<std::vector<HalfedgeHandle>> holes; std::vector<std::vector<HalfedgeHandle>> holes;
}; };