Welcome to mirror list, hosted at ThFree Co, Russian Federation.

filler.hpp « selections « libnest2d « libnest2d « src « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0da7220a19952d4056eb5455de4193f8d5fe61d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef FILLER_HPP
#define FILLER_HPP

#include "selection_boilerplate.hpp"

namespace libnest2d { namespace selections {

template<class RawShape>
class _FillerSelection: public SelectionBoilerplate<RawShape> {
    using Base = SelectionBoilerplate<RawShape>;
public:
    using typename Base::Item;
    using Config = int; //dummy

private:
    using Base::packed_bins_;
    using typename Base::ItemGroup;
    using Container = ItemGroup;
    Container store_;

public:

    void configure(const Config& /*config*/) { }

    template<class TPlacer, class TIterator,
             class TBin = typename PlacementStrategyLike<TPlacer>::BinType,
             class PConfig = typename PlacementStrategyLike<TPlacer>::Config>
    void packItems(TIterator first,
                   TIterator last,
                   TBin&& bin,
                   PConfig&& pconfig = PConfig())
    {

        store_.clear();
        auto total = last-first;
        store_.reserve(total);
        packed_bins_.emplace_back();

        auto makeProgress = [this, &total](
                PlacementStrategyLike<TPlacer>& placer)
        {
            packed_bins_.back() = placer.getItems();
#ifndef NDEBUG
            packed_bins_.back().insert(packed_bins_.back().end(),
                                       placer.getDebugItems().begin(),
                                       placer.getDebugItems().end());
#endif
            this->progress_(--total);
        };

        std::copy(first, last, std::back_inserter(store_));

        auto sortfunc = [](Item& i1, Item& i2) {
            return i1.area() > i2.area();
        };

        std::sort(store_.begin(), store_.end(), sortfunc);

        PlacementStrategyLike<TPlacer> placer(bin);
        placer.configure(pconfig);

        auto it = store_.begin();
        while(it != store_.end()) {
            if(!placer.pack(*it, {std::next(it), store_.end()}))  {
                if(packed_bins_.back().empty()) ++it;
                placer.clearItems();
                packed_bins_.emplace_back();
            } else {
                makeProgress(placer);
                ++it;
            }
        }

    }
};

}
}

#endif //BOTTOMLEFT_HPP