From 8d1e13fccd5e3be505be5f185f0f91b194e95c10 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Fri, 20 Nov 2020 13:36:58 +0100 Subject: [PATCH] Anchoring of sparse infills can now be disabled. --- src/libslic3r/Fill/Fill.cpp | 26 ++++++++++++-------------- src/libslic3r/Fill/Fill3DHoneycomb.cpp | 2 +- src/libslic3r/Fill/FillAdaptive.cpp | 2 +- src/libslic3r/Fill/FillBase.cpp | 16 ++++++++-------- src/libslic3r/Fill/FillBase.hpp | 8 ++++---- src/libslic3r/Fill/FillGyroid.cpp | 2 +- src/libslic3r/Fill/FillHoneycomb.cpp | 2 +- src/libslic3r/Fill/FillLine.cpp | 2 +- src/libslic3r/Fill/FillPlanePath.cpp | 2 +- src/libslic3r/Fill/FillRectilinear.cpp | 4 ++-- src/libslic3r/PrintConfig.cpp | 5 +++-- 11 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp index 33ebf4ca23..90cd5699f3 100644 --- a/src/libslic3r/Fill/Fill.cpp +++ b/src/libslic3r/Fill/Fill.cpp @@ -33,12 +33,11 @@ struct SurfaceFillParams // FillParams 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. bool dont_adjust = false; // Length of the infill anchor along the perimeter line. - float anchor_length = std::numeric_limits::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 // For the output, for fill generator. @@ -67,7 +66,6 @@ struct SurfaceFillParams RETURN_COMPARE_NON_EQUAL(overlap); RETURN_COMPARE_NON_EQUAL(angle); 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(anchor_length); RETURN_COMPARE_NON_EQUAL(flow.width); @@ -86,7 +84,6 @@ struct SurfaceFillParams this->overlap == rhs.overlap && this->angle == rhs.angle && this->density == rhs.density && - this->dont_connect == rhs.dont_connect && this->dont_adjust == rhs.dont_adjust && this->anchor_length == rhs.anchor_length && this->flow == rhs.flow && @@ -154,7 +151,11 @@ std::vector group_fills(const Layer &layer) ); // 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 // for all layers, for avoiding the ugly effect of // misaligned infill on first layer because of different extrusion width and @@ -167,12 +168,11 @@ std::vector group_fills(const Layer &layer) -1, // auto width *layer.object() ).spacing(); - } else - params.spacing = params.flow.spacing(); - - params.anchor_length = float(region_config.infill_anchor); - if (region_config.infill_anchor.percent) - params.anchor_length *= 0.01 * params.spacing; + // Anchor a sparse infill to inner perimeters with the following anchor length: + params.anchor_length = float(region_config.infill_anchor); + if (region_config.infill_anchor.percent) + params.anchor_length *= 0.01 * params.spacing; + } auto it_params = set_surface_params.find(params); if (it_params == set_surface_params.end()) @@ -543,8 +543,6 @@ void Layer::make_ironing() fill.z = this->print_z; fill.overlap = 0; fill_params.density = 1.; -// fill_params.dont_connect = true; - fill_params.dont_connect = false; fill_params.monotonic = true; for (size_t i = 0; i < by_extruder.size(); ++ i) { diff --git a/src/libslic3r/Fill/Fill3DHoneycomb.cpp b/src/libslic3r/Fill/Fill3DHoneycomb.cpp index 69a7f9923c..2ddca7fe4a 100644 --- a/src/libslic3r/Fill/Fill3DHoneycomb.cpp +++ b/src/libslic3r/Fill/Fill3DHoneycomb.cpp @@ -165,7 +165,7 @@ void Fill3DHoneycomb::_fill_surface_single( polylines = intersection_pl(polylines, to_polygons(expolygon)); // 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))); else this->connect_infill(std::move(polylines), expolygon, polylines_out, this->spacing, params); diff --git a/src/libslic3r/Fill/FillAdaptive.cpp b/src/libslic3r/Fill/FillAdaptive.cpp index 07c454c806..3b62976261 100644 --- a/src/libslic3r/Fill/FillAdaptive.cpp +++ b/src/libslic3r/Fill/FillAdaptive.cpp @@ -1332,7 +1332,7 @@ void Filler::_fill_surface_single( } #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))); else connect_infill(std::move(all_polylines_with_hooks), expolygon, polylines_out, this->spacing, params); diff --git a/src/libslic3r/Fill/FillBase.cpp b/src/libslic3r/Fill/FillBase.cpp index cacc79d52c..3cb93e0739 100644 --- a/src/libslic3r/Fill/FillBase.cpp +++ b/src/libslic3r/Fill/FillBase.cpp @@ -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 &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms) { assert(! infill_ordered.empty()); + assert(params.anchor_length >= 0.01f); const auto anchor_length = float(scale_(params.anchor_length)); #if 0 @@ -1239,7 +1240,6 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector::max(); }; - const float take_max_length = anchor_length > 0.f ? anchor_length : std::numeric_limits::max(); const float line_half_width = 0.5f * scale_(spacing); #if 0 @@ -1276,7 +1276,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectorcontour_idx], cp1, cp2, connection_cost.reversed); @@ -1285,8 +1285,8 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectorcontour_idx], boundary_params[cp1->contour_idx], cp1, cp2, 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, 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, anchor_length, line_half_width); } } #endif @@ -1314,7 +1314,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectorpoint_idx] == polyline1.points.front() || contour[cp1->point_idx] == polyline1.points.back()); if (contour[cp1->point_idx] == polyline1.points.front()) @@ -1359,7 +1359,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector::max() || (anchor_length > 0.f && l > anchor_length * 2.5)) + if (l == std::numeric_limits::max() || l > anchor_length * 2.5) break; // Take the complete contour. bool reversed = l == lprev; @@ -1400,9 +1400,9 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector SCALED_EPSILON) { 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 - 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); } } } diff --git a/src/libslic3r/Fill/FillBase.hpp b/src/libslic3r/Fill/FillBase.hpp index 4f8456bfa3..4ebad7a8d9 100644 --- a/src/libslic3r/Fill/FillBase.hpp +++ b/src/libslic3r/Fill/FillBase.hpp @@ -33,15 +33,15 @@ public: struct FillParams { 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> float density { 0.f }; // Length of an infill anchor along the perimeter. - float anchor_length { std::numeric_limits::max() }; - - // Don't connect the fill lines around the inner perimeter. - bool dont_connect { false }; + // 1000mm is roughly the maximum length line that fits into a 32bit coord_t. + float anchor_length { 1000.f }; // Don't adjust spacing to fill the space evenly. bool dont_adjust { true }; diff --git a/src/libslic3r/Fill/FillGyroid.cpp b/src/libslic3r/Fill/FillGyroid.cpp index c70c4439ea..5cbfed57cf 100644 --- a/src/libslic3r/Fill/FillGyroid.cpp +++ b/src/libslic3r/Fill/FillGyroid.cpp @@ -192,7 +192,7 @@ void FillGyroid::_fill_surface_single( if (! polylines.empty()) { // connect lines size_t polylines_out_first_idx = polylines_out.size(); - if (params.dont_connect) + if (params.dont_connect()) append(polylines_out, chain_polylines(polylines)); else this->connect_infill(std::move(polylines), expolygon, polylines_out, this->spacing, params); diff --git a/src/libslic3r/Fill/FillHoneycomb.cpp b/src/libslic3r/Fill/FillHoneycomb.cpp index 8d80529ec5..5e70000888 100644 --- a/src/libslic3r/Fill/FillHoneycomb.cpp +++ b/src/libslic3r/Fill/FillHoneycomb.cpp @@ -74,7 +74,7 @@ void FillHoneycomb::_fill_surface_single( } 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))); else connect_infill(std::move(all_polylines), expolygon, polylines_out, this->spacing, params); diff --git a/src/libslic3r/Fill/FillLine.cpp b/src/libslic3r/Fill/FillLine.cpp index 1e6ed52846..1cb9b2244d 100644 --- a/src/libslic3r/Fill/FillLine.cpp +++ b/src/libslic3r/Fill/FillLine.cpp @@ -76,7 +76,7 @@ void FillLine::_fill_surface_single( size_t n_polylines_out_old = polylines_out.size(); // 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) ExPolygon expolygon_off; { diff --git a/src/libslic3r/Fill/FillPlanePath.cpp b/src/libslic3r/Fill/FillPlanePath.cpp index 0ce992ca34..a7a33b13d7 100644 --- a/src/libslic3r/Fill/FillPlanePath.cpp +++ b/src/libslic3r/Fill/FillPlanePath.cpp @@ -46,7 +46,7 @@ void FillPlanePath::_fill_surface_single( // intersection(polylines_src, offset((Polygons)expolygon, scale_(0.02)), &polylines); polylines = intersection_pl(std::move(polylines), to_polygons(expolygon)); 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)); else connect_infill(std::move(polylines), expolygon, chained, this->spacing, params); diff --git a/src/libslic3r/Fill/FillRectilinear.cpp b/src/libslic3r/Fill/FillRectilinear.cpp index 09bb442010..0a75b6729a 100644 --- a/src/libslic3r/Fill/FillRectilinear.cpp +++ b/src/libslic3r/Fill/FillRectilinear.cpp @@ -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) itsct.prev_on_contour_quality = SegmentIntersection::LinkQuality::TooLong; 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) fill_lines = chain_polylines(std::move(fill_lines)); append(polylines_out, std::move(fill_lines)); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index e59e67cffc..dc2ae61f8e 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1064,14 +1064,15 @@ void PrintConfigDef::init_fff_params() def->enum_values.push_back("5"); def->enum_values.push_back("10"); 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("2 mm"); def->enum_labels.push_back("5 mm"); def->enum_labels.push_back("10 mm"); def->enum_labels.push_back(L("1000 (unlimited)")); 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->label = L("Infill extruder");