33 {
34
35 using Placer = PlacementStrategyLike<TPlacer>;
36
38 store_.reserve(last-first);
39
40 std::vector<Placer> placers;
41 placers.reserve(last-first);
42
43 std::for_each(first, last, [
this](
Item& itm) {
44 if(itm.isFixed()) {
45 if (itm.binId() < 0) itm.binId(0);
46 auto binidx = size_t(itm.binId());
47
48 while(packed_bins_.size() <= binidx)
49 packed_bins_.emplace_back();
50
51 packed_bins_[binidx].emplace_back(itm);
52 } else {
53 store_.emplace_back(itm);
54 }
55 });
56
57
58
59
61 placers.emplace_back(bin);
62 placers.back().configure(pconfig);
63 placers.back().preload(ig);
64 }
65
66 auto sortfunc = [](
Item& i1,
Item& i2) {
67 int p1 = i1.priority(), p2 = i2.priority();
68 return p1 == p2 ? i1.area() > i2.area() : p1 > p2;
69 };
70
72
73 auto total = last-first;
74 auto makeProgress = [this, &total](Placer& placer, size_t bin_idx) {
77 this->
progress_(
static_cast<unsigned>(--total));
78 };
79
81
82 this->
template remove_unpackable_items<Placer>(
store_, bin, pconfig);
83
85
86 while(it !=
store_.end() && !cancelled()) {
87 bool was_packed = false;
88 size_t j = 0;
89 while(!was_packed && !cancelled()) {
90 for(; j < placers.size() && !was_packed && !cancelled(); j++) {
91 if((was_packed = placers[j].pack(*it,
rem(it,
store_) ))) {
92 it->get().binId(int(j));
93 makeProgress(placers[j], j);
94 }
95 }
96
97 if(!was_packed) {
98 placers.emplace_back(bin);
99 placers.back().configure(pconfig);
101 j = placers.size() - 1;
102 }
103 }
104 ++it;
105 }
106 }
_ItemGroup< RawShape > ItemGroup
Definition selection_boilerplate.hpp:14
_Item< RawShape > Item
Definition selection_boilerplate.hpp:13
PackGroup packed_bins_
Definition selection_boilerplate.hpp:56
Container store_
Definition firstfit.hpp:20
StopCondition stopcond_
Definition selection_boilerplate.hpp:58
ProgressFunction progress_
Definition selection_boilerplate.hpp:57
ConstItemRange< typename Container::const_iterator > rem(typename Container::const_iterator it, const Container &cont)
Definition nester.hpp:534