Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libnest2d::selections::_FillerSelection< RawShape > Class Template Reference

#include <src/libnest2d/include/libnest2d/selections/filler.hpp>

+ Inheritance diagram for libnest2d::selections::_FillerSelection< RawShape >:
+ Collaboration diagram for libnest2d::selections::_FillerSelection< RawShape >:

Public Types

using Config = int
 
using Item = _Item< RawShape >
 
using ShapeType = RawShape
 
using PackGroup = _PackGroup< RawShape >
 

Public Member Functions

void configure (const 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())
 
const PackGroupgetResult () const
 
int lastPackedBinId () const
 
void progressIndicator (ProgressFunction fn)
 
void stopCondition (StopCondition cond)
 
void clear ()
 

Protected Member Functions

template<class Placer , class Container , class Bin , class PCfg >
void remove_unpackable_items (Container &c, const Bin &bin, const PCfg &pcfg)
 

Protected Attributes

ProgressFunction progress_ = [](unsigned){}
 
StopCondition stopcond_ = [](){ return false; }
 
int last_packed_bin_id_ = -1
 

Private Types

using Base = SelectionBoilerplate< RawShape >
 
using Container = ItemGroup
 
using ItemGroup = _ItemGroup< RawShape >
 

Private Attributes

Container store_
 
PackGroup packed_bins_
 

Detailed Description

template<class RawShape>
class libnest2d::selections::_FillerSelection< RawShape >

Member Typedef Documentation

◆ Base

template<class RawShape >
using libnest2d::selections::_FillerSelection< RawShape >::Base = SelectionBoilerplate<RawShape>
private

◆ Config

template<class RawShape >
using libnest2d::selections::_FillerSelection< RawShape >::Config = int

◆ Container

template<class RawShape >
using libnest2d::selections::_FillerSelection< RawShape >::Container = ItemGroup
private

◆ Item

template<class RawShape >
using libnest2d::selections::SelectionBoilerplate< RawShape >::Item = _Item<RawShape>

◆ ItemGroup

template<class RawShape >
using libnest2d::selections::SelectionBoilerplate< RawShape >::ItemGroup = _ItemGroup<RawShape>
private

◆ PackGroup

template<class RawShape >
using libnest2d::selections::SelectionBoilerplate< RawShape >::PackGroup = _PackGroup<RawShape>
inherited

◆ ShapeType

template<class RawShape >
using libnest2d::selections::SelectionBoilerplate< RawShape >::ShapeType = RawShape
inherited

Member Function Documentation

◆ clear()

template<class RawShape >
void libnest2d::selections::SelectionBoilerplate< RawShape >::clear ( )
inlineinherited
27{ packed_bins_.clear(); }
PackGroup packed_bins_
Definition selection_boilerplate.hpp:56

References libnest2d::selections::SelectionBoilerplate< RawShape >::packed_bins_.

◆ configure()

template<class RawShape >
void libnest2d::selections::_FillerSelection< RawShape >::configure ( const Config )
inline
23{ }

◆ getResult()

template<class RawShape >
const PackGroup & libnest2d::selections::SelectionBoilerplate< RawShape >::getResult ( ) const
inlineinherited

◆ lastPackedBinId()

template<class RawShape >
int libnest2d::selections::SelectionBoilerplate< RawShape >::lastPackedBinId ( ) const
inlineinherited

◆ packItems()

template<class RawShape >
template<class TPlacer , class TIterator , class TBin = typename PlacementStrategyLike<TPlacer>::BinType, class PConfig = typename PlacementStrategyLike<TPlacer>::Config>
void libnest2d::selections::_FillerSelection< RawShape >::packItems ( TIterator  first,
TIterator  last,
TBin &&  bin,
PConfig &&  pconfig = PConfig() 
)
inline
32 {
33 using Placer = PlacementStrategyLike<TPlacer>;
34
35 store_.clear();
36 auto total = last-first;
37 store_.reserve(total);
38
39 // TODO: support preloading
40 packed_bins_.clear();
41
42 packed_bins_.emplace_back();
43
44 auto makeProgress = [this, &total](
45 PlacementStrategyLike<TPlacer>& placer)
46 {
47 packed_bins_.back() = placer.getItems();
48#ifndef NDEBUG
49 packed_bins_.back().insert(packed_bins_.back().end(),
50 placer.getDebugItems().begin(),
51 placer.getDebugItems().end());
52#endif
53 this->progress_(--total);
54 };
55
56 std::copy(first, last, std::back_inserter(store_));
57
58 auto sortfunc = [](Item& i1, Item& i2) {
59 return i1.area() > i2.area();
60 };
61
62 this->template remove_unpackable_items<Placer>(store_, bin, pconfig);
63
64 std::sort(store_.begin(), store_.end(), sortfunc);
65
66 Placer placer(bin);
67 placer.configure(pconfig);
68
69 auto it = store_.begin();
70 while(it != store_.end() && !this->stopcond_()) {
71 if(!placer.pack(*it, {std::next(it), store_.end()})) {
72 if(packed_bins_.back().empty()) ++it;
73 placer.clearItems();
74 packed_bins_.emplace_back();
75 } else {
76 makeProgress(placer);
77 ++it;
78 }
79 }
80
81 }
_Item< RawShape > Item
Definition selection_boilerplate.hpp:13
PackGroup packed_bins_
Definition selection_boilerplate.hpp:56
Container store_
Definition filler.hpp:19
ProgressFunction progress_
Definition selection_boilerplate.hpp:57

References libnest2d::_Item< RawShape >::area(), libnest2d::selections::_FillerSelection< RawShape >::packed_bins_, libnest2d::selections::SelectionBoilerplate< RawShape >::progress_, and libnest2d::selections::_FillerSelection< RawShape >::store_.

+ Here is the call graph for this function:

◆ progressIndicator()

template<class RawShape >
void libnest2d::selections::SelectionBoilerplate< RawShape >::progressIndicator ( ProgressFunction  fn)
inlineinherited

◆ remove_unpackable_items()

template<class RawShape >
template<class Placer , class Container , class Bin , class PCfg >
void libnest2d::selections::SelectionBoilerplate< RawShape >::remove_unpackable_items ( Container &  c,
const Bin &  bin,
const PCfg &  pcfg 
)
inlineprotectedinherited
33 {
34 // Safety test: try to pack each item into an empty bin. If it fails
35 // then it should be removed from the list
36 auto it = c.begin();
37 while (it != c.end() && !stopcond_()) {
38
39 // WARNING: The copy of itm needs to be created before Placer.
40 // Placer is working with references and its destructor still
41 // manipulates the item this is why the order of stack creation
42 // matters here.
43 const Item& itm = *it;
44 Item cpy{itm};
45
46 Placer p{bin};
47 p.configure(pcfg);
48 if (itm.area() <= 0 || !p.pack(cpy)) {
49 static_cast<Item&>(*it).binId(BIN_ID_UNSET);
50 it = c.erase(it);
51 }
52 else it++;
53 }
54 }
_Item< RawShape > Item
Definition selection_boilerplate.hpp:13
StopCondition stopcond_
Definition selection_boilerplate.hpp:58
static const constexpr int BIN_ID_UNSET
Definition nester.hpp:15

References libnest2d::_Item< RawShape >::area(), libnest2d::BIN_ID_UNSET, libnest2d::_Item< RawShape >::binId(), and libnest2d::selections::SelectionBoilerplate< RawShape >::stopcond_.

+ Here is the call graph for this function:

◆ stopCondition()

template<class RawShape >
void libnest2d::selections::SelectionBoilerplate< RawShape >::stopCondition ( StopCondition  cond)
inlineinherited

Member Data Documentation

◆ last_packed_bin_id_

◆ packed_bins_

template<class RawShape >
PackGroup libnest2d::selections::SelectionBoilerplate< RawShape >::packed_bins_
private

◆ progress_

◆ stopcond_

◆ store_


The documentation for this class was generated from the following file: