Skip to content

Commit

Permalink
stop_at_min_width : do not extends the thin wall if it's over the min…
Browse files Browse the repository at this point in the history
…_width (can be toggled when calling expolygon.medial_axis).
  • Loading branch information
supermerill committed Dec 7, 2018
1 parent ca9f3f7 commit 6643d78
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
9 changes: 3 additions & 6 deletions xs/src/libslic3r/ExPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion xs/src/libslic3r/ExPolygon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 21 additions & 7 deletions xs/src/libslic3r/MedialAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//{
Expand All @@ -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";
Expand Down
1 change: 1 addition & 0 deletions xs/src/libslic3r/MedialAxis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
};
Expand Down

0 comments on commit 6643d78

Please sign in to comment.