refactor border finding code
This commit is contained in:
parent
f1d632bdb6
commit
45357d3771
@ -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);
|
||||
|
@ -1,11 +1,30 @@
|
||||
#include "mesh_processing.h"
|
||||
#include <list>
|
||||
|
||||
|
||||
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<HalfedgeStrip> findBorders(MyMesh &mesh) {
|
||||
std::vector<HalfedgeStrip> 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);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,14 @@
|
||||
|
||||
#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
|
Loading…
Reference in New Issue
Block a user