Further refactoring
This commit is contained in:
parent
b2867f9227
commit
6ae50a710a
@ -65,7 +65,7 @@ void nest(Iterator from, Iterator to,
|
|||||||
const typename Placer::Config& pconf = {},
|
const typename Placer::Config& pconf = {},
|
||||||
const typename Selector::Config& sconf = {})
|
const typename Selector::Config& sconf = {})
|
||||||
{
|
{
|
||||||
Nester<Placer, Selector> nester(bin, dist, pconf, sconf);
|
_Nester<Placer, Selector> nester(bin, dist, pconf, sconf);
|
||||||
nester.execute(from, to);
|
nester.execute(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ void nest(Iterator from, Iterator to,
|
|||||||
const typename Placer::Config& pconf = {},
|
const typename Placer::Config& pconf = {},
|
||||||
const typename Selector::Config& sconf = {})
|
const typename Selector::Config& sconf = {})
|
||||||
{
|
{
|
||||||
Nester<Placer, Selector> nester(bin, dist, pconf, sconf);
|
_Nester<Placer, Selector> nester(bin, dist, pconf, sconf);
|
||||||
if(prg) nester.progressIndicator(prg);
|
if(prg) nester.progressIndicator(prg);
|
||||||
if(scond) nester.stopCondition(scond);
|
if(scond) nester.stopCondition(scond);
|
||||||
nester.execute(from, to);
|
nester.execute(from, to);
|
||||||
|
@ -741,12 +741,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Arranger is the front-end class for the libnest2d library. It takes the
|
* The _Nester is the front-end class for the libnest2d library. It takes the
|
||||||
* input items and outputs the items with the proper transformations to be
|
* input items and changes their transformations to be inside the provided bin.
|
||||||
* inside the provided bin.
|
|
||||||
*/
|
*/
|
||||||
template<class PlacementStrategy, class SelectionStrategy >
|
template<class PlacementStrategy, class SelectionStrategy >
|
||||||
class Nester {
|
class _Nester {
|
||||||
using TSel = SelectionStrategyLike<SelectionStrategy>;
|
using TSel = SelectionStrategyLike<SelectionStrategy>;
|
||||||
TSel selector_;
|
TSel selector_;
|
||||||
public:
|
public:
|
||||||
@ -771,12 +770,12 @@ private:
|
|||||||
using TSItem = remove_cvref_t<SItem>;
|
using TSItem = remove_cvref_t<SItem>;
|
||||||
|
|
||||||
StopCondition stopfn_;
|
StopCondition stopfn_;
|
||||||
|
|
||||||
template<class It> using TVal = remove_cvref_t<typename It::value_type>;
|
template<class It> using TVal = remove_ref_t<typename It::value_type>;
|
||||||
|
|
||||||
template<class It, class Out>
|
template<class It, class Out>
|
||||||
using ConvertibleOnly =
|
using ItemIteratorOnly =
|
||||||
enable_if_t< std::is_convertible<TVal<It>, TPItem>::value, void>;
|
enable_if_t<std::is_convertible<TVal<It>&, TPItem&>::value, Out>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -789,10 +788,8 @@ public:
|
|||||||
template<class TBinType = BinType,
|
template<class TBinType = BinType,
|
||||||
class PConf = PlacementConfig,
|
class PConf = PlacementConfig,
|
||||||
class SConf = SelectionConfig>
|
class SConf = SelectionConfig>
|
||||||
Nester( TBinType&& bin,
|
_Nester(TBinType&& bin, Coord min_obj_distance = 0,
|
||||||
Coord min_obj_distance = 0,
|
const PConf& pconfig = PConf(), const SConf& sconfig = SConf()):
|
||||||
const PConf& pconfig = PConf(),
|
|
||||||
const SConf& sconfig = SConf()):
|
|
||||||
bin_(std::forward<TBinType>(bin)),
|
bin_(std::forward<TBinType>(bin)),
|
||||||
pconfig_(pconfig),
|
pconfig_(pconfig),
|
||||||
min_obj_distance_(min_obj_distance)
|
min_obj_distance_(min_obj_distance)
|
||||||
@ -817,14 +814,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Arrange an input sequence and return a PackGroup object with
|
* \brief Arrange an input sequence of _Item-s.
|
||||||
* the packed groups corresponding to the bins.
|
*
|
||||||
|
* To get the result, call the translation(), rotation() and binId()
|
||||||
|
* methods of each item. If only the transformed polygon is needed, call
|
||||||
|
* transformedShape() to get the properly transformed shapes.
|
||||||
*
|
*
|
||||||
* The number of groups in the pack group is the number of bins opened by
|
* The number of groups in the pack group is the number of bins opened by
|
||||||
* the selection algorithm.
|
* the selection algorithm.
|
||||||
*/
|
*/
|
||||||
template<class It>
|
template<class It>
|
||||||
inline ConvertibleOnly<It, void> execute(It from, It to)
|
inline ItemIteratorOnly<It, void> execute(It from, It to)
|
||||||
{
|
{
|
||||||
auto infl = static_cast<Coord>(std::ceil(min_obj_distance_/2.0));
|
auto infl = static_cast<Coord>(std::ceil(min_obj_distance_/2.0));
|
||||||
if(infl > 0) std::for_each(from, to, [this, infl](Item& item) {
|
if(infl > 0) std::for_each(from, to, [this, infl](Item& item) {
|
||||||
@ -840,13 +840,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set a progress indicator function object for the selector.
|
/// Set a progress indicator function object for the selector.
|
||||||
inline Nester& progressIndicator(ProgressFunction func)
|
inline _Nester& progressIndicator(ProgressFunction func)
|
||||||
{
|
{
|
||||||
selector_.progressIndicator(func); return *this;
|
selector_.progressIndicator(func); return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a predicate to tell when to abort nesting.
|
/// Set a predicate to tell when to abort nesting.
|
||||||
inline Nester& stopCondition(StopCondition fn)
|
inline _Nester& stopCondition(StopCondition fn)
|
||||||
{
|
{
|
||||||
stopfn_ = fn; selector_.stopCondition(fn); return *this;
|
stopfn_ = fn; selector_.stopCondition(fn); return *this;
|
||||||
}
|
}
|
||||||
|
@ -370,7 +370,7 @@ TEST(GeometryAlgorithms, ArrangeRectanglesTight)
|
|||||||
ASSERT_EQ(getX(bin.center()), 105);
|
ASSERT_EQ(getX(bin.center()), 105);
|
||||||
ASSERT_EQ(getY(bin.center()), 125);
|
ASSERT_EQ(getY(bin.center()), 125);
|
||||||
|
|
||||||
Nester<BottomLeftPlacer, DJDHeuristic> arrange(bin);
|
_Nester<BottomLeftPlacer, DJDHeuristic> arrange(bin);
|
||||||
|
|
||||||
arrange.execute(rects.begin(), rects.end());
|
arrange.execute(rects.begin(), rects.end());
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ TEST(GeometryAlgorithms, ArrangeRectanglesLoose)
|
|||||||
|
|
||||||
Coord min_obj_distance = 5;
|
Coord min_obj_distance = 5;
|
||||||
|
|
||||||
Nester<BottomLeftPlacer, DJDHeuristic> arrange(bin, min_obj_distance);
|
_Nester<BottomLeftPlacer, DJDHeuristic> arrange(bin, min_obj_distance);
|
||||||
|
|
||||||
arrange.execute(rects.begin(), rects.end());
|
arrange.execute(rects.begin(), rects.end());
|
||||||
|
|
||||||
|
@ -66,10 +66,6 @@ using Circle = _Circle<clppr::IntPoint>;
|
|||||||
using Segment = _Segment<clppr::IntPoint>;
|
using Segment = _Segment<clppr::IntPoint>;
|
||||||
using MultiPolygon = TMultiShape<clppr::Polygon>;
|
using MultiPolygon = TMultiShape<clppr::Polygon>;
|
||||||
|
|
||||||
// The return value of nesting, a vector (for each logical bed) of Item
|
|
||||||
// reference vectors.
|
|
||||||
using PackGroup = _PackGroup<clppr::Polygon>;
|
|
||||||
|
|
||||||
// Summon the spatial indexing facilities from boost
|
// Summon the spatial indexing facilities from boost
|
||||||
namespace bgi = boost::geometry::index;
|
namespace bgi = boost::geometry::index;
|
||||||
using SpatElement = std::pair<Box, unsigned>;
|
using SpatElement = std::pair<Box, unsigned>;
|
||||||
@ -102,7 +98,7 @@ void fillConfig(PConf& pcfg) {
|
|||||||
pcfg.parallel = true;
|
pcfg.parallel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply penality to object function result. This is used only when alignment
|
// Apply penalty to object function result. This is used only when alignment
|
||||||
// after arrange is explicitly disabled (PConfig::Alignment::DONT_ALIGN)
|
// after arrange is explicitly disabled (PConfig::Alignment::DONT_ALIGN)
|
||||||
double fixed_overfit(const std::tuple<double, Box>& result, const Box &binbb)
|
double fixed_overfit(const std::tuple<double, Box>& result, const Box &binbb)
|
||||||
{
|
{
|
||||||
@ -123,7 +119,7 @@ public:
|
|||||||
// Useful type shortcuts...
|
// Useful type shortcuts...
|
||||||
using Placer = typename placers::_NofitPolyPlacer<clppr::Polygon, TBin>;
|
using Placer = typename placers::_NofitPolyPlacer<clppr::Polygon, TBin>;
|
||||||
using Selector = selections::_FirstFitSelection<clppr::Polygon>;
|
using Selector = selections::_FirstFitSelection<clppr::Polygon>;
|
||||||
using Packer = Nester<Placer, Selector>;
|
using Packer = _Nester<Placer, Selector>;
|
||||||
using PConfig = typename Packer::PlacementConfig;
|
using PConfig = typename Packer::PlacementConfig;
|
||||||
using Distance = TCoord<PointImpl>;
|
using Distance = TCoord<PointImpl>;
|
||||||
|
|
||||||
|
@ -1609,7 +1609,7 @@ struct Plater::priv
|
|||||||
if (m_selected.empty()) m_selected.swap(m_unselected);
|
if (m_selected.empty()) m_selected.swap(m_unselected);
|
||||||
|
|
||||||
// The strides have to be removed from the fixed items. For the
|
// The strides have to be removed from the fixed items. For the
|
||||||
// arrangeable (selected) items it bed_idx is ignored and the
|
// arrangeable (selected) items bed_idx is ignored and the
|
||||||
// translation is irrelevant.
|
// translation is irrelevant.
|
||||||
for (auto &p : m_unselected) p.translation(X) -= p.bed_idx * stride;
|
for (auto &p : m_unselected) p.translation(X) -= p.bed_idx * stride;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user