From bb5e2af5091dabef9d359b4784d862f7f4fcb043 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Sat, 3 Aug 2024 22:01:37 +0800 Subject: [PATCH] Fix/crashing when generating walls (#6325) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix crash when filling very tiny (1-5nm) gaps (#6279) Cherry-picked from prusa3d/PrusaSlicer@8784ca0ecf538d0e4071086b09c9dbecb68b1c22 Co-authored-by: Lukáš Hejl * SPE-2256: Fix the issue that we used the old Voronoi graph during the detection of invalid Voronoi diagrams. This happens because we didn't set a modified flag that is required to be set before we use the new Voronoi graph. Possibly related to #12385 Cherry-picked from prusa3d/PrusaSlicer@2de1f3aa45cd609f4c6adad3a56137fc9955bada Co-authored-by: Lukáš Hejl --------- Co-authored-by: Lukáš Hejl --- src/libslic3r/Geometry/MedialAxis.cpp | 13 +++++++++++++ src/libslic3r/Geometry/Voronoi.cpp | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Geometry/MedialAxis.cpp b/src/libslic3r/Geometry/MedialAxis.cpp index 2a27db1d8..d3a6ac6c8 100644 --- a/src/libslic3r/Geometry/MedialAxis.cpp +++ b/src/libslic3r/Geometry/MedialAxis.cpp @@ -449,6 +449,19 @@ MedialAxis::MedialAxis(double min_width, double max_width, const ExPolygon &expo void MedialAxis::build(ThickPolylines* polylines) { m_vd.construct_voronoi(m_lines.begin(), m_lines.end()); + + // For several ExPolygons in SPE-1729, an invalid Voronoi diagram was produced that wasn't fixable by rotating input data. + // Those ExPolygons contain very thin lines and holes formed by very close (1-5nm) vertices that are on the edge of our resolution. + // Those thin lines and holes are both unprintable and cause the Voronoi diagram to be invalid. + // So we filter out such thin lines and holes and try to compute the Voronoi diagram again. + if (!m_vd.is_valid()) { + m_lines = to_lines(closing_ex({m_expolygon}, float(2. * SCALED_EPSILON))); + m_vd.construct_voronoi(m_lines.begin(), m_lines.end()); + + if (!m_vd.is_valid()) + BOOST_LOG_TRIVIAL(error) << "MedialAxis - Invalid Voronoi diagram even after morphological closing."; + } + Slic3r::Voronoi::annotate_inside_outside(m_vd, m_lines); // static constexpr double threshold_alpha = M_PI / 12.; // 30 degrees // std::vector skeleton_edges = Slic3r::Voronoi::skeleton_edges_rough(vd, lines, threshold_alpha); diff --git a/src/libslic3r/Geometry/Voronoi.cpp b/src/libslic3r/Geometry/Voronoi.cpp index fc7ead40d..f9ab6a694 100644 --- a/src/libslic3r/Geometry/Voronoi.cpp +++ b/src/libslic3r/Geometry/Voronoi.cpp @@ -146,6 +146,9 @@ void VoronoiDiagram::copy_to_local(voronoi_diagram_type &voronoi_diagram) { new_edge.prev(&m_edges[prev_edge_idx]); } } + + m_voronoi_diagram.clear(); + m_is_modified = true; } template @@ -346,9 +349,6 @@ VoronoiDiagram::try_to_repair_degenerated_voronoi_diagram_by_rotation(const Segm for (vertex_type &vertex : m_vertices) vertex.color(0); - m_voronoi_diagram.clear(); - m_is_modified = true; - return issue_type; }