From 208f7c32da04b653aef16d8813d8a6ea09d9223f Mon Sep 17 00:00:00 2001 From: "salt.wei" Date: Fri, 16 Jun 2023 17:17:14 +0800 Subject: [PATCH] ENH: fix another assert in wall generator Thanks PrusaSlicer. Signed-off-by: salt.wei Change-Id: I9173f91629fa6c90d8bc3756d7d1fdbfd8605eab --- src/libslic3r/Arachne/utils/ExtrusionLine.cpp | 4 +-- src/libslic3r/VariableWidth.cpp | 29 +++++++++++++------ src/libslic3r/VariableWidth.hpp | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/Arachne/utils/ExtrusionLine.cpp b/src/libslic3r/Arachne/utils/ExtrusionLine.cpp index 1038a245c..30f06f21d 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), SCALED_EPSILON)); + Slic3r::append(dst, thick_polyline_to_multi_path(thick_polyline, role, flow, scaled(0.05), float(SCALED_EPSILON)).paths); } } 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), SCALED_EPSILON)); + Slic3r::append(dst, thick_polyline_to_multi_path(thick_polyline, role, flow, scaled(0.05), float(SCALED_EPSILON)).paths); } } // namespace Slic3r \ No newline at end of file diff --git a/src/libslic3r/VariableWidth.cpp b/src/libslic3r/VariableWidth.cpp index f77a4a9f1..6f7407d70 100644 --- a/src/libslic3r/VariableWidth.cpp +++ b/src/libslic3r/VariableWidth.cpp @@ -2,18 +2,29 @@ namespace Slic3r { -ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_polyline, ExtrusionRole role, const Flow &flow, const float tolerance, const float merge_tolerance) +ExtrusionMultiPath thick_polyline_to_multi_path(const ThickPolyline& thick_polyline, ExtrusionRole role, const Flow& flow, const float tolerance, const float merge_tolerance) { - ExtrusionPaths paths; - ExtrusionPath path(role); - ThickLines lines = thick_polyline.thicklines(); - + ExtrusionMultiPath multi_path; + ExtrusionPath path(role); + ThickLines lines = thick_polyline.thicklines(); + for (int i = 0; i < (int)lines.size(); ++i) { const ThickLine& line = lines[i]; assert(line.a_width >= SCALED_EPSILON && line.b_width >= SCALED_EPSILON); const coordf_t line_len = line.length(); - if (line_len < SCALED_EPSILON) continue; + if (line_len < SCALED_EPSILON) { + // The line is so tiny that we don't care about its width when we connect it to another line. + if (!path.empty()) + path.polyline.points.back() = line.b; // If the variable path is non-empty, connect this tiny line to it. + else if (i + 1 < (int)lines.size()) // If there is at least one following line, connect this tiny line to it. + lines[i + 1].a = line.a; + else if (!multi_path.paths.empty()) + multi_path.paths.back().polyline.points.back() = line.b; // Connect this tiny line to the last finished path. + + // If any of the above isn't satisfied, then remove this tiny line. + continue; + } double thickness_delta = fabs(line.a_width - line.b_width); if (thickness_delta > tolerance) { @@ -73,15 +84,15 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly path.polyline.append(line.b); } else { // we need to initialize a new line - paths.emplace_back(std::move(path)); + multi_path.paths.emplace_back(std::move(path)); path = ExtrusionPath(role); -- i; } } } if (path.polyline.is_valid()) - paths.emplace_back(std::move(path)); - return paths; + multi_path.paths.emplace_back(std::move(path)); + return multi_path; } //BBS: new function to filter width to avoid too fragmented segments diff --git a/src/libslic3r/VariableWidth.hpp b/src/libslic3r/VariableWidth.hpp index bfca418a3..f6eca9708 100644 --- a/src/libslic3r/VariableWidth.hpp +++ b/src/libslic3r/VariableWidth.hpp @@ -6,7 +6,7 @@ #include "Flow.hpp" namespace Slic3r { - ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline& thick_polyline, ExtrusionRole role, const Flow& flow, const float tolerance, const float merge_tolerance); + ExtrusionMultiPath thick_polyline_to_multi_path(const ThickPolyline& thick_polyline, ExtrusionRole role, const Flow& flow, const float tolerance, const float merge_tolerance); void variable_width(const ThickPolylines& polylines, ExtrusionRole role, const Flow& flow, std::vector& out); }