FIX: arranging multi-color objects not correct

Arranging multi-color objects with disabled
multi_materials_on_same_plate option was not currect.

Previously we only consider the first extruder id for multi-color
objects. Now we consider all extruders.

Jira: STUDIO-2164
Change-Id: If64ff4f88f0fe4f6c31ebf657b3449b19bf063f0
(cherry picked from commit f4f6bdd00a0c3d3e13406b69be9b5b0468b27d44)
This commit is contained in:
Arthur 2023-02-02 17:26:49 +08:00 committed by Lane.Wei
parent 126ef98690
commit 59f7c4595c
3 changed files with 16 additions and 10 deletions

View file

@ -75,7 +75,7 @@ class _Item {
public: public:
int itemid_{ 0 }; int itemid_{ 0 };
int extrude_id{ 1 }; std::vector<int> extrude_ids;
double height{ 0 }; double height{ 0 };
double print_temp{ 0 }; double print_temp{ 0 };
double bed_temp{ 0 }; double bed_temp{ 0 };

View file

@ -114,13 +114,14 @@ public:
double score = LARGE_COST_TO_REJECT+1, best_score = LARGE_COST_TO_REJECT+1; double score = LARGE_COST_TO_REJECT+1, best_score = LARGE_COST_TO_REJECT+1;
double score_all_plates = 0, score_all_plates_best = std::numeric_limits<double>::max(); double score_all_plates = 0, score_all_plates_best = std::numeric_limits<double>::max();
typename Placer::PackResult result, result_best, result_firstfit; typename Placer::PackResult result, result_best, result_firstfit;
size_t j = 0; int j = 0;
while(!was_packed && !cancelled()) { while(!was_packed && !cancelled()) {
for(; j < placers.size() && !was_packed && !cancelled(); j++) { for(; j < placers.size() && !was_packed && !cancelled(); j++) {
result = placers[j].pack(*it, rem(it, store_)); result = placers[j].pack(*it, rem(it, store_));
score = result.score(); score = result.score();
score_all_plates = std::accumulate(placers.begin(), placers.begin() + j, score, score_all_plates = std::accumulate(placers.begin(), placers.begin() + j, score,
[](double sum, const Placer& elem) { return sum + elem.score(); }); [](double sum, const Placer& elem) { return sum + elem.score(); });
if (this->unfitindicator_) this->unfitindicator_(it->get().name + " bed_id="+std::to_string(j) + ",score=" + std::to_string(score));
if(score >= 0 && score < LARGE_COST_TO_REJECT) { if(score >= 0 && score < LARGE_COST_TO_REJECT) {
if (bed_id_firstfit == -1) { if (bed_id_firstfit == -1) {

View file

@ -452,19 +452,24 @@ protected:
} }
std::set<int> extruder_ids; std::set<int> extruder_ids;
int non_virt_cnt = 0;
for (int i = 0; i < m_items.size(); i++) { for (int i = 0; i < m_items.size(); i++) {
Item& p = m_items[i]; Item& p = m_items[i];
if (p.is_virt_object) continue; if (p.is_virt_object) continue;
extruder_ids.insert(p.extrude_id); extruder_ids.insert(p.extrude_ids.begin(),p.extrude_ids.end());
// add a large cost if not multi materials on same plate is not allowed non_virt_cnt++;
if (!params.allow_multi_materials_on_same_plate)
score += LARGE_COST_TO_REJECT * (item.extrude_id != p.extrude_id);
} }
extruder_ids.insert(item.extrude_ids.begin(),item.extrude_ids.end());
// add a large cost if not multi materials on same plate is not allowed
if (!params.allow_multi_materials_on_same_plate) {
// non_virt_cnt==0 means it's the first object, which can be multi-color
if (extruder_ids.size() > 1 && non_virt_cnt > 0)
score += LARGE_COST_TO_REJECT * 1.1;
}
// for layered printing, we want extruder change as few as possible // for layered printing, we want extruder change as few as possible
// this has very weak effect, CAN NOT use a large weight // this has very weak effect, CAN NOT use a large weight
if (!params.is_seq_print) { if (!params.is_seq_print) {
extruder_ids.insert(item.extrude_id);
score += 1 * std::max(0, ((int) extruder_ids.size() - 1)); score += 1 * std::max(0, ((int) extruder_ids.size() - 1));
} }
@ -601,7 +606,7 @@ public:
} }
else { else {
return i1.bed_temp != i2.bed_temp ? (i1.bed_temp > i2.bed_temp) : return i1.bed_temp != i2.bed_temp ? (i1.bed_temp > i2.bed_temp) :
(i1.extrude_id != i2.extrude_id ? (i1.extrude_id < i2.extrude_id) : (i1.area() > i2.area())); (i1.extrude_ids != i2.extrude_ids ? (i1.extrude_ids.front() < i2.extrude_ids.front()) : (i1.area() > i2.area()));
} }
}; };
@ -850,7 +855,7 @@ static void process_arrangeable(const ArrangePolygon &arrpoly,
item.binId(arrpoly.bed_idx); item.binId(arrpoly.bed_idx);
item.priority(arrpoly.priority); item.priority(arrpoly.priority);
item.itemId(arrpoly.itemid); item.itemId(arrpoly.itemid);
item.extrude_id = arrpoly.extrude_ids.front(); item.extrude_ids = arrpoly.extrude_ids;
item.height = arrpoly.height; item.height = arrpoly.height;
item.name = arrpoly.name; item.name = arrpoly.name;
//BBS: add virtual object logic //BBS: add virtual object logic