Skip to content

Commit

Permalink
WIP: Directly create Manifold from PolySet before attempting repair
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel committed Mar 5, 2024
1 parent 4d291d1 commit 84917c1
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions src/geometry/manifold/manifoldutils.cc
Expand Up @@ -149,44 +149,45 @@ std::shared_ptr<const ManifoldGeometry> createManifoldFromPolySet(const PolySet&
LOG("Warning: [manifold] PolySet -> Manifold conversion failed: %1$s\n"
"Trying to repair and reconstruct mesh",
ManifoldUtils::statusToString(mani->Status()));
{
#ifdef ENABLE_CGAL
PolySet psq(ps);
std::vector<Vector3d> points3d;
psq.quantizeVertices(&points3d);
auto ps_tri = PolySetUtils::tessellate_faces(psq);

CGAL_DoubleMesh m;

if (ps_tri->is_convex()) {
using K = CGAL::Epick;
// Collect point cloud
std::vector<K::Point_3> points(points3d.size());
for (size_t i = 0, n = points3d.size(); i < n; i++) {
points[i] = CGALUtils::vector_convert<K::Point_3>(points3d[i]);
{
#ifdef ENABLE_CGAL
PolySet psq(ps);
std::vector<Vector3d> points3d;
psq.quantizeVertices(&points3d);
auto ps_tri = PolySetUtils::tessellate_faces(psq);

CGAL_DoubleMesh m;

if (ps_tri->is_convex()) {
using K = CGAL::Epick;
// Collect point cloud
std::vector<K::Point_3> points(points3d.size());
for (size_t i = 0, n = points3d.size(); i < n; i++) {
points[i] = CGALUtils::vector_convert<K::Point_3>(points3d[i]);
}
if (points.size() <= 3) return std::make_shared<ManifoldGeometry>();

// Apply hull
CGAL::Surface_mesh<CGAL::Point_3<K>> r;
CGAL::convex_hull_3(points.begin(), points.end(), r);
CGALUtils::copyMesh(r, m);
} else {
CGALUtils::createMeshFromPolySet(*ps_tri, m);
}
if (points.size() <= 3) return std::make_shared<ManifoldGeometry>();

// Apply hull
CGAL::Surface_mesh<CGAL::Point_3<K>> r;
CGAL::convex_hull_3(points.begin(), points.end(), r);
CGALUtils::copyMesh(r, m);
} else {
CGALUtils::createMeshFromPolySet(*ps_tri, m);
}

if (!ps_tri->is_convex()) {
if (CGALUtils::isClosed(m)) {
CGALUtils::orientToBoundAVolume(m);
} else {
LOG(message_group::Error, "[manifold] Input mesh is not closed!");
if (!ps_tri->is_convex()) {
if (CGALUtils::isClosed(m)) {
CGALUtils::orientToBoundAVolume(m);
} else {
LOG(message_group::Error, "[manifold] Input mesh is not closed!");
}
}
}

return createManifoldFromSurfaceMesh(m);
#else
return std::make_shared<ManifoldGeometry>();
#endif
return createManifoldFromSurfaceMesh(m);
#else
return std::make_shared<ManifoldGeometry>();
#endif
}
}

std::shared_ptr<const ManifoldGeometry> createManifoldFromGeometry(const std::shared_ptr<const Geometry>& geom) {
Expand Down

0 comments on commit 84917c1

Please sign in to comment.