Compare commits

..

No commits in common. "63074306c2093f0faec3f7cb731978bbfb194ff3" and "45357d3771fa80163f7cd893e0f9215f7edee319" have entirely different histories.

4 changed files with 24 additions and 73 deletions

View File

@ -43,13 +43,10 @@ void MainWindow::open(const QString &path) {
for (const VertexHandle &vh : mesh.vertices()) {
mesh.set_color(vh, MyMesh::Color(0, 0, 0));
}
for (HalfedgeHandle border : findBorders(mesh)) {
setBorderColor(mesh, border, {1, 0, 0});
fillHoleDumb(mesh, border);
}
if (glm != nullptr) mesh_viewer.removeOpenGLMesh(glm);
for (HalfedgeStrip border : findBorders(mesh)) {
setBorderColor(mesh, border, {1, 0, 0});
}
glm = mesh_viewer.addOpenGLMeshFromOpenMesh(&mesh);
for (QAction *a : toolbar_actions) {
a->setEnabled(true);

View File

@ -1,54 +1,30 @@
#include "mesh_processing.h"
#include <QGenericMatrix>
#include <unordered_set>
#include <list>
std::vector<HalfedgeHandle> findBorders(MyMesh &mesh) {
std::vector<HalfedgeHandle> borders;
std::set<HalfedgeHandle> ignore;
for (HalfedgeHandle it : mesh.halfedges()) {
if (mesh.is_boundary(it)
&& ignore.find(it) == ignore.end()) {
borders.push_back(it);
ignore.insert(it);
for (HalfedgeHandle it2 : HalfedgeLoopRange(mesh, it)) {
ignore.insert(it2);
}
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 HalfedgeHandle &border,
void setBorderColor(MyMesh &mesh, const HalfedgeStrip &border,
MyMesh::Color color) {
for (HalfedgeHandle it : HalfedgeLoopRange(mesh, border)) {
for (MyMesh::HalfedgeHandle it : border) {
mesh.set_color(mesh.to_vertex_handle(it), color);
}
}
void fillHoleDumb(MyMesh &mesh, HalfedgeHandle &border) {
mesh.request_vertex_status();
mesh.request_edge_status();
mesh.request_face_status();
Point center(0, 0, 0);
size_t length = 0;
for (HalfedgeHandle it : HalfedgeLoopRange(mesh, border)) {
VertexHandle vert = mesh.to_vertex_handle(it);
center += mesh.point(vert);
length++;
}
center /= length;
VertexHandle center_handle = mesh.new_vertex_dirty(center);
for (HalfedgeHandle it = border;
mesh.to_vertex_handle(it) != center_handle;) {
HalfedgeHandle next = mesh.next_halfedge_handle(it);
mesh.add_face(mesh.from_vertex_handle(it),
mesh.to_vertex_handle(it),
center_handle);
it = next;
}
}

View File

@ -6,12 +6,11 @@
#include <vector>
std::vector<HalfedgeHandle> findBorders(MyMesh &mesh);
typedef std::vector<MyMesh::HalfedgeHandle> HalfedgeStrip;
void setBorderColor(MyMesh &mesh, const HalfedgeHandle &border,
std::vector<HalfedgeStrip> findBorders(MyMesh &mesh);
void setBorderColor(MyMesh &mesh, const HalfedgeStrip &border,
MyMesh::Color color);
void fillHoleDumb(MyMesh &mesh, HalfedgeHandle &border);
#endif

View File

@ -14,27 +14,6 @@ struct MyTraits : public OpenMesh::DefaultTraits {
typedef OpenMesh::Vec3f Color;
};
typedef OpenMesh::PolyMesh_ArrayKernelT<MyTraits> MyMesh;
typedef MyMesh::FaceHandle FaceHandle;
typedef MyMesh::VertexHandle VertexHandle;
typedef MyMesh::HalfedgeHandle HalfedgeHandle;
typedef MyMesh::EdgeHandle EdgeHandle;
typedef MyMesh::Point Point;
class HalfedgeLoopRange {
MyMesh &mesh;
const HalfedgeHandle &start;
public:
HalfedgeLoopRange(MyMesh &mesh, const HalfedgeHandle &start)
:mesh(mesh), start(start) {}
MyMesh::HalfedgeLoopIter begin() {
return mesh.hl_begin(start);
}
MyMesh::HalfedgeLoopIter end() {
return mesh.hl_end(start);
}
};
#endif