From a9116ea4fdeef96d456a70c9365ded60289b8297 Mon Sep 17 00:00:00 2001 From: surynek Date: Mon, 27 Jan 2025 17:36:00 +0100 Subject: [PATCH] Changed the PrinterGeometry structure to accommodate polygonal bed shape. --- .../include/libseqarrange/seq_interface.hpp | 10 +++-- src/libseqarrange/src/seq_interface.cpp | 29 +++++++++++--- src/libseqarrange/src/seq_utilities.cpp | 17 ++++---- src/libseqarrange/test/seq_test_interface.cpp | 39 +++++++++++-------- src/slic3r/GUI/ArrangeHelper.cpp | 7 ++++ 5 files changed, 68 insertions(+), 34 deletions(-) diff --git a/src/libseqarrange/include/libseqarrange/seq_interface.hpp b/src/libseqarrange/include/libseqarrange/seq_interface.hpp index 7eb14e3fd7..c6c5df4c9a 100644 --- a/src/libseqarrange/include/libseqarrange/seq_interface.hpp +++ b/src/libseqarrange/include/libseqarrange/seq_interface.hpp @@ -34,8 +34,7 @@ namespace Sequential struct PrinterGeometry { - coord_t x_size; - coord_t y_size; + Slic3r::Polygon plate; // at least height 0 (corresponding to nozzle) must be present in convex_height std::set convex_heights; @@ -44,8 +43,7 @@ struct PrinterGeometry // , at least one polygon must be present for height 0 std::map > extruder_slices; - int convert_Geometry2PlateBoundingBoxSize(void) const; - void convert_Geometry2PlateBoundingBoxSize(int &X_bounding_box_size, int &Y_bounding_box_size) const; + bool convert_Geometry2PlateBounds(int &x_bounding_box_size, int &y_bounding_box_size, Slic3r::Polygon &plate_bounding_polygon) const; }; @@ -75,8 +73,12 @@ struct SolverConfiguration int bounding_box_size_optimization_step; int minimum_bounding_box_size; + int x_plate_bounding_box_size; int y_plate_bounding_box_size; + + Slic3r::Polygon plate_bounding_polygon; + int max_refines; int object_group_size; diff --git a/src/libseqarrange/src/seq_interface.cpp b/src/libseqarrange/src/seq_interface.cpp index e8872c80b2..5647a39a35 100644 --- a/src/libseqarrange/src/seq_interface.cpp +++ b/src/libseqarrange/src/seq_interface.cpp @@ -75,16 +75,33 @@ const coord_t SEQ_PRUSA_XL_GANTRY_LEVEL = 26000000; /*----------------------------------------------------------------*/ -int PrinterGeometry::convert_Geometry2PlateBoundingBoxSize(void) const +bool PrinterGeometry::convert_Geometry2PlateBounds(int &x_plate_bounding_box_size, int &y_plate_bounding_box_size, Slic3r::Polygon &plate_bounding_polygon) const { - return MAX(x_size / SEQ_SLICER_SCALE_FACTOR, y_size / SEQ_SLICER_SCALE_FACTOR); -} + coord_t x_size, y_size; + BoundingBox plate_box = get_extents(plate); + + x_size = plate_box.max.x() - plate_box.min.x(); + y_size = plate_box.max.y() - plate_box.min.y(); -void PrinterGeometry::convert_Geometry2PlateBoundingBoxSize(int &x_plate_bounding_box_size, int &y_plate_bounding_box_size) const -{ x_plate_bounding_box_size = x_size / SEQ_SLICER_SCALE_FACTOR; y_plate_bounding_box_size = y_size / SEQ_SLICER_SCALE_FACTOR; + + coord_t plate_box_area = x_size * y_size; + + if (plate.area() != plate_box_area) + { + for (unsigned int i = 0; i < plate.points.size(); ++i) + { + plate_bounding_polygon.points.insert(plate_bounding_polygon.points.begin() + i, Point(plate.points[i].x() / SEQ_SLICER_SCALE_FACTOR, + plate.points[i].y() / SEQ_SLICER_SCALE_FACTOR)); + } + // non-rectangular plate is currently not supported + assert(false); + + return false; + } + return true; } @@ -150,7 +167,7 @@ double SolverConfiguration::convert_DecimationPrecision2Tolerance(DecimationPrec void SolverConfiguration::setup(const PrinterGeometry &printer_geometry) { - printer_geometry.convert_Geometry2PlateBoundingBoxSize(x_plate_bounding_box_size, y_plate_bounding_box_size); + printer_geometry.convert_Geometry2PlateBounds(x_plate_bounding_box_size, y_plate_bounding_box_size, plate_bounding_polygon); } diff --git a/src/libseqarrange/src/seq_utilities.cpp b/src/libseqarrange/src/seq_utilities.cpp index 2532714370..ec43304ba5 100644 --- a/src/libseqarrange/src/seq_utilities.cpp +++ b/src/libseqarrange/src/seq_utilities.cpp @@ -132,7 +132,10 @@ int load_printer_geometry_from_text(const std::string &geometry_text, PrinterGeo int load_printer_geometry_from_stream(std::istream &geometry_stream, PrinterGeometry &printer_geometry) { Polygon *current_polygon = NULL; - std::string line; + std::string line; + + coord_t x_size = -1; + coord_t y_size = -1; while (geometry_stream) { @@ -193,20 +196,20 @@ int load_printer_geometry_from_stream(std::istream &geometry_stream, PrinterGeom std::stringstream ss(line); std::string val; ss >> val; - coord_t x_size = std::stoi(val); - - printer_geometry.x_size = x_size; + x_size = std::stoi(val); } else if (find_and_remove(line, "Y_SIZE")) { std::stringstream ss(line); std::string val; ss >> val; - coord_t y_size = std::stoi(val); - - printer_geometry.y_size = y_size; + y_size = std::stoi(val); } } + assert(x_size > 0 && y_size > 0); + + printer_geometry.plate = { {0, 0}, {x_size, 0}, {x_size, y_size}, {0, y_size} }; + return 0; } diff --git a/src/libseqarrange/test/seq_test_interface.cpp b/src/libseqarrange/test/seq_test_interface.cpp index d34f9316c9..7f9c381f61 100644 --- a/src/libseqarrange/test/seq_test_interface.cpp +++ b/src/libseqarrange/test/seq_test_interface.cpp @@ -634,12 +634,8 @@ TEST_CASE("Interface test 3", "[Sequential Arrangement Interface]") printf("Printer geometry load error.\n"); return; } - - printf("x_size: %d\n", printer_geometry.x_size); - printf("y_size: %d\n", printer_geometry.y_size); - REQUIRE(printer_geometry.x_size > 0); - REQUIRE(printer_geometry.y_size > 0); + REQUIRE(printer_geometry.plate.points.size() == 4); for (const auto& convex_height: printer_geometry.convex_heights) { @@ -723,10 +719,13 @@ TEST_CASE("Interface test 4", "[Sequential Arrangement Interface]") for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects) { cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; - REQUIRE(scheduled_object.x >= 0); - REQUIRE(scheduled_object.x <= printer_geometry.x_size); - REQUIRE(scheduled_object.y >= 0); - REQUIRE(scheduled_object.y <= printer_geometry.y_size); + + BoundingBox plate_box = get_extents(printer_geometry.plate); + + REQUIRE(scheduled_object.x >= plate_box.min.x()); + REQUIRE(scheduled_object.x <= plate_box.max.x()); + REQUIRE(scheduled_object.y >= plate_box.min.y()); + REQUIRE(scheduled_object.y <= plate_box.max.y()); } } @@ -790,10 +789,13 @@ TEST_CASE("Interface test 5", "[Sequential Arrangement Interface]") for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects) { cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; - REQUIRE(scheduled_object.x >= 0); - REQUIRE(scheduled_object.x <= printer_geometry.x_size); - REQUIRE(scheduled_object.y >= 0); - REQUIRE(scheduled_object.y <= printer_geometry.y_size); + + BoundingBox plate_box = get_extents(printer_geometry.plate); + + REQUIRE(scheduled_object.x >= plate_box.min.x()); + REQUIRE(scheduled_object.x <= plate_box.max.x()); + REQUIRE(scheduled_object.y >= plate_box.min.y()); + REQUIRE(scheduled_object.y <= plate_box.max.y()); } } @@ -878,10 +880,13 @@ TEST_CASE("Interface test 6", "[Sequential Arrangement Interface]") for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects) { cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; - REQUIRE(scheduled_object.x >= 0); - REQUIRE(scheduled_object.x <= printer_geometry.x_size); - REQUIRE(scheduled_object.y >= 0); - REQUIRE(scheduled_object.y <= printer_geometry.y_size); + + BoundingBox plate_box = get_extents(printer_geometry.plate); + + REQUIRE(scheduled_object.x >= plate_box.min.x()); + REQUIRE(scheduled_object.x <= plate_box.max.x()); + REQUIRE(scheduled_object.y >= plate_box.min.y()); + REQUIRE(scheduled_object.y <= plate_box.max.y()); } } diff --git a/src/slic3r/GUI/ArrangeHelper.cpp b/src/slic3r/GUI/ArrangeHelper.cpp index 69f59e88ea..ec83db3489 100644 --- a/src/slic3r/GUI/ArrangeHelper.cpp +++ b/src/slic3r/GUI/ArrangeHelper.cpp @@ -46,8 +46,15 @@ static Sequential::PrinterGeometry get_printer_geometry() { slices.push_back(ExtruderSlice{17000000, BOX, { { { -300000000, -35000000 }, { 300000000, -35000000 }, { 300000000, -21000000 }, { -300000000, -21000000 } } } }); */ Sequential::PrinterGeometry out; + + /* out.x_size = scaled(s_multiple_beds.get_bed_size().x()); out.y_size = scaled(s_multiple_beds.get_bed_size().y()); + */ + coord_t plate_x_size = scaled(s_multiple_beds.get_bed_size().x()); + coord_t plate_y_size = scaled(s_multiple_beds.get_bed_size().y()); + out.plate = { { 0, 0 }, { plate_x_size, 0}, { plate_x_size, plate_y_size }, { 0, plate_y_size } }; + for (const ExtruderSlice& slice : slices) { (slice.shape_type == CONVEX ? out.convex_heights : out.box_heights).emplace(slice.height); out.extruder_slices.insert(std::make_pair(slice.height, slice.polygons));