refactor border finding code

This commit is contained in:
papush! 2021-10-01 10:07:54 +02:00
parent f1d632bdb6
commit 45357d3771
3 changed files with 34 additions and 7 deletions

View File

@ -44,7 +44,9 @@ void MainWindow::open(const QString &path) {
mesh.set_color(vh, MyMesh::Color(0, 0, 0)); 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); for (HalfedgeStrip border : findBorders(mesh)) {
setBorderColor(mesh, border, {1, 0, 0});
}
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);

View File

@ -1,11 +1,30 @@
#include "mesh_processing.h" #include "mesh_processing.h"
#include <list>
void findHoles(MyMesh &mesh) { std::vector<HalfedgeStrip> findBorders(MyMesh &mesh) {
for (const MyMesh::HalfedgeHandle &eh : mesh.halfedges()) { std::vector<HalfedgeStrip> borders(1);
if (mesh.is_boundary(eh)) { size_t current = 0;
MyMesh::VertexHandle vh = mesh.to_vertex_handle(eh); for (auto it = mesh.halfedges_begin(); it != mesh.halfedges_end(); ++it) {
mesh.set_color(vh, {.8, .2, .7}); 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);
} }
} }

View File

@ -3,8 +3,14 @@
#include "my_mesh.h" #include "my_mesh.h"
#include <vector>
void findHoles(MyMesh &mesh);
typedef std::vector<MyMesh::HalfedgeHandle> HalfedgeStrip;
std::vector<HalfedgeStrip> findBorders(MyMesh &mesh);
void setBorderColor(MyMesh &mesh, const HalfedgeStrip &border,
MyMesh::Color color);
#endif #endif