mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-22 21:50:51 -05:00
Fix overhang speeds measured against a stale layer after skipped layers (#16861)
This commit is contained in:
1 parent
1478735b58
commit
0a2cdfc1a3
3 files changed
+286
-38
No files matched your search
+10
-13
@@ -5126,24 +5126,24 @@ struct PrecomputedLayer
|
||||
};
|
||||
} // namespace
|
||||
|
||||
// Whether process_layer() prepares the overhang estimator for `layer`.
|
||||
template<typename OverhangSpeed>
|
||||
static bool prepares_overhang_estimator(const Layer &layer, bool overhang_fan, OverhangSpeed overhang_speed)
|
||||
// Whether process_layer() prepares the overhang estimator for `layer`. Any filament may print the layer, and
|
||||
// process_layer() prepares it before the layer's tool changes, so a region's overhang speed counts if it is enabled for
|
||||
// any nozzle.
|
||||
static bool prepares_overhang_estimator(const Layer &layer, bool overhang_fan)
|
||||
{
|
||||
const LayerRegionPtrs ®ions = layer.regions();
|
||||
return std::any_of(regions.begin(), regions.end(), [overhang_fan, &overhang_speed](const LayerRegion *region) {
|
||||
return region->has_extrusions() && (overhang_fan || overhang_speed(*region));
|
||||
return std::any_of(regions.begin(), regions.end(), [overhang_fan](const LayerRegion *region) {
|
||||
return region->has_extrusions() &&
|
||||
(overhang_fan || any_enabled(region->region().config().enable_overhang_speed));
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<PrecomputedOverhangLayer> precompute_overhang_layers(const std::vector<GCode::LayerToPrint> &layers, bool overhang_fan)
|
||||
{
|
||||
// Any filament may print the layer, so a region's overhang speed counts if it is enabled for any.
|
||||
auto overhang_speed = [](const LayerRegion ®ion) { return any_enabled(region.region().config().enable_overhang_speed); };
|
||||
std::vector<PrecomputedOverhangLayer> out;
|
||||
for (const GCode::LayerToPrint &layer : layers)
|
||||
if (layer.object_layer != nullptr && layer.object_layer->lower_layer != nullptr &&
|
||||
prepares_overhang_estimator(*layer.object_layer, overhang_fan, overhang_speed)) {
|
||||
prepares_overhang_estimator(*layer.object_layer, overhang_fan)) {
|
||||
const LayerRegionPtrs ®ions = layer.object_layer->regions();
|
||||
const bool curled_lines = std::any_of(regions.begin(), regions.end(), [](const LayerRegion *region) {
|
||||
return any_enabled(region->region().config().slowdown_for_curled_perimeters);
|
||||
@@ -7027,12 +7027,9 @@ LayerResult GCode::process_layer(
|
||||
return next_extruder;
|
||||
};
|
||||
|
||||
const bool overhang_fan = overhang_fan_enabled(m_config, m_enable_cooling_markers);
|
||||
auto overhang_speed = [this](const LayerRegion ®ion) {
|
||||
return bool(region.region().config().enable_overhang_speed.get_at(get_nozzle_config_index(m_writer.filament()->id())));
|
||||
};
|
||||
const bool overhang_fan = overhang_fan_enabled(m_config, m_enable_cooling_markers);
|
||||
for (const auto &layer_to_print : layers)
|
||||
if (layer_to_print.object_layer && prepares_overhang_estimator(*layer_to_print.object_layer, overhang_fan, overhang_speed))
|
||||
if (layer_to_print.object_layer && prepares_overhang_estimator(*layer_to_print.object_layer, overhang_fan))
|
||||
m_extrusion_quality_estimator.prepare_for_new_layer(layer_to_print.original_object, layer_to_print.object_layer);
|
||||
|
||||
// Group extrusions by an extruder, then by an object, an island and a region.
|
||||
|
||||
@@ -493,9 +493,8 @@ class ExtrusionQualityEstimator
|
||||
using CurledLines = AABBTreeLines::LinesDistancer<CurledLine>;
|
||||
std::unordered_map<const PrintObject*, std::shared_ptr<const Boundaries>> prev_layer_boundaries;
|
||||
std::unordered_map<const PrintObject*, std::shared_ptr<const CurledLines>> prev_curled_extrusions;
|
||||
// The layers the trees above are built from, and the layers prepared last.
|
||||
// The layers the trees above are built from.
|
||||
std::unordered_map<const PrintObject*, const Layer*> prev_layer_sources;
|
||||
std::unordered_map<const PrintObject*, const Layer*> last_prepared_layers;
|
||||
std::vector<PrecomputedOverhangLayer> precomputed_layers;
|
||||
const PrintObject *current_object;
|
||||
|
||||
@@ -518,18 +517,19 @@ public:
|
||||
// Takes the data computed ahead for the layer about to be generated, replacing the previous layer's.
|
||||
void set_precomputed_layers(std::vector<PrecomputedOverhangLayer> &&layers) { precomputed_layers = std::move(layers); }
|
||||
|
||||
// Measures the layer against the layer prepared before it.
|
||||
// Measures the layer against the layer below it. Not against the layer prepared before it: process_layer() skips
|
||||
// layers that need no overhang detection, e.g. where a height range modifier turns overhang speed off.
|
||||
void prepare_for_new_layer(const PrintObject * obj, const Layer *layer)
|
||||
{
|
||||
if (layer == nullptr) return;
|
||||
const PrintObject *object = obj;
|
||||
const Layer *prev = std::exchange(last_prepared_layers[object], layer);
|
||||
const Layer *prev = layer->lower_layer;
|
||||
prev_layer_sources[object] = prev;
|
||||
const PrecomputedOverhangLayer *precomputed = precomputed_for(object);
|
||||
if (prev == nullptr) {
|
||||
prev_layer_boundaries[object] = nullptr;
|
||||
prev_curled_extrusions[object] = nullptr;
|
||||
} else if (precomputed != nullptr && precomputed->layer == layer && layer->lower_layer == prev) {
|
||||
} else if (precomputed != nullptr && precomputed->layer == layer) {
|
||||
prev_layer_boundaries[object] = precomputed->lower_boundaries;
|
||||
prev_curled_extrusions[object] = precomputed->lower_curled_lines;
|
||||
} else {
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
#include "test_helpers.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include "libslic3r/Line.hpp"
|
||||
#include "libslic3r/Point.hpp"
|
||||
#include <cstddef>
|
||||
@@ -30,8 +32,11 @@
|
||||
#include "libslic3r/Layer.hpp"
|
||||
#include "libslic3r/ExtrusionEntityCollection.hpp"
|
||||
#include "libslic3r/ExtrusionEntity.hpp"
|
||||
#include "libslic3r/ExPolygon.hpp"
|
||||
#include "libslic3r/Polygon.hpp"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
|
||||
@@ -343,8 +348,10 @@ double cooled_length(const std::vector<ExtendedPoint<2>>& points, float fan_over
|
||||
return length;
|
||||
}
|
||||
|
||||
DynamicPrintConfig caged_overhang_config(const char* wall_generator){
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
// The overhang settings of these tests, on top of `config`, which gives the printer and its filaments. They set one
|
||||
// 0.4mm nozzle: a test on more nozzles sets nozzle_diameter again.
|
||||
DynamicPrintConfig caged_overhang_config(const char* wall_generator,
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config()){
|
||||
config.set_deserialize_strict({
|
||||
{"nozzle_diameter", "0.4"},
|
||||
{"initial_layer_print_height", caged_layer_height},
|
||||
@@ -612,7 +619,7 @@ bool has_curled_lines(const PrintObject &object)
|
||||
return std::any_of(layers.begin(), layers.end(), [](const Layer *layer) { return !layer->curled_lines.empty(); });
|
||||
}
|
||||
|
||||
// Estimates every wall of `layer` against whatever layer `estimator` was last prepared with before it.
|
||||
// Estimates every wall of `layer` against the layer below the one `estimator` was last prepared for.
|
||||
Walls estimate_walls(ExtrusionQualityEstimator &estimator, const PrintObject *object, const Layer &layer)
|
||||
{
|
||||
const ConfigOptionPercents overlaps({90, 75, 50, 25, 13, 0});
|
||||
@@ -693,26 +700,38 @@ TEST_CASE("Overhang data computed ahead of the generator gives the same wall spe
|
||||
check_identical(estimate_walls(precomputed, cage.object, *cage.layer), expected);
|
||||
}
|
||||
|
||||
TEST_CASE("Overhang distances measured against another layer than the previous one are not used", "[ExtrusionProcessor]")
|
||||
// process_layer() prepares the estimator only for the layers that need overhang detection, so the layer it was prepared
|
||||
// for before may be a lower one than the layer below, the same layer again, or none at all. Whether the distances are
|
||||
// queried or computed ahead, the walls must come out as if the estimator had been prepared for every layer.
|
||||
TEST_CASE("Walls are measured against the layer below them whichever layer was prepared before", "[ExtrusionProcessor][Regression]")
|
||||
{
|
||||
// Nothing, the layer two below, or the same layer.
|
||||
const int prepared_before = GENERATE(0, 1, 2);
|
||||
const bool precomputed = GENERATE(false, true);
|
||||
CAPTURE(prepared_before, precomputed);
|
||||
const SlicedCage cage;
|
||||
const Layer *two_below = cage.layer->lower_layer->lower_layer;
|
||||
const Layer *one_below = cage.layer->lower_layer;
|
||||
REQUIRE(one_below != nullptr);
|
||||
const Layer *two_below = one_below->lower_layer;
|
||||
REQUIRE(two_below != nullptr);
|
||||
|
||||
ExtrusionQualityEstimator queried;
|
||||
queried.prepare_for_new_layer(cage.object, two_below);
|
||||
queried.prepare_for_new_layer(cage.object, cage.layer);
|
||||
const Walls expected = estimate_walls(queried, cage.object, *cage.layer);
|
||||
ExtrusionQualityEstimator one_below;
|
||||
one_below.prepare_for_new_layer(cage.object, cage.layer->lower_layer);
|
||||
one_below.prepare_for_new_layer(cage.object, cage.layer);
|
||||
REQUIRE(any_difference(estimate_walls(one_below, cage.object, *cage.layer), expected));
|
||||
ExtrusionQualityEstimator continuous;
|
||||
continuous.prepare_for_new_layer(cage.object, one_below);
|
||||
continuous.prepare_for_new_layer(cage.object, cage.layer);
|
||||
const Walls expected = estimate_walls(continuous, cage.object, *cage.layer);
|
||||
// Measured against the layer two below, the walls differ, so matching `expected` below is no coincidence.
|
||||
ExtrusionQualityEstimator stale;
|
||||
stale.prepare_for_new_layer(cage.object, one_below);
|
||||
REQUIRE(any_difference(estimate_walls(stale, cage.object, *cage.layer), expected));
|
||||
|
||||
ExtrusionQualityEstimator precomputed;
|
||||
precomputed.prepare_for_new_layer(cage.object, two_below);
|
||||
precomputed.set_precomputed_layers({precompute_overhang_layer(cage.object, *cage.layer)});
|
||||
precomputed.prepare_for_new_layer(cage.object, cage.layer);
|
||||
check_identical(estimate_walls(precomputed, cage.object, *cage.layer), expected);
|
||||
const Layer *const prepared_layers[] = {nullptr, two_below, cage.layer};
|
||||
ExtrusionQualityEstimator estimator;
|
||||
if (prepared_layers[prepared_before] != nullptr)
|
||||
estimator.prepare_for_new_layer(cage.object, prepared_layers[prepared_before]);
|
||||
if (precomputed)
|
||||
estimator.set_precomputed_layers({precompute_overhang_layer(cage.object, *cage.layer)});
|
||||
estimator.prepare_for_new_layer(cage.object, cage.layer);
|
||||
check_identical(estimate_walls(estimator, cage.object, *cage.layer), expected);
|
||||
}
|
||||
|
||||
TEST_CASE("Overhang data computed for another layer is not used", "[ExtrusionProcessor]")
|
||||
@@ -726,9 +745,9 @@ TEST_CASE("Overhang data computed for another layer is not used", "[ExtrusionPro
|
||||
queried.prepare_for_new_layer(cage.object, one_below);
|
||||
queried.prepare_for_new_layer(cage.object, cage.layer);
|
||||
const Walls expected = estimate_walls(queried, cage.object, *cage.layer);
|
||||
// Measures the walls against the layer below one_below, the layer the data computed for one_below holds.
|
||||
ExtrusionQualityEstimator two_below;
|
||||
two_below.prepare_for_new_layer(cage.object, one_below->lower_layer);
|
||||
two_below.prepare_for_new_layer(cage.object, cage.layer);
|
||||
two_below.prepare_for_new_layer(cage.object, one_below);
|
||||
REQUIRE(any_difference(estimate_walls(two_below, cage.object, *cage.layer), expected));
|
||||
|
||||
ExtrusionQualityEstimator precomputed;
|
||||
@@ -738,6 +757,52 @@ TEST_CASE("Overhang data computed for another layer is not used", "[ExtrusionPro
|
||||
check_identical(estimate_walls(precomputed, cage.object, *cage.layer), expected);
|
||||
}
|
||||
|
||||
// The curled edges that slow a wall down come from the layer below it too, not from a layer prepared before.
|
||||
TEST_CASE("Walls are slowed for the curled edges of the layer below them whichever layer was prepared before", "[ExtrusionProcessor][Regression]")
|
||||
{
|
||||
// Nothing, a stale layer, or the stale layer and then the layer below.
|
||||
const int prepared_before = GENERATE(0, 1, 2);
|
||||
CAPTURE(prepared_before);
|
||||
Print print;
|
||||
Model model;
|
||||
init_print({cube(20.)}, print, model);
|
||||
PrintObject *object = print.get_object(0);
|
||||
Layer *stale = object->add_layer(0, 0.2, 0.2, 0.1);
|
||||
Layer *below = object->add_layer(1, 0.2, 0.4, 0.3);
|
||||
Layer *layer = object->add_layer(2, 0.2, 0.6, 0.5);
|
||||
below->lower_layer = stale;
|
||||
layer->lower_layer = below;
|
||||
// The 0.4mm wide wall runs 0.2mm inside the edge of the layer below, so it is fully supported, but along an edge
|
||||
// that curled up 1mm. The stale layer ends 0.8mm short of the wall and has no curled edges: measured against it,
|
||||
// the wall would be a full overhang.
|
||||
below->lslices = {ExPolygon(Polygon{Point::new_scale(0, 0), Point::new_scale(40, 0),
|
||||
Point::new_scale(40, 10), Point::new_scale(0, 10)})};
|
||||
below->curled_lines = {CurledLine(Point::new_scale(1, 0.2), Point::new_scale(39, 0.2), 1.f)};
|
||||
stale->lslices = {ExPolygon(Polygon{Point::new_scale(0, 1), Point::new_scale(40, 1),
|
||||
Point::new_scale(40, 10), Point::new_scale(0, 10)})};
|
||||
ExtrusionPath wall(erExternalPerimeter, 0.08, 0.4f, 0.2f);
|
||||
wall.polyline.points = {Point3::new_scale(1, 0.2, 0), Point3::new_scale(39, 0.2, 0)};
|
||||
|
||||
ExtrusionQualityEstimator estimator;
|
||||
estimator.set_current_object(object);
|
||||
if (prepared_before >= 1)
|
||||
estimator.prepare_for_new_layer(object, stale);
|
||||
if (prepared_before >= 2)
|
||||
estimator.prepare_for_new_layer(object, below);
|
||||
estimator.prepare_for_new_layer(object, layer);
|
||||
// 100mm/s when fully supported, 20mm/s when a whole width out.
|
||||
const std::vector<ProcessedPoint> points = estimator.estimate_extrusion_quality(wall,
|
||||
ConfigOptionPercents({100, 0}),
|
||||
ConfigOptionFloatsOrPercents({FloatOrPercent{100, false}, FloatOrPercent{20, false}}), 100.f, 100.f, true);
|
||||
|
||||
// A 1mm curl under a 0.2mm layer reads as half the width, 0.2mm, out: halfway between the two speeds.
|
||||
REQUIRE_FALSE(points.empty());
|
||||
for (const ProcessedPoint &point : points) {
|
||||
CHECK_THAT(point.speed, Catch::Matchers::WithinAbs(60., 0.5));
|
||||
CHECK_THAT(point.overlap, Catch::Matchers::WithinAbs(0.5, 1e-3));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Precomputed overhang data has the curled-line tree exactly when a region slows down for curled perimeters", "[ExtrusionProcessor]")
|
||||
{
|
||||
const bool slowdown = GENERATE(false, true);
|
||||
@@ -844,6 +909,192 @@ TEST_CASE("Caged external overhangs are slowed when printed by object or through
|
||||
REQUIRE(*std::max_element(feed_rates.begin(), feed_rates.end()) < caged_slow_speed * MM_PER_MIN);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// A 20 x 10 x 2mm wedge whose front face leans out by one layer height per layer (45 degrees), from y = 2 at the bed
|
||||
// to y = 0 at the top, while its back face at y = 12 stands vertical and fully supported.
|
||||
constexpr double wedge_height = 2.;
|
||||
constexpr double wedge_base_front_y = 2.;
|
||||
constexpr double wedge_back_y = 12.;
|
||||
|
||||
TriangleMesh wedge_mesh()
|
||||
{
|
||||
const float length = 20.f, top = float(wedge_height), front = float(wedge_base_front_y), back = float(wedge_back_y);
|
||||
return TriangleMesh(
|
||||
{
|
||||
{0.f, front, 0.f}, {length, front, 0.f}, {length, back, 0.f}, {0.f, back, 0.f},
|
||||
{0.f, 0.f, top}, {length, 0.f, top}, {length, back, top}, {0.f, back, top},
|
||||
},
|
||||
{
|
||||
{0, 2, 1}, {0, 3, 2}, {4, 5, 6}, {4, 6, 7},
|
||||
{0, 1, 5}, {0, 5, 4}, {1, 2, 6}, {1, 6, 5},
|
||||
{2, 3, 7}, {2, 7, 6}, {3, 0, 4}, {3, 4, 7},
|
||||
});
|
||||
}
|
||||
|
||||
// A height range modifier over these heights. Layers are sliced half a layer below their print_z, at 0.1, 0.3, 0.5 and
|
||||
// so on, so the bounds fall between slice planes: the layers printed at 0.6 and 0.8 take the range's settings.
|
||||
constexpr double wedge_range_min = 0.4;
|
||||
constexpr double wedge_range_max = 0.8;
|
||||
|
||||
bool in_wedge_range(double print_z)
|
||||
{
|
||||
const double slice_z = print_z - 0.5 * caged_layer_height;
|
||||
return slice_z > wedge_range_min && slice_z < wedge_range_max;
|
||||
}
|
||||
|
||||
// The wedge with overhang speed set to `object_speed`, and to `range_speed` by the height range modifier.
|
||||
std::string wedge_gcode(bool object_speed, bool range_speed)
|
||||
{
|
||||
DynamicPrintConfig config = caged_overhang_config("classic");
|
||||
config.set_deserialize_strict({
|
||||
{"enable_overhang_speed", object_speed ? "1" : "0"},
|
||||
// The overhang fan has every layer prepared for overhang detection, whether overhang speed is on or not.
|
||||
{"enable_overhang_bridge_fan", "0"},
|
||||
});
|
||||
Print print;
|
||||
Model model;
|
||||
init_print(std::vector<TriangleMesh>{wedge_mesh()}, print, model, config, nullptr, false);
|
||||
DynamicPrintConfig range_config;
|
||||
// Every layer range must carry a layer_height (see layer_height_profile_from_ranges).
|
||||
range_config.set_key_value("layer_height", new ConfigOptionFloat(caged_layer_height));
|
||||
range_config.set_deserialize_strict("enable_overhang_speed", range_speed ? "1" : "0");
|
||||
model.objects.front()->layer_config_ranges[{wedge_range_min, wedge_range_max}].assign_config(
|
||||
std::move(range_config));
|
||||
print.apply(model, config);
|
||||
return gcode(print);
|
||||
}
|
||||
|
||||
// Feed rates of the outer wall moves printed at print_z along the wedge's sloped front face, or along its back face.
|
||||
// The side walls run from one face to the other, so neither filter takes them.
|
||||
std::vector<double> wedge_wall_feed_rates(const std::string &gcode, double print_z, bool front)
|
||||
{
|
||||
return outer_wall_feed_rates(gcode, [print_z, front](const GCodeReader &self, const GCodeReader::GCodeLine &line) {
|
||||
const auto on_face = [front](double y) { return front ? y < wedge_base_front_y + 1. : y > wedge_back_y - 1.; };
|
||||
return std::abs(line.new_Z(self) - print_z) < 0.5 * caged_layer_height && on_face(self.y()) &&
|
||||
on_face(line.new_Y(self));
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Regression: the estimator measured each layer against the layer it was prepared for before. process_layer() skips the
|
||||
// layers with overhang speed off, so the first layer above a range turning it off was measured against the layer below
|
||||
// the range, and the first layer of a range turning it on against no layer at all, which slowed even supported walls.
|
||||
TEST_CASE("Walls printed with overhang speed on match a print with it always on when a height range toggles it", "[ExtrusionProcessor][Regression]")
|
||||
{
|
||||
const bool object_speed = GENERATE(true, false);
|
||||
INFO("overhang speed " << (object_speed ? "on" : "off") << " for the object, " << (object_speed ? "off" : "on")
|
||||
<< " for the range");
|
||||
const std::string toggled = wedge_gcode(object_speed, !object_speed);
|
||||
const std::string always_on = wedge_gcode(true, true);
|
||||
|
||||
// The first layers printed with the other setting, at either end of the range.
|
||||
for (const double print_z : {wedge_range_min + caged_layer_height, wedge_range_max + caged_layer_height}) {
|
||||
INFO("back wall at z = " << print_z);
|
||||
const std::vector<double> feed_rates = wedge_wall_feed_rates(toggled, print_z, false);
|
||||
REQUIRE_FALSE(feed_rates.empty());
|
||||
for (const double feed_rate : feed_rates)
|
||||
CHECK_THAT(feed_rate / MM_PER_MIN, Catch::Matchers::WithinRel(caged_outer_wall_speed, 0.01));
|
||||
}
|
||||
|
||||
// Every layer printed with overhang speed on, above the first, which is never slowed for overhangs.
|
||||
const int layer_count = int(std::lround(wedge_height / caged_layer_height));
|
||||
for (int layer = 2; layer <= layer_count; ++layer) {
|
||||
const double print_z = layer * caged_layer_height;
|
||||
if (in_wedge_range(print_z) == object_speed)
|
||||
continue;
|
||||
INFO("slope at z = " << print_z);
|
||||
const std::vector<double> expected = wedge_wall_feed_rates(always_on, print_z, true);
|
||||
REQUIRE_FALSE(expected.empty());
|
||||
// The slope is slowed down, so matching speeds are not merely the wall speed.
|
||||
REQUIRE(*std::max_element(expected.begin(), expected.end()) < caged_slow_speed * MM_PER_MIN);
|
||||
const std::vector<double> actual = wedge_wall_feed_rates(toggled, print_z, true);
|
||||
REQUIRE(actual.size() == expected.size());
|
||||
for (size_t i = 0; i < actual.size(); ++i)
|
||||
CHECK_THAT(actual[i], Catch::Matchers::WithinAbs(expected[i], 1.));
|
||||
}
|
||||
}
|
||||
|
||||
// Regression: process_layer() prepared the estimator only when overhang speed was on for the nozzle active before the
|
||||
// layer's tool changes. Here the second nozzle prints the walls and slows down for overhangs, the first prints the
|
||||
// infill and has overhang speed off. A layer starts with the nozzle that ended the layer below, so every other layer
|
||||
// starts with the first one and was not prepared: its walls were measured against an older layer, or against none.
|
||||
TEST_CASE("Walls printed by a nozzle with overhang speed on match a print with it on for every nozzle",
|
||||
"[ExtrusionProcessor][Regression]")
|
||||
{
|
||||
const auto two_nozzle_gcode = [](const char *overhang_speed) {
|
||||
DynamicPrintConfig config = caged_overhang_config("classic", multifilament_config(2));
|
||||
config.set_deserialize_strict({
|
||||
{"nozzle_diameter", "0.4,0.4"},
|
||||
{"printer_extruder_id", "1,2"},
|
||||
{"printer_extruder_variant", "Direct Drive Standard;Direct Drive Standard"},
|
||||
{"extruder_printable_height", "0,0"},
|
||||
{"filament_self_index", "1,2"},
|
||||
{"single_extruder_multi_material", 0},
|
||||
// Each filament on its own nozzle: left to the automatic grouping, both may share one.
|
||||
{"filament_map_mode", "Manual"},
|
||||
{"filament_map", "1,2"},
|
||||
{"enable_prime_tower", 0},
|
||||
// A process column per nozzle, or every nozzle reads the first overhang speed switch.
|
||||
{"print_extruder_id", "1,2"},
|
||||
{"print_extruder_variant", "Direct Drive Standard;Direct Drive Standard"},
|
||||
{"enable_overhang_speed", overhang_speed},
|
||||
// The overhang fan has every layer prepared for overhang detection, whether overhang speed is on or not.
|
||||
{"enable_overhang_bridge_fan", "0"},
|
||||
{"outer_wall_filament_id", 2},
|
||||
{"inner_wall_filament_id", 2},
|
||||
{"sparse_infill_filament_id", 1},
|
||||
{"internal_solid_filament_id", 1},
|
||||
{"top_surface_filament_id", 1},
|
||||
{"bottom_surface_filament_id", 1},
|
||||
{"skirt_loops", 0},
|
||||
{"brim_type", "no_brim"},
|
||||
});
|
||||
size_flush_to_nozzles(config);
|
||||
Print print;
|
||||
Model model;
|
||||
init_print(std::vector<TriangleMesh>{wedge_mesh()}, print, model, config, nullptr, false);
|
||||
return gcode(print);
|
||||
};
|
||||
const std::string mixed = two_nozzle_gcode("0,1");
|
||||
const std::string always_on = two_nozzle_gcode("1,1");
|
||||
|
||||
// The regression shows only on the layers process_layer() starts with the first filament (T0), on the first
|
||||
// nozzle. Make sure the checked layers include some: the tool order, not this test, decides which layers those are.
|
||||
int layers_starting_with_first_nozzle = 0;
|
||||
std::istringstream lines(mixed);
|
||||
int tool = -1;
|
||||
for (std::string line; std::getline(lines, line);) {
|
||||
if (line.size() > 1 && line[0] == 'T' && std::isdigit(static_cast<unsigned char>(line[1])))
|
||||
tool = std::stoi(line.substr(1));
|
||||
else if (tool == 0 && line.compare(0, 3, ";Z:") == 0 && std::stod(line.substr(3)) > 1.5 * caged_layer_height)
|
||||
++layers_starting_with_first_nozzle;
|
||||
}
|
||||
REQUIRE(layers_starting_with_first_nozzle > 0);
|
||||
|
||||
// Every layer above the first, which is never slowed for overhangs.
|
||||
const int layer_count = int(std::lround(wedge_height / caged_layer_height));
|
||||
for (int layer = 2; layer <= layer_count; ++layer) {
|
||||
const double print_z = layer * caged_layer_height;
|
||||
INFO("z = " << print_z);
|
||||
// The supported back wall keeps the wall speed, so the print with overhang speed on for every nozzle measures
|
||||
// each layer against a layer below, not against none, which would slow both prints alike.
|
||||
const std::vector<double> back_wall = wedge_wall_feed_rates(always_on, print_z, false);
|
||||
REQUIRE_FALSE(back_wall.empty());
|
||||
for (const double feed_rate : back_wall)
|
||||
CHECK_THAT(feed_rate / MM_PER_MIN, Catch::Matchers::WithinRel(caged_outer_wall_speed, 0.01));
|
||||
const std::vector<double> expected = wedge_wall_feed_rates(always_on, print_z, true);
|
||||
REQUIRE_FALSE(expected.empty());
|
||||
// The slope is slowed down, so matching speeds are not merely the wall speed.
|
||||
REQUIRE(*std::max_element(expected.begin(), expected.end()) < caged_slow_speed * MM_PER_MIN);
|
||||
const std::vector<double> actual = wedge_wall_feed_rates(mixed, print_z, true);
|
||||
REQUIRE(actual.size() == expected.size());
|
||||
for (size_t i = 0; i < actual.size(); ++i)
|
||||
CHECK_THAT(actual[i], Catch::Matchers::WithinAbs(expected[i], 1.));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Benchmark caged overhang interior sampling", "[ExtrusionProcessor][!benchmark]"){
|
||||
const char* wall_generator = GENERATE("classic", "arachne");
|
||||
|
||||
|
||||
Reference in new issue
Block a user