From 6e40e061f6fa057767ffe2a7916f8e175c48e4f6 Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Mon, 3 Apr 2023 15:14:07 +0200 Subject: [PATCH] Finish rough implementation of slowdown over curled filament --- src/libslic3r/GCode/ExtrusionProcessor.hpp | 33 ++++++++++++---------- src/libslic3r/JumpPointSearch.cpp | 4 +-- src/libslic3r/Layer.hpp | 3 +- src/libslic3r/Line.hpp | 12 ++++++++ src/libslic3r/SupportSpotsGenerator.cpp | 12 ++++---- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/libslic3r/GCode/ExtrusionProcessor.hpp b/src/libslic3r/GCode/ExtrusionProcessor.hpp index bf59543dd5..ffa351c27e 100644 --- a/src/libslic3r/GCode/ExtrusionProcessor.hpp +++ b/src/libslic3r/GCode/ExtrusionProcessor.hpp @@ -13,6 +13,7 @@ #include "../ClipperUtils.hpp" #include "../Flow.hpp" #include "../Config.hpp" +#include "../Line.hpp" #include #include @@ -246,8 +247,8 @@ class ExtrusionQualityEstimator { std::unordered_map> prev_layer_boundaries; std::unordered_map> next_layer_boundaries; - std::unordered_map> prev_curled_extrusions; - std::unordered_map> next_curled_extrusions; + std::unordered_map> prev_curled_extrusions; + std::unordered_map> next_curled_extrusions; const PrintObject *current_object; public: @@ -261,12 +262,7 @@ public: prev_layer_boundaries[object] = next_layer_boundaries[object]; next_layer_boundaries[object] = AABBTreeLines::LinesDistancer{to_unscaled_linesf(layer->lslices)}; prev_curled_extrusions[object] = next_curled_extrusions[object]; - Linesf curled_lines; - curled_lines.reserve(layer->malformed_lines.size()); - for (const Line &l : layer->malformed_lines) { - curled_lines.push_back(Linef(unscaled(l.a), unscaled(l.b))); - } - next_curled_extrusions[object] = AABBTreeLines::LinesDistancer{curled_lines}; + next_curled_extrusions[object] = AABBTreeLines::LinesDistancer{layer->curled_lines}; } std::vector estimate_speed_from_extrusion_quality( @@ -296,13 +292,20 @@ public: std::vector extended_points = estimate_points_properties(path.polyline.points, prev_layer_boundaries[current_object], path.width); - - for (ExtendedPoint& ep : extended_points) { - // We are going to enforce slowdown by increasing the point distance. The overhang speed is based on signed distance from - // the prev layer, where 0 means fully overlapping extrusions and thus no slowdown, while extrusion_width and more means full overhang, - // thus full slowdown. However, for curling, we take unsinged distance from the curled lines and artifically modifiy the distance - float distance_from_curled = prev_curled_extrusions[current_object].distance_from_lines(ep.position); - ep.distance = std::max(ep.distance, (path.width - distance_from_curled)); + + for (ExtendedPoint &ep : extended_points) { + // We are going to enforce slowdown over curled extrusions by increasing the point distance. The overhang speed is based on + // signed distance from the prev layer, where 0 means fully overlapping extrusions and thus no slowdown, while extrusion_width + // and more means full overhang, thus full slowdown. However, for curling, we take unsinged distance from the curled lines and + // artifically modifiy the distance + auto [distance_from_curled, line_idx, + p] = prev_curled_extrusions[current_object].distance_from_lines_extra(Point::new_scale(ep.position)); + if (distance_from_curled < scale_(2.0 * path.width)) { + float articifally_increased_distance = path.width * + prev_curled_extrusions[current_object].get_line(line_idx).curled_height / + (path.height * 10.0f); // max_curled_height_factor from SupportSpotGenerator + ep.distance = std::max(ep.distance, articifally_increased_distance); + } } std::vector processed_points; diff --git a/src/libslic3r/JumpPointSearch.cpp b/src/libslic3r/JumpPointSearch.cpp index ef3dba45e7..dbae42151b 100644 --- a/src/libslic3r/JumpPointSearch.cpp +++ b/src/libslic3r/JumpPointSearch.cpp @@ -211,8 +211,8 @@ void JPSPathFinder::add_obstacles(const Layer *layer, const Point &global_origin this->print_z = layer->print_z; Lines obstacles; - obstacles.reserve(layer->malformed_lines.size()); - for (const Line &l : layer->malformed_lines) { obstacles.push_back(Line{l.a + global_origin, l.b + global_origin}); } + obstacles.reserve(layer->curled_lines.size()); + for (const Line &l : layer->curled_lines) { obstacles.push_back(Line{l.a + global_origin, l.b + global_origin}); } add_obstacles(obstacles); } diff --git a/src/libslic3r/Layer.hpp b/src/libslic3r/Layer.hpp index b3d071c9d2..5cfdf9cfad 100644 --- a/src/libslic3r/Layer.hpp +++ b/src/libslic3r/Layer.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_Layer_hpp_ #define slic3r_Layer_hpp_ +#include "Line.hpp" #include "libslic3r.h" #include "BoundingBox.hpp" #include "Flow.hpp" @@ -325,7 +326,7 @@ public: coordf_t bottom_z() const { return this->print_z - this->height; } //Extrusions estimated to be seriously malformed, estimated during "Estimating curled extrusions" step. These lines should be avoided during fast travels. - Lines malformed_lines; + CurledLines curled_lines; // Collection of expolygons generated by slicing the possibly multiple meshes of the source geometry // (with possibly differing extruder ID and slicing parameters) and merged. diff --git a/src/libslic3r/Line.hpp b/src/libslic3r/Line.hpp index 90f5648980..1edd1f5e9f 100644 --- a/src/libslic3r/Line.hpp +++ b/src/libslic3r/Line.hpp @@ -209,6 +209,18 @@ public: double a_width, b_width; }; +class CurledLine : public Line +{ +public: + CurledLine() : curled_height(0.0f) {} + CurledLine(const Point& a, const Point& b) : Line(a, b), curled_height(0.0f) {} + CurledLine(const Point& a, const Point& b, float curled_height) : Line(a, b), curled_height(curled_height) {} + + float curled_height; +}; + +using CurledLines = std::vector; + class Line3 { public: diff --git a/src/libslic3r/SupportSpotsGenerator.cpp b/src/libslic3r/SupportSpotsGenerator.cpp index ee62b1e6ce..71ea7264d0 100644 --- a/src/libslic3r/SupportSpotsGenerator.cpp +++ b/src/libslic3r/SupportSpotsGenerator.cpp @@ -39,7 +39,7 @@ #include "Geometry/ConvexHull.hpp" // #define DETAILED_DEBUG_LOGS -#define DEBUG_FILES +// #define DEBUG_FILES #ifdef DEBUG_FILES #include @@ -234,7 +234,7 @@ float estimate_curled_up_height( if (point.curvature > 0.01){ float radius = std::max(1.0 / point.curvature - flow_width / 2.0, 0.001); - float curling_t = radius / 100; + float curling_t = sqrt(radius / 100); float b = curling_t * flow_width; float a = curling_section; float c = sqrt(std::max(0.0f,a*a - b*b)); @@ -1066,7 +1066,7 @@ void estimate_supports_malformations(SupportLayerPtrs &layers, float flow_width, AABBTreeLines::LinesDistancer prev_layer_lines{}; for (SupportLayer *l : layers) { - l->malformed_lines.clear(); + l->curled_lines.clear(); std::vector current_layer_lines; for (const ExtrusionEntity *extrusion : l->support_fills.flatten().entities) { @@ -1102,7 +1102,7 @@ void estimate_supports_malformations(SupportLayerPtrs &layers, float flow_width, for (const ExtrusionLine &line : current_layer_lines) { if (line.curled_up_height > params.curling_tolerance_limit) { - l->malformed_lines.push_back(Line{Point::new_scale(line.a), Point::new_scale(line.b)}); + l->curled_lines.push_back(CurledLine{Point::new_scale(line.a), Point::new_scale(line.b), line.curled_up_height}); } } @@ -1138,7 +1138,7 @@ void estimate_malformations(LayerPtrs &layers, const Params ¶ms) LD prev_layer_lines{}; for (Layer *l : layers) { - l->malformed_lines.clear(); + l->curled_lines.clear(); std::vector boundary_lines = l->lower_layer != nullptr ? to_unscaled_linesf(l->lower_layer->lslices) : std::vector(); AABBTreeLines::LinesDistancer prev_layer_boundary{std::move(boundary_lines)}; std::vector current_layer_lines; @@ -1176,7 +1176,7 @@ void estimate_malformations(LayerPtrs &layers, const Params ¶ms) for (const ExtrusionLine &line : current_layer_lines) { if (line.curled_up_height > params.curling_tolerance_limit) { - l->malformed_lines.push_back(Line{Point::new_scale(line.a), Point::new_scale(line.b)}); + l->curled_lines.push_back(CurledLine{Point::new_scale(line.a), Point::new_scale(line.b), line.curled_up_height}); } }