Changed the PrinterGeometry structure to accommodate polygonal bed shape.

This commit is contained in:
surynek 2025-01-27 17:36:00 +01:00 committed by Lukas Matena
parent 8f89b038af
commit a9116ea4fd
5 changed files with 68 additions and 34 deletions

View File

@ -34,8 +34,7 @@ namespace Sequential
struct PrinterGeometry struct PrinterGeometry
{ {
coord_t x_size; Slic3r::Polygon plate;
coord_t y_size;
// at least height 0 (corresponding to nozzle) must be present in convex_height // at least height 0 (corresponding to nozzle) must be present in convex_height
std::set<coord_t> convex_heights; std::set<coord_t> convex_heights;
@ -44,8 +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;
int convert_Geometry2PlateBoundingBoxSize(void) const; bool convert_Geometry2PlateBounds(int &x_bounding_box_size, int &y_bounding_box_size, Slic3r::Polygon &plate_bounding_polygon) const;
void convert_Geometry2PlateBoundingBoxSize(int &X_bounding_box_size, int &Y_bounding_box_size) const;
}; };
@ -75,8 +73,12 @@ 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; int x_plate_bounding_box_size;
int y_plate_bounding_box_size; int y_plate_bounding_box_size;
Slic3r::Polygon plate_bounding_polygon;
int max_refines; int max_refines;
int object_group_size; int object_group_size;

View File

@ -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; x_plate_bounding_box_size = x_size / SEQ_SLICER_SCALE_FACTOR;
y_plate_bounding_box_size = y_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) 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);
} }

View File

@ -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) int load_printer_geometry_from_stream(std::istream &geometry_stream, PrinterGeometry &printer_geometry)
{ {
Polygon *current_polygon = NULL; Polygon *current_polygon = NULL;
std::string line; std::string line;
coord_t x_size = -1;
coord_t y_size = -1;
while (geometry_stream) while (geometry_stream)
{ {
@ -193,20 +196,20 @@ int load_printer_geometry_from_stream(std::istream &geometry_stream, PrinterGeom
std::stringstream ss(line); std::stringstream ss(line);
std::string val; std::string val;
ss >> val; ss >> val;
coord_t x_size = std::stoi(val); x_size = std::stoi(val);
printer_geometry.x_size = x_size;
} }
else if (find_and_remove(line, "Y_SIZE")) else if (find_and_remove(line, "Y_SIZE"))
{ {
std::stringstream ss(line); std::stringstream ss(line);
std::string val; std::string val;
ss >> val; ss >> val;
coord_t y_size = std::stoi(val); y_size = std::stoi(val);
printer_geometry.y_size = y_size;
} }
} }
assert(x_size > 0 && y_size > 0);
printer_geometry.plate = { {0, 0}, {x_size, 0}, {x_size, y_size}, {0, y_size} };
return 0; return 0;
} }

View File

@ -634,12 +634,8 @@ TEST_CASE("Interface test 3", "[Sequential Arrangement Interface]")
printf("Printer geometry load error.\n"); printf("Printer geometry load error.\n");
return; 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.plate.points.size() == 4);
REQUIRE(printer_geometry.y_size > 0);
for (const auto& convex_height: printer_geometry.convex_heights) 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) for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects)
{ {
cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; 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); BoundingBox plate_box = get_extents(printer_geometry.plate);
REQUIRE(scheduled_object.y >= 0);
REQUIRE(scheduled_object.y <= printer_geometry.y_size); 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) for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects)
{ {
cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; 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); BoundingBox plate_box = get_extents(printer_geometry.plate);
REQUIRE(scheduled_object.y >= 0);
REQUIRE(scheduled_object.y <= printer_geometry.y_size); 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) for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects)
{ {
cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; 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); BoundingBox plate_box = get_extents(printer_geometry.plate);
REQUIRE(scheduled_object.y >= 0);
REQUIRE(scheduled_object.y <= printer_geometry.y_size); 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());
} }
} }

View File

@ -46,8 +46,15 @@ static Sequential::PrinterGeometry get_printer_geometry() {
slices.push_back(ExtruderSlice{17000000, BOX, { { { -300000000, -35000000 }, { 300000000, -35000000 }, { 300000000, -21000000 }, { -300000000, -21000000 } } } }); slices.push_back(ExtruderSlice{17000000, BOX, { { { -300000000, -35000000 }, { 300000000, -35000000 }, { 300000000, -21000000 }, { -300000000, -21000000 } } } });
*/ */
Sequential::PrinterGeometry out; Sequential::PrinterGeometry out;
/*
out.x_size = scaled(s_multiple_beds.get_bed_size().x()); out.x_size = scaled(s_multiple_beds.get_bed_size().x());
out.y_size = scaled(s_multiple_beds.get_bed_size().y()); 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) { for (const ExtruderSlice& slice : slices) {
(slice.shape_type == CONVEX ? out.convex_heights : out.box_heights).emplace(slice.height); (slice.shape_type == CONVEX ? out.convex_heights : out.box_heights).emplace(slice.height);
out.extruder_slices.insert(std::make_pair(slice.height, slice.polygons)); out.extruder_slices.insert(std::make_pair(slice.height, slice.polygons));