From b0aa937215ba44161b06d19b7c0db774760c7e60 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 29 Jan 2020 15:57:49 +0100 Subject: [PATCH] Trying to improve drilling stability by handling CGAL exceptions --- src/libslic3r/MeshBoolean.cpp | 13 +++++++++++-- src/libslic3r/SLAPrintSteps.cpp | 14 ++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/MeshBoolean.cpp b/src/libslic3r/MeshBoolean.cpp index 69db96d3f..734bfaca8 100644 --- a/src/libslic3r/MeshBoolean.cpp +++ b/src/libslic3r/MeshBoolean.cpp @@ -150,8 +150,17 @@ void minus(TriangleMesh &A, const TriangleMesh &B) triangle_mesh_to_cgal(B, meshB.m); CGALMesh meshResult; - CGALProc::corefine_and_compute_difference(meshA.m, meshB.m, meshResult.m); - + bool success = false; + try { + success = CGALProc::corefine_and_compute_difference(meshA.m, meshB.m, meshResult.m, + CGALParams::throw_on_self_intersection(true), CGALParams::throw_on_self_intersection(true)); + } + catch (const CGAL::Polygon_mesh_processing::Corefinement::Self_intersection_exception&) { + success = false; + } + if (! success) + throw std::runtime_error("CGAL corefine_and_compute_difference failed"); + A = cgal_to_triangle_mesh(meshResult.m); } diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index 44ef5fe45..8c0aac6fa 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -83,9 +83,9 @@ void SLAPrint::Steps::hollow_model(SLAPrintObject &po) bool drilling_needed = ! po.m_model_object->sla_drain_holes.empty(); // If the mesh is broken, stop immediately, even before hollowing. - if (drilling_needed && po.transformed_mesh().needed_repair()) - throw std::runtime_error(L("The mesh appears to be too broken " - "to drill holes into it reliably.")); + //if (drilling_needed && po.transformed_mesh().needed_repair()) + // throw std::runtime_error(L("The mesh appears to be too broken " + // "to drill holes into it reliably.")); if (! po.m_config.hollowing_enable.getBool()) BOOST_LOG_TRIVIAL(info) << "Skipping hollowing step!"; @@ -133,7 +133,13 @@ void SLAPrint::Steps::hollow_model(SLAPrintObject &po) TriangleMesh &hollowed_mesh = po.m_hollowing_data->hollow_mesh_with_holes; hollowed_mesh = po.get_mesh_to_print(); - MeshBoolean::cgal::minus(hollowed_mesh, holes_mesh); + try { + MeshBoolean::cgal::minus(hollowed_mesh, holes_mesh); + } + catch (const std::runtime_error& ex) { + throw std::runtime_error(L("Drilling holes into the mesh failed. " + "This is usually caused by broken model. Try to fix it first.")); + } hollowed_mesh.require_shared_vertices(); } }