From 4db1a6d46eda7957517036cb57a6820e392865fc Mon Sep 17 00:00:00 2001 From: manch1n Date: Fri, 5 May 2023 14:04:20 +0800 Subject: [PATCH] ENH: allow big obj arrange into bed with calibration region Change-Id: I4dac878e0c5ec75a4b06dd5803c0a4839f312bfe (cherry picked from commit b216a5f4ae97b29eb5ba0c2b5de3b12da80f374d) --- src/libnest2d/include/libnest2d/nester.hpp | 13 +++++++++++++ .../include/libnest2d/placers/nfpplacer.hpp | 7 +++++++ .../libnest2d/placers/placer_boilerplate.hpp | 11 +++++++++++ .../include/libnest2d/selections/firstfit.hpp | 18 ++++++++++++++++++ .../selections/selection_boilerplate.hpp | 2 +- 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/libnest2d/include/libnest2d/nester.hpp b/src/libnest2d/include/libnest2d/nester.hpp index 2ac0392d7..9038a9d63 100644 --- a/src/libnest2d/include/libnest2d/nester.hpp +++ b/src/libnest2d/include/libnest2d/nester.hpp @@ -84,6 +84,7 @@ public: //BBS: virtual object to mark unprintable region on heatbed bool is_virt_object{ false }; bool is_wipe_tower{ false }; + bool has_tried_with_excluded{ false }; /// The type of the shape which was handed over as the template argument. using ShapeType = RawShape; @@ -662,9 +663,21 @@ public: /// Get the packed items. inline ItemGroup getItems() { return impl_.getItems(); } + inline int getPackedSize() + { + int size = 0; + auto items = getItems(); + for (const auto &itm : items) { + if (itm.get().isFixed() == false) { size++; } + } + return size; + } + /// Clear the packed items so a new session can be started. inline void clearItems() { impl_.clearItems(); } + inline void clearItems(const std::function &func) { impl_.clearItems(func); } + inline double filledArea() const { return impl_.filledArea(); } inline double score() const { return impl_.score(); } diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp index ae0fcb36e..1a6339477 100644 --- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp @@ -555,6 +555,13 @@ public: Base::clearItems(); } + //clearFunc: itm will be cleared if return ture + inline void clearItems(const std::function &clearFunc) + { + finalAlign(bin_); + Base::clearItems(clearFunc); + } + void preload(const ItemGroup& packeditems) { Base::preload(packeditems); if (config_.on_preload) diff --git a/src/libnest2d/include/libnest2d/placers/placer_boilerplate.hpp b/src/libnest2d/include/libnest2d/placers/placer_boilerplate.hpp index 4b2af5f7b..ae2d9712d 100644 --- a/src/libnest2d/include/libnest2d/placers/placer_boilerplate.hpp +++ b/src/libnest2d/include/libnest2d/placers/placer_boilerplate.hpp @@ -96,6 +96,17 @@ public: farea_valid_ = false; } + //clearFunc: will be cleared if return true + inline void clearItems(const std::function &clearFunc) + { + ItemGroup newGroup; + for (auto &i : items_) { + if (clearFunc(i.get()) == false) { newGroup.push_back(i); } + } + std::swap(newGroup, items_); + farea_valid_ = false; + } + inline double filledArea() const { if(farea_valid_) return farea_; else { diff --git a/src/libnest2d/include/libnest2d/selections/firstfit.hpp b/src/libnest2d/include/libnest2d/selections/firstfit.hpp index e739a8870..ef05398da 100644 --- a/src/libnest2d/include/libnest2d/selections/firstfit.hpp +++ b/src/libnest2d/include/libnest2d/selections/firstfit.hpp @@ -161,6 +161,24 @@ public: makeProgress(placers[j], j); } + if (was_packed && it->get().has_tried_with_excluded) { + placers[j].clearItems([](const Item &itm) { return itm.isFixed() && !itm.is_wipe_tower; }); + placers[j].preload(fixed_bins[placers.size() - 1]); + } + bool placer_not_packed = !was_packed && !placers.empty() && j == placers.size() && placers[j - 1].getPackedSize() == 0; // large item is not placed into the bin + if (placer_not_packed) { + if (it->get().has_tried_with_excluded == false) { + it->get().has_tried_with_excluded = true; + placers[j - 1].clearItems([](const Item &itm) { return itm.isFixed()&&!itm.is_wipe_tower; }); + placers[j - 1].preload(pconfig.m_excluded_items); + j = j - 1; + continue; + } else { + placers[j - 1].clearItems([](const Item &itm) { return itm.isFixed() && !itm.is_wipe_tower; }); + placers[j - 1].preload(fixed_bins[placers.size() - 1]); + } + } + if(!was_packed){ if (this->unfitindicator_ && !placers.empty()) this->unfitindicator_(it->get().name + ", height=" +std::to_string(it->get().height) diff --git a/src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp b/src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp index ffb878e41..a9871dcb1 100644 --- a/src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp +++ b/src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp @@ -37,7 +37,7 @@ protected: // then it should be removed from the list Placer p{ bin }; p.configure(pcfg); - //p.preload(pcfg.m_excluded_items); + p.preload(pcfg.m_excluded_items); auto it = c.begin(); while (it != c.end() && !stopcond_()) {