Unify AutoArranger subclasses

This commit is contained in:
tamasmeszaros 2019-07-02 12:15:53 +02:00
parent ba82cbe007
commit 914bf63228
2 changed files with 301 additions and 268 deletions

View file

@ -774,14 +774,14 @@ public:
using BinType = typename TPlacer::BinType; using BinType = typename TPlacer::BinType;
using PlacementConfig = typename TPlacer::Config; using PlacementConfig = typename TPlacer::Config;
using SelectionConfig = typename TSel::Config; using SelectionConfig = typename TSel::Config;
using Unit = TCoord<TPoint<typename Item::ShapeType>>; using Coord = TCoord<TPoint<typename Item::ShapeType>>;
using PackGroup = _PackGroup<typename Item::ShapeType>; using PackGroup = _PackGroup<typename Item::ShapeType>;
using ResultType = PackGroup; using ResultType = PackGroup;
private: private:
BinType bin_; BinType bin_;
PlacementConfig pconfig_; PlacementConfig pconfig_;
Unit min_obj_distance_; Coord min_obj_distance_;
using SItem = typename SelectionStrategy::Item; using SItem = typename SelectionStrategy::Item;
using TPItem = remove_cvref_t<Item>; using TPItem = remove_cvref_t<Item>;
@ -802,7 +802,7 @@ public:
class PConf = PlacementConfig, class PConf = PlacementConfig,
class SConf = SelectionConfig> class SConf = SelectionConfig>
Nester( TBinType&& bin, Nester( TBinType&& bin,
Unit min_obj_distance = 0, Coord min_obj_distance = 0,
const PConf& pconfig = PConf(), const PConf& pconfig = PConf(),
const SConf& sconfig = SConf()): const SConf& sconfig = SConf()):
bin_(std::forward<TBinType>(bin)), bin_(std::forward<TBinType>(bin)),
@ -895,7 +895,7 @@ private:
template<class TIter> inline void __execute(TIter from, TIter to) template<class TIter> inline void __execute(TIter from, TIter to)
{ {
if(min_obj_distance_ > 0) std::for_each(from, to, [this](Item& item) { if(min_obj_distance_ > 0) std::for_each(from, to, [this](Item& item) {
item.addOffset(static_cast<Unit>(std::ceil(min_obj_distance_/2.0))); item.addOffset(static_cast<Coord>(std::ceil(min_obj_distance_/2.0)));
}); });
selector_.template packItems<PlacementStrategy>( selector_.template packItems<PlacementStrategy>(

View file

@ -171,24 +171,76 @@ Box boundingBox(const Box& pilebb, const Box& ibb ) {
return Box(minc, maxc); return Box(minc, maxc);
} }
// This is "the" object function which is evaluated many times for each vertex // Fill in the placer algorithm configuration with values carefully chosen for
// (decimated with the accuracy parameter) of each object. Therefore it is // Slic3r.
// upmost crucial for this function to be as efficient as it possibly can be but template<class PConf>
// at the same time, it has to provide reasonable results. void fillConfig(PConf& pcfg) {
std::tuple<double /*score*/, Box /*farthest point from bin center*/>
objfunc(const PointImpl& bincenter, // Align the arranged pile into the center of the bin
const MultiPolygon& merged_pile, pcfg.alignment = PConf::Alignment::CENTER;
const Box& pilebb,
const ItemGroup& items, // Start placing the items from the center of the print bed
const Item &item, pcfg.starting_point = PConf::Alignment::CENTER;
double bin_area,
double norm, // A norming factor for physical dimensions // TODO cannot use rotations until multiple objects of same geometry can
// a spatial index to quickly get neighbors of the candidate item // handle different rotations
const SpatIndex& spatindex, // arranger.useMinimumBoundigBoxRotation();
const SpatIndex& smalls_spatindex, pcfg.rotations = { 0.0 };
const ItemGroup& remaining
) // The accuracy of optimization.
{ // Goes from 0.0 to 1.0 and scales performance as well
pcfg.accuracy = 0.65f;
pcfg.parallel = true;
}
// Type trait for an arranger class for different bin types (box, circle,
// polygon, etc...)
//template<class TBin>
//class AutoArranger {};
template<class Bin> clppr::IntPoint center(const Bin& bin) { return bin.center(); }
template<> clppr::IntPoint center(const clppr::Polygon &bin) { return sl::boundingBox(bin).center(); }
// A class encapsulating the libnest2d Nester class and extending it with other
// management and spatial index structures for acceleration.
template<class TBin>
class AutoArranger {
public:
// Useful type shortcuts...
using Placer = typename placers::_NofitPolyPlacer<clppr::Polygon, TBin>;
using Selector = selections::_FirstFitSelection<clppr::Polygon>;
using Packer = Nester<Placer, Selector>;
using PConfig = typename Packer::PlacementConfig;
using Distance = TCoord<PointImpl>;
protected:
Packer m_pck;
PConfig m_pconf; // Placement configuration
TBin m_bin;
double m_bin_area; // caching
PointImpl m_bincenter; // caching
SpatIndex m_rtree; // spatial index for the normal (bigger) objects
SpatIndex m_smallsrtree; // spatial index for only the smaller items
double m_norm; // A coefficient to scale distances
MultiPolygon m_merged_pile; // The already merged pile (vector of items)
Box m_pilebb; // The bounding box of the merged pile.
ItemGroup m_remaining; // Remaining items (m_items at the beginning)
ItemGroup m_items; // The items to be packed
// This is "the" object function which is evaluated many times for each
// vertex (decimated with the accuracy parameter) of each object.
// Therefore it is upmost crucial for this function to be as efficient
// as it possibly can be but at the same time, it has to provide
// reasonable results.
std::tuple<double /*score*/, Box /*farthest point from bin center*/>
objfunc(const Item &item )
{
const double bin_area = m_bin_area;
const SpatIndex& spatindex = m_rtree;
const SpatIndex& smalls_spatindex = m_smallsrtree;
const ItemGroup& remaining = m_remaining;
// We will treat big items (compared to the print bed) differently // We will treat big items (compared to the print bed) differently
auto isBig = [bin_area](double a) { auto isBig = [bin_area](double a) {
return a/bin_area > BIG_ITEM_TRESHOLD ; return a/bin_area > BIG_ITEM_TRESHOLD ;
@ -198,7 +250,7 @@ objfunc(const PointImpl& bincenter,
auto ibb = sl::boundingBox(item.transformedShape()); auto ibb = sl::boundingBox(item.transformedShape());
// Calculate the full bounding box of the pile with the candidate item // Calculate the full bounding box of the pile with the candidate item
auto fullbb = boundingBox(pilebb, ibb); auto fullbb = boundingBox(m_pilebb, ibb);
// The bounding box of the big items (they will accumulate in the center // The bounding box of the big items (they will accumulate in the center
// of the pile // of the pile
@ -233,8 +285,8 @@ objfunc(const PointImpl& bincenter,
dists[4] = pl::distance(bottom_right, cc); dists[4] = pl::distance(bottom_right, cc);
// The smalles distance from the arranged pile center: // The smalles distance from the arranged pile center:
auto dist = *(std::min_element(dists.begin(), dists.end())) / norm; double dist = *(std::min_element(dists.begin(), dists.end())) / m_norm;
auto bindist = pl::distance(ibb.center(), bincenter) / norm; double bindist = pl::distance(ibb.center(), m_bincenter) / m_norm;
dist = 0.8*dist + 0.2*bindist; dist = 0.8*dist + 0.2*bindist;
// Density is the pack density: how big is the arranged pile // Density is the pack density: how big is the arranged pile
@ -242,27 +294,28 @@ objfunc(const PointImpl& bincenter,
if(remaining.empty()) { if(remaining.empty()) {
auto mp = merged_pile; auto mp = m_merged_pile;
mp.emplace_back(item.transformedShape()); mp.emplace_back(item.transformedShape());
auto chull = sl::convexHull(mp); auto chull = sl::convexHull(mp);
placers::EdgeCache<clppr::Polygon> ec(chull); placers::EdgeCache<clppr::Polygon> ec(chull);
double circ = ec.circumference() / norm; double circ = ec.circumference() / m_norm;
double bcirc = 2.0*(fullbb.width() + fullbb.height()) / norm; double bcirc = 2.0*(fullbb.width() + fullbb.height()) / m_norm;
score = 0.5*circ + 0.5*bcirc; score = 0.5*circ + 0.5*bcirc;
} else { } else {
// Prepare a variable for the alignment score. // Prepare a variable for the alignment score.
// This will indicate: how well is the candidate item aligned with // This will indicate: how well is the candidate item
// its neighbors. We will check the alignment with all neighbors and // aligned with its neighbors. We will check the alignment
// return the score for the best alignment. So it is enough for the // with all neighbors and return the score for the best
// candidate to be aligned with only one item. // alignment. So it is enough for the candidate to be
// aligned with only one item.
auto alignment_score = 1.0; auto alignment_score = 1.0;
density = std::sqrt((fullbb.width() / norm )*
(fullbb.height() / norm));
auto querybb = item.boundingBox(); auto querybb = item.boundingBox();
density = std::sqrt((fullbb.width() / m_norm )*
(fullbb.height() / m_norm));
// Query the spatial index for the neighbors // Query the spatial index for the neighbors
std::vector<SpatElement> result; std::vector<SpatElement> result;
@ -275,9 +328,10 @@ objfunc(const PointImpl& bincenter,
std::back_inserter(result)); std::back_inserter(result));
} }
for(auto& e : result) { // now get the score for the best alignment // now get the score for the best alignment
for(auto& e : result) {
auto idx = e.second; auto idx = e.second;
Item& p = items[idx]; Item& p = m_items[idx];
auto parea = p.area(); auto parea = p.area();
if(std::abs(1.0 - parea/item.area()) < 1e-6) { if(std::abs(1.0 - parea/item.area()) < 1e-6) {
auto bb = boundingBox(p.boundingBox(), ibb); auto bb = boundingBox(p.boundingBox(), ibb);
@ -288,10 +342,10 @@ objfunc(const PointImpl& bincenter,
} }
} }
// The final mix of the score is the balance between the distance // The final mix of the score is the balance between the
// from the full pile center, the pack density and the // distance from the full pile center, the pack density and
// alignment with the neighbors // the alignment with the neighbors
if(result.empty()) if (result.empty())
score = 0.5 * dist + 0.5 * density; score = 0.5 * dist + 0.5 * density;
else else
score = 0.40 * dist + 0.40 * density + 0.2 * alignment_score; score = 0.40 * dist + 0.40 * density + 0.2 * alignment_score;
@ -301,70 +355,24 @@ objfunc(const PointImpl& bincenter,
// already processed bigger items. // already processed bigger items.
// No need to play around with the anchor points, the center will be // No need to play around with the anchor points, the center will be
// just fine for small items // just fine for small items
score = pl::distance(ibb.center(), bigbb.center()) / norm; score = pl::distance(ibb.center(), bigbb.center()) / m_norm;
} }
return std::make_tuple(score, fullbb); return std::make_tuple(score, fullbb);
} }
// Fill in the placer algorithm configuration with values carefully chosen for std::function<double(const Item&)> get_objfn();
// Slic3r.
template<class PConf>
void fillConfig(PConf& pcfg) {
// Align the arranged pile into the center of the bin
pcfg.alignment = PConf::Alignment::CENTER;
// Start placing the items from the center of the print bed
pcfg.starting_point = PConf::Alignment::CENTER;
// TODO cannot use rotations until multiple objects of same geometry can
// handle different rotations
// arranger.useMinimumBoundigBoxRotation();
pcfg.rotations = { 0.0 };
// The accuracy of optimization.
// Goes from 0.0 to 1.0 and scales performance as well
pcfg.accuracy = 0.65f;
pcfg.parallel = true;
}
// Type trait for an arranger class for different bin types (box, circle,
// polygon, etc...)
template<class TBin>
class AutoArranger {};
// A class encapsulating the libnest2d Nester class and extending it with other
// management and spatial index structures for acceleration.
template<class TBin>
class _ArrBase {
public:
// Useful type shortcuts...
using Placer = typename placers::_NofitPolyPlacer<clppr::Polygon, TBin>;
using Selector = selections::_FirstFitSelection<clppr::Polygon>;
using Packer = Nester<Placer, Selector>;
using PConfig = typename Packer::PlacementConfig;
using Distance = TCoord<PointImpl>;
protected:
Packer m_pck;
PConfig m_pconf; // Placement configuration
double m_bin_area;
SpatIndex m_rtree; // spatial index for the normal (bigger) objects
SpatIndex m_smallsrtree; // spatial index for only the smaller items
double m_norm; // A coefficient to scale distances
MultiPolygon m_merged_pile; // The already merged pile (vector of items)
Box m_pilebb; // The bounding box of the merged pile.
ItemGroup m_remaining; // Remaining items (m_items at the beginning)
ItemGroup m_items; // The items to be packed
public: public:
_ArrBase(const TBin& bin, Distance dist, AutoArranger(const TBin & bin,
Distance dist,
std::function<void(unsigned)> progressind, std::function<void(unsigned)> progressind,
std::function<bool(void)> stopcond): std::function<bool(void)> stopcond)
m_pck(bin, dist), m_bin_area(sl::area(bin)), : m_pck(bin, dist)
m_norm(std::sqrt(m_bin_area)) , m_bin(bin)
, m_bin_area(sl::area(bin))
, m_bincenter(center(bin))
, m_norm(std::sqrt(m_bin_area))
{ {
fillConfig(m_pconf); fillConfig(m_pconf);
@ -396,8 +404,12 @@ public:
} }
}; };
m_pconf.object_function = get_objfn();
if (progressind) m_pck.progressIndicator(progressind); if (progressind) m_pck.progressIndicator(progressind);
if (stopcond) m_pck.stopCondition(stopcond); if (stopcond) m_pck.stopCondition(stopcond);
m_pck.configure(m_pconf);
} }
template<class...Args> inline PackGroup operator()(Args&&...args) { template<class...Args> inline PackGroup operator()(Args&&...args) {
@ -405,15 +417,16 @@ public:
return m_pck.execute(std::forward<Args>(args)...); return m_pck.execute(std::forward<Args>(args)...);
} }
inline void preload(const PackGroup& pg) { inline void preload(std::vector<Item>& fixeditems) {
m_pconf.alignment = PConfig::Alignment::DONT_ALIGN; m_pconf.alignment = PConfig::Alignment::DONT_ALIGN;
m_pconf.object_function = nullptr; // drop the special objectfunction // m_pconf.object_function = nullptr; // drop the special objectfunction
m_pck.preload(pg); // m_pck.preload(pg);
// Build the rtree for queries to work // Build the rtree for queries to work
for(const ItemGroup& grp : pg)
for(unsigned idx = 0; idx < grp.size(); ++idx) { for(unsigned idx = 0; idx < fixeditems.size(); ++idx) {
Item& itm = grp[idx]; Item& itm = fixeditems[idx];
itm.markAsFixed();
m_rtree.insert({itm.boundingBox(), idx}); m_rtree.insert({itm.boundingBox(), idx});
} }
@ -429,72 +442,27 @@ public:
} }
}; };
// Arranger specialization for a Box shaped bin. template<> std::function<double(const Item&)> AutoArranger<Box>::get_objfn()
template<> class AutoArranger<Box>: public _ArrBase<Box> { {
public: return [this](const Item &itm) {
auto result = objfunc(itm);
AutoArranger(const Box& bin, Distance dist,
std::function<void(unsigned)> progressind = [](unsigned){},
std::function<bool(void)> stopcond = [](){return false;}):
_ArrBase<Box>(bin, dist, progressind, stopcond)
{
// Here we set up the actual object function that calls the common
// object function for all bin shapes than does an additional inside
// check for the arranged pile.
m_pconf.object_function = [this, bin] (const Item &item) {
auto result = objfunc(bin.center(),
m_merged_pile,
m_pilebb,
m_items,
item,
m_bin_area,
m_norm,
m_rtree,
m_smallsrtree,
m_remaining);
double score = std::get<0>(result); double score = std::get<0>(result);
auto& fullbb = std::get<1>(result); auto& fullbb = std::get<1>(result);
double miss = Placer::overfit(fullbb, bin); double miss = Placer::overfit(fullbb, m_bin);
miss = miss > 0? miss : 0; miss = miss > 0? miss : 0;
score += miss*miss; score += miss*miss;
return score; return score;
}; };
m_pck.configure(m_pconf);
}
};
inline Circle to_lnCircle(const CircleBed& circ) {
return Circle({circ.center()(0), circ.center()(1)}, circ.radius());
} }
// Arranger specialization for circle shaped bin. template<> std::function<double(const Item&)> AutoArranger<Circle>::get_objfn()
template<> class AutoArranger<Circle>: public _ArrBase<Circle> { {
public: return [this](const Item &item) {
AutoArranger(const Circle& bin, Distance dist, auto result = objfunc(item);
std::function<void(unsigned)> progressind = [](unsigned){},
std::function<bool(void)> stopcond = [](){return false;}):
_ArrBase<Circle>(bin, dist, progressind, stopcond) {
// As with the box, only the inside check is different.
m_pconf.object_function = [this, &bin] (const Item &item) {
auto result = objfunc(bin.center(),
m_merged_pile,
m_pilebb,
m_items,
item,
m_bin_area,
m_norm,
m_rtree,
m_smallsrtree,
m_remaining);
double score = std::get<0>(result); double score = std::get<0>(result);
@ -506,48 +474,112 @@ public:
auto mp = m_merged_pile; auto mp = m_merged_pile;
mp.push_back(item.transformedShape()); mp.push_back(item.transformedShape());
auto chull = sl::convexHull(mp); auto chull = sl::convexHull(mp);
double miss = Placer::overfit(chull, bin); double miss = Placer::overfit(chull, m_bin);
if(miss < 0) miss = 0; if(miss < 0) miss = 0;
score += miss*miss; score += miss*miss;
} }
return score; return score;
}; };
}
m_pck.configure(m_pconf); template<> std::function<double(const Item&)> AutoArranger<clppr::Polygon>::get_objfn()
} {
}; return [this] (const Item &item) { return std::get<0>(objfunc(item)); };
}
// Arranger specialization for a Box shaped bin.
//template<> class AutoArranger<Box>: public _ArrBase<Box> {
//public:
// AutoArranger(const Box& bin, Distance dist,
// std::function<void(unsigned)> progressind = [](unsigned){},
// std::function<bool(void)> stopcond = [](){return false;}):
// _ArrBase<Box>(bin, dist, progressind, stopcond)
// {
// // Here we set up the actual object function that calls the common
// // object function for all bin shapes than does an additional inside
// // check for the arranged pile.
// m_pconf.object_function = [this, bin](const Item &item) {
// auto result = objfunc(bin.center(), item);
// double score = std::get<0>(result);
// auto& fullbb = std::get<1>(result);
// double miss = Placer::overfit(fullbb, bin);
// miss = miss > 0? miss : 0;
// score += miss*miss;
// return score;
// };
// m_pck.configure(m_pconf);
// }
//};
inline Circle to_lnCircle(const CircleBed& circ) {
return Circle({circ.center()(0), circ.center()(1)}, circ.radius());
}
//// Arranger specialization for circle shaped bin.
//template<> class AutoArranger<Circle>: public _ArrBase<Circle> {
//public:
// AutoArranger(const Circle& bin, Distance dist,
// std::function<void(unsigned)> progressind = [](unsigned){},
// std::function<bool(void)> stopcond = [](){return false;}):
// _ArrBase<Circle>(bin, dist, progressind, stopcond) {
// // As with the box, only the inside check is different.
// m_pconf.object_function = [this, &bin](const Item &item) {
// auto result = objfunc(bin.center(), item);
// double score = std::get<0>(result);
// auto isBig = [this](const Item& itm) {
// return itm.area()/m_bin_area > BIG_ITEM_TRESHOLD ;
// };
// if(isBig(item)) {
// auto mp = m_merged_pile;
// mp.push_back(item.transformedShape());
// auto chull = sl::convexHull(mp);
// double miss = Placer::overfit(chull, bin);
// if(miss < 0) miss = 0;
// score += miss*miss;
// }
// return score;
// };
// m_pck.configure(m_pconf);
// }
//};
// Arranger specialization for a generalized polygon. // Arranger specialization for a generalized polygon.
// Warning: this is unfinished business. It may or may not work. // Warning: this is unfinished business. It may or may not work.
template<> class AutoArranger<PolygonImpl>: public _ArrBase<PolygonImpl> { //template<> class AutoArranger<PolygonImpl>: public _ArrBase<PolygonImpl> {
public: //public:
AutoArranger(const PolygonImpl& bin, Distance dist, // AutoArranger(const PolygonImpl& bin, Distance dist,
std::function<void(unsigned)> progressind = [](unsigned){}, // std::function<void(unsigned)> progressind = [](unsigned){},
std::function<bool(void)> stopcond = [](){return false;}): // std::function<bool(void)> stopcond = [](){return false;}):
_ArrBase<PolygonImpl>(bin, dist, progressind, stopcond) // _ArrBase<PolygonImpl>(bin, dist, progressind, stopcond)
{ // {
m_pconf.object_function = [this, &bin] (const Item &item) { // m_pconf.object_function = [this, &bin] (const Item &item) {
auto binbb = sl::boundingBox(bin); // auto binbb = sl::boundingBox(bin);
auto result = objfunc(binbb.center(), // auto result = objfunc(binbb.center(), item);
m_merged_pile, // double score = std::get<0>(result);
m_pilebb,
m_items,
item,
m_bin_area,
m_norm,
m_rtree,
m_smallsrtree,
m_remaining);
double score = std::get<0>(result);
return score; // return score;
}; // };
m_pck.configure(m_pconf); // m_pck.configure(m_pconf);
} // }
}; //};
// Get the type of bed geometry from a simple vector of points. // Get the type of bed geometry from a simple vector of points.
BedShapeHint bedShape(const Polyline &bed) { BedShapeHint bedShape(const Polyline &bed) {
@ -628,9 +660,9 @@ BedShapeHint bedShape(const Polyline &bed) {
return ret; return ret;
} }
template<class BinT> template<class BinT> // Arrange for arbitrary bin type
PackGroup _arrange(std::vector<Item> & shapes, PackGroup _arrange(std::vector<Item> & shapes,
const PackGroup & preshapes, std::vector<Item> & excludes,
const BinT & bin, const BinT & bin,
coord_t minobjd, coord_t minobjd,
std::function<void(unsigned)> prind, std::function<void(unsigned)> prind,
@ -638,9 +670,13 @@ PackGroup _arrange(std::vector<Item> & shapes,
{ {
AutoArranger<BinT> arranger{bin, minobjd, prind, stopfn}; AutoArranger<BinT> arranger{bin, minobjd, prind, stopfn};
for(auto it = excludes.begin(); it != excludes.end(); ++it)
if (!sl::isInside(it->transformedShape(), bin))
it = excludes.erase(it);
// If there is something on the plate // If there is something on the plate
if(!preshapes.empty() && !preshapes.front().empty()) { if(!excludes.empty()) {
arranger.preload(preshapes); // arranger.preload(preshapes);
auto binbb = sl::boundingBox(bin); auto binbb = sl::boundingBox(bin);
// Try to put the first item to the center, as the arranger will not // Try to put the first item to the center, as the arranger will not
@ -652,7 +688,8 @@ PackGroup _arrange(std::vector<Item> & shapes,
itm.translate(d); itm.translate(d);
if (!arranger.is_colliding(itm)) { if (!arranger.is_colliding(itm)) {
arranger.preload({{itm}}); itm.markAsFixed();
// arranger.preload({{itm}});
// Write the transformation data into the item. The callback // Write the transformation data into the item. The callback
// was set on the instantiation of Item and calls the // was set on the instantiation of Item and calls the
@ -674,8 +711,8 @@ inline SLIC3R_CONSTEXPR coord_t stride_padding(coord_t w)
return w + w / 5; return w + w / 5;
} }
//// The final client function to arrange the Model. A progress indicator and // The final client function for arrangement. A progress indicator and
//// a stop predicate can be also be passed to control the process. // a stop predicate can be also be passed to control the process.
bool arrange(ArrangeablePtrs & arrangables, bool arrange(ArrangeablePtrs & arrangables,
const ArrangeablePtrs & excludes, const ArrangeablePtrs & excludes,
coord_t min_obj_distance, coord_t min_obj_distance,
@ -686,12 +723,10 @@ bool arrange(ArrangeablePtrs & arrangables,
bool ret = true; bool ret = true;
namespace clppr = ClipperLib; namespace clppr = ClipperLib;
std::vector<Item> items, excluded_items; std::vector<Item> items, fixeditems;
items.reserve(arrangables.size()); items.reserve(arrangables.size());
coord_t binwidth = 0; coord_t binwidth = 0;
PackGroup preshapes{ {} }; // pack group with one initial bin for preloading
auto process_arrangeable = auto process_arrangeable =
[](const Arrangeable * arrangeable, [](const Arrangeable * arrangeable,
std::vector<Item> & outp, std::vector<Item> & outp,
@ -733,9 +768,7 @@ bool arrange(ArrangeablePtrs & arrangables,
} }
for (const Arrangeable * fixed: excludes) for (const Arrangeable * fixed: excludes)
process_arrangeable(fixed, excluded_items, nullptr); process_arrangeable(fixed, fixeditems, nullptr);
for(Item& excl : excluded_items) preshapes.front().emplace_back(excl);
// Integer ceiling the min distance from the bed perimeters // Integer ceiling the min distance from the bed perimeters
coord_t md = min_obj_distance - SCALED_EPSILON; coord_t md = min_obj_distance - SCALED_EPSILON;
@ -751,7 +784,7 @@ bool arrange(ArrangeablePtrs & arrangables,
Box binbb{{bbb.min(X), bbb.min(Y)}, {bbb.max(X), bbb.max(Y)}}; Box binbb{{bbb.min(X), bbb.min(Y)}, {bbb.max(X), bbb.max(Y)}};
binwidth = coord_t(binbb.width()); binwidth = coord_t(binbb.width());
_arrange(items, preshapes, binbb, min_obj_distance, progressind, cfn); _arrange(items, fixeditems, binbb, min_obj_distance, progressind, cfn);
break; break;
} }
case BedShapeType::CIRCLE: { case BedShapeType::CIRCLE: {
@ -759,7 +792,7 @@ bool arrange(ArrangeablePtrs & arrangables,
auto cc = to_lnCircle(c); auto cc = to_lnCircle(c);
binwidth = scaled(c.radius()); binwidth = scaled(c.radius());
_arrange(items, preshapes, cc, min_obj_distance, progressind, cfn); _arrange(items, fixeditems, cc, min_obj_distance, progressind, cfn);
break; break;
} }
case BedShapeType::IRREGULAR: { case BedShapeType::IRREGULAR: {
@ -768,7 +801,7 @@ bool arrange(ArrangeablePtrs & arrangables,
BoundingBox polybb(bedhint.shape.polygon); BoundingBox polybb(bedhint.shape.polygon);
binwidth = (polybb.max(X) - polybb.min(X)); binwidth = (polybb.max(X) - polybb.min(X));
_arrange(items, preshapes, irrbed, min_obj_distance, progressind, cfn); _arrange(items, fixeditems, irrbed, min_obj_distance, progressind, cfn);
break; break;
} }
case BedShapeType::INFINITE: { case BedShapeType::INFINITE: {
@ -776,12 +809,12 @@ bool arrange(ArrangeablePtrs & arrangables,
//Box infbb{{nobin.center.x(), nobin.center.y()}}; //Box infbb{{nobin.center.x(), nobin.center.y()}};
Box infbb; Box infbb;
_arrange(items, preshapes, infbb, min_obj_distance, progressind, cfn); _arrange(items, fixeditems, infbb, min_obj_distance, progressind, cfn);
break; break;
} }
case BedShapeType::UNKNOWN: { case BedShapeType::UNKNOWN: {
// We know nothing about the bed, let it be infinite and zero centered // We know nothing about the bed, let it be infinite and zero centered
_arrange(items, preshapes, Box{}, min_obj_distance, progressind, cfn); _arrange(items, fixeditems, Box{}, min_obj_distance, progressind, cfn);
break; break;
} }
}; };
@ -791,7 +824,7 @@ bool arrange(ArrangeablePtrs & arrangables,
return ret; return ret;
} }
/// Arrange, without the fixed items (excludes) // Arrange, without the fixed items (excludes)
bool arrange(ArrangeablePtrs & inp, bool arrange(ArrangeablePtrs & inp,
coord_t min_d, coord_t min_d,
const BedShapeHint & bedhint, const BedShapeHint & bedhint,