From 96f4a7b90e2fc5a1f16ffa69062114c9de55cddd Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 23 Jul 2020 02:12:28 -0500 Subject: [PATCH 1/2] Use the constant for clipper offset scale (needed because we are passing the jtSquare), fix an off-by-one error where the outermost loop was never generated. Add a test to check the extents of the generated brim. tests: Allow a different center to be specified when initializing test prints instead of 100,100. --- src/test/libslic3r/test_skirt_brim.cpp | 42 +++++++++++++++++++++++--- src/test/test_data.cpp | 8 ++--- src/test/test_data.hpp | 4 +-- xs/src/libslic3r/Print.cpp | 4 +-- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/test/libslic3r/test_skirt_brim.cpp b/src/test/libslic3r/test_skirt_brim.cpp index c49b240dc5..c995a64940 100644 --- a/src/test/libslic3r/test_skirt_brim.cpp +++ b/src/test/libslic3r/test_skirt_brim.cpp @@ -71,12 +71,12 @@ SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") { Slic3r::Model model; auto gcode {std::stringstream("")}; gcode.clear(); + const double used_layer_height = 0.01; GIVEN("A default configuration") { auto config {Config::new_from_defaults()}; config->set("support_material_speed", 99); - config->set("first_layer_height", 0.3); + config->set("first_layer_height", used_layer_height); config->set("gcode_comments", true); - // avoid altering speeds unexpectedly config->set("cooling", false); config->set("first_layer_speed", "100%"); @@ -88,14 +88,23 @@ SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") { config->set("perimeters", 0); config->set("skirts", 0); config->set("brim_width", 5); + config->set("interior_brim_width", 0); + config->set("brim_connections_width", 0); + config->set("first_layer_extrusion_width", 0.10); + config->set("extrusion_width", 0.10); + config->set("nozzle_diameter", "0.05"); + THEN("Configuration is sane.") { + REQUIRE(config->get("first_layer_extrusion_width").get_abs_value(used_layer_height) > 0.05); + REQUIRE(used_layer_height < 0.05); + } THEN("Brim is generated") { auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)}; Slic3r::Test::gcode(gcode, print); bool brim_generated = false; auto support_speed = config->get("support_material_speed") * MM_PER_MIN; - parser.parse_stream(gcode, [&brim_generated, support_speed] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line) + parser.parse_stream(gcode, [&brim_generated, support_speed, used_layer_height] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line) { - if (self.Z == Approx(0.3) || line.new_Z() == Approx(0.3)) { + if (self.Z == Approx(used_layer_height) || line.new_Z() == Approx(used_layer_height)) { if (line.extruding() && self.F == Approx(support_speed)) { brim_generated = true; } @@ -103,6 +112,31 @@ SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") { }); REQUIRE(brim_generated); } + THEN("Brim width is 5mm around the object.") { + auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config, false, Slic3r::Pointf(0, 0))}; + Slic3r::Test::gcode(gcode, print); + double max_x = 0, min_x = 0, max_y = 0, min_y = 0; + auto support_speed = config->get("support_material_speed") * MM_PER_MIN; + auto line_width = config->get("first_layer_extrusion_width").get_abs_value(used_layer_height); + auto brim = config->get("brim_width"); + parser.parse_stream(gcode, [&max_x, &max_y, &min_x, &min_y, line_width, support_speed, used_layer_height] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line) + { + if (self.Z == Approx(used_layer_height) || line.new_Z() == Approx(used_layer_height)) { + if (line.extruding() && self.F == Approx(support_speed)) { + max_x = std::max(double(self.X), max_x); + min_x = std::min(double(self.X), min_x); + max_y = std::max(double(self.Y), max_y); + min_y = std::min(double(self.Y), min_y); + } + } + }); + // match the centerline of our extrusion min/max, should be very close to +/-15mm + REQUIRE(max_x == Approx(15.0-(line_width / 2.0)).epsilon(line_width * 0.01)); + REQUIRE(max_y == Approx(15.0-(line_width / 2.0)).epsilon(line_width * 0.01)); + REQUIRE(min_x == Approx(-15.0+(line_width / 2.0)).epsilon(line_width * 0.01)); + REQUIRE(min_y == Approx(-15.0+(line_width / 2.0)).epsilon(line_width * 0.01)); + } + } WHEN("Skirt area is smaller than the brim") { diff --git a/src/test/test_data.cpp b/src/test/test_data.cpp index 96b8922733..16057f443d 100644 --- a/src/test/test_data.cpp +++ b/src/test/test_data.cpp @@ -201,7 +201,7 @@ TriangleMesh mesh(TestMesh m) { } -shared_Print init_print(std::initializer_list meshes, Slic3r::Model& model, config_ptr _config, bool comments) { +shared_Print init_print(std::initializer_list meshes, Slic3r::Model& model, config_ptr _config, bool comments, Slic3r::Pointf center) { auto config {Slic3r::Config::new_from_defaults()}; config->apply(_config); @@ -224,7 +224,7 @@ shared_Print init_print(std::initializer_list meshes, Slic3r::Model& m } model.arrange_objects(print->config.min_object_distance()); - model.center_instances_around_point(Slic3r::Pointf(100,100)); + model.center_instances_around_point(center); for (auto* mo : model.objects) { print->auto_assign_extruders(mo); print->add_model_object(mo); @@ -234,7 +234,7 @@ shared_Print init_print(std::initializer_list meshes, Slic3r::Model& m return print; } -shared_Print init_print(std::initializer_list meshes, Slic3r::Model& model, config_ptr _config, bool comments) { +shared_Print init_print(std::initializer_list meshes, Slic3r::Model& model, config_ptr _config, bool comments, Slic3r::Pointf center) { auto config {Slic3r::Config::new_from_defaults()}; config->apply(_config); @@ -257,7 +257,7 @@ shared_Print init_print(std::initializer_list meshes, Slic3r::Mode } model.arrange_objects(print->config.min_object_distance()); - model.center_instances_around_point(Slic3r::Pointf(100,100)); + model.center_instances_around_point(center); for (auto* mo : model.objects) { print->auto_assign_extruders(mo); print->add_model_object(mo); diff --git a/src/test/test_data.hpp b/src/test/test_data.hpp index 0ac92c2e24..ed81c15c89 100644 --- a/src/test/test_data.hpp +++ b/src/test/test_data.hpp @@ -65,8 +65,8 @@ bool _equiv(const T& a, const T& b, double epsilon) { return abs(a - b) < epsilo Slic3r::Model model(const std::string& model_name, TriangleMesh&& _mesh); -shared_Print init_print(std::initializer_list meshes, Slic3r::Model& model, config_ptr _config = Slic3r::Config::new_from_defaults(), bool comments = false); -shared_Print init_print(std::initializer_list meshes, Slic3r::Model& model, config_ptr _config = Slic3r::Config::new_from_defaults(), bool comments = false); +shared_Print init_print(std::initializer_list meshes, Slic3r::Model& model, config_ptr _config = Slic3r::Config::new_from_defaults(), bool comments = false, Slic3r::Pointf center = Slic3r::Pointf(100,100)); +shared_Print init_print(std::initializer_list meshes, Slic3r::Model& model, config_ptr _config = Slic3r::Config::new_from_defaults(), bool comments = false, Slic3r::Pointf center = Slic3r::Pointf(100,100)); void gcode(std::stringstream& gcode, shared_Print print); diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 72413ebb80..dce0b0b4fa 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -1118,7 +1118,7 @@ Print::_make_brim() Polygons loops; const int num_loops = floor(this->config.brim_width / flow.width + 0.5); - for (int i = num_loops; i >= 1; --i) { + for (int i = num_loops+1; i >= 1; --i) { // JT_SQUARE ensures no vertex is outside the given offset distance // -0.5 because islands are not represented by their centerlines // (first offset more, then step back - reverse order than the one used for @@ -1127,7 +1127,7 @@ Print::_make_brim() islands, flow.scaled_width() + flow.scaled_spacing() * (i - 1.5 + 0.5), flow.scaled_spacing() * -0.525, // WORKAROUND for brim placement, original 0.5 leaves too much of a gap. - 100000, + CLIPPER_OFFSET_SCALE, ClipperLib::jtSquare )); } From 00e7b009537e865604428bc18159ccb64f11751f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 23 Jul 2020 15:11:21 -0500 Subject: [PATCH 2/2] Bump up the brim counts by one (the width gets revised so there should be more loops) --- src/test/libslic3r/test_print.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/libslic3r/test_print.cpp b/src/test/libslic3r/test_print.cpp index abfed1a7de..f60b2f4632 100644 --- a/src/test/libslic3r/test_print.cpp +++ b/src/test/libslic3r/test_print.cpp @@ -121,16 +121,16 @@ SCENARIO("Print: Brim generation") { config->set("brim_width", 3); auto print {Slic3r::Test::init_print({m}, model, config)}; print->make_brim(); - THEN("Brim Extrusion collection has 3 loops in it") { - REQUIRE(print->brim.items_count() == 3); + THEN("Brim Extrusion collection has 4 loops in it") { + REQUIRE(print->brim.items_count() == 4); } } WHEN("Brim is set to 6mm") { config->set("brim_width", 6); auto print {Slic3r::Test::init_print({m}, model, config)}; print->make_brim(); - THEN("Brim Extrusion collection has 6 loops in it") { - REQUIRE(print->brim.items_count() == 6); + THEN("Brim Extrusion collection has 7 loops in it") { + REQUIRE(print->brim.items_count() == 7); } } WHEN("Brim is set to 6mm, extrusion width 0.5mm") { @@ -138,8 +138,8 @@ SCENARIO("Print: Brim generation") { config->set("first_layer_extrusion_width", 0.5); auto print {Slic3r::Test::init_print({m}, model, config)}; print->make_brim(); - THEN("Brim Extrusion collection has 12 loops in it") { - REQUIRE(print->brim.items_count() == 12); + THEN("Brim Extrusion collection has 13 loops in it") { + REQUIRE(print->brim.items_count() == 13); } } }