diff --git a/docs/HLSD/multiline-infill.md b/docs/HLSD/multiline-infill.md index a12295bdd6..8995ee546f 100644 --- a/docs/HLSD/multiline-infill.md +++ b/docs/HLSD/multiline-infill.md @@ -13,10 +13,19 @@ any other infill. Clipping also cuts an outline at its first point, which may be anywhere along a line, so `join_cut_outlines()` joins the pieces back first. Outlines of centerlines that cross each other overlap at every crossing, which -over-extrudes the wall intersections. The line-crossing patterns Grid, -Triangles, Tri-hexagon, Cubic and Quarter Cubic therefore build centerlines that -never cross (`FillRectilinear::fill_surface_trapezoidal()`), and so do Adaptive Cubic and -Support Cubic (`FillAdaptive`). 3D Honeycomb skips `multiline_fill()` and draws +over-extrudes the wall intersections. `sparse_infill_strategy` chooses what the +line-crossing patterns Grid, Triangles, Tri-hexagon, Cubic, Quarter Cubic, +Adaptive Cubic and Support Cubic do about it. Non-crossing builds centerlines +that never cross (`FillRectilinear::fill_surface_trapezoidal()`, and `FillAdaptive` +for the two octree patterns). With a single line, `d1 = spacing` and those +centerlines are printed as they are. Crossing keeps the straight lines of the +single-line pattern and prints each wall as N copies of its line, `spacing` +apart: the `FillRectilinear` patterns slice the region with the copies, as +Rectilinear does, and `FillAdaptive` shifts copies of each octree segment. The +walls overlap where they cross. +Default crosses with one line and turns back with more. `make_fills()` resolves +Default per region before grouping the surfaces, so regions that print the same +paths share a fill. 3D Honeycomb skips `multiline_fill()` and draws its N lines itself as parallel copies of each wave, which never cross (`Fill3DHoneycomb`). Rectilinear, Aligned Rectilinear, Lateral Lattice and Lateral Honeycomb have only parallel lines, so they skip `multiline_fill()` too: @@ -50,7 +59,8 @@ Cubic run at 0°, 60° and 120°. Those rows rotate by 120° every layer about a 3-fold center of the arrangement, so each family takes every role in turn. The pattern is phased on fixed positions, so it lines up across layers and across the regions of one layer. Rounding the corners with -`sparse_infill_smooth_factor` happens before `multiline_fill()`. +`sparse_infill_smooth_factor` happens before `multiline_fill()`, and only these +paths have corners to round: the crossing lines are straight. Each region builds only the rows over its bounding box in that frame, and outlines only the centerlines within `d1 / 2` of it, the ones whose outlines diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp index bde6919482..4c1cb1cfa0 100644 --- a/src/libslic3r/Fill/Fill.cpp +++ b/src/libslic3r/Fill/Fill.cpp @@ -276,6 +276,7 @@ struct SurfaceFillParams float density = 0.f; // Infill line multiplier count. int multiline = 1; + InfillStrategy infill_strategy = InfillStrategy::Default; // Don't adjust spacing to fill the space evenly. // bool dont_adjust = false; // Length of the infill anchor along the perimeter line. @@ -345,6 +346,7 @@ struct SurfaceFillParams RETURN_COMPARE_NON_EQUAL(fixed_angle); RETURN_COMPARE_NON_EQUAL(density); RETURN_COMPARE_NON_EQUAL(multiline); + RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, infill_strategy); // RETURN_COMPARE_NON_EQUAL_TYPED(unsigned, dont_adjust); RETURN_COMPARE_NON_EQUAL(anchor_length); RETURN_COMPARE_NON_EQUAL(anchor_length_max); @@ -386,6 +388,7 @@ struct SurfaceFillParams this->bridge_angle == rhs.bridge_angle && this->density == rhs.density && this->multiline == rhs.multiline && + this->infill_strategy == rhs.infill_strategy && // this->dont_adjust == rhs.dont_adjust && this->anchor_length == rhs.anchor_length && this->anchor_length_max == rhs.anchor_length_max && @@ -1020,6 +1023,9 @@ std::vector group_fills(const Layer &layer, LockRegionParam &lock_p } // Orca: apply fill multiline only for sparse infill params.multiline = params.extrusion_role == erInternalInfill ? int(region_config.fill_multiline) : 1; + // Orca: resolved, so the regions printing the same paths share a fill. + params.infill_strategy = params.extrusion_role != erInternalInfill || !has_infill_strategy(params.pattern) ? InfillStrategy::Default : + is_non_crossing_strategy(region_config.sparse_infill_strategy.value, params.multiline) ? InfillStrategy::NonCrossing : InfillStrategy::Crossing; // Orca: Pass through separated_infills only where it can move the pattern. params.separated_infills = region_config.separated_infills && is_separable_infill_pattern(params.pattern) && @@ -1045,7 +1051,7 @@ std::vector group_fills(const Layer &layer, LockRegionParam &lock_p // Orca: the smoothing factor only applies to the sparse infill patterns that // implement it. The fills clamp and validate the value themselves. - if (is_smoothable_infill_pattern(params.pattern, params.multiline)) + if (is_smoothable_infill_pattern(params.pattern, params.multiline, params.infill_strategy)) params.smooth_factor = 0.01 * region_config.sparse_infill_smooth_factor.value; } else { const bool top_layer_direction_set = surface.is_top() && region_config.top_layer_direction.value >= 0.; @@ -1435,6 +1441,7 @@ void Layer::make_fills(const FillAdaptive::RegionOctrees* fill_octrees, FillLigh FillParams params; params.density = float(0.01 * surface_fill.params.density); params.multiline = surface_fill.params.multiline; + params.infill_strategy = surface_fill.params.infill_strategy; params.dont_adjust = false; // surface_fill.params.dont_adjust; params.anchor_length = surface_fill.params.anchor_length; params.anchor_length_max = surface_fill.params.anchor_length_max; @@ -1668,6 +1675,7 @@ Polylines Layer::generate_sparse_infill_polylines_for_anchoring(const FillAdapti params.lateral_lattice_angle_2 = surface_fill.params.lateral_lattice_angle_2; params.infill_overhang_angle = surface_fill.params.infill_overhang_angle; params.multiline = surface_fill.params.multiline; + params.infill_strategy = surface_fill.params.infill_strategy; params.gyroid_optimized = surface_fill.params.gyroid_optimized; params.adaptive_infill_mode = surface_fill.params.adaptive_infill_mode; params.adaptive_infill_interior_density = float(0.01 * surface_fill.params.adaptive_infill_interior_density); diff --git a/src/libslic3r/Fill/FillAdaptive.cpp b/src/libslic3r/Fill/FillAdaptive.cpp index ddfe54665c..4c7448afef 100644 --- a/src/libslic3r/Fill/FillAdaptive.cpp +++ b/src/libslic3r/Fill/FillAdaptive.cpp @@ -1894,7 +1894,7 @@ void Filler::_fill_surface_single( all_polylines.reserve(lines.size()); std::transform(lines.begin(), lines.end(), std::back_inserter(all_polylines), [](const Line& l) { return Polyline{ l.a, l.b }; }); - if (params.multiline > 1) { + if (params.non_crossing()) { const double d1 = scale_(this->spacing) * params.multiline; BoundingBox cover = get_extents(expolygon); cover.offset(coord_t(4. * d1)); @@ -1903,18 +1903,27 @@ void Filler::_fill_surface_single( // Line ends overlap the walls they stop on by half a line, so that they bond. if (Polylines paths = multiline_paths(lines, d1, 0.5 * scale_(this->spacing), sweep, cover); !paths.empty()) all_polylines = std::move(paths); + multiline_fill(all_polylines, params, spacing); + } else if (params.multiline > 1) { + // Crossing walls are parallel copies of their line, spacing apart, like those of the other crossing patterns. + all_polylines.clear(); + all_polylines.reserve(lines.size() * params.multiline); + for (const Line &line : lines) { + const Vec2d normal = perp(line.vector().cast().normalized()); + for (int i = 0; i < params.multiline; ++ i) { + const Point shift(Vec2d(normal * ((i - 0.5 * (params.multiline - 1)) * scale_(this->spacing)))); + all_polylines.emplace_back(Polyline{ line.a + shift, line.b + shift }); + } + } } - // Apply multiline offset if needed - multiline_fill(all_polylines, params, spacing); - // Crop all polylines all_polylines = intersection_pl(std::move(all_polylines), expolygon); join_cut_outlines(all_polylines, params); #endif } - if (params.multiline == 1) { + if (params.multiline == 1 && !params.non_crossing()) { // After intersection_pl some polylines with only one line are split into more lines for (Polyline& polyline : all_polylines) { // FIXME assert that all the points are collinear and in between the start and end point. @@ -1944,7 +1953,7 @@ void Filler::_fill_surface_single( chain_or_connect_infill(std::move(all_polylines_with_hooks), expolygon, polylines_out, this->spacing, params); } else { - // if multiline is > 1 infill is ready to connect + // Multiline walls and non-crossing paths are ready to connect. chain_or_connect_infill(std::move(all_polylines), expolygon, polylines_out, this->spacing, params); } diff --git a/src/libslic3r/Fill/FillBase.hpp b/src/libslic3r/Fill/FillBase.hpp index a8990961e8..0c32b3796f 100644 --- a/src/libslic3r/Fill/FillBase.hpp +++ b/src/libslic3r/Fill/FillBase.hpp @@ -65,6 +65,8 @@ struct FillParams // Fill density, fraction in <0, 1> float density { 0.f }; int multiline{1}; + InfillStrategy infill_strategy { InfillStrategy::Default }; + bool non_crossing() const { return is_non_crossing_strategy(infill_strategy, multiline); } // Length of an infill anchor along the perimeter. // 1000mm is roughly the maximum length line that fits into a 32bit coord_t. diff --git a/src/libslic3r/Fill/FillRectilinear.cpp b/src/libslic3r/Fill/FillRectilinear.cpp index ce913cc001..85ddd1b214 100644 --- a/src/libslic3r/Fill/FillRectilinear.cpp +++ b/src/libslic3r/Fill/FillRectilinear.cpp @@ -3113,7 +3113,7 @@ bool FillRectilinear::fill_surface_trapezoidal( Polylines& polylines_out, int Pattern_type) // 0=grid, 1=triangular, 2=stars, 3=cubic, 4=quarter cubic { - assert(params.multiline > 1); + assert(params.non_crossing()); Polylines polylines; @@ -3163,7 +3163,7 @@ bool FillRectilinear::fill_surface_trapezoidal( switch (Pattern_type) { case 0: // Grid / Trapezoidal { - // Generate a non-crossing trapezoidal pattern to avoid overextrusion at intersections when `multiline > 1`. + // Generate a non-crossing trapezoidal pattern to avoid overextrusion at intersections. /* * P2--P3 * / \ @@ -3606,7 +3606,7 @@ Polylines FillGrid::fill_surface(const Surface *surface, const FillParams ¶m { Polylines polylines_out; - if (params.multiline > 1) { + if (params.non_crossing()) { // Experimental trapezoidal grid if (!this->fill_surface_trapezoidal( surface, params, polylines_out, 0)) @@ -3646,7 +3646,7 @@ Polylines FillLateralLattice::fill_surface(const Surface *surface, const FillPar Polylines FillTriangles::fill_surface(const Surface *surface, const FillParams ¶ms){ Polylines polylines_out; - if (params.multiline > 1) { + if (params.non_crossing()) { // Experimental trapezoidal grid if (!this->fill_surface_trapezoidal( surface, params, polylines_out, 1)) @@ -3666,7 +3666,7 @@ Polylines FillTriangles::fill_surface(const Surface *surface, const FillParams & Polylines FillStars::fill_surface(const Surface *surface, const FillParams ¶ms) { Polylines polylines_out; - if (params.multiline > 1) { + if (params.non_crossing()) { if (!this->fill_surface_trapezoidal( surface, params, polylines_out, 2)) BOOST_LOG_TRIVIAL(error) << "FillStars::fill_surface_trapezoidal() failed."; @@ -3683,7 +3683,7 @@ Polylines FillStars::fill_surface(const Surface *surface, const FillParams ¶ Polylines FillCubic::fill_surface(const Surface *surface, const FillParams ¶ms) { Polylines polylines_out; - if (params.multiline > 1) { + if (params.non_crossing()) { if (!this->fill_surface_trapezoidal(surface, params, polylines_out, 3)) BOOST_LOG_TRIVIAL(error) << "FillCubic::fill_surface_trapezoidal() failed."; return polylines_out; @@ -3700,7 +3700,7 @@ Polylines FillCubic::fill_surface(const Surface *surface, const FillParams ¶ Polylines FillQuarterCubic::fill_surface(const Surface* surface, const FillParams& params) { Polylines polylines_out; - if (params.multiline > 1) { + if (params.non_crossing()) { if (!this->fill_surface_trapezoidal(surface, params, polylines_out, 4)) BOOST_LOG_TRIVIAL(error) << "FillQuarterCubic::fill_surface_trapezoidal() failed."; return polylines_out; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index ac5143dabf..82f89d160c 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1216,6 +1216,7 @@ static std::vector s_Preset_print_options{ "is_infill_first", "sparse_infill_density", "fill_multiline", + "sparse_infill_strategy", "adaptive_infill_mode", "adaptive_infill_interior_density", "adaptive_infill_gradient", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index dec0ed3072..415d59b27c 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -2540,6 +2540,22 @@ StringObjectException Print::validate(std::vector *warnin } } + for (const PrintObject *object : m_objects) + for (const PrintRegion ®ion : object->all_regions()) { + const PrintRegionConfig &cfg = region.config(); + if (cfg.sparse_infill_strategy.value == InfillStrategy::Crossing && cfg.fill_multiline.value > 3 && + has_infill_strategy(cfg.sparse_infill_pattern.value) && cfg.sparse_infill_density.value > 0. && + cfg.sparse_infill_density.value < 100.) { + // TRN %1% is the object name. + warn(Slic3r::format(_u8L("The sparse infill of the object %1% uses the Crossing strategy with more than 3 lines. " + "Its walls overlap over a large area at every crossing, which can over-extrude there " + "and make the nozzle scrape the infill. Use the Non-crossing strategy or fewer lines."), + object->model_object()->name), + "sparse_infill_strategy", object); + break; + } + } + // Cache of layer height profiles for checking: // 1) Whether all layers are synchronized if printing with wipe tower and / or unsynchronized supports. // 2) Whether layer height is constant for Organic supports. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 61b012b5a7..59b700c121 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -384,6 +384,13 @@ static t_config_enum_values s_keys_map_SurfaceFillOrder{ CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(SurfaceFillOrder) //Orca +static t_config_enum_values s_keys_map_InfillStrategy{ + { "default", int(InfillStrategy::Default) }, + { "crossing", int(InfillStrategy::Crossing) }, + { "non_crossing", int(InfillStrategy::NonCrossing) }, +}; +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(InfillStrategy) + static t_config_enum_values s_keys_map_AdaptiveInfillMode{ { "disabled", int(AdaptiveInfillMode::Disabled) }, { "distance_warp", int(AdaptiveInfillMode::DistanceWarp) }, @@ -3897,6 +3904,26 @@ void PrintConfigDef::init_fff_params() def->max = 10; // Maximum number of lines for infill pattern def->set_default_value(new ConfigOptionInt(1)); + def = this->add("sparse_infill_strategy", coEnum); + def->label = L("Sparse infill strategy"); + def->category = L("Strength"); + def->tooltip = L("How the lines of the Grid, Triangles, Tri-hexagon, Cubic, Quarter Cubic, Adaptive Cubic and " + "Support Cubic patterns meet.\n" + " - Default: crossing with a single line, non-crossing with multiline infill.\n" + " - Crossing: the lines run straight across each other. With multiline infill, the lines of two " + "walls overlap where they cross.\n" + " - Non-crossing: the lines turn back where they meet instead of crossing, so the walls touch " + "without overlapping."); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values.push_back("default"); + def->enum_values.push_back("crossing"); + def->enum_values.push_back("non_crossing"); + def->enum_labels.push_back(L("Default")); + def->enum_labels.push_back(L("Crossing")); + def->enum_labels.push_back(L("Non-crossing")); + def->mode = comExpert; + def->set_default_value(new ConfigOptionEnum(InfillStrategy::Default)); + def = this->add("adaptive_infill_mode", coEnum); def->label = L("Adaptive density (experimental)"); def->category = L("Strength"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index a170065227..e6fba1c46a 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -176,10 +176,40 @@ inline bool is_octree_infill_pattern(InfillPattern pattern) { return pattern == // Orca: Infill patterns graded by the "adaptive_infill_mode" option. inline bool is_adaptive_infill_pattern(InfillPattern pattern) { return pattern == ipGyroid || pattern == ipTpmsD || pattern == ipTpmsFK; } +// Orca: whether the sparse infill lines run across each other or turn back where they cross. +enum class InfillStrategy { + Default, + Crossing, + NonCrossing, +}; + +// Orca: Infill patterns whose lines can either cross or turn back at the crossings. +inline bool has_infill_strategy(InfillPattern pattern) +{ + switch (pattern) { + case ipGrid: + case ipTriangles: + case ipStars: + case ipCubic: + case ipQuarterCubic: + case ipAdaptiveCubic: + case ipSupportCubic: + return true; + default: + return false; + } +} + +// Orca: The default strategy crosses with a single line per infill wall and turns back with more. +inline bool is_non_crossing_strategy(InfillStrategy strategy, int multiline) +{ + return strategy == InfillStrategy::Default ? multiline > 1 : strategy == InfillStrategy::NonCrossing; +} + // Orca: Infill patterns that round their corners by the "sparse_infill_smooth_factor" option. -// Grid, Triangles and Tri-hexagon only do so in their trapezoidal form, which is generated with more -// than one line per infill wall; a single line makes them plain crossing lines with nothing to round. -inline bool is_smoothable_infill_pattern(InfillPattern pattern, int multiline = 1) +// Grid, Triangles, Tri-hexagon, Cubic and Quarter Cubic only do so with the non-crossing strategy; +// crossing makes them straight lines with nothing to round. +inline bool is_smoothable_infill_pattern(InfillPattern pattern, int multiline = 1, InfillStrategy strategy = InfillStrategy::Default) { switch (pattern) { case ipHilbertCurve: @@ -195,7 +225,7 @@ inline bool is_smoothable_infill_pattern(InfillPattern pattern, int multiline = case ipStars: case ipCubic: case ipQuarterCubic: - return multiline > 1; + return is_non_crossing_strategy(strategy, multiline); default: return false; } @@ -834,6 +864,7 @@ CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ToolChangeOrderingType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PowerLossRecoveryMode) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ArcFittingMode) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(SurfaceFillOrder) +CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(InfillStrategy) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(AdaptiveInfillMode) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(AdaptiveInfillGradient) @@ -1533,6 +1564,7 @@ PRINT_CONFIG_CLASS_DEFINE( // Orca: ((ConfigOptionFloatOrPercent, infill_combination_max_layer_height)) ((ConfigOptionInt, fill_multiline)) + ((ConfigOptionEnum, sparse_infill_strategy)) ((ConfigOptionEnum, adaptive_infill_mode)) ((ConfigOptionPercent, adaptive_infill_interior_density)) ((ConfigOptionEnum, adaptive_infill_gradient)) diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index bb7346426d..221fa73454 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -1732,7 +1732,8 @@ bool PrintObject::invalidate_state_by_config_options( || opt_key == "small_area_infill_flow_compensation" || opt_key == "lateral_lattice_angle_1" || opt_key == "lateral_lattice_angle_2" - || opt_key == "infill_overhang_angle") { + || opt_key == "infill_overhang_angle" + || opt_key == "sparse_infill_strategy") { steps.emplace_back(posInfill); } else if (opt_key == "sparse_infill_pattern" || opt_key == "adaptive_infill_mode" diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 6eebb50e09..86e974f11c 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -855,6 +855,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, in // gyroid_optimized only applies when the sparse infill pattern is gyroid without adaptive density; // hide the whole line otherwise. toggle_line("gyroid_optimized", have_infill && pattern == ipGyroid && !have_adaptive_infill, -1, _L("Select Gyroid infill with nonzero sparse infill density and disable adaptive density to use this setting.")); + toggle_line("sparse_infill_strategy", have_infill && has_infill_strategy(pattern), -1, _L("Select the Grid, Triangles, Tri-hexagon, Cubic, Quarter Cubic, Adaptive Cubic or Support Cubic sparse infill pattern with nonzero sparse infill density to use this setting.")); // If there is infill, enable/disable fill_multiline according to whether the pattern supports multiline infill. if (have_infill) { @@ -904,7 +905,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, in bool has_bottom_shell = config->opt_int("bottom_shell_layers") > 0; const wxString bottom_shell_reason = _L("Set bottom shell layers above zero to use this setting."); bool has_solid_infill = has_top_shell_layers || has_bottom_shell; - toggle_line("sparse_infill_smooth_factor", have_infill && is_smoothable_infill_pattern(pattern, config->opt_int("fill_multiline")), -1, _L("Use nonzero sparse infill density and an infill pattern and multiline setting that support infill smoothing.")); + toggle_line("sparse_infill_smooth_factor", have_infill && is_smoothable_infill_pattern(pattern, config->opt_int("fill_multiline"), config->opt_enum("sparse_infill_strategy")), -1, _L("Use nonzero sparse infill density and an infill pattern, multiline and strategy setting that support infill smoothing.")); toggle_field("top_surface_pattern", has_top_shell, -1, top_shell_reason); toggle_field("bottom_surface_pattern", has_bottom_shell, -1, bottom_shell_reason); toggle_field("top_surface_density", has_top_shell_layers, -1, top_shell_layers_reason); diff --git a/src/slic3r/GUI/GUI_Factories.cpp b/src/slic3r/GUI/GUI_Factories.cpp index 75c3d22265..4a1d4adfdc 100644 --- a/src/slic3r/GUI/GUI_Factories.cpp +++ b/src/slic3r/GUI/GUI_Factories.cpp @@ -157,6 +157,7 @@ std::map> SettingsFactory::PART_CATE {"sparse_infill_density", "", 1}, {"fill_multiline", "", 1}, {"sparse_infill_pattern", "", 1}, + {"sparse_infill_strategy", "", 1}, {"adaptive_infill_mode", "", 1}, {"adaptive_infill_interior_density", "", 1}, {"adaptive_infill_gradient", "", 1}, diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 23e8ad0107..e657d7fadc 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3207,6 +3207,7 @@ void TabPrint::build() optgroup->append_single_option_line("sparse_infill_density", "strength_settings_infill#sparse-infill-density"); optgroup->append_single_option_line("fill_multiline", "strength_settings_infill#fill-multiline"); optgroup->append_single_option_line("sparse_infill_pattern", "strength_settings_infill#sparse-infill-pattern"); + optgroup->append_single_option_line("sparse_infill_strategy", "strength_settings_infill#strategy"); optgroup->append_single_option_line("adaptive_infill_mode", "strength_settings_patterns#adaptive-density"); optgroup->append_single_option_line("adaptive_infill_interior_density", "strength_settings_patterns#interior-density"); optgroup->append_single_option_line("adaptive_infill_gradient", "strength_settings_patterns#adaptive-gradient"); diff --git a/tests/fff_print/test_fill.cpp b/tests/fff_print/test_fill.cpp index b81932edef..a39f386397 100644 --- a/tests/fff_print/test_fill.cpp +++ b/tests/fff_print/test_fill.cpp @@ -1631,35 +1631,98 @@ TEST_CASE("Cross hatch infill rounds its transition layers with the smooth facto REQUIRE(smooth.length < sharp.length); } -TEST_CASE("Trapezoidal infill rounds its corners only with more than one line", "[Fill]") +TEST_CASE("Trapezoidal infill rounds its corners only with the non-crossing strategy", "[Fill]") { const std::string pattern = GENERATE("grid", "quartercubic"); - CAPTURE(pattern); - auto shape_for = [&pattern](int multiline, const std::string &smooth_factor) { + // The default strategy is non-crossing with more than one line per infill wall and crossing with one. + const auto [multiline, strategy, non_crossing] = GENERATE(table({ { 2, "default", true }, + { 1, "default", false }, + { 1, "non_crossing", true }, + { 2, "crossing", false } })); + CAPTURE(pattern, multiline, strategy); + auto shape_for = [&pattern, multiline = multiline, strategy = strategy](const std::string &smooth_factor) { Print print; Slic3r::Test::init_and_process_print({Slic3r::Test::cube(20)}, print, {{"sparse_infill_pattern", pattern}, {"sparse_infill_density", "20%"}, {"fill_multiline", multiline}, + {"sparse_infill_strategy", strategy}, {"sparse_infill_smooth_factor", smooth_factor}, {"layer_height", 0.2}}); return sparse_infill_shape(print); }; - const SparseInfillShape sharp = shape_for(2, "0%"); - const SparseInfillShape smooth = shape_for(2, "100%"); - + const SparseInfillShape sharp = shape_for("0%"); + const SparseInfillShape smooth = shape_for("100%"); REQUIRE(sharp.point_count > 0); - REQUIRE(smooth.point_count > sharp.point_count); - REQUIRE(smooth.sharp_turns < sharp.sharp_turns); - REQUIRE(smooth.length < sharp.length); + if (non_crossing) { + CHECK(smooth.point_count > sharp.point_count); + CHECK(smooth.sharp_turns < sharp.sharp_turns); + CHECK(smooth.length < sharp.length); + } else { + // Crossing lines are straight, with no corner of their own. + CHECK(smooth.sequence == sharp.sequence); + } +} - // A single line per infill wall is the plain crossing lines, which have no corner of their own. - const SparseInfillShape single_sharp = shape_for(1, "0%"); - const SparseInfillShape single_smooth = shape_for(1, "100%"); - REQUIRE(single_sharp.point_count > 0); - REQUIRE(single_smooth.point_count == single_sharp.point_count); - REQUIRE(single_smooth.length == single_sharp.length); +TEST_CASE("Sparse infill strategy makes the lines cross or turn back where they meet", "[Fill]") +{ + const std::string pattern = GENERATE("grid", "triangles", "tri-hexagon", "cubic", "quartercubic", "adaptivecubic", "supportcubic"); + const int multiline = GENERATE(1, 2); + const std::string strategy = GENERATE("default", "crossing", "non_crossing"); + CAPTURE(pattern, multiline, strategy); + + Print print; + Slic3r::Test::init_and_process_print({Slic3r::Test::cube(20)}, print, + {{"sparse_infill_pattern", pattern}, + {"sparse_infill_density", "20%"}, + {"fill_multiline", multiline}, + {"sparse_infill_strategy", strategy}, + // The bare pattern, without connections along the boundary. + {"infill_anchor", 0}, + {"infill_anchor_max", 0}, + {"layer_height", 0.3}}); + + size_t layers = 0, crossing_layers = 0; + for (const Layer *layer : print.objects().front()->layers()) { + Polylines printed; + for (const LayerRegion *region : layer->regions()) + for (const ExtrusionEntity *entity : region->fills.flatten().entities) + if (entity->role() == erInternalInfill) + entity->collect_polylines(printed); + if (printed.empty()) + continue; + ++layers; + if (!get_intersections(to_lines(printed)).empty()) + ++crossing_layers; + } + REQUIRE(layers > 0); + if (strategy == "crossing" || (strategy == "default" && multiline == 1)) + CHECK(crossing_layers > 0); + else + CHECK(crossing_layers == 0); +} + +TEST_CASE("Sparse infill strategy leaves the patterns without one unchanged", "[Fill]") +{ + const std::string pattern = GENERATE("gyroid", "honeycomb"); + const int multiline = GENERATE(1, 2); + CAPTURE(pattern, multiline); + auto shape_for = [&pattern, multiline](const std::string &strategy) { + Print print; + Slic3r::Test::init_and_process_print({Slic3r::Test::cube(20)}, print, + {{"sparse_infill_pattern", pattern}, + {"sparse_infill_density", "20%"}, + {"fill_multiline", multiline}, + {"sparse_infill_strategy", strategy}, + {"layer_height", 0.3}}); + return sparse_infill_shape(print); + }; + + const SparseInfillShape reference = shape_for("default"); + REQUIRE(reference.point_count > 0); + CHECK(shape_for("crossing").sequence == reference.sequence); + CHECK(shape_for("non_crossing").sequence == reference.sequence); } TEST_CASE("Multiline infill of an object matches the infill of a larger object with the same center", "[Fill]") diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index aeea954712..2b6dbfcdc6 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -3623,3 +3623,24 @@ TEST_CASE("A changed AMS filament inventory invalidates the grouping steps", "[P CHECK(print.apply(model, config) != PrintBase::APPLY_STATUS_INVALIDATED); CHECK(print.get_extruder_filament_info().empty()); } + +TEST_CASE("Print validation warns about crossing sparse infill walls of more than 3 lines", "[Print]") +{ + const auto [pattern, strategy, lines, warned] = GENERATE(table({ + { "grid", "crossing", 4, true }, + { "adaptivecubic", "crossing", 4, true }, + { "grid", "crossing", 3, false }, + { "grid", "non_crossing", 4, false }, + { "grid", "default", 4, false }, + { "gyroid", "crossing", 4, false } })); + CAPTURE(pattern, strategy, lines); + + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + config.set_deserialize_strict({ { "sparse_infill_pattern", pattern }, + { "sparse_infill_strategy", strategy }, + { "fill_multiline", lines }, + { "sparse_infill_density", "20%" } }); + std::vector warnings; + REQUIRE(validate_cubes(config, warnings).string.empty()); + CHECK(count_opt_key(warnings, "sparse_infill_strategy") == (warned ? 1u : 0u)); +}