Trying to improve drilling stability by handling CGAL exceptions

This commit is contained in:
Lukas Matena 2020-01-29 15:57:49 +01:00
parent b41c6d7d64
commit b0aa937215
2 changed files with 21 additions and 6 deletions

View File

@ -150,7 +150,16 @@ void minus(TriangleMesh &A, const TriangleMesh &B)
triangle_mesh_to_cgal(B, meshB.m); triangle_mesh_to_cgal(B, meshB.m);
CGALMesh meshResult; 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); A = cgal_to_triangle_mesh(meshResult.m);
} }

View File

@ -83,9 +83,9 @@ void SLAPrint::Steps::hollow_model(SLAPrintObject &po)
bool drilling_needed = ! po.m_model_object->sla_drain_holes.empty(); bool drilling_needed = ! po.m_model_object->sla_drain_holes.empty();
// If the mesh is broken, stop immediately, even before hollowing. // If the mesh is broken, stop immediately, even before hollowing.
if (drilling_needed && po.transformed_mesh().needed_repair()) //if (drilling_needed && po.transformed_mesh().needed_repair())
throw std::runtime_error(L("The mesh appears to be too broken " // throw std::runtime_error(L("The mesh appears to be too broken "
"to drill holes into it reliably.")); // "to drill holes into it reliably."));
if (! po.m_config.hollowing_enable.getBool()) if (! po.m_config.hollowing_enable.getBool())
BOOST_LOG_TRIVIAL(info) << "Skipping hollowing step!"; 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; TriangleMesh &hollowed_mesh = po.m_hollowing_data->hollow_mesh_with_holes;
hollowed_mesh = po.get_mesh_to_print(); hollowed_mesh = po.get_mesh_to_print();
try {
MeshBoolean::cgal::minus(hollowed_mesh, holes_mesh); 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(); hollowed_mesh.require_shared_vertices();
} }
} }