Skip to content

Commit

Permalink
Fix test case and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel committed Mar 11, 2024
1 parent dc0ec9b commit dfc72b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
30 changes: 16 additions & 14 deletions src/geometry/manifold/manifoldutils.cc
Expand Up @@ -128,27 +128,29 @@ std::unique_ptr<const manifold::Manifold> createManifoldFromTriangularPolySet(co

std::shared_ptr<const ManifoldGeometry> createManifoldFromPolySet(const PolySet& ps)
{
// FIXME: To create a Manifold object, we may need to first triangulate.
// The incoming PolySet could be severely broken if it originated from user or file input, so
// be prepared to repair it.
// 1. If it's not triangular, attempt to triangulate it directly
// 2. Try to create a Manifold object
// 3. If the Manifold object is broken (e.g. not a manifold), attempt repair
// 4. If successfully repaired, try to create Manifold again.

std::unique_ptr<const PolySet> ps_tri;
// 1. If the PolySet is already manifold, we should be able to build a Manifold object directly
// (through using manifold::Mesh).
// We need to make sure our PolySet is triangulated before doing that.
// Note: We currently don't have a way of directly checking if a PolySet is manifold,
// so we just try converting to a Manifold object and check its status.
std::unique_ptr<const PolySet> triangulated;
if (!ps.isTriangular()) {
ps_tri = PolySetUtils::tessellate_faces(ps);
triangulated = PolySetUtils::tessellate_faces(ps);
}
const PolySet good_ps = ps.isTriangular() ? ps : *ps_tri;
auto mani = createManifoldFromTriangularPolySet(good_ps);
const PolySet triangle_set = ps.isTriangular() ? ps : *triangulated;

auto mani = createManifoldFromTriangularPolySet(triangle_set);
if (mani->Status() == Error::NoError) {
return std::make_shared<const ManifoldGeometry>(std::shared_ptr<const manifold::Manifold>(std::move(mani)));
}

LOG("Warning: [manifold] PolySet -> Manifold conversion failed: %1$s\n"
"Trying to repair and reconstruct mesh",
// FIXME: Should we suppress this warning, as it may not be very actionable?
LOG(message_group::Warning,"PolySet -> Manifold conversion failed: %1$s\n"
"Trying to repair and reconstruct mesh..",
ManifoldUtils::statusToString(mani->Status()));

// 2. If the PolySet couldn't be converted into a Manifold object, let's try to repair it.
// We currently have to utilize some CGAL functions to do this.
{
#ifdef ENABLE_CGAL
PolySet psq(ps);
Expand Down
16 changes: 0 additions & 16 deletions tests/CMakeLists.txt
Expand Up @@ -1073,22 +1073,6 @@ add_cmdline_test(stlpngtest SCRIPT ${EX_IM_PNGTEST_PY} ARGS ${OPENSCAD_ARG} --fo

set_tests_properties(
# Manifold construction error. Probably due to polygon soup strategy
3mfpngtest_polyhedron-self-touch-face-nonmanifold
3mfpngtest_polyhedron-self-touch-face
objpngtest_polyhedron-self-touch-face-nonmanifold
objpngtest_polyhedron-self-touch-face
offpngtest_polyhedron-self-touch-face-nonmanifold
offpngtest_polyhedron-self-touch-face
stlpngtest_polyhedron-self-touch-face-nonmanifold
stlpngtest_polyhedron-self-touch-face
3mfpngtest_polyhedrons-touch-face-nonmanifold
3mfpngtest_polyhedrons-touch-face
objpngtest_polyhedrons-touch-face-nonmanifold
objpngtest_polyhedrons-touch-face
offpngtest_polyhedrons-touch-face-nonmanifold
offpngtest_polyhedrons-touch-face
stlpngtest_polyhedrons-touch-face-nonmanifold
stlpngtest_polyhedrons-touch-face
PROPERTIES DISABLED TRUE
)

Expand Down
4 changes: 2 additions & 2 deletions tests/data/scad/3D/misc/polyhedron-self-touch-face.scad
Expand Up @@ -20,7 +20,7 @@ polyhedron(
[0.5, 0.6, 0.5],
],
faces=[
[5,4,11],[5,11,12]
[5,4,11],[5,11,12],
[4,6,11],
[6,13,11],
[6,7,13],
Expand All @@ -39,5 +39,5 @@ polyhedron(
[4,5,1],[4,1,0],
[5,7,3],[5,3,1],
[7,6,2],[7,2,3],
[6,4,0,2],[6,0,2],
[6,4,0],[6,0,2],
]);
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dfc72b2

Please sign in to comment.