From 2ce0d3a94643803fed89f82f8798871195562a3b Mon Sep 17 00:00:00 2001 From: supermerill Date: Fri, 4 Jan 2019 19:08:18 +0100 Subject: [PATCH] Medial axis: taper the end of thin walls --- src/libslic3r/MedialAxis.cpp | 41 ++++++++++++++++++++++++++++++------ src/libslic3r/MedialAxis.hpp | 1 + 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/MedialAxis.cpp b/src/libslic3r/MedialAxis.cpp index c869ef36a..c4ddd1399 100644 --- a/src/libslic3r/MedialAxis.cpp +++ b/src/libslic3r/MedialAxis.cpp @@ -1283,7 +1283,6 @@ MedialAxis::ensure_not_overextrude(ThickPolylines& pp) for (ThickPolyline& polyline : pp) { for (coordf_t &width : polyline.width) { width *= reduce_by; - width *= reduce_by; } } } @@ -1333,8 +1332,7 @@ MedialAxis::simplify_polygon_frontier() } void -MedialAxis::build(ThickPolylines* polylines_out) -{ +MedialAxis::build(ThickPolylines* polylines_out) { this->id++; //std::cout << layerid << "\n"; //{ @@ -1361,7 +1359,7 @@ MedialAxis::build(ThickPolylines* polylines_out) // compute the Voronoi diagram and extract medial axis polylines ThickPolylines pp; this->polyline_from_voronoi(this->expolygon.lines(), &pp); - + concatThickPolylines(pp); //std::cout << "concatThickPolylines\n"; @@ -1374,8 +1372,8 @@ MedialAxis::build(ThickPolylines* polylines_out) // svg.draw(pp); // svg.Close(); //} - - /* Find the maximum width returned; we're going to use this for validating and + + /* Find the maximum width returned; we're going to use this for validating and filtering the output segments. */ double max_w = 0; for (ThickPolylines::const_iterator it = pp.begin(); it != pp.end(); ++it) @@ -1488,8 +1486,10 @@ MedialAxis::build(ThickPolylines* polylines_out) // svg.draw(pp); // svg.Close(); //} - if (nozzle_diameter != min_width) + if (nozzle_diameter != min_width) { grow_to_nozzle_diameter(pp, diff_ex(this->bounds, this->expolygon)); + taper_ends(pp); + } polylines_out->insert(polylines_out->end(), pp.begin(), pp.end()); @@ -1513,6 +1513,33 @@ MedialAxis::grow_to_nozzle_diameter(ThickPolylines& pp, const ExPolygons& anchor } } +void +MedialAxis::taper_ends(ThickPolylines& pp) { + //ensure the width is not lower than 0.4. + for (ThickPolyline& polyline : pp) { + if (polyline.length() < nozzle_diameter * 2) continue; + if (polyline.endpoints.first) { + polyline.width[0] = min_width; + coord_t current_dist = min_width; + for (size_t i = 1; i polyline.width[i]) break; + polyline.width[i] = current_dist; + } + } + if (polyline.endpoints.second) { + size_t last_idx = polyline.width.size() - 1; + polyline.width[last_idx] = min_width; + coord_t current_dist = min_width; + for (size_t i = 1; i polyline.width[last_idx - i]) break; + polyline.width[last_idx - i] = current_dist; + } + } + } +} + ExtrusionEntityCollection thin_variable_width(const ThickPolylines &polylines, ExtrusionRole role, Flow flow) { // this value determines granularity of adaptive width, as G-code does not allow // variable extrusion within a single move; this value shall only affect the amount diff --git a/src/libslic3r/MedialAxis.hpp b/src/libslic3r/MedialAxis.hpp index 85607b718..9d71207b1 100644 --- a/src/libslic3r/MedialAxis.hpp +++ b/src/libslic3r/MedialAxis.hpp @@ -63,6 +63,7 @@ namespace Slic3r { void remove_too_short_polylines(ThickPolylines& pp, const coord_t min_size); void ensure_not_overextrude(ThickPolylines& pp); void grow_to_nozzle_diameter(ThickPolylines& pp, const ExPolygons& anchors); + void taper_ends(ThickPolylines& pp); }; ExtrusionEntityCollection thin_variable_width(const ThickPolylines &polylines, ExtrusionRole role, Flow flow);