Skip to content

Commit

Permalink
Fix of #8455 - Fixed the incorrect computation of the threshold for g…
Browse files Browse the repository at this point in the history
…rouping 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.
  • Loading branch information
hejllukas authored and Godrak committed Jul 29, 2022
1 parent dd6205a commit 69b070c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/libslic3r/Arachne/utils/ExtrusionLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 12 additions & 11 deletions src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -57,29 +57,30 @@ 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
path.mm3_per_mm = new_flow.mm3_per_mm();
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
Expand Down

0 comments on commit 69b070c

Please sign in to comment.