Fix of #8455 - Fixed the incorrect computation of the threshold for grouping ExtrusionPaths with the same extrusion width in thick_polyline_to_extrusion_paths() that was affecting Arachne and gap fill.

The previous behavior didn't merge two ExtrusionPaths with the same extrusion width, and it also could merge two ExtrusionPaths with different widths, which was unintentional, and it could also possibly create visible artifacts in some cases.
Because simplification of ExtrusionLoop in GCode::extrude_loop is working on ExtrusionPath and not on whole ExtrusionLoop, so previous incorrect behavior was preventing simplification and removing small extrusions like in #8455.
This commit is contained in:
Lukáš Hejl 2022-07-14 08:57:53 +02:00
parent 200ab7441b
commit e2e1272003
2 changed files with 14 additions and 13 deletions

View file

@ -268,13 +268,13 @@ void extrusion_paths_append(ExtrusionPaths &dst, const ClipperLib_Z::Paths &extr
{
for (const ClipperLib_Z::Path &extrusion_path : extrusion_paths) {
ThickPolyline thick_polyline = Arachne::to_thick_polyline(extrusion_path);
Slic3r::append(dst, thick_polyline_to_extrusion_paths(thick_polyline, role, flow, scaled<float>(0.05), 0));
Slic3r::append(dst, thick_polyline_to_extrusion_paths(thick_polyline, role, flow, scaled<float>(0.05), SCALED_EPSILON));
}
}
void extrusion_paths_append(ExtrusionPaths &dst, const Arachne::ExtrusionLine &extrusion, const ExtrusionRole role, const Flow &flow)
{
ThickPolyline thick_polyline = Arachne::to_thick_polyline(extrusion);
Slic3r::append(dst, thick_polyline_to_extrusion_paths(thick_polyline, role, flow, scaled<float>(0.05), 0));
Slic3r::append(dst, thick_polyline_to_extrusion_paths(thick_polyline, role, flow, scaled<float>(0.05), SCALED_EPSILON));
}
} // namespace Slic3r

View file

@ -25,7 +25,7 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly
const coordf_t line_len = line.length();
if (line_len < SCALED_EPSILON) continue;
double thickness_delta = fabs(line.a_width - line.b_width);
if (thickness_delta > tolerance) {
const auto segments = (unsigned int)ceil(thickness_delta / tolerance);
@ -37,18 +37,18 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly
width.push_back(line.a_width);
for (size_t j = 1; j < segments; ++j) {
pp.push_back((line.a.cast<double>() + (line.b - line.a).cast<double>().normalized() * (j * seg_len)).cast<coord_t>());
coordf_t w = line.a_width + (j*seg_len) * (line.b_width-line.a_width) / line_len;
width.push_back(w);
width.push_back(w);
}
pp.push_back(line.b);
width.push_back(line.b_width);
assert(pp.size() == segments + 1u);
assert(width.size() == segments*2);
}
// delete this line and insert new ones
lines.erase(lines.begin() + i);
for (size_t j = 0; j < segments; ++j) {
@ -57,18 +57,18 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly
new_line.b_width = width[2*j+1];
lines.insert(lines.begin() + i + j, new_line);
}
-- i;
continue;
}
const double w = fmax(line.a_width, line.b_width);
const double w = fmax(line.a_width, line.b_width);
const Flow new_flow = (role == erOverhangPerimeter && flow.bridge()) ? flow : flow.with_width(unscale<float>(w) + flow.height() * float(1. - 0.25 * PI));
if (path.polyline.points.empty()) {
path.polyline.append(line.a);
path.polyline.append(line.b);
// Convert from spacing to extrusion width based on the extrusion model
// of a square extrusion ended with semi circles.
Flow new_flow = (role == erOverhangPerimeter && flow.bridge()) ? flow : flow.with_width(unscale<float>(w) + flow.height() * float(1. - 0.25 * PI));
#ifdef SLIC3R_DEBUG
printf(" filling %f gap\n", flow.width);
#endif
@ -76,10 +76,11 @@ ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyline &thick_poly
path.width = new_flow.width();
path.height = new_flow.height();
} else {
thickness_delta = fabs(scale_(flow.width()) - w);
assert(path.width >= EPSILON);
thickness_delta = scaled<double>(fabs(path.width - new_flow.width()));
if (thickness_delta <= merge_tolerance) {
// the width difference between this line and the current flow width is
// within the accepted tolerance
// the width difference between this line and the current flow
// (of the previous line) width is within the accepted tolerance
path.polyline.append(line.b);
} else {
// we need to initialize a new line