From f1d632bdb677a73964fb955a348a070d4527b73d Mon Sep 17 00:00:00 2001 From: papush! Date: Thu, 30 Sep 2021 17:20:25 +0200 Subject: [PATCH] add hole detection and visualization --- src/main_window.cpp | 8 ++++++-- src/mesh_processing.cpp | 11 +++++++++++ src/mesh_processing.h | 10 ++++++++++ src/mesh_viewer.cpp | 7 ++++--- tp.pro | 2 ++ 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 src/mesh_processing.cpp create mode 100644 src/mesh_processing.h diff --git a/src/main_window.cpp b/src/main_window.cpp index d9568ee..f3d3632 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -1,4 +1,5 @@ #include "main_window.h" +#include "mesh_processing.h" #include #include @@ -33,14 +34,17 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::open(const QString &path) { - if (!OpenMesh::IO::read_mesh(mesh, path.toUtf8().constData())) { + OpenMesh::IO::Options options; + options.set(OpenMesh::IO::Options::VertexColor); + if (!OpenMesh::IO::read_mesh(mesh, path.toUtf8().constData(), options)) { qWarning() << "Failed to read" << path; return; } for (const VertexHandle &vh : mesh.vertices()) { - mesh.set_color(vh, MyMesh::Color(.5, .5, .5)); + mesh.set_color(vh, MyMesh::Color(0, 0, 0)); } if (glm != nullptr) mesh_viewer.removeOpenGLMesh(glm); + findHoles(mesh); glm = mesh_viewer.addOpenGLMeshFromOpenMesh(&mesh); for (QAction *a : toolbar_actions) { a->setEnabled(true); diff --git a/src/mesh_processing.cpp b/src/mesh_processing.cpp new file mode 100644 index 0000000..6908aca --- /dev/null +++ b/src/mesh_processing.cpp @@ -0,0 +1,11 @@ +#include "mesh_processing.h" + + +void findHoles(MyMesh &mesh) { + for (const MyMesh::HalfedgeHandle &eh : mesh.halfedges()) { + if (mesh.is_boundary(eh)) { + MyMesh::VertexHandle vh = mesh.to_vertex_handle(eh); + mesh.set_color(vh, {.8, .2, .7}); + } + } +} diff --git a/src/mesh_processing.h b/src/mesh_processing.h new file mode 100644 index 0000000..bc84b3f --- /dev/null +++ b/src/mesh_processing.h @@ -0,0 +1,10 @@ +#ifndef MESH_PROCESSING_H +#define MESH_PROCESSING_H + +#include "my_mesh.h" + + +void findHoles(MyMesh &mesh); + + +#endif \ No newline at end of file diff --git a/src/mesh_viewer.cpp b/src/mesh_viewer.cpp index e705e15..da532e0 100644 --- a/src/mesh_viewer.cpp +++ b/src/mesh_viewer.cpp @@ -28,8 +28,9 @@ uniform bool wireframe; uniform float alpha; void main() { - if (wireframe) - gl_FragColor = vec4(wf_col, alpha); + if (!wireframe) + // gl_FragColor = vec4(wf_col, alpha); + gl_FragColor = vec4(.5, .5, .5, 1); else gl_FragColor = vec4(frag_col, alpha); } @@ -169,7 +170,7 @@ void MeshViewer::paintGL() { glUniform1f(wireframe_attr, 1); glDrawArrays(GL_TRIANGLES, 0, m.nverts); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glLineWidth(1); + glLineWidth(3); glUniform1f(wireframe_attr, 0); } } diff --git a/tp.pro b/tp.pro index e8be321..7dcb269 100644 --- a/tp.pro +++ b/tp.pro @@ -19,7 +19,9 @@ win32 { HEADERS += src/my_mesh.h HEADERS += src/main_window.h HEADERS += src/mesh_viewer.h +HEADERS += src/mesh_processing.h SOURCES += src/main.cpp SOURCES += src/main_window.cpp SOURCES += src/mesh_viewer.cpp +SOURCES += src/mesh_processing.cpp