From 35d6e048ff0cc5cee81038c3205e60d268138657 Mon Sep 17 00:00:00 2001 From: arthur Date: Tue, 9 Aug 2022 01:52:15 +0800 Subject: [PATCH] FIX: auto-arrange fails in several cases Jira: STUDIO-644, STUDIO-661 Change-Id: I3cd1fcd4e1fabf9a401c9fd536e8f55592775fbd --- .../include/libnest2d/placers/nfpplacer.hpp | 4 +-- src/libslic3r/Arrange.cpp | 25 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp index 2cf356401..29de288b9 100644 --- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp @@ -67,7 +67,7 @@ struct NfpPConfig { * the already packed items. * */ - std::function&)> object_function; + std::function&, const ItemGroup&)> object_function; /** * @brief The quality of search for an optimal placement. @@ -666,7 +666,7 @@ private: // This is the kernel part of the object function that is // customizable by the library client std::function _objfunc; - if(config_.object_function) _objfunc = config_.object_function; + if (config_.object_function) _objfunc = [this](const Item& item) {return config_.object_function(item, this->items_); }; else { // Inside check has to be strict if no alignment was enabled diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index e08a3c208..cc2f1721a 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -447,7 +447,7 @@ protected: return std::make_tuple(score, fullbb); } - std::function get_objfn(); + std::function get_objfn(); public: AutoArranger(const TBin & bin, @@ -508,7 +508,8 @@ public: bin_poly.contour.points.emplace_back(c0.x(), c1.y()); return bin_poly; }; - + + // preload fixed items (and excluded regions) on plate m_pconf.on_preload = [this](const ItemGroup &items, PConfig &cfg) { if (items.empty()) return; @@ -527,8 +528,12 @@ public: } } - cfg.object_function = [this, bb, starting_point](const Item& item) { - return fixed_overfit_topright_sliding(objfunc(item, starting_point), bb); + cfg.object_function = [this, bb, starting_point](const Item& item, const ItemGroup& packed_items) { + bool packed_are_excluded_region = std::all_of(packed_items.begin(), packed_items.end(), [](Item& itm) { return itm.is_virt_object && !itm.is_wipe_tower; }); + if(packed_are_excluded_region) + return fixed_overfit_topright_sliding(objfunc(item, starting_point), bb); + else + return fixed_overfit(objfunc(item, starting_point), bb); }; }; @@ -597,11 +602,11 @@ public: } }; -template<> std::function AutoArranger::get_objfn() +template<> std::function AutoArranger::get_objfn() { auto origin_pack = m_pconf.starting_point == PConfig::Alignment::CENTER ? m_bin.center() : m_bin.minCorner(); - return [this, origin_pack](const Item &itm) { + return [this, origin_pack](const Item &itm, const ItemGroup&) { auto result = objfunc(itm, origin_pack); double score = std::get<0>(result); @@ -623,11 +628,11 @@ template<> std::function AutoArranger::get_objfn() }; } -template<> std::function AutoArranger::get_objfn() +template<> std::function AutoArranger::get_objfn() { auto bb = sl::boundingBox(m_bin); auto origin_pack = m_pconf.starting_point == PConfig::Alignment::CENTER ? bb.center() : bb.minCorner(); - return [this, origin_pack](const Item &item) { + return [this, origin_pack](const Item &item, const ItemGroup&) { auto result = objfunc(item, origin_pack); @@ -653,11 +658,11 @@ template<> std::function AutoArranger::get_objfn() // Specialization for a generalized polygon. // Warning: this is much slower than with Box bed. Need further speedup. template<> -std::function AutoArranger::get_objfn() +std::function AutoArranger::get_objfn() { auto bb = sl::boundingBox(m_bin); auto origin_pack = m_pconf.starting_point == PConfig::Alignment::CENTER ? bb.center() : bb.minCorner(); - return [this, origin_pack](const Item &itm) { + return [this, origin_pack](const Item &itm, const ItemGroup&) { auto result = objfunc(itm, origin_pack); double score = std::get<0>(result);