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

Repair meshes in manifold & fast-csg routes #4832

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ochafik
Copy link
Contributor

@ochafik ochafik commented Nov 16, 2023

This PR introduces some crude mesh repairs in manifold & fast-csg modes.

Since orient_to_bound_a_volume seems happy to throw assert and precondition exceptions at us when the mesh has self-intersections or isn't closed, I'm catching these, remove any self intersections & plug any holes (then try orienting again w/ a more lenient method).

This fixes 3D/features/linear_extrude-scale-zero-tests.scad along with a few models I had that have invalid geometry but that I prefer seeing repaired than exploding in flight.

TODO before undrafting:

  • Are unclosed meshes ever valid? This PR is probably enforcing their repair / closing, with extra costs (before, orientation routine was fenced by CGAL::is_closed)
  • Check performance regression (switched to using Epick kernel in Manifold factory to avoid inexact checks in orientation, but this could be slower)
  • Add more tests?

CGAL::Surface_mesh<CGAL::Point_3<K>> r;
CGAL::convex_hull_3(points.begin(), points.end(), r);
CGALUtils::copyMesh(r, m);
CGAL::convex_hull_3(points.begin(), points.end(), m);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the hull function in manifold. We don't do much optimization for now but we may do them later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I probably checked the wrong thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, good to know it's there, not sure about here (would have to inline this logic in a manifold-specific way) but I'll probably give it a spin where we perform the hull primitive itself.

@pca006132
Copy link
Member

Looking at CGAL, it seems that they do have algorithm for repairing non-manifold triangular soup called duplicate_non_manifold_vertices. They are called combinatorial repair https://doc.cgal.org/latest/Polygon_mesh_processing/index.html#PMPCombinatorialRepair.

I think the existing mesh processing in this PR are for dealing with self-intersections, but not sure if this can deal with topological issues (manifoldness).

@pca006132
Copy link
Member

Ah, bad news. I tried duplicate_non_manifold_vertices and repair_polygon_soup with no luck. It doesn't work on the example in #4838.

@pca006132
Copy link
Member

pca006132 commented Nov 22, 2023

Good news: We need to first repair_polygon_soup, and then orient_polygon_soup. Here is a demo:

782eb0c

This works for the simple cases where two cubes are touching at a corner/edge. I did not try more complicated cases. Should be nice to include in this PR.

That code is basically copied from https://github.com/CGAL/cgal/blob/master/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h

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

Successfully merging this pull request may close these issues.

None yet

2 participants