FIX: auto arranging gets collision with occlusion areas

jira: STUDIO-6645
Change-Id: I57e62b824e3faadf9fae1294ef329456055893d0
(cherry picked from commit a678094ffa3d6b8b7900f3e3cac0d3f18fed9f30)
This commit is contained in:
Arthur 2024-09-03 17:33:29 +08:00 committed by Lane.Wei
parent 1fc6330014
commit 499b39b133
2 changed files with 41 additions and 39 deletions

View File

@ -96,6 +96,7 @@ struct NfpPConfig {
*/ */
bool parallel = true; bool parallel = true;
bool save_svg = false;
/** /**
* @brief before_packing Callback that is called just before a search for * @brief before_packing Callback that is called just before a search for
* a new item's position is started. You can use this to create various * a new item's position is started. You can use this to create various
@ -163,9 +164,9 @@ template<class RawShape> class EdgeCache {
std::vector<ContourCache> holes_; std::vector<ContourCache> holes_;
double accuracy_ = 1.0; double accuracy_ = 1.0;
static double length(const Edge &e) static double length(const Edge &e)
{ {
return std::sqrt(e.template sqlength<double>()); return std::sqrt(e.template sqlength<double>());
} }
@ -784,7 +785,7 @@ private:
if(can_pack) break; if(can_pack) break;
} }
item.inflation(inflation_back); item.inflation(inflation_back);
if (can_pack) if (can_pack)
global_score = 0.2; global_score = 0.2;
item.rotation(best_rot); item.rotation(best_rot);
@ -987,38 +988,39 @@ private:
} }
#ifdef SVGTOOLS_HPP #ifdef SVGTOOLS_HPP
svg::SVGWriter<RawShape> svgwriter; if (config_.save_svg) {
Box binbb2(binbb.width() * 2, binbb.height() * 2, binbb.center()); // expand bbox to allow object be drawed outside svg::SVGWriter<RawShape> svgwriter;
svgwriter.setSize(binbb2); Box binbb2(binbb.width() * 2, binbb.height() * 2, binbb.center()); // expand bbox to allow object be drawed outside
svgwriter.conf_.x0 = binbb.width(); svgwriter.setSize(binbb2);
svgwriter.conf_.y0 = -binbb.height()/2; // origin is top left corner svgwriter.conf_.x0 = binbb.width();
svgwriter.add_comment("bed"); svgwriter.conf_.y0 = -binbb.height() / 2; // origin is top left corner
svgwriter.writeShape(box2RawShape(binbb), "none", "black"); svgwriter.add_comment("bed");
svgwriter.add_comment("nfps"); svgwriter.writeShape(box2RawShape(binbb), "none", "black");
for (int i = 0; i < nfps.size(); i++) svgwriter.add_comment("nfps");
svgwriter.writeShape(nfps[i], "none", "blue"); for (int i = 0; i < nfps.size(); i++) svgwriter.writeShape(nfps[i], "none", "blue");
for (int i = 0; i < items_.size(); i++) { for (int i = 0; i < items_.size(); i++) {
svgwriter.add_comment(items_[i].get().name); svgwriter.add_comment(items_[i].get().name);
svgwriter.writeItem(items_[i], "none", "black"); svgwriter.writeItem(items_[i], "none", "black");
} }
svgwriter.add_comment("merged_pile_"); svgwriter.add_comment("merged_pile_");
for (int i = 0; i < merged_pile_.size(); i++) for (int i = 0; i < merged_pile_.size(); i++) svgwriter.writeShape(merged_pile_[i], "none", "yellow");
svgwriter.writeShape(merged_pile_[i], "none", "yellow"); svgwriter.add_comment("current item");
svgwriter.add_comment("current item"); svgwriter.writeItem(item, "red", "red", 2);
svgwriter.writeItem(item, "red", "red", 2);
std::stringstream ss; std::stringstream ss;
ss.setf(std::ios::fixed | std::ios::showpoint); ss.setf(std::ios::fixed | std::ios::showpoint);
ss.precision(1); ss.precision(1);
ss << "t=" << round(item.translation().x() / 1e6) << "," << round(item.translation().y() / 1e6) ss << "t=" << round(item.translation().x() / 1e6) << ","
//<< "-rot=" << round(item.rotation().toDegrees()) << round(item.translation().y() / 1e6)
<< "-sco=" << round(global_score); //<< "-rot=" << round(item.rotation().toDegrees())
svgwriter.draw_text(20, 20, ss.str(), "blue", 20); << "-sco=" << round(global_score);
ss.str(""); svgwriter.draw_text(20, 20, ss.str(), "blue", 20);
ss << "items.size=" << items_.size() ss.str("");
<< "-merged_pile.size=" << merged_pile_.size(); ss << "items.size=" << items_.size() << "-merged_pile.size=" << merged_pile_.size();
svgwriter.draw_text(20, 40, ss.str(), "blue", 20); svgwriter.draw_text(20, 40, ss.str(), "blue", 20);
svgwriter.save(boost::filesystem::path("C:/Users/arthur.tang/AppData/Roaming/BambuStudioInternal/SVG")/ ("nfpplacer_" + std::to_string(plate_id) + "_" + ss.str() + "_" + item.name + ".svg")); svgwriter.save(boost::filesystem::path("C:/Users/arthur.tang/AppData/Roaming/BambuStudioInternal/SVG") /
("nfpplacer_" + std::to_string(plate_id) + "_" + ss.str() + "_" + item.name + ".svg"));
}
#endif #endif
if(can_pack) { if(can_pack) {
@ -1142,7 +1144,7 @@ private:
default: ; // DONT_ALIGN default: ; // DONT_ALIGN
} }
auto d = cb - ci; auto d = cb - ci;
// BBS make sure the item won't clash with excluded regions // BBS make sure the item won't clash with excluded regions
// do we have wipe tower after arranging? // do we have wipe tower after arranging?
@ -1194,7 +1196,7 @@ private:
void setInitialPosition(Item& item) { void setInitialPosition(Item& item) {
Box bb = item.boundingBox(); Box bb = item.boundingBox();
Vertex ci, cb; Vertex ci, cb;
Box bbin = sl::boundingBox(bin_); Box bbin = sl::boundingBox(bin_);
Vertex shrink(10, 10); Vertex shrink(10, 10);

View File

@ -129,7 +129,7 @@ void update_unselected_items_inflation(ArrangePolygons& unselected, const Dynami
exclusion_gap = std::max(exclusion_gap, params.min_obj_distance / 2 + scaled<coord_t>(params.bed_shrink_x + 1.f)); // +1mm gap so the exclusion region is not too close exclusion_gap = std::max(exclusion_gap, params.min_obj_distance / 2 + scaled<coord_t>(params.bed_shrink_x + 1.f)); // +1mm gap so the exclusion region is not too close
// dont forget to move the excluded region // dont forget to move the excluded region
for (auto& region : unselected) { for (auto& region : unselected) {
if (region.is_virt_object) region.poly.translate(scaled(params.bed_shrink_x), scaled(params.bed_shrink_y)); if (region.is_virt_object) region.poly.translate(scaled(params.bed_shrink_x+1.f), scaled(params.bed_shrink_y+1.f));
} }
} }
// For occulusion regions, inflation should be larger to prevent genrating brim on them. // For occulusion regions, inflation should be larger to prevent genrating brim on them.
@ -142,7 +142,7 @@ void update_unselected_items_inflation(ArrangePolygons& unselected, const Dynami
: (ap.is_extrusion_cali_object ? 0 : exclusion_gap); }); : (ap.is_extrusion_cali_object ? 0 : exclusion_gap); });
} }
//it will bed accurate after call update_params //it will be accurate after call update_params
Points get_shrink_bedpts(const DynamicPrintConfig & print_cfg, const ArrangeParams& params) Points get_shrink_bedpts(const DynamicPrintConfig & print_cfg, const ArrangeParams& params)
{ {
Points bedpts = get_bed_shape(print_cfg); Points bedpts = get_bed_shape(print_cfg);