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

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2019-09-10 14:31:29 +0300
committertamasmeszaros <meszaros.q@gmail.com>2019-09-10 14:31:29 +0300
commit1c20c4c43d4c3c448e599c9d169749f522bb8ea5 (patch)
treedb665e8b93c1859a471d9b006042808bee80bf06 /src/libnest2d
parent2fef16c39aea81831ac376caae472b51082d6582 (diff)
Fix arrangement of objects larger than the print bed. Issue #2897
Diffstat (limited to 'src/libnest2d')
-rw-r--r--src/libnest2d/include/libnest2d/placers/nfpplacer.hpp16
-rw-r--r--src/libnest2d/include/libnest2d/selections/djd_heuristic.hpp11
-rw-r--r--src/libnest2d/include/libnest2d/selections/filler.hpp9
-rw-r--r--src/libnest2d/include/libnest2d/selections/firstfit.hpp13
-rw-r--r--src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp15
5 files changed, 38 insertions, 26 deletions
diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp
index 4ef1fe71d..1a341d691 100644
--- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp
+++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp
@@ -546,7 +546,12 @@ public:
inline explicit _NofitPolyPlacer(const BinType& bin):
Base(bin),
- norm_(std::sqrt(sl::area(bin))) {}
+ norm_(std::sqrt(sl::area(bin)))
+ {
+ // In order to not have items out of bin, it will be shrinked by an
+ // very little empiric offset value.
+ // sl::offset(bin_, 1e-5 * norm_);
+ }
_NofitPolyPlacer(const _NofitPolyPlacer&) = default;
_NofitPolyPlacer& operator=(const _NofitPolyPlacer&) = default;
@@ -1179,7 +1184,14 @@ private:
}
void setInitialPosition(Item& item) {
- Box&& bb = item.boundingBox();
+ auto sh = item.rawShape();
+ sl::translate(sh, item.translation());
+ sl::rotate(sh, item.rotation());
+
+ Box bb = sl::boundingBox(sh);
+ bb.minCorner() += item.translation();
+ bb.maxCorner() += item.translation();
+
Vertex ci, cb;
auto bbin = sl::boundingBox(bin_);
diff --git a/src/libnest2d/include/libnest2d/selections/djd_heuristic.hpp b/src/libnest2d/include/libnest2d/selections/djd_heuristic.hpp
index f904210aa..30ee7b627 100644
--- a/src/libnest2d/include/libnest2d/selections/djd_heuristic.hpp
+++ b/src/libnest2d/include/libnest2d/selections/djd_heuristic.hpp
@@ -550,16 +550,7 @@ public:
return ret;
};
- // Safety test: try to pack each item into an empty bin. If it fails
- // then it should be removed from the not_packed list
- { auto it = store_.begin();
- while (it != store_.end() && !this->stopcond_()) {
- Placer p(bin); p.configure(pconfig);
- if(!p.pack(*it, rem(it, store_))) {
- it = store_.erase(it);
- } else it++;
- }
- }
+ this->template remove_unpackable_items<Placer>(store_, bin, pconfig);
int acounter = int(store_.size());
std::atomic_flag flg = ATOMIC_FLAG_INIT;
diff --git a/src/libnest2d/include/libnest2d/selections/filler.hpp b/src/libnest2d/include/libnest2d/selections/filler.hpp
index 19c44bfaa..3b6527d3e 100644
--- a/src/libnest2d/include/libnest2d/selections/filler.hpp
+++ b/src/libnest2d/include/libnest2d/selections/filler.hpp
@@ -30,7 +30,8 @@ public:
TBin&& bin,
PConfig&& pconfig = PConfig())
{
-
+ using Placer = PlacementStrategyLike<TPlacer>;
+
store_.clear();
auto total = last-first;
store_.reserve(total);
@@ -57,10 +58,12 @@ public:
auto sortfunc = [](Item& i1, Item& i2) {
return i1.area() > i2.area();
};
-
+
+ this->template remove_unpackable_items<Placer>(store_, bin, pconfig);
+
std::sort(store_.begin(), store_.end(), sortfunc);
- PlacementStrategyLike<TPlacer> placer(bin);
+ Placer placer(bin);
placer.configure(pconfig);
auto it = store_.begin();
diff --git a/src/libnest2d/include/libnest2d/selections/firstfit.hpp b/src/libnest2d/include/libnest2d/selections/firstfit.hpp
index 5585e565d..373e8b618 100644
--- a/src/libnest2d/include/libnest2d/selections/firstfit.hpp
+++ b/src/libnest2d/include/libnest2d/selections/firstfit.hpp
@@ -77,17 +77,8 @@ public:
};
auto& cancelled = this->stopcond_;
-
- // Safety test: try to pack each item into an empty bin. If it fails
- // then it should be removed from the list
- { auto it = store_.begin();
- while (it != store_.end() && !cancelled()) {
- Placer p(bin); p.configure(pconfig);
- if(!p.pack(*it)) {
- it = store_.erase(it);
- } else it++;
- }
- }
+
+ this->template remove_unpackable_items<Placer>(store_, bin, pconfig);
auto it = store_.begin();
diff --git a/src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp b/src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp
index 9ae92fe29..741893078 100644
--- a/src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp
+++ b/src/libnest2d/include/libnest2d/selections/selection_boilerplate.hpp
@@ -25,6 +25,21 @@ public:
inline void clear() { packed_bins_.clear(); }
protected:
+
+ template<class Placer, class Container, class Bin, class PCfg>
+ void remove_unpackable_items(Container &c, const Bin &bin, const PCfg& pcfg)
+ {
+ // Safety test: try to pack each item into an empty bin. If it fails
+ // then it should be removed from the list
+ auto it = c.begin();
+ while (it != c.end() && !stopcond_()) {
+ Placer p{bin};
+ p.configure(pcfg);
+ Item cpy{*it};
+ if (!p.pack(cpy)) it = c.erase(it);
+ else it++;
+ }
+ }
PackGroup packed_bins_;
ProgressFunction progress_ = [](unsigned){};