Converting surface mesh to manifold surface mesh
jtressle opened this issue · 3 comments
Hi,
Great software! I had one question about converting a surface mesh to a manifold surface mesh. Basically, I have a non-manifold mesh (duplicate halfedges), and I'm trying to see if there's a way to delete faces of these duplicated halfedges before I use makeManifoldSurfaceMeshAndGeometry?
Thanks
Hi,
I was able to get something to work. I first tried reading as a manifold surface mesh. If that fails, I create a surface mesh, and find the duplicate edges (based on your code):
std::unordered_map<std::tuple<size_t, size_t>, size_t, pair_hash> created_half_edges;
std::vector<std::vector<size_t>> cleaned_polygons;
std::cout << "- Cleaning up mesh..." << std::endl;
for (Face face : mesh->faces()) {
std::vector<size_t> cleaned_polygon;
// Iterate over the halfedges of the face
size_t iFaceHe = 0;
for (Halfedge halfedge : face.adjacentHalfedges()) {
const size_t indTail = halfedge.tailVertex().getIndex();
const size_t indTip = halfedge.tipVertex().getIndex();
// Skip self-edges
if (indTail == indTip) continue;
// Get an index for this halfedge
std::tuple<size_t, size_t> heKey{indTail, indTip};
auto it = created_half_edges.find(heKey);
// Skip duplicate edges
if (it != created_half_edges.end()) continue;
// half edge is valid so add it to the polygon
cleaned_polygon.push_back(indTail);
// mark halfedge as created
created_half_edges[heKey] = iFaceHe;
++iFaceHe;
}
if (cleaned_polygon.size() == 3) {
cleaned_polygons.push_back(cleaned_polygon);
}
}
I then reindex the vertices and polygons before using them to create a manifold surface mesh.
Thanks
As a followup, I'm having issues with vertices "appears in more than one boundary loop". I'll see if I can fix this. Do you any recommendations for mesh cleanup using geometry central? Or is that out of the scope?
Thanks
Hi! Glad to hear you're making use of geometry-central!
This kind of 'mesh repair' operations / 'make it manifold' operations are definitely in-scope. It would be great to have some implemented in the library, we have just never gotten around to it.
In case you haven't figured it out already, the 'appears in more than one boundary loop' error is caused by configurations like the center vertex here:
where there are multiple separate 'wedges' of the boundary/interior incident on the same vertex. This technically violates the definition of manifoldness-with-boundary, however a lot of other software doesn't actually flag this case. For geometry-central's datastructures it really matters, so we do check for this case and report an error.