mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-31 10:34:35 +08:00
fix rotation for initial placement
This commit is contained in:
parent
8027f6608a
commit
3e73473334
@ -663,62 +663,79 @@ private:
|
|||||||
remlist.insert(remlist.end(), remaining.from, remaining.to);
|
remlist.insert(remlist.end(), remaining.from, remaining.to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double global_score = std::numeric_limits<double>::max();
|
||||||
|
|
||||||
|
auto initial_tr = item.translation();
|
||||||
|
auto initial_rot = item.rotation();
|
||||||
|
Vertex final_tr = {0, 0};
|
||||||
|
Radians final_rot = initial_rot;
|
||||||
|
Shapes nfps;
|
||||||
|
|
||||||
|
auto& bin = bin_;
|
||||||
|
double norm = norm_;
|
||||||
|
auto pbb = sl::boundingBox(merged_pile_);
|
||||||
|
auto binbb = sl::boundingBox(bin);
|
||||||
|
|
||||||
|
// This is the kernel part of the object function that is
|
||||||
|
// customizable by the library client
|
||||||
|
std::function<double(const Item&)> _objfunc;
|
||||||
|
if(config_.object_function) _objfunc = config_.object_function;
|
||||||
|
else {
|
||||||
|
|
||||||
|
// Inside check has to be strict if no alignment was enabled
|
||||||
|
std::function<double(const Box&)> ins_check;
|
||||||
|
if(config_.alignment == Config::Alignment::DONT_ALIGN)
|
||||||
|
ins_check = [&binbb, norm](const Box& fullbb) {
|
||||||
|
double ret = 0;
|
||||||
|
if(!sl::isInside(fullbb, binbb))
|
||||||
|
ret += norm;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
else
|
||||||
|
ins_check = [&bin](const Box& fullbb) {
|
||||||
|
double miss = overfit(fullbb, bin);
|
||||||
|
miss = miss > 0? miss : 0;
|
||||||
|
return std::pow(miss, 2);
|
||||||
|
};
|
||||||
|
|
||||||
|
_objfunc = [norm, binbb, pbb, ins_check](const Item& item)
|
||||||
|
{
|
||||||
|
auto ibb = item.boundingBox();
|
||||||
|
auto fullbb = sl::boundingBox(pbb, ibb);
|
||||||
|
|
||||||
|
double score = pl::distance(ibb.center(),
|
||||||
|
binbb.center());
|
||||||
|
score /= norm;
|
||||||
|
|
||||||
|
score += ins_check(fullbb);
|
||||||
|
|
||||||
|
return score;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if(items_.empty()) {
|
if(items_.empty()) {
|
||||||
setInitialPosition(item);
|
setInitialPosition(item);
|
||||||
|
auto best_tr = item.translation();
|
||||||
|
auto best_rot = item.rotation();
|
||||||
best_overfit = overfit(item.transformedShape(), bin_);
|
best_overfit = overfit(item.transformedShape(), bin_);
|
||||||
can_pack = best_overfit <= 0;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
double global_score = std::numeric_limits<double>::max();
|
for(auto rot : config_.rotations) {
|
||||||
|
item.translation(initial_tr);
|
||||||
auto initial_tr = item.translation();
|
item.rotation(initial_rot + rot);
|
||||||
auto initial_rot = item.rotation();
|
setInitialPosition(item);
|
||||||
Vertex final_tr = {0, 0};
|
double of = 0.;
|
||||||
Radians final_rot = initial_rot;
|
if ((of = overfit(item.transformedShape(), bin_)) < best_overfit) {
|
||||||
Shapes nfps;
|
best_overfit = of;
|
||||||
|
best_tr = item.translation();
|
||||||
auto& bin = bin_;
|
best_rot = item.rotation();
|
||||||
double norm = norm_;
|
}
|
||||||
auto pbb = sl::boundingBox(merged_pile_);
|
|
||||||
auto binbb = sl::boundingBox(bin);
|
|
||||||
|
|
||||||
// This is the kernel part of the object function that is
|
|
||||||
// customizable by the library client
|
|
||||||
std::function<double(const Item&)> _objfunc;
|
|
||||||
if(config_.object_function) _objfunc = config_.object_function;
|
|
||||||
else {
|
|
||||||
|
|
||||||
// Inside check has to be strict if no alignment was enabled
|
|
||||||
std::function<double(const Box&)> ins_check;
|
|
||||||
if(config_.alignment == Config::Alignment::DONT_ALIGN)
|
|
||||||
ins_check = [&binbb, norm](const Box& fullbb) {
|
|
||||||
double ret = 0;
|
|
||||||
if(!sl::isInside(fullbb, binbb))
|
|
||||||
ret += norm;
|
|
||||||
return ret;
|
|
||||||
};
|
|
||||||
else
|
|
||||||
ins_check = [&bin](const Box& fullbb) {
|
|
||||||
double miss = overfit(fullbb, bin);
|
|
||||||
miss = miss > 0? miss : 0;
|
|
||||||
return std::pow(miss, 2);
|
|
||||||
};
|
|
||||||
|
|
||||||
_objfunc = [norm, binbb, pbb, ins_check](const Item& item)
|
|
||||||
{
|
|
||||||
auto ibb = item.boundingBox();
|
|
||||||
auto fullbb = sl::boundingBox(pbb, ibb);
|
|
||||||
|
|
||||||
double score = pl::distance(ibb.center(),
|
|
||||||
binbb.center());
|
|
||||||
score /= norm;
|
|
||||||
|
|
||||||
score += ins_check(fullbb);
|
|
||||||
|
|
||||||
return score;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
can_pack = best_overfit <= 0;
|
||||||
|
item.rotation(best_rot);
|
||||||
|
item.translation(best_tr);
|
||||||
|
} else {
|
||||||
|
|
||||||
Pile merged_pile = merged_pile_;
|
Pile merged_pile = merged_pile_;
|
||||||
|
|
||||||
for(auto rot : config_.rotations) {
|
for(auto rot : config_.rotations) {
|
||||||
@ -948,10 +965,9 @@ private:
|
|||||||
if(items_.empty() ||
|
if(items_.empty() ||
|
||||||
config_.alignment == Config::Alignment::DONT_ALIGN) return;
|
config_.alignment == Config::Alignment::DONT_ALIGN) return;
|
||||||
|
|
||||||
nfp::Shapes<RawShape> m;
|
Box bb = items_.front().get().boundingBox();
|
||||||
m.reserve(items_.size());
|
for(Item& item : items_)
|
||||||
for(Item& item : items_) m.emplace_back(item.transformedShape());
|
bb = sl::boundingBox(item.boundingBox(), bb);
|
||||||
auto&& bb = sl::boundingBox(m);
|
|
||||||
|
|
||||||
Vertex ci, cb;
|
Vertex ci, cb;
|
||||||
|
|
||||||
@ -988,7 +1004,7 @@ private:
|
|||||||
for(Item& item : items_) item.translate(d);
|
for(Item& item : items_) item.translate(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInitialPosition(Item& item) {
|
void setInitialPosition(Item& item) {
|
||||||
Box bb = item.boundingBox();
|
Box bb = item.boundingBox();
|
||||||
|
|
||||||
Vertex ci, cb;
|
Vertex ci, cb;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user