Added general bed zero position.

This commit is contained in:
surynek 2025-02-03 23:30:08 +01:00 committed by Lukas Matena
parent 2d1b498d2b
commit ac659a3c9b
6 changed files with 54 additions and 41 deletions

View File

@ -43,7 +43,7 @@ struct PrinterGeometry
// <height, polygons at given height>, at least one polygon must be present for height 0 // <height, polygons at given height>, at least one polygon must be present for height 0
std::map<coord_t, std::vector<Slic3r::Polygon> > extruder_slices; std::map<coord_t, std::vector<Slic3r::Polygon> > 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 bounding_box_size_optimization_step;
int minimum_bounding_box_size; int minimum_bounding_box_size;
int x_plate_bounding_box_size; Slic3r::BoundingBox plate_bounding_box;
int y_plate_bounding_box_size;
Slic3r::Polygon plate_bounding_polygon; Slic3r::Polygon plate_bounding_polygon;
int max_refines; int max_refines;

View File

@ -75,21 +75,11 @@ 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); BoundingBox plate_box = get_extents(plate);
x_size = plate_box.max.x() - plate_box.min.x(); if (fabs(plate.area() - plate_box.polygon().area()) > EPSILON)
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)
{ {
for (unsigned int i = 0; i < plate.points.size(); ++i) for (unsigned int i = 0; i < plate.points.size(); ++i)
{ {
@ -101,7 +91,13 @@ bool PrinterGeometry::convert_Geometry2PlateBounds(int &x_plate_bounding_box_siz
return 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() SolverConfiguration::SolverConfiguration()
: bounding_box_size_optimization_step(SEQ_BOUNDING_BOX_SIZE_OPTIMIZATION_STEP) : bounding_box_size_optimization_step(SEQ_BOUNDING_BOX_SIZE_OPTIMIZATION_STEP)
, minimum_bounding_box_size(SEQ_MINIMUM_BOUNDING_BOX_SIZE) , 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) , max_refines(SEQ_MAX_REFINES)
, object_group_size(SEQ_OBJECT_GROUP_SIZE) , object_group_size(SEQ_OBJECT_GROUP_SIZE)
, fixed_object_grouping_limit(SEQ_FIXED_OBJECT_GROUPING_LIMIT) , 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) 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);
} }

View File

@ -523,7 +523,7 @@ Polygon transform_UpsideDown(const SolverConfiguration &solver_configuration, co
for (unsigned int i = 0; i < poly.points.size(); ++i) for (unsigned int i = 0; i < poly.points.size(); ++i)
{ {
poly.points[i] = Point(poly.points[i].x(), 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; 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) 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_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); 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(); 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; return false;
} }
coord_t y_size = polygon_box.max.y() - polygon_box.min.y(); 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; return false;
} }
@ -887,11 +890,14 @@ bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configur
{ {
BoundingBox polygon_box = get_extents(polygon); 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; 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; return false;
} }
@ -903,14 +909,17 @@ bool check_PolygonSizeFitToPlate(const SolverConfiguration &solver_configuration
{ {
BoundingBox polygon_box = get_extents(polygon); 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(); 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; return false;
} }
coord_t y_size = polygon_box.max.y() - polygon_box.min.y(); 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; return false;
} }
@ -923,6 +932,9 @@ bool check_PolygonPositionWithinPlate(const SolverConfiguration &solver_configur
{ {
BoundingBox polygon_box = get_extents(polygon); BoundingBox polygon_box = get_extents(polygon);
// general plate polygons are currently not supported
assert(solver_configuration.plate_bounding_polygon.points.size() == 0);
#ifdef DEBUG #ifdef DEBUG
{ {
printf("x: %d,%d\n", polygon_box.min.x() + x, polygon_box.max.x() + x); 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 #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; 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; return false;
} }

View File

@ -1468,6 +1468,8 @@ bool checkExtens_SequentialWeakPolygonNonoverlapping(coord_t
bool optimize_SequentialWeakPolygonNonoverlappingBinaryCentered(z3::solver &Solver, bool optimize_SequentialWeakPolygonNonoverlappingBinaryCentered(z3::solver &Solver,
z3::context &Context, z3::context &Context,
const SolverConfiguration &solver_configuration, const SolverConfiguration &solver_configuration,
int &box_half_x_min,
int &box_half_y_min,
int &box_half_x_max, int &box_half_x_max,
int &box_half_y_max, int &box_half_y_max,
const z3::expr_vector &dec_vars_X, const z3::expr_vector &dec_vars_X,
@ -1486,6 +1488,8 @@ bool optimize_SequentialWeakPolygonNonoverlappingBinaryCentered(z3::solver
bool optimize_ConsequentialWeakPolygonNonoverlappingBinaryCentered(z3::solver &Solver, bool optimize_ConsequentialWeakPolygonNonoverlappingBinaryCentered(z3::solver &Solver,
z3::context &Context, z3::context &Context,
const SolverConfiguration &solver_configuration, const SolverConfiguration &solver_configuration,
int &box_half_x_min,
int &box_half_y_min,
int &box_half_x_max, int &box_half_x_max,
int &box_half_y_max, int &box_half_y_max,
const z3::expr_vector &dec_vars_X, const z3::expr_vector &dec_vars_X,

View File

@ -244,8 +244,8 @@ int decimate_Polygons(const CommandParameters &command_parameters)
transformed_polygon = transform_UpsideDown(solver_configuration, transformed_polygon = transform_UpsideDown(solver_configuration,
scaleUp_PolygonForSlicer(1, scaleUp_PolygonForSlicer(1,
shift_polygon, shift_polygon,
rand() % (solver_configuration.x_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,
rand() % (solver_configuration.y_plate_bounding_box_size * 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 else
{ {
@ -351,10 +351,14 @@ int decimate_Polygons(const CommandParameters &command_parameters)
preview_svg.draw(display_polygon, color); preview_svg.draw(display_polygon, color);
} }
Polygon bed_polygon({ { 0, 0}, // general plate polygons are currently not supported
{ solver_configuration.x_plate_bounding_box_size, 0 }, assert(solver_configuration.plate_bounding_polygon.points.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 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, Polygon display_bed_polygon = scaleUp_PolygonForSlicer(SEQ_SVG_SCALE_FACTOR,
bed_polygon, bed_polygon,
0, 0,

View File

@ -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()); 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}, Polygon plate_polygon({ { solver_configuration.plate_bounding_box.min.x(), solver_configuration.plate_bounding_box.min.y() },
{ solver_configuration.x_plate_bounding_box_size, 0 }, { solver_configuration.plate_bounding_box.max.x(), solver_configuration.plate_bounding_box.min.y() },
{ solver_configuration.x_plate_bounding_box_size, solver_configuration.y_plate_bounding_box_size}, { solver_configuration.plate_bounding_box.max.x(), solver_configuration.plate_bounding_box.max.y() },
{ 0, solver_configuration.y_plate_bounding_box_size} }); { solver_configuration.plate_bounding_box.min.x(), solver_configuration.plate_bounding_box.max.y() } });
Polygon display_plate_polygon = scaleUp_PolygonForSlicer(SEQ_SVG_SCALE_FACTOR, Polygon display_plate_polygon = scaleUp_PolygonForSlicer(SEQ_SVG_SCALE_FACTOR,
plate_polygon, plate_polygon,
0, 0,