add hole detection and visualization

This commit is contained in:
papush! 2021-09-30 17:20:25 +02:00
parent 0dd3d434f6
commit f1d632bdb6
5 changed files with 33 additions and 5 deletions

View File

@ -1,4 +1,5 @@
#include "main_window.h" #include "main_window.h"
#include "mesh_processing.h"
#include <QApplication> #include <QApplication>
#include <QFileDialog> #include <QFileDialog>
@ -33,14 +34,17 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::open(const QString &path) { 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; qWarning() << "Failed to read" << path;
return; return;
} }
for (const VertexHandle &vh : mesh.vertices()) { 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); if (glm != nullptr) mesh_viewer.removeOpenGLMesh(glm);
findHoles(mesh);
glm = mesh_viewer.addOpenGLMeshFromOpenMesh(&mesh); glm = mesh_viewer.addOpenGLMeshFromOpenMesh(&mesh);
for (QAction *a : toolbar_actions) { for (QAction *a : toolbar_actions) {
a->setEnabled(true); a->setEnabled(true);

11
src/mesh_processing.cpp Normal file
View File

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

10
src/mesh_processing.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef MESH_PROCESSING_H
#define MESH_PROCESSING_H
#include "my_mesh.h"
void findHoles(MyMesh &mesh);
#endif

View File

@ -28,8 +28,9 @@ uniform bool wireframe;
uniform float alpha; uniform float alpha;
void main() { void main() {
if (wireframe) if (!wireframe)
gl_FragColor = vec4(wf_col, alpha); // gl_FragColor = vec4(wf_col, alpha);
gl_FragColor = vec4(.5, .5, .5, 1);
else else
gl_FragColor = vec4(frag_col, alpha); gl_FragColor = vec4(frag_col, alpha);
} }
@ -169,7 +170,7 @@ void MeshViewer::paintGL() {
glUniform1f(wireframe_attr, 1); glUniform1f(wireframe_attr, 1);
glDrawArrays(GL_TRIANGLES, 0, m.nverts); glDrawArrays(GL_TRIANGLES, 0, m.nverts);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glLineWidth(1); glLineWidth(3);
glUniform1f(wireframe_attr, 0); glUniform1f(wireframe_attr, 0);
} }
} }

2
tp.pro
View File

@ -19,7 +19,9 @@ win32 {
HEADERS += src/my_mesh.h HEADERS += src/my_mesh.h
HEADERS += src/main_window.h HEADERS += src/main_window.h
HEADERS += src/mesh_viewer.h HEADERS += src/mesh_viewer.h
HEADERS += src/mesh_processing.h
SOURCES += src/main.cpp SOURCES += src/main.cpp
SOURCES += src/main_window.cpp SOURCES += src/main_window.cpp
SOURCES += src/mesh_viewer.cpp SOURCES += src/mesh_viewer.cpp
SOURCES += src/mesh_processing.cpp