Fix crash when all the holes fail to drill

This commit is contained in:
tamasmeszaros 2021-07-13 16:02:58 +02:00
parent 47f265f77f
commit 782e220890
3 changed files with 16 additions and 7 deletions

View File

@ -276,6 +276,11 @@ bool does_bound_a_volume(const CGALMesh &mesh)
return CGALProc::does_bound_a_volume(mesh.m);
}
bool empty(const CGALMesh &mesh)
{
return mesh.m.is_empty();
}
} // namespace cgal
} // namespace MeshBoolean

View File

@ -55,6 +55,7 @@ bool does_self_intersect(const TriangleMesh &mesh);
bool does_self_intersect(const CGALMesh &mesh);
bool does_bound_a_volume(const CGALMesh &mesh);
bool empty(const CGALMesh &mesh);
}

View File

@ -391,11 +391,10 @@ void SLAPrint::Steps::drill_holes(SLAPrintObject &po)
holept.normal += Vec3f{dist(m_rng), dist(m_rng), dist(m_rng)};
holept.normal.normalize();
holept.pos += Vec3f{dist(m_rng), dist(m_rng), dist(m_rng)};
TriangleMesh m{holept.to_mesh()};
m.require_shared_vertices();
indexed_triangle_set m = holept.to_mesh();
part_to_drill.indices.clear();
auto bb = m.bounding_box();
auto bb = bounding_box(m);
Eigen::AlignedBox<float, 3> ebb{bb.min.cast<float>(),
bb.max.cast<float>()};
@ -429,19 +428,23 @@ void SLAPrint::Steps::drill_holes(SLAPrintObject &po)
auto hollowed_mesh_cgal = MeshBoolean::cgal::triangle_mesh_to_cgal(hollowed_mesh);
if (!MeshBoolean::cgal::does_bound_a_volume(*hollowed_mesh_cgal)) {
po.active_step_add_warning(PrintStateBase::WarningLevel::NON_CRITICAL,
po.active_step_add_warning(
PrintStateBase::WarningLevel::NON_CRITICAL,
L("Mesh to be hollowed is not suitable for hollowing (does not "
"bound a volume)."));
}
if (!MeshBoolean::cgal::does_bound_a_volume(*holes_mesh_cgal)) {
po.active_step_add_warning(PrintStateBase::WarningLevel::NON_CRITICAL,
if (!MeshBoolean::cgal::empty(*holes_mesh_cgal)
&& !MeshBoolean::cgal::does_bound_a_volume(*holes_mesh_cgal)) {
po.active_step_add_warning(
PrintStateBase::WarningLevel::NON_CRITICAL,
L("Unable to drill the current configuration of holes into the "
"model."));
}
try {
MeshBoolean::cgal::minus(*hollowed_mesh_cgal, *holes_mesh_cgal);
if (!MeshBoolean::cgal::empty(*holes_mesh_cgal))
MeshBoolean::cgal::minus(*hollowed_mesh_cgal, *holes_mesh_cgal);
hollowed_mesh = MeshBoolean::cgal::cgal_to_triangle_mesh(*hollowed_mesh_cgal);
mesh_view = hollowed_mesh;