From ac659a3c9b04fc4116296f8a706d1c1d2c4b4072 Mon Sep 17 00:00:00 2001 From: surynek Date: Mon, 3 Feb 2025 23:30:08 +0100 Subject: [PATCH] Added general bed zero position. --- .../include/libseqarrange/seq_interface.hpp | 6 ++-- src/libseqarrange/src/seq_interface.cpp | 28 +++++++--------- src/libseqarrange/src/seq_preprocess.cpp | 32 +++++++++++++------ src/libseqarrange/src/seq_sequential.hpp | 4 +++ .../src/sequential_decimator.cpp | 16 ++++++---- src/libseqarrange/src/sequential_prusa.cpp | 9 +++--- 6 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/libseqarrange/include/libseqarrange/seq_interface.hpp b/src/libseqarrange/include/libseqarrange/seq_interface.hpp index c6c5df4c9a..804d0df20f 100644 --- a/src/libseqarrange/include/libseqarrange/seq_interface.hpp +++ b/src/libseqarrange/include/libseqarrange/seq_interface.hpp @@ -43,7 +43,7 @@ struct PrinterGeometry // , at least one polygon must be present for height 0 std::map > extruder_slices; - bool convert_Geometry2PlateBounds(int &x_bounding_box_size, int &y_bounding_box_size, Slic3r::Polygon &plate_bounding_polygon) const; + bool convert_Geometry2PlateBounds(Slic3r::BoundingBox &plate_bounding_box, Slic3r::Polygon &plate_bounding_polygon) const; }; @@ -74,9 +74,7 @@ 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::BoundingBox plate_bounding_box; Slic3r::Polygon plate_bounding_polygon; int max_refines; diff --git a/src/libseqarrange/src/seq_interface.cpp b/src/libseqarrange/src/seq_interface.cpp index 5647a39a35..1673bb1280 100644 --- a/src/libseqarrange/src/seq_interface.cpp +++ b/src/libseqarrange/src/seq_interface.cpp @@ -75,33 +75,29 @@ const coord_t SEQ_PRUSA_XL_GANTRY_LEVEL = 26000000; /*----------------------------------------------------------------*/ -bool PrinterGeometry::convert_Geometry2PlateBounds(int &x_plate_bounding_box_size, int &y_plate_bounding_box_size, Slic3r::Polygon &plate_bounding_polygon) const +bool PrinterGeometry::convert_Geometry2PlateBounds(Slic3r::BoundingBox &plate_bounding_box, Slic3r::Polygon &plate_bounding_polygon) const { - 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(); - 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) + if (fabs(plate.area() - plate_box.polygon().area()) > EPSILON) { 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; + else + { + plate_bounding_box = BoundingBox({ plate_box.min.x() / SEQ_SLICER_SCALE_FACTOR, plate_box.min.y() / SEQ_SLICER_SCALE_FACTOR }, + { plate_box.max.x() / SEQ_SLICER_SCALE_FACTOR, plate_box.max.y() / SEQ_SLICER_SCALE_FACTOR }); + + return true; + } } @@ -110,8 +106,6 @@ bool PrinterGeometry::convert_Geometry2PlateBounds(int &x_plate_bounding_box_siz SolverConfiguration::SolverConfiguration() : bounding_box_size_optimization_step(SEQ_BOUNDING_BOX_SIZE_OPTIMIZATION_STEP) , minimum_bounding_box_size(SEQ_MINIMUM_BOUNDING_BOX_SIZE) - , x_plate_bounding_box_size(SEQ_PRUSA_MK3S_X_SIZE) - , y_plate_bounding_box_size(SEQ_PRUSA_MK3S_Y_SIZE) , max_refines(SEQ_MAX_REFINES) , object_group_size(SEQ_OBJECT_GROUP_SIZE) , fixed_object_grouping_limit(SEQ_FIXED_OBJECT_GROUPING_LIMIT) @@ -167,7 +161,7 @@ double SolverConfiguration::convert_DecimationPrecision2Tolerance(DecimationPrec void SolverConfiguration::setup(const PrinterGeometry &printer_geometry) { - printer_geometry.convert_Geometry2PlateBounds(x_plate_bounding_box_size, y_plate_bounding_box_size, plate_bounding_polygon); + printer_geometry.convert_Geometry2PlateBounds(plate_bounding_box, plate_bounding_polygon); } diff --git a/src/libseqarrange/src/seq_preprocess.cpp b/src/libseqarrange/src/seq_preprocess.cpp index f2c265c27f..213bf0f34c 100644 --- a/src/libseqarrange/src/seq_preprocess.cpp +++ b/src/libseqarrange/src/seq_preprocess.cpp @@ -523,7 +523,7 @@ Polygon transform_UpsideDown(const SolverConfiguration &solver_configuration, co for (unsigned int i = 0; i < poly.points.size(); ++i) { poly.points[i] = Point(poly.points[i].x(), - (coord_t)(solver_configuration.y_plate_bounding_box_size * scale_factor - poly.points[i].y())); + (coord_t)((solver_configuration.plate_bounding_box.max.y() - solver_configuration.plate_bounding_box.min.y()) * scale_factor - poly.points[i].y())); } return poly; @@ -539,7 +539,7 @@ void transform_UpsideDown(const SolverConfiguration &solver_configuration, const void transform_UpsideDown(const SolverConfiguration &solver_configuration, coord_t scale_factor, const coord_t &scaled_x_pos, const coord_t &scaled_y_pos, coord_t &transformed_x_pos, coord_t &transformed_y_pos) { transformed_x_pos = scaled_x_pos; - transformed_y_pos = solver_configuration.y_plate_bounding_box_size * scale_factor - scaled_y_pos; + transformed_y_pos = (solver_configuration.plate_bounding_box.max.y() - solver_configuration.plate_bounding_box.min.y()) * scale_factor - scaled_y_pos; } @@ -868,14 +868,17 @@ bool check_PolygonSizeFitToPlate(const SolverConfiguration &solver_configuration { BoundingBox polygon_box = get_extents(polygon); + // general plate polygons are currently not supported + assert(solver_configuration.plate_bounding_polygon.points.size() == 0); + coord_t x_size = polygon_box.max.x() - polygon_box.min.x(); - if (x_size > solver_configuration.x_plate_bounding_box_size) + if (x_size > (solver_configuration.plate_bounding_box.max.x() - solver_configuration.plate_bounding_box.min.x())) { return false; } coord_t y_size = polygon_box.max.y() - polygon_box.min.y(); - if (y_size > solver_configuration.y_plate_bounding_box_size) + if (y_size > (solver_configuration.plate_bounding_box.max.y() - solver_configuration.plate_bounding_box.min.y())) { return false; } @@ -887,11 +890,14 @@ bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configur { BoundingBox polygon_box = get_extents(polygon); - if (x + polygon_box.min.x() < 0 || x + polygon_box.max.x() > solver_configuration.x_plate_bounding_box_size) + // general plate polygons are currently not supported + assert(solver_configuration.plate_bounding_polygon.points.size() == 0); + + if (x + polygon_box.min.x() < solver_configuration.plate_bounding_box.min.x() || x + polygon_box.max.x() > solver_configuration.plate_bounding_box.max.x()) { return false; } - if (y + polygon_box.min.y() < 0 || y + polygon_box.max.y() > solver_configuration.y_plate_bounding_box_size) + if (y + polygon_box.min.y() < solver_configuration.plate_bounding_box.min.y() || y + polygon_box.max.y() > solver_configuration.plate_bounding_box.max.y()) { return false; } @@ -903,14 +909,17 @@ bool check_PolygonSizeFitToPlate(const SolverConfiguration &solver_configuration { BoundingBox polygon_box = get_extents(polygon); + // general plate polygons are currently not supported + assert(solver_configuration.plate_bounding_polygon.points.size() == 0); + coord_t x_size = polygon_box.max.x() - polygon_box.min.x(); - if (x_size > solver_configuration.x_plate_bounding_box_size * scale_factor) + if (x_size > (solver_configuration.plate_bounding_box.max.x() - solver_configuration.plate_bounding_box.min.x()) * scale_factor) { return false; } coord_t y_size = polygon_box.max.y() - polygon_box.min.y(); - if (y_size > solver_configuration.y_plate_bounding_box_size * scale_factor) + if (y_size > (solver_configuration.plate_bounding_box.max.x() - solver_configuration.plate_bounding_box.min.x()) * scale_factor) { return false; } @@ -923,6 +932,9 @@ bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configur { BoundingBox polygon_box = get_extents(polygon); + // general plate polygons are currently not supported + assert(solver_configuration.plate_bounding_polygon.points.size() == 0); + #ifdef DEBUG { printf("x: %d,%d\n", polygon_box.min.x() + x, polygon_box.max.x() + x); @@ -932,11 +944,11 @@ bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configur } #endif - if (x + polygon_box.min.x() < 0 || x + polygon_box.max.x() > solver_configuration.x_plate_bounding_box_size * scale_factor) + if (x + polygon_box.min.x() < solver_configuration.plate_bounding_box.min.x() * scale_factor || x + polygon_box.max.x() > solver_configuration.plate_bounding_box.max.x() * scale_factor) { return false; } - if (y + polygon_box.min.y() < 0 || y + polygon_box.max.y() > solver_configuration.y_plate_bounding_box_size * scale_factor) + if (y + polygon_box.min.y() < solver_configuration.plate_bounding_box.min.y() * scale_factor || y + polygon_box.max.y() > solver_configuration.plate_bounding_box.max.y() * scale_factor) { return false; } diff --git a/src/libseqarrange/src/seq_sequential.hpp b/src/libseqarrange/src/seq_sequential.hpp index 07d4da5cd9..129ff9ccbc 100644 --- a/src/libseqarrange/src/seq_sequential.hpp +++ b/src/libseqarrange/src/seq_sequential.hpp @@ -1468,6 +1468,8 @@ bool checkExtens_SequentialWeakPolygonNonoverlapping(coord_t bool optimize_SequentialWeakPolygonNonoverlappingBinaryCentered(z3::solver &Solver, z3::context &Context, const SolverConfiguration &solver_configuration, + int &box_half_x_min, + int &box_half_y_min, int &box_half_x_max, int &box_half_y_max, const z3::expr_vector &dec_vars_X, @@ -1486,6 +1488,8 @@ bool optimize_SequentialWeakPolygonNonoverlappingBinaryCentered(z3::solver bool optimize_ConsequentialWeakPolygonNonoverlappingBinaryCentered(z3::solver &Solver, z3::context &Context, const SolverConfiguration &solver_configuration, + int &box_half_x_min, + int &box_half_y_min, int &box_half_x_max, int &box_half_y_max, const z3::expr_vector &dec_vars_X, diff --git a/src/libseqarrange/src/sequential_decimator.cpp b/src/libseqarrange/src/sequential_decimator.cpp index 62d9381896..433249f5e8 100644 --- a/src/libseqarrange/src/sequential_decimator.cpp +++ b/src/libseqarrange/src/sequential_decimator.cpp @@ -244,8 +244,8 @@ int decimate_Polygons(const CommandParameters &command_parameters) transformed_polygon = transform_UpsideDown(solver_configuration, scaleUp_PolygonForSlicer(1, shift_polygon, - rand() % (solver_configuration.x_plate_bounding_box_size * SEQ_SLICER_SCALE_FACTOR), - rand() % (solver_configuration.y_plate_bounding_box_size * SEQ_SLICER_SCALE_FACTOR))); + (solver_configuration.plate_bounding_box.min.x() + rand() % (solver_configuration.plate_bounding_box.max.x() - solver_configuration.plate_bounding_box.min.x())) * SEQ_SLICER_SCALE_FACTOR, + (solver_configuration.plate_bounding_box.min.y() + rand() % (solver_configuration.plate_bounding_box.max.y() - solver_configuration.plate_bounding_box.min.y()) * SEQ_SLICER_SCALE_FACTOR))); } else { @@ -351,10 +351,14 @@ int decimate_Polygons(const CommandParameters &command_parameters) preview_svg.draw(display_polygon, color); } - Polygon bed_polygon({ { 0, 0}, - { solver_configuration.x_plate_bounding_box_size, 0 }, - { solver_configuration.x_plate_bounding_box_size, solver_configuration.y_plate_bounding_box_size}, - { 0, solver_configuration.y_plate_bounding_box_size} }); + // general plate polygons are currently not supported + assert(solver_configuration.plate_bounding_polygon.points.size() == 0); + + Polygon bed_polygon({ { solver_configuration.plate_bounding_box.min.x(), solver_configuration.plate_bounding_box.min.y() }, + { solver_configuration.plate_bounding_box.max.x(), solver_configuration.plate_bounding_box.min.y() }, + { solver_configuration.plate_bounding_box.max.x(), solver_configuration.plate_bounding_box.max.y() }, + { solver_configuration.plate_bounding_box.min.x(), solver_configuration.plate_bounding_box.max.y() } }); + Polygon display_bed_polygon = scaleUp_PolygonForSlicer(SEQ_SVG_SCALE_FACTOR, bed_polygon, 0, diff --git a/src/libseqarrange/src/sequential_prusa.cpp b/src/libseqarrange/src/sequential_prusa.cpp index 7924c443f4..d91f3ccf91 100644 --- a/src/libseqarrange/src/sequential_prusa.cpp +++ b/src/libseqarrange/src/sequential_prusa.cpp @@ -692,10 +692,11 @@ int solve_SequentialPrint(const CommandParameters &command_parameters) preview_svg.draw_text(Point(x, y), ("ID:" + std::to_string(original_index_map[decided_polygons[i]]) + " T:" + std::to_string(times_T[decided_polygons[i]].as_int64())).c_str(), text_color.c_str()); } - Polygon plate_polygon({ { 0, 0}, - { solver_configuration.x_plate_bounding_box_size, 0 }, - { solver_configuration.x_plate_bounding_box_size, solver_configuration.y_plate_bounding_box_size}, - { 0, solver_configuration.y_plate_bounding_box_size} }); + Polygon plate_polygon({ { solver_configuration.plate_bounding_box.min.x(), solver_configuration.plate_bounding_box.min.y() }, + { solver_configuration.plate_bounding_box.max.x(), solver_configuration.plate_bounding_box.min.y() }, + { solver_configuration.plate_bounding_box.max.x(), solver_configuration.plate_bounding_box.max.y() }, + { solver_configuration.plate_bounding_box.min.x(), solver_configuration.plate_bounding_box.max.y() } }); + Polygon display_plate_polygon = scaleUp_PolygonForSlicer(SEQ_SVG_SCALE_FACTOR, plate_polygon, 0,