Medial axis: taper the end of thin walls

This commit is contained in:
supermerill 2019-01-04 19:08:18 +01:00
parent b053a23e1e
commit 2ce0d3a946
2 changed files with 35 additions and 7 deletions

View File

@ -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";
//{
@ -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.size(); ++i) {
current_dist += polyline.points[i - 1].distance_to(polyline.points[i]);
if (current_dist > 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.size(); ++i) {
current_dist += polyline.points[last_idx - i + 1].distance_to(polyline.points[last_idx - i]);
if (current_dist > 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

View File

@ -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);