Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libnest2d::PlacementStrategyLike< PlacementStrategy > Class Template Reference

A wrapper interface (trait) class for any placement strategy provider. More...

#include <src/libnest2d/include/libnest2d/nester.hpp>

Public Types

using RawShape = typename PlacementStrategy::ShapeType
 
using Item = _Item< RawShape >
 The item type that the placer works with.
 
using Config = typename PlacementStrategy::Config
 The placer's config type. Should be a simple struct but can be anything.
 
using BinType = typename PlacementStrategy::BinType
 The type of the bin that the placer works with.
 
using PackResult = typename PlacementStrategy::PackResult
 Pack result that can be used to accept or discard it. See trypack method.
 
using ItemGroup = _ItemGroup< RawShape >
 
using DefaultIterator = typename ItemGroup::const_iterator
 

Public Member Functions

 PlacementStrategyLike (const BinType &bin, const Config &config=Config())
 Constructor taking the bin and an optional configuration.
 
void configure (const Config &config)
 Provide a different configuration for the placer.
 
template<class Iter = DefaultIterator>
PackResult trypack (Item &item, const ConstItemRange< Iter > &remaining=ConstItemRange< Iter >())
 
void accept (PackResult &r)
 A method to accept a previously tried item (or items).
 
template<class Range = ConstItemRange<DefaultIterator>>
bool pack (Item &item, const Range &remaining=Range())
 pack Try to pack and immediately accept it on success.
 
void preload (const ItemGroup &packeditems)
 
void unpackLast ()
 Unpack the last element (remove it from the list of packed items).
 
const BinTypebin () const
 Get the bin object.
 
void bin (const BinType &bin)
 Set a new bin object.
 
ItemGroup getItems ()
 Get the packed items.
 
void clearItems ()
 Clear the packed items so a new session can be started.
 
double filledArea () const
 

Private Attributes

PlacementStrategy impl_
 

Detailed Description

template<class PlacementStrategy>
class libnest2d::PlacementStrategyLike< PlacementStrategy >

A wrapper interface (trait) class for any placement strategy provider.

If a client wants to use its own placement algorithm, all it has to do is to specialize this class template and define all the ten methods it has. It can use the strategies::PlacerBoilerplace class for creating a new placement strategy where only the constructor and the trypack method has to be provided and it will work out of the box.

Member Typedef Documentation

◆ BinType

template<class PlacementStrategy >
using libnest2d::PlacementStrategyLike< PlacementStrategy >::BinType = typename PlacementStrategy::BinType

The type of the bin that the placer works with.

Can be a box or an arbitrary shape or just a width or height without a second dimension if an infinite bin is considered.

◆ Config

template<class PlacementStrategy >
using libnest2d::PlacementStrategyLike< PlacementStrategy >::Config = typename PlacementStrategy::Config

The placer's config type. Should be a simple struct but can be anything.

◆ DefaultIterator

template<class PlacementStrategy >
using libnest2d::PlacementStrategyLike< PlacementStrategy >::DefaultIterator = typename ItemGroup::const_iterator

◆ Item

template<class PlacementStrategy >
using libnest2d::PlacementStrategyLike< PlacementStrategy >::Item = _Item<RawShape>

The item type that the placer works with.

◆ ItemGroup

template<class PlacementStrategy >
using libnest2d::PlacementStrategyLike< PlacementStrategy >::ItemGroup = _ItemGroup<RawShape>

◆ PackResult

template<class PlacementStrategy >
using libnest2d::PlacementStrategyLike< PlacementStrategy >::PackResult = typename PlacementStrategy::PackResult

Pack result that can be used to accept or discard it. See trypack method.

◆ RawShape

template<class PlacementStrategy >
using libnest2d::PlacementStrategyLike< PlacementStrategy >::RawShape = typename PlacementStrategy::ShapeType

Constructor & Destructor Documentation

◆ PlacementStrategyLike()

template<class PlacementStrategy >
libnest2d::PlacementStrategyLike< PlacementStrategy >::PlacementStrategyLike ( const BinType bin,
const Config config = Config() 
)
inlineexplicit

Constructor taking the bin and an optional configuration.

Parameters
binThe bin object whose type is defined by the placement strategy.
configThe configuration for the particular placer.
583 :
584 impl_(bin)
585 {
586 configure(config);
587 }
PlacementStrategy impl_
Definition nester.hpp:549
void configure(const Config &config)
Provide a different configuration for the placer.
Definition nester.hpp:597
const BinType & bin() const
Get the bin object.
Definition nester.hpp:661

References libnest2d::PlacementStrategyLike< PlacementStrategy >::configure().

+ Here is the call graph for this function:

Member Function Documentation

◆ accept()

template<class PlacementStrategy >
void libnest2d::PlacementStrategyLike< PlacementStrategy >::accept ( PackResult r)
inline

A method to accept a previously tried item (or items).

If the pack result is a failure the method should ignore it.

Parameters
rThe result of a previous trypack call.
625{ impl_.accept(r); }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

◆ bin() [1/2]

template<class PlacementStrategy >
const BinType & libnest2d::PlacementStrategyLike< PlacementStrategy >::bin ( ) const
inline

Get the bin object.

661{ return impl_.bin(); }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

Referenced by libnest2d::PlacementStrategyLike< PlacementStrategy >::bin().

+ Here is the caller graph for this function:

◆ bin() [2/2]

template<class PlacementStrategy >
void libnest2d::PlacementStrategyLike< PlacementStrategy >::bin ( const BinType bin)
inline

Set a new bin object.

664{ impl_.bin(bin); }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::bin(), and libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

+ Here is the call graph for this function:

◆ clearItems()

template<class PlacementStrategy >
void libnest2d::PlacementStrategyLike< PlacementStrategy >::clearItems ( )
inline

Clear the packed items so a new session can be started.

670{ impl_.clearItems(); }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

◆ configure()

template<class PlacementStrategy >
void libnest2d::PlacementStrategyLike< PlacementStrategy >::configure ( const Config config)
inline

Provide a different configuration for the placer.

Note that it depends on the particular placer implementation how it reacts to config changes in the middle of a calculation.

Parameters
configThe configuration object defined by the placement strategy.
597{ impl_.configure(config); }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

Referenced by libnest2d::PlacementStrategyLike< PlacementStrategy >::PlacementStrategyLike().

+ Here is the caller graph for this function:

◆ filledArea()

template<class PlacementStrategy >
double libnest2d::PlacementStrategyLike< PlacementStrategy >::filledArea ( ) const
inline

◆ getItems()

template<class PlacementStrategy >
ItemGroup libnest2d::PlacementStrategyLike< PlacementStrategy >::getItems ( )
inline

Get the packed items.

667{ return impl_.getItems(); }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

◆ pack()

template<class PlacementStrategy >
template<class Range = ConstItemRange<DefaultIterator>>
bool libnest2d::PlacementStrategyLike< PlacementStrategy >::pack ( Item item,
const Range &  remaining = Range() 
)
inline

pack Try to pack and immediately accept it on success.

A default implementation would be to call { auto&& r = trypack(...); accept(r); return r; } but we should let the implementor of the placement strategy to harvest any optimizations from the absence of an intermediate step. The above version can still be used in the implementation.

Parameters
itemThe item to pack.
Returns
Returns true if the item was packed or false if it could not be packed.
644 {
645 return impl_.pack(item, remaining);
646 }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

◆ preload()

template<class PlacementStrategy >
void libnest2d::PlacementStrategyLike< PlacementStrategy >::preload ( const ItemGroup packeditems)
inline

This method makes possible to "preload" some items into the placer. It will not move these items but will consider them as already packed.

653 {
654 impl_.preload(packeditems);
655 }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

◆ trypack()

template<class PlacementStrategy >
template<class Iter = DefaultIterator>
PackResult libnest2d::PlacementStrategyLike< PlacementStrategy >::trypack ( Item item,
const ConstItemRange< Iter > &  remaining = ConstItemRange<Iter>() 
)
inline

Try to pack an item with a result object that contains the packing information for later accepting it.

Parameters
item_storeA container of items that are intended to be packed later. Can be used by the placer to switch tactics. When it's knows that many items will come a greedy strategy may not be the best.
fromThe iterator to the item from which the packing should start, including the pointed item
countHow many items should be packed. If the value is 1, than just the item pointed to by "from" argument should be packed.
615 {
616 return impl_.trypack(item, remaining);
617 }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

◆ unpackLast()

template<class PlacementStrategy >
void libnest2d::PlacementStrategyLike< PlacementStrategy >::unpackLast ( )
inline

Unpack the last element (remove it from the list of packed items).

658{ impl_.unpackLast(); }

References libnest2d::PlacementStrategyLike< PlacementStrategy >::impl_.

Member Data Documentation

◆ impl_


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