From 69b070cb771163f8b5ed3f703b4136594992045f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Thu, 14 Jul 2022 08:57:53 +0200 Subject: [PATCH] Fix of #8455 - Fixed the incorrect computation of the threshold for grouping ExtrusionPaths with the same extrusion width in thick_polyline_to_extrusion_paths() that was affecting Arachne and gap fill. The previous behavior didn't merge two ExtrusionPaths with the same extrusion width, and it also could merge two ExtrusionPaths with different widths, which was unintentional, and it could also possibly create visible artifacts in some cases. Because simplification of ExtrusionLoop in GCode::extrude_loop is working on ExtrusionPath and not on whole ExtrusionLoop, so previous incorrect behavior was preventing simplification and removing small extrusions like in #8455. --- src/libslic3r/Arachne/utils/ExtrusionLine.cpp | 4 ++-- src/libslic3r/PerimeterGenerator.cpp | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Arachne/utils/ExtrusionLine.cpp b/src/libslic3r/Arachne/utils/ExtrusionLine.cpp index c594b8b91e3..4ddbb01d1cd 100644 --- a/src/libslic3r/Arachne/utils/ExtrusionLine.cpp +++ b/src/libslic3r/Arachne/utils/ExtrusionLine.cpp @@ -268,13 +268,13 @@ void extrusion_paths_append(ExtrusionPaths &dst, const ClipperLib_Z::Paths &extr { for (const ClipperLib_Z::Path &extrusion_path : extrusion_paths) { ThickPolyline thick_polyline = Arachne::to_thick_polyline(extrusion_path); - Slic3r::append(dst, thick_polyline_to_extrusion_paths(thick_polyline, role, flow, scaled(0.05), 0)); + Slic3r::append(dst, thick_polyline_to_extrusion_paths(thick_polyline, role, flow, scaled(0.05), SCALED_EPSILON)); } } void extrusion_paths_append(ExtrusionPaths &dst, const Arachne::ExtrusionLine &extrusion, const ExtrusionRole role, const Flow &flow) { ThickPolyline thick_polyline = Arachne::to_thick_polyline(extrusion); - Slic3r::append(dst, thick_polyline_to_extrusion_paths(thick_polyline, role, flow, scaled(0.05), 0)); + Slic3r::append(dst, thick_polyline_to_extrusion_paths(thick_polyline, role, flow, scaled(0.05), SCALED_EPSILON)); } } // namespace Slic3r \ No newline at end of file diff --git a/src/libslic3r/PerimeterGenerator.cpp b/src/libslic3r/PerimeterGenerator.cpp index 539679e8d45..0bbe601e208 100644 --- a/src/libslic3r/PerimeterGenerator.cpp +++ b/src/libslic3r/PerimeterGenerator.cpp @@ -25,7 +25,7 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly const coordf_t line_len = line.length(); if (line_len < SCALED_EPSILON) continue; - + double thickness_delta = fabs(line.a_width - line.b_width); if (thickness_delta > tolerance) { const auto segments = (unsigned int)ceil(thickness_delta / tolerance); @@ -37,18 +37,18 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly width.push_back(line.a_width); for (size_t j = 1; j < segments; ++j) { pp.push_back((line.a.cast() + (line.b - line.a).cast().normalized() * (j * seg_len)).cast()); - + coordf_t w = line.a_width + (j*seg_len) * (line.b_width-line.a_width) / line_len; width.push_back(w); width.push_back(w); } pp.push_back(line.b); width.push_back(line.b_width); - + assert(pp.size() == segments + 1u); assert(width.size() == segments*2); } - + // delete this line and insert new ones lines.erase(lines.begin() + i); for (size_t j = 0; j < segments; ++j) { @@ -57,18 +57,18 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly new_line.b_width = width[2*j+1]; lines.insert(lines.begin() + i + j, new_line); } - + -- i; continue; } - - const double w = fmax(line.a_width, line.b_width); + + const double w = fmax(line.a_width, line.b_width); + const Flow new_flow = (role == erOverhangPerimeter && flow.bridge()) ? flow : flow.with_width(unscale(w) + flow.height() * float(1. - 0.25 * PI)); if (path.polyline.points.empty()) { path.polyline.append(line.a); path.polyline.append(line.b); // Convert from spacing to extrusion width based on the extrusion model // of a square extrusion ended with semi circles. - Flow new_flow = (role == erOverhangPerimeter && flow.bridge()) ? flow : flow.with_width(unscale(w) + flow.height() * float(1. - 0.25 * PI)); #ifdef SLIC3R_DEBUG printf(" filling %f gap\n", flow.width); #endif @@ -76,10 +76,11 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly path.width = new_flow.width(); path.height = new_flow.height(); } else { - thickness_delta = fabs(scale_(flow.width()) - w); + assert(path.width >= EPSILON); + thickness_delta = scaled(fabs(path.width - new_flow.width())); if (thickness_delta <= merge_tolerance) { - // the width difference between this line and the current flow width is - // within the accepted tolerance + // the width difference between this line and the current flow + // (of the previous line) width is within the accepted tolerance path.polyline.append(line.b); } else { // we need to initialize a new line