Anchoring of sparse infills can now be disabled.

This commit is contained in:
Vojtech Bubnik 2020-11-20 13:36:58 +01:00
parent 03b336145f
commit 8d1e13fccd
11 changed files with 35 additions and 36 deletions

View File

@ -33,12 +33,11 @@ struct SurfaceFillParams
// FillParams // FillParams
float density = 0.f; float density = 0.f;
// Don't connect the fill lines around the inner perimeter.
bool dont_connect = false;
// Don't adjust spacing to fill the space evenly. // Don't adjust spacing to fill the space evenly.
bool dont_adjust = false; bool dont_adjust = false;
// Length of the infill anchor along the perimeter line. // Length of the infill anchor along the perimeter line.
float anchor_length = std::numeric_limits<float>::max(); // 1000mm is roughly the maximum length line that fits into a 32bit coord_t.
float anchor_length = 1000.f;
// width, height of extrusion, nozzle diameter, is bridge // width, height of extrusion, nozzle diameter, is bridge
// For the output, for fill generator. // For the output, for fill generator.
@ -67,7 +66,6 @@ struct SurfaceFillParams
RETURN_COMPARE_NON_EQUAL(overlap); RETURN_COMPARE_NON_EQUAL(overlap);
RETURN_COMPARE_NON_EQUAL(angle); RETURN_COMPARE_NON_EQUAL(angle);
RETURN_COMPARE_NON_EQUAL(density); RETURN_COMPARE_NON_EQUAL(density);
RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, dont_connect);
RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, dont_adjust); RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, dont_adjust);
RETURN_COMPARE_NON_EQUAL(anchor_length); RETURN_COMPARE_NON_EQUAL(anchor_length);
RETURN_COMPARE_NON_EQUAL(flow.width); RETURN_COMPARE_NON_EQUAL(flow.width);
@ -86,7 +84,6 @@ struct SurfaceFillParams
this->overlap == rhs.overlap && this->overlap == rhs.overlap &&
this->angle == rhs.angle && this->angle == rhs.angle &&
this->density == rhs.density && this->density == rhs.density &&
this->dont_connect == rhs.dont_connect &&
this->dont_adjust == rhs.dont_adjust && this->dont_adjust == rhs.dont_adjust &&
this->anchor_length == rhs.anchor_length && this->anchor_length == rhs.anchor_length &&
this->flow == rhs.flow && this->flow == rhs.flow &&
@ -154,7 +151,11 @@ std::vector<SurfaceFill> group_fills(const Layer &layer)
); );
// Calculate flow spacing for infill pattern generation. // Calculate flow spacing for infill pattern generation.
if (! surface.is_solid() && ! is_bridge) { if (surface.is_solid() || is_bridge) {
params.spacing = params.flow.spacing();
// Don't limit anchor length for solid or bridging infill.
params.anchor_length = 1000.f;
} else {
// it's internal infill, so we can calculate a generic flow spacing // it's internal infill, so we can calculate a generic flow spacing
// for all layers, for avoiding the ugly effect of // for all layers, for avoiding the ugly effect of
// misaligned infill on first layer because of different extrusion width and // misaligned infill on first layer because of different extrusion width and
@ -167,12 +168,11 @@ std::vector<SurfaceFill> group_fills(const Layer &layer)
-1, // auto width -1, // auto width
*layer.object() *layer.object()
).spacing(); ).spacing();
} else // Anchor a sparse infill to inner perimeters with the following anchor length:
params.spacing = params.flow.spacing(); params.anchor_length = float(region_config.infill_anchor);
if (region_config.infill_anchor.percent)
params.anchor_length = float(region_config.infill_anchor); params.anchor_length *= 0.01 * params.spacing;
if (region_config.infill_anchor.percent) }
params.anchor_length *= 0.01 * params.spacing;
auto it_params = set_surface_params.find(params); auto it_params = set_surface_params.find(params);
if (it_params == set_surface_params.end()) if (it_params == set_surface_params.end())
@ -543,8 +543,6 @@ void Layer::make_ironing()
fill.z = this->print_z; fill.z = this->print_z;
fill.overlap = 0; fill.overlap = 0;
fill_params.density = 1.; fill_params.density = 1.;
// fill_params.dont_connect = true;
fill_params.dont_connect = false;
fill_params.monotonic = true; fill_params.monotonic = true;
for (size_t i = 0; i < by_extruder.size(); ++ i) { for (size_t i = 0; i < by_extruder.size(); ++ i) {

View File

@ -165,7 +165,7 @@ void Fill3DHoneycomb::_fill_surface_single(
polylines = intersection_pl(polylines, to_polygons(expolygon)); polylines = intersection_pl(polylines, to_polygons(expolygon));
// connect lines if needed // connect lines if needed
if (params.dont_connect || polylines.size() <= 1) if (params.dont_connect() || polylines.size() <= 1)
append(polylines_out, chain_polylines(std::move(polylines))); append(polylines_out, chain_polylines(std::move(polylines)));
else else
this->connect_infill(std::move(polylines), expolygon, polylines_out, this->spacing, params); this->connect_infill(std::move(polylines), expolygon, polylines_out, this->spacing, params);

View File

@ -1332,7 +1332,7 @@ void Filler::_fill_surface_single(
} }
#endif /* ADAPTIVE_CUBIC_INFILL_DEBUG_OUTPUT */ #endif /* ADAPTIVE_CUBIC_INFILL_DEBUG_OUTPUT */
if (params.dont_connect || all_polylines_with_hooks.size() <= 1) if (params.dont_connect() || all_polylines_with_hooks.size() <= 1)
append(polylines_out, chain_polylines(std::move(all_polylines_with_hooks))); append(polylines_out, chain_polylines(std::move(all_polylines_with_hooks)));
else else
connect_infill(std::move(all_polylines_with_hooks), expolygon, polylines_out, this->spacing, params); connect_infill(std::move(all_polylines_with_hooks), expolygon, polylines_out, this->spacing, params);

View File

@ -1067,6 +1067,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const Polygons &boundary_s
void Fill::connect_infill(Polylines &&infill_ordered, const std::vector<const Polygon*> &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams &params) void Fill::connect_infill(Polylines &&infill_ordered, const std::vector<const Polygon*> &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams &params)
{ {
assert(! infill_ordered.empty()); assert(! infill_ordered.empty());
assert(params.anchor_length >= 0.01f);
const auto anchor_length = float(scale_(params.anchor_length)); const auto anchor_length = float(scale_(params.anchor_length));
#if 0 #if 0
@ -1239,7 +1240,6 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector<const Po
return std::numeric_limits<size_t>::max(); return std::numeric_limits<size_t>::max();
}; };
const float take_max_length = anchor_length > 0.f ? anchor_length : std::numeric_limits<float>::max();
const float line_half_width = 0.5f * scale_(spacing); const float line_half_width = 0.5f * scale_(spacing);
#if 0 #if 0
@ -1276,7 +1276,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector<const Po
idx_first = get_and_update_merged_with(idx_first); idx_first = get_and_update_merged_with(idx_first);
assert(idx_first < idx_second); assert(idx_first < idx_second);
assert(idx_second == merged_with[idx_second]); assert(idx_second == merged_with[idx_second]);
if (could_connect && (anchor_length == 0.f || length < anchor_length * 2.5)) { if (could_connect && length < anchor_length * 2.5) {
// Take the complete contour. // Take the complete contour.
// Connect the two polygons using the boundary contour. // Connect the two polygons using the boundary contour.
take(infill_ordered[idx_first], infill_ordered[idx_second], boundary[cp1->contour_idx], cp1, cp2, connection_cost.reversed); take(infill_ordered[idx_first], infill_ordered[idx_second], boundary[cp1->contour_idx], cp1, cp2, connection_cost.reversed);
@ -1285,8 +1285,8 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector<const Po
infill_ordered[idx_second].points.clear(); infill_ordered[idx_second].points.clear();
} else { } else {
// Try to connect cp1 resp. cp2 with a piece of perimeter line. // Try to connect cp1 resp. cp2 with a piece of perimeter line.
take_limited(infill_ordered[idx_first], boundary[cp1->contour_idx], boundary_params[cp1->contour_idx], cp1, cp2, connection_cost.reversed, take_max_length, line_half_width); take_limited(infill_ordered[idx_first], boundary[cp1->contour_idx], boundary_params[cp1->contour_idx], cp1, cp2, connection_cost.reversed, anchor_length, line_half_width);
take_limited(infill_ordered[idx_second], boundary[cp1->contour_idx], boundary_params[cp1->contour_idx], cp2, cp1, ! connection_cost.reversed, take_max_length, line_half_width); take_limited(infill_ordered[idx_second], boundary[cp1->contour_idx], boundary_params[cp1->contour_idx], cp2, cp1, ! connection_cost.reversed, anchor_length, line_half_width);
} }
} }
#endif #endif
@ -1314,7 +1314,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector<const Po
if (polyline_idx1 != polyline_idx2) { if (polyline_idx1 != polyline_idx2) {
Polyline &polyline1 = infill_ordered[polyline_idx1]; Polyline &polyline1 = infill_ordered[polyline_idx1];
Polyline &polyline2 = infill_ordered[polyline_idx2]; Polyline &polyline2 = infill_ordered[polyline_idx2];
if (anchor_length == 0.f || arc.arc_length < anchor_length * 2.5) { if (arc.arc_length < anchor_length * 2.5) {
// Not closing a loop, connecting the lines. // Not closing a loop, connecting the lines.
assert(contour[cp1->point_idx] == polyline1.points.front() || contour[cp1->point_idx] == polyline1.points.back()); assert(contour[cp1->point_idx] == polyline1.points.front() || contour[cp1->point_idx] == polyline1.points.back());
if (contour[cp1->point_idx] == polyline1.points.front()) if (contour[cp1->point_idx] == polyline1.points.front())
@ -1359,7 +1359,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector<const Po
assert(contour[contour_point.point_idx] == polyline.points.front() || contour[contour_point.point_idx] == polyline.points.back()); assert(contour[contour_point.point_idx] == polyline.points.front() || contour[contour_point.point_idx] == polyline.points.back());
bool connected = false; bool connected = false;
for (float l : { std::min(lprev, lnext), std::max(lprev, lnext) }) { for (float l : { std::min(lprev, lnext), std::max(lprev, lnext) }) {
if (l == std::numeric_limits<float>::max() || (anchor_length > 0.f && l > anchor_length * 2.5)) if (l == std::numeric_limits<float>::max() || l > anchor_length * 2.5)
break; break;
// Take the complete contour. // Take the complete contour.
bool reversed = l == lprev; bool reversed = l == lprev;
@ -1400,9 +1400,9 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector<const Po
float l = std::max(contour_point.contour_not_taken_length_prev, contour_point.contour_not_taken_length_next); float l = std::max(contour_point.contour_not_taken_length_prev, contour_point.contour_not_taken_length_next);
if (l > SCALED_EPSILON) { if (l > SCALED_EPSILON) {
if (contour_point.contour_not_taken_length_prev > contour_point.contour_not_taken_length_next) if (contour_point.contour_not_taken_length_prev > contour_point.contour_not_taken_length_next)
take_limited(polyline, contour, contour_params, &contour_point, contour_point.prev_on_contour, true, take_max_length, line_half_width); take_limited(polyline, contour, contour_params, &contour_point, contour_point.prev_on_contour, true, anchor_length, line_half_width);
else else
take_limited(polyline, contour, contour_params, &contour_point, contour_point.next_on_contour, false, take_max_length, line_half_width); take_limited(polyline, contour, contour_params, &contour_point, contour_point.next_on_contour, false, anchor_length, line_half_width);
} }
} }
} }

View File

@ -33,15 +33,15 @@ public:
struct FillParams struct FillParams
{ {
bool full_infill() const { return density > 0.9999f; } bool full_infill() const { return density > 0.9999f; }
// Don't connect the fill lines around the inner perimeter.
bool dont_connect() const { return anchor_length < 0.05f; }
// Fill density, fraction in <0, 1> // Fill density, fraction in <0, 1>
float density { 0.f }; float density { 0.f };
// Length of an infill anchor along the perimeter. // Length of an infill anchor along the perimeter.
float anchor_length { std::numeric_limits<float>::max() }; // 1000mm is roughly the maximum length line that fits into a 32bit coord_t.
float anchor_length { 1000.f };
// Don't connect the fill lines around the inner perimeter.
bool dont_connect { false };
// Don't adjust spacing to fill the space evenly. // Don't adjust spacing to fill the space evenly.
bool dont_adjust { true }; bool dont_adjust { true };

View File

@ -192,7 +192,7 @@ void FillGyroid::_fill_surface_single(
if (! polylines.empty()) { if (! polylines.empty()) {
// connect lines // connect lines
size_t polylines_out_first_idx = polylines_out.size(); size_t polylines_out_first_idx = polylines_out.size();
if (params.dont_connect) if (params.dont_connect())
append(polylines_out, chain_polylines(polylines)); append(polylines_out, chain_polylines(polylines));
else else
this->connect_infill(std::move(polylines), expolygon, polylines_out, this->spacing, params); this->connect_infill(std::move(polylines), expolygon, polylines_out, this->spacing, params);

View File

@ -74,7 +74,7 @@ void FillHoneycomb::_fill_surface_single(
} }
all_polylines = intersection_pl(std::move(all_polylines), to_polygons(expolygon)); all_polylines = intersection_pl(std::move(all_polylines), to_polygons(expolygon));
if (params.dont_connect || all_polylines.size() <= 1) if (params.dont_connect() || all_polylines.size() <= 1)
append(polylines_out, chain_polylines(std::move(all_polylines))); append(polylines_out, chain_polylines(std::move(all_polylines)));
else else
connect_infill(std::move(all_polylines), expolygon, polylines_out, this->spacing, params); connect_infill(std::move(all_polylines), expolygon, polylines_out, this->spacing, params);

View File

@ -76,7 +76,7 @@ void FillLine::_fill_surface_single(
size_t n_polylines_out_old = polylines_out.size(); size_t n_polylines_out_old = polylines_out.size();
// connect lines // connect lines
if (! params.dont_connect && ! polylines.empty()) { // prevent calling leftmost_point() on empty collections if (! params.dont_connect() && ! polylines.empty()) { // prevent calling leftmost_point() on empty collections
// offset the expolygon by max(min_spacing/2, extra) // offset the expolygon by max(min_spacing/2, extra)
ExPolygon expolygon_off; ExPolygon expolygon_off;
{ {

View File

@ -46,7 +46,7 @@ void FillPlanePath::_fill_surface_single(
// intersection(polylines_src, offset((Polygons)expolygon, scale_(0.02)), &polylines); // intersection(polylines_src, offset((Polygons)expolygon, scale_(0.02)), &polylines);
polylines = intersection_pl(std::move(polylines), to_polygons(expolygon)); polylines = intersection_pl(std::move(polylines), to_polygons(expolygon));
Polylines chained; Polylines chained;
if (params.dont_connect || params.density > 0.5 || polylines.size() <= 1) if (params.dont_connect() || params.density > 0.5 || polylines.size() <= 1)
chained = chain_polylines(std::move(polylines)); chained = chain_polylines(std::move(polylines));
else else
connect_infill(std::move(polylines), expolygon, chained, this->spacing, params); connect_infill(std::move(polylines), expolygon, chained, this->spacing, params);

View File

@ -1109,7 +1109,7 @@ static void connect_segment_intersections_by_contours(
} }
} }
if (params.dont_connect) { if (params.dont_connect()) {
if (itsct.prev_on_contour_quality == SegmentIntersection::LinkQuality::Valid) if (itsct.prev_on_contour_quality == SegmentIntersection::LinkQuality::Valid)
itsct.prev_on_contour_quality = SegmentIntersection::LinkQuality::TooLong; itsct.prev_on_contour_quality = SegmentIntersection::LinkQuality::TooLong;
if (itsct.next_on_contour_quality == SegmentIntersection::LinkQuality::Valid) if (itsct.next_on_contour_quality == SegmentIntersection::LinkQuality::Valid)
@ -2820,7 +2820,7 @@ bool FillRectilinear::fill_surface_by_multilines(const Surface *surface, FillPar
} }
} }
if (params.dont_connect || fill_lines.size() <= 1) { if (params.dont_connect() || fill_lines.size() <= 1) {
if (fill_lines.size() > 1) if (fill_lines.size() > 1)
fill_lines = chain_polylines(std::move(fill_lines)); fill_lines = chain_polylines(std::move(fill_lines));
append(polylines_out, std::move(fill_lines)); append(polylines_out, std::move(fill_lines));

View File

@ -1064,14 +1064,15 @@ void PrintConfigDef::init_fff_params()
def->enum_values.push_back("5"); def->enum_values.push_back("5");
def->enum_values.push_back("10"); def->enum_values.push_back("10");
def->enum_values.push_back("1000"); def->enum_values.push_back("1000");
def->enum_labels.push_back(L("0 (unprintable)")); def->enum_labels.push_back(L("0 (not anchored)"));
def->enum_labels.push_back("1 mm"); def->enum_labels.push_back("1 mm");
def->enum_labels.push_back("2 mm"); def->enum_labels.push_back("2 mm");
def->enum_labels.push_back("5 mm"); def->enum_labels.push_back("5 mm");
def->enum_labels.push_back("10 mm"); def->enum_labels.push_back("10 mm");
def->enum_labels.push_back(L("1000 (unlimited)")); def->enum_labels.push_back(L("1000 (unlimited)"));
def->mode = comAdvanced; def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloatOrPercent(300, true)); // def->set_default_value(new ConfigOptionFloatOrPercent(300, true));
def->set_default_value(new ConfigOptionFloatOrPercent(1000, false));
def = this->add("infill_extruder", coInt); def = this->add("infill_extruder", coInt);
def->label = L("Infill extruder"); def->label = L("Infill extruder");