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";
}
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);

View File

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

View File

@ -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();

View File

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