Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting surface mesh to manifold surface mesh #158

Open
jtressle opened this issue Jun 16, 2023 · 3 comments
Open

Converting surface mesh to manifold surface mesh #158

jtressle opened this issue Jun 16, 2023 · 3 comments

Comments

@jtressle
Copy link

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

@jtressle
Copy link
Author

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

@jtressle
Copy link
Author

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

@nmwsharp
Copy link
Owner

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:
image
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants