From 6643d7876930e7c6ec7df71bfc7c2b5f97a2a047 Mon Sep 17 00:00:00 2001 From: supermerill Date: Fri, 7 Dec 2018 13:25:23 +0100 Subject: [PATCH] stop_at_min_width : do not extends the thin wall if it's over the min_width (can be toggled when calling expolygon.medial_axis). --- xs/src/libslic3r/ExPolygon.cpp | 9 +++------ xs/src/libslic3r/ExPolygon.hpp | 2 +- xs/src/libslic3r/MedialAxis.cpp | 28 +++++++++++++++++++++------- xs/src/libslic3r/MedialAxis.hpp | 1 + 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index 87c119a04fe..bfc3d5077a0 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -210,12 +210,9 @@ ExPolygon::remove_point_too_near(const coord_t tolerance) { } void -ExPolygon::medial_axis(const ExPolygon &bounds, double max_width, double min_width, ThickPolylines* polylines, double height) const { - ExPolygon simplifiedBounds = bounds; - simplifiedBounds.remove_point_too_near(SCALED_RESOLUTION); - ExPolygon simplifiedPolygon = *this; - simplifiedPolygon.remove_point_too_near(SCALED_RESOLUTION); - Slic3r::MedialAxis ma(simplifiedPolygon, simplifiedBounds, max_width, min_width, height); +ExPolygon::medial_axis(const ExPolygon &bounds, double max_width, double min_width, ThickPolylines* polylines, double height, bool stop_at_min_width) const { + Slic3r::MedialAxis ma(*this, bounds, max_width, min_width, height); + ma.stop_at_min_width = stop_at_min_width; ma.build(polylines); } diff --git a/xs/src/libslic3r/ExPolygon.hpp b/xs/src/libslic3r/ExPolygon.hpp index 92610cc5673..cd3ab9ea7e9 100644 --- a/xs/src/libslic3r/ExPolygon.hpp +++ b/xs/src/libslic3r/ExPolygon.hpp @@ -43,7 +43,7 @@ class ExPolygon ExPolygons simplify(double tolerance) const; void simplify(double tolerance, ExPolygons* expolygons) const; void remove_point_too_near(const coord_t tolerance); - void medial_axis(const ExPolygon &bounds, double max_width, double min_width, ThickPolylines* polylines, double height) const; + void medial_axis(const ExPolygon &bounds, double max_width, double min_width, ThickPolylines* polylines, double height, bool stop_at_min_width = true) const; void medial_axis(double max_width, double min_width, Polylines* polylines) const; void get_trapezoids(Polygons* polygons) const; void get_trapezoids(Polygons* polygons, double angle) const; diff --git a/xs/src/libslic3r/MedialAxis.cpp b/xs/src/libslic3r/MedialAxis.cpp index ba3e5fdfdd1..2cd602db1fb 100644 --- a/xs/src/libslic3r/MedialAxis.cpp +++ b/xs/src/libslic3r/MedialAxis.cpp @@ -1360,6 +1360,18 @@ MedialAxis::build(ThickPolylines* polylines_out) //fusion right-angle corners. fusion_corners(pp); + // Loop through all returned polylines in order to extend their endpoints to the + // expolygon boundaries (if done here, it may be cut later if not thick enough) + if (stop_at_min_width) { + const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(this->bounds, this->expolygon)), -SCALED_RESOLUTION, SCALED_RESOLUTION); + for (size_t i = 0; i < pp.size(); ++i) { + ThickPolyline& polyline = pp[i]; + extends_line(polyline, anchors, min_width); + polyline.reverse(); + extends_line(polyline, anchors, min_width); + } + } + //reduce extrusion when it's too thin to be printable remove_too_thin_extrusion(pp); //{ @@ -1385,13 +1397,15 @@ MedialAxis::build(ThickPolylines* polylines_out) // Loop through all returned polylines in order to extend their endpoints to the // expolygon boundaries - const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(this->bounds, this->expolygon)), -SCALED_RESOLUTION, SCALED_RESOLUTION); - for (size_t i = 0; i < pp.size(); ++i) { - ThickPolyline& polyline = pp[i]; - extends_line(polyline, anchors, min_width); - polyline.reverse(); - extends_line(polyline, anchors, min_width); - } + if (!stop_at_min_width) { + const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(this->bounds, this->expolygon)), -SCALED_RESOLUTION, SCALED_RESOLUTION); + for (size_t i = 0; i < pp.size(); ++i) { + ThickPolyline& polyline = pp[i]; + extends_line(polyline, anchors, min_width); + polyline.reverse(); + extends_line(polyline, anchors, min_width); + } + } //{ // stringstream stri; // stri << "medial_axis_5_expand_" << id << ".svg"; diff --git a/xs/src/libslic3r/MedialAxis.hpp b/xs/src/libslic3r/MedialAxis.hpp index 93f6725db2d..3ec9d467d27 100644 --- a/xs/src/libslic3r/MedialAxis.hpp +++ b/xs/src/libslic3r/MedialAxis.hpp @@ -23,6 +23,7 @@ namespace Slic3r { const double max_width; const double min_width; const double height; + bool stop_at_min_width = true; MedialAxis(const ExPolygon &_expolygon, const ExPolygon &_bounds, const double _max_width, const double _min_width, const double _height) : surface(_expolygon), bounds(_bounds), max_width(_max_width), min_width(_min_width), height(_height) { };