From 45357d3771fa80163f7cd893e0f9215f7edee319 Mon Sep 17 00:00:00 2001 From: papush! Date: Fri, 1 Oct 2021 10:07:54 +0200 Subject: [PATCH] refactor border finding code --- src/main_window.cpp | 4 +++- src/mesh_processing.cpp | 29 ++++++++++++++++++++++++----- src/mesh_processing.h | 8 +++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main_window.cpp b/src/main_window.cpp index f3d3632..cbce79a 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -44,7 +44,9 @@ void MainWindow::open(const QString &path) { mesh.set_color(vh, MyMesh::Color(0, 0, 0)); } if (glm != nullptr) mesh_viewer.removeOpenGLMesh(glm); - findHoles(mesh); + for (HalfedgeStrip border : findBorders(mesh)) { + setBorderColor(mesh, border, {1, 0, 0}); + } 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 index 6908aca..16261e5 100644 --- a/src/mesh_processing.cpp +++ b/src/mesh_processing.cpp @@ -1,11 +1,30 @@ #include "mesh_processing.h" +#include -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}); +std::vector findBorders(MyMesh &mesh) { + std::vector borders(1); + size_t current = 0; + for (auto it = mesh.halfedges_begin(); it != mesh.halfedges_end(); ++it) { + while (mesh.is_boundary(*it)) { + borders[current].push_back(*it); + ++it; + } + if (borders[current].size() > 0) { + borders.emplace_back(); + current++; } } + if (borders.back().size() == 0) { + borders.pop_back(); + } + return borders; +} + + +void setBorderColor(MyMesh &mesh, const HalfedgeStrip &border, + MyMesh::Color color) { + for (MyMesh::HalfedgeHandle it : border) { + mesh.set_color(mesh.to_vertex_handle(it), color); + } } diff --git a/src/mesh_processing.h b/src/mesh_processing.h index bc84b3f..aa7e786 100644 --- a/src/mesh_processing.h +++ b/src/mesh_processing.h @@ -3,8 +3,14 @@ #include "my_mesh.h" +#include -void findHoles(MyMesh &mesh); +typedef std::vector HalfedgeStrip; + +std::vector findBorders(MyMesh &mesh); + +void setBorderColor(MyMesh &mesh, const HalfedgeStrip &border, + MyMesh::Color color); #endif \ No newline at end of file