Arrange selection if shift is pressed. Remove first item centering

This commit is contained in:
tamasmeszaros 2019-07-19 18:10:10 +02:00
parent 72ed8c034e
commit 63fada9469
2 changed files with 97 additions and 65 deletions

View file

@ -136,6 +136,9 @@ protected:
ItemGroup m_remaining; // Remaining items (m_items at the beginning)
ItemGroup m_items; // The items to be packed
// Used only for preloading objects before arrange
// std::vector<SpatIndex> m_preload_idx; // spatial index for preloaded beds
template<class T> ArithmeticOnly<T, double> norm(T val)
{
return double(val) / m_norm;
@ -318,6 +321,7 @@ public:
m_pilebb = sl::boundingBox(merged_pile);
m_rtree.clear();
// m_preload_idx.clear();
m_smallsrtree.clear();
// We will treat big items (compared to the print bed) differently
@ -341,7 +345,7 @@ public:
}
template<class...Args> inline void operator()(Args&&...args) {
m_rtree.clear();
m_rtree.clear(); /*m_preload_idx.clear();*/
m_pck.execute(std::forward<Args>(args)...);
}
@ -358,19 +362,25 @@ public:
for(unsigned idx = 0; idx < fixeditems.size(); ++idx) {
Item& itm = fixeditems[idx];
itm.markAsFixed();
m_rtree.insert({itm.boundingBox(), idx});
// size_t bedidx = itm.binId() < 0 ? 0u : size_t(itm.binId());
// while (m_preload_idx.size() <= bedidx) m_preload_idx.emplace_back();
// m_preload_idx[bedidx].insert({itm.boundingBox(), idx});
}
m_pck.configure(m_pconf);
}
bool is_colliding(const Item& item) {
if(m_rtree.empty()) return false;
std::vector<SpatElement> result;
m_rtree.query(bgi::intersects(item.boundingBox()),
std::back_inserter(result));
return !result.empty();
}
// int is_colliding(const Item& item) {
// size_t bedidx = item.binId() < 0 ? 0u : size_t(item.binId());
// if (m_preload_idx.size() <= bedidx || m_preload_idx[bedidx].empty())
// return false;
// std::vector<SpatElement> result;
// m_preload_idx[bedidx].query(bgi::intersects(item.boundingBox()),
// std::back_inserter(result));
// return !result.empty();
// }
};
template<> std::function<double(const Item&)> AutoArranger<Box>::get_objfn()
@ -534,24 +544,21 @@ void _arrange(
++it : it = excludes.erase(it);
// If there is something on the plate
if(!excludes.empty())
{
arranger.preload(excludes);
auto binbb = sl::boundingBox(corrected_bin);
if (!excludes.empty()) {
arranger.preload(excludes);
// auto binbb = sl::boundingBox(corrected_bin);
// Try to put the first item to the center, as the arranger
// will not do this for us.
for (Item &itm : shapes) {
auto ibb = itm.boundingBox();
auto d = binbb.center() - ibb.center();
itm.translate(d);
// // Try to put the first item to the center, as the arranger
// // will not do this for us.
// for (Item &itm : shapes) {
// auto ibb = itm.boundingBox();
// auto d = binbb.center() - ibb.center();
// itm.translate(d);
// itm.binId(UNARRANGED);
if (!arranger.is_colliding(itm)) {
itm.markAsFixed();
break;
}
}
}
// if (!arranger.is_colliding(itm)) { itm.markAsFixed(); break; }
// }
}
std::vector<std::reference_wrapper<Item>> inp;
inp.reserve(shapes.size() + excludes.size());