From 869ae0247ebe69e51df4a794825f286fea42a9ae Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 2 Dec 2020 17:53:22 +0100 Subject: [PATCH] Use smarter object function in partial arrangement with empty bed. --- .../include/libnest2d/placers/nfpplacer.hpp | 8 ++++++++ src/libslic3r/Arrange.cpp | 20 +++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp index 35e7e160d..83f7bd246 100644 --- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp @@ -167,6 +167,8 @@ struct NfpPConfig { const ItemGroup& // remaining items )> before_packing; + std::function on_preload; + NfpPConfig(): rotations({0.0, Pi/2.0, Pi, 3*Pi/2}), alignment(Alignment::CENTER), starting_point(Alignment::CENTER) {} }; @@ -577,6 +579,12 @@ public: Base::clearItems(); } + void preload(const ItemGroup& packeditems) { + Base::preload(packeditems); + if (config_.on_preload) + config_.on_preload(packeditems, config_); + } + private: using Shapes = TMultiShape; diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index 705e213e3..eaa9726dd 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -109,6 +109,7 @@ void fill_config(PConf& pcfg, const ArrangeParams ¶ms) { // Apply penalty to object function result. This is used only when alignment // after arrange is explicitly disabled (PConfig::Alignment::DONT_ALIGN) +// Also, this will only work well for Box shaped beds. static double fixed_overfit(const std::tuple& result, const Box &binbb) { double score = std::get<0>(result); @@ -348,6 +349,17 @@ public: m_pconf.object_function = get_objfn(); + m_pconf.on_preload = [this](const ItemGroup &items, PConfig &cfg) { + if (items.empty()) return; + + cfg.alignment = PConfig::Alignment::DONT_ALIGN; + auto bb = sl::boundingBox(m_bin); + auto bbcenter = bb.center(); + cfg.object_function = [this, bb, bbcenter](const Item &item) { + return fixed_overfit(objfunc(item, bbcenter), bb); + }; + }; + auto on_packed = params.on_packed; if (progressind || on_packed) @@ -384,13 +396,6 @@ public: const PConfig& config() const { return m_pconf; } inline void preload(std::vector& fixeditems) { - m_pconf.alignment = PConfig::Alignment::DONT_ALIGN; - auto bb = sl::boundingBox(m_bin); - auto bbcenter = bb.center(); - m_pconf.object_function = [this, bb, bbcenter](const Item &item) { - return fixed_overfit(objfunc(item, bbcenter), bb); - }; - // Build the rtree for queries to work for(unsigned idx = 0; idx < fixeditems.size(); ++idx) { @@ -398,7 +403,6 @@ public: itm.markAsFixedInBin(itm.binId()); } - m_pck.configure(m_pconf); m_item_count += fixeditems.size(); } };