From dfb1ec99ac2699840e0dbe40163fade9df3e966b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 19 Mar 2016 19:40:11 +0100 Subject: [PATCH] Variable-width thin walls. Yay! --- xs/src/libslic3r/ExtrusionEntity.hpp | 5 ++-- xs/src/libslic3r/PerimeterGenerator.cpp | 36 ++++++++++++------------- xs/src/libslic3r/PerimeterGenerator.hpp | 2 +- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/xs/src/libslic3r/ExtrusionEntity.hpp b/xs/src/libslic3r/ExtrusionEntity.hpp index 2cba689a5..7b4e796e4 100644 --- a/xs/src/libslic3r/ExtrusionEntity.hpp +++ b/xs/src/libslic3r/ExtrusionEntity.hpp @@ -54,6 +54,7 @@ class ExtrusionEntity virtual Polygons grow() const = 0; virtual double min_mm3_per_mm() const = 0; virtual Polyline as_polyline() const = 0; + virtual double length() const { return 0; }; }; typedef std::vector ExtrusionEntitiesPtr; @@ -76,7 +77,7 @@ class ExtrusionPath : public ExtrusionEntity void subtract_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const; void clip_end(double distance); void simplify(double tolerance); - double length() const; + virtual double length() const; bool is_perimeter() const; bool is_infill() const; bool is_solid_infill() const; @@ -121,7 +122,7 @@ class ExtrusionLoop : public ExtrusionEntity Point first_point() const; Point last_point() const; Polygon polygon() const; - double length() const; + virtual double length() const; bool split_at_vertex(const Point &point); void split_at(const Point &point); void clip_end(double distance, ExtrusionPaths* paths) const; diff --git a/xs/src/libslic3r/PerimeterGenerator.cpp b/xs/src/libslic3r/PerimeterGenerator.cpp index af12161df..cffe14b67 100644 --- a/xs/src/libslic3r/PerimeterGenerator.cpp +++ b/xs/src/libslic3r/PerimeterGenerator.cpp @@ -64,7 +64,7 @@ PerimeterGenerator::process() std::vector contours(loop_number+1); // depth => loops std::vector holes(loop_number+1); // depth => loops - Polylines thin_walls; + ThickPolylines thin_walls; // we loop one time more than needed in order to find gaps after the last perimeter was applied for (signed short i = 0; i <= loop_number+1; ++i) { // outer loop is 0 @@ -96,16 +96,8 @@ PerimeterGenerator::process() ExPolygons expp = offset2_ex(diffpp, -min_width/2, +min_width/2); // the maximum thickness of our thin wall area is equal to the minimum thickness of a single loop - Polylines pp; for (ExPolygons::const_iterator ex = expp.begin(); ex != expp.end(); ++ex) - ex->medial_axis(ext_pwidth + ext_pspacing2, min_width, &pp); - - double threshold = ext_pwidth * 2; - for (Polylines::const_iterator p = pp.begin(); p != pp.end(); ++p) { - if (p->length() > threshold) { - thin_walls.push_back(*p); - } - } + ex->medial_axis(ext_pwidth + ext_pspacing2, min_width, &thin_walls); #ifdef DEBUG printf(" %zu thin walls detected\n", thin_walls.size()); @@ -329,7 +321,7 @@ PerimeterGenerator::process() ExtrusionEntityCollection PerimeterGenerator::_traverse_loops(const PerimeterGeneratorLoops &loops, - Polylines &thin_walls) const + ThickPolylines &thin_walls) const { // loops is an arrayref of ::Loop objects // turn each one into an ExtrusionLoop object @@ -403,15 +395,21 @@ PerimeterGenerator::_traverse_loops(const PerimeterGeneratorLoops &loops, } // append thin walls to the nearest-neighbor search (only for first iteration) - for (Polylines::const_iterator polyline = thin_walls.begin(); polyline != thin_walls.end(); ++polyline) { - ExtrusionPath path(erExternalPerimeter); - path.polyline = *polyline; - path.mm3_per_mm = this->_mm3_per_mm; - path.width = this->perimeter_flow.width; - path.height = this->layer_height; - coll.append(path); + { + ExtrusionEntityCollection tw = this->_variable_width + (thin_walls, erExternalPerimeter, this->ext_perimeter_flow); + + const double threshold = this->ext_perimeter_flow.scaled_width() * 2; + for (size_t i = 0; i < tw.entities.size(); ++i) { + if (tw.entities[i]->length() < threshold) { + tw.remove(i); + --i; + } + } + + coll.append(tw.entities); + thin_walls.clear(); } - thin_walls.clear(); // sort entities into a new collection using a nearest-neighbor search, // preserving the original indices which are useful for detecting thin walls diff --git a/xs/src/libslic3r/PerimeterGenerator.hpp b/xs/src/libslic3r/PerimeterGenerator.hpp index fe1a0aa15..eb3fa0fcb 100644 --- a/xs/src/libslic3r/PerimeterGenerator.hpp +++ b/xs/src/libslic3r/PerimeterGenerator.hpp @@ -65,7 +65,7 @@ class PerimeterGenerator { Polygons _lower_slices_p; ExtrusionEntityCollection _traverse_loops(const PerimeterGeneratorLoops &loops, - Polylines &thin_walls) const; + ThickPolylines &thin_walls) const; ExtrusionEntityCollection _variable_width (const ThickPolylines &polylines, ExtrusionRole role, Flow flow) const; };