mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-10 08:17:51 -06:00
FIX: auto-arrange fails in several cases
Jira: STUDIO-644, STUDIO-661 Change-Id: I3cd1fcd4e1fabf9a401c9fd536e8f55592775fbd
This commit is contained in:
parent
1e0301dbde
commit
35d6e048ff
2 changed files with 17 additions and 12 deletions
|
@ -67,7 +67,7 @@ struct NfpPConfig {
|
||||||
* the already packed items.
|
* the already packed items.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
std::function<double(const _Item<RawShape>&)> object_function;
|
std::function<double(const _Item<RawShape>&, const ItemGroup&)> object_function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The quality of search for an optimal placement.
|
* @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
|
// This is the kernel part of the object function that is
|
||||||
// customizable by the library client
|
// customizable by the library client
|
||||||
std::function<double(const Item&)> _objfunc;
|
std::function<double(const Item&)> _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 {
|
else {
|
||||||
|
|
||||||
// Inside check has to be strict if no alignment was enabled
|
// Inside check has to be strict if no alignment was enabled
|
||||||
|
|
|
@ -447,7 +447,7 @@ protected:
|
||||||
return std::make_tuple(score, fullbb);
|
return std::make_tuple(score, fullbb);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<double(const Item&)> get_objfn();
|
std::function<double(const Item&, const ItemGroup&)> get_objfn();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AutoArranger(const TBin & bin,
|
AutoArranger(const TBin & bin,
|
||||||
|
@ -509,6 +509,7 @@ public:
|
||||||
return bin_poly;
|
return bin_poly;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// preload fixed items (and excluded regions) on plate
|
||||||
m_pconf.on_preload = [this](const ItemGroup &items, PConfig &cfg) {
|
m_pconf.on_preload = [this](const ItemGroup &items, PConfig &cfg) {
|
||||||
if (items.empty()) return;
|
if (items.empty()) return;
|
||||||
|
|
||||||
|
@ -527,8 +528,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.object_function = [this, bb, starting_point](const Item& item) {
|
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);
|
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<double(const Item&)> AutoArranger<Box>::get_objfn()
|
template<> std::function<double(const Item&, const ItemGroup&)> AutoArranger<Box>::get_objfn()
|
||||||
{
|
{
|
||||||
auto origin_pack = m_pconf.starting_point == PConfig::Alignment::CENTER ? m_bin.center() : m_bin.minCorner();
|
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);
|
auto result = objfunc(itm, origin_pack);
|
||||||
|
|
||||||
double score = std::get<0>(result);
|
double score = std::get<0>(result);
|
||||||
|
@ -623,11 +628,11 @@ template<> std::function<double(const Item&)> AutoArranger<Box>::get_objfn()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> std::function<double(const Item&)> AutoArranger<Circle>::get_objfn()
|
template<> std::function<double(const Item&, const ItemGroup&)> AutoArranger<Circle>::get_objfn()
|
||||||
{
|
{
|
||||||
auto bb = sl::boundingBox(m_bin);
|
auto bb = sl::boundingBox(m_bin);
|
||||||
auto origin_pack = m_pconf.starting_point == PConfig::Alignment::CENTER ? bb.center() : bb.minCorner();
|
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);
|
auto result = objfunc(item, origin_pack);
|
||||||
|
|
||||||
|
@ -653,11 +658,11 @@ template<> std::function<double(const Item&)> AutoArranger<Circle>::get_objfn()
|
||||||
// Specialization for a generalized polygon.
|
// Specialization for a generalized polygon.
|
||||||
// Warning: this is much slower than with Box bed. Need further speedup.
|
// Warning: this is much slower than with Box bed. Need further speedup.
|
||||||
template<>
|
template<>
|
||||||
std::function<double(const Item &)> AutoArranger<ExPolygon>::get_objfn()
|
std::function<double(const Item &, const ItemGroup&)> AutoArranger<ExPolygon>::get_objfn()
|
||||||
{
|
{
|
||||||
auto bb = sl::boundingBox(m_bin);
|
auto bb = sl::boundingBox(m_bin);
|
||||||
auto origin_pack = m_pconf.starting_point == PConfig::Alignment::CENTER ? bb.center() : bb.minCorner();
|
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);
|
auto result = objfunc(itm, origin_pack);
|
||||||
|
|
||||||
double score = std::get<0>(result);
|
double score = std::get<0>(result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue