mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
FIX: tool change time is too long
Change-Id: Iaecc3dc832c6a20a2acc180a79923e45b97f18f3 (cherry picked from commit a3528545af4176bdba3240120ebde32abf8a9d8d) (cherry picked from commit cbdab12b2e218427e51f39d6860b00a844caef7a)
This commit is contained in:
parent
9e561a3887
commit
96707fc4b4
1 changed files with 31 additions and 37 deletions
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <libslic3r.h>
|
#include <libslic3r.h>
|
||||||
|
|
||||||
|
@ -20,45 +21,35 @@ namespace Slic3r {
|
||||||
|
|
||||||
const static bool g_wipe_into_objects = false;
|
const static bool g_wipe_into_objects = false;
|
||||||
|
|
||||||
void dfs_get_all_sorted_extruders(const std::vector<std::vector<float>> & wipe_volumes,
|
|
||||||
const std::vector<unsigned int> & all_extruders,
|
|
||||||
std::vector<unsigned int> & sorted_extruders,
|
|
||||||
float flush_volume,
|
|
||||||
std::map<float, std::vector<unsigned int>> &volumes_to_extruder_order)
|
|
||||||
{
|
|
||||||
if (sorted_extruders.size() == all_extruders.size()) {
|
|
||||||
volumes_to_extruder_order.insert(std::pair(flush_volume, sorted_extruders));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto extruder_id : all_extruders) {
|
|
||||||
if (sorted_extruders.empty()) {
|
|
||||||
sorted_extruders.push_back(extruder_id);
|
|
||||||
dfs_get_all_sorted_extruders(wipe_volumes, all_extruders, sorted_extruders, flush_volume, volumes_to_extruder_order);
|
|
||||||
sorted_extruders.pop_back();
|
|
||||||
} else {
|
|
||||||
auto itor = std::find(sorted_extruders.begin(), sorted_extruders.end(), extruder_id);
|
|
||||||
if (itor == sorted_extruders.end()) {
|
|
||||||
float delta_flush_volume = wipe_volumes[sorted_extruders.back()][extruder_id];
|
|
||||||
flush_volume += delta_flush_volume;
|
|
||||||
sorted_extruders.push_back(extruder_id);
|
|
||||||
dfs_get_all_sorted_extruders(wipe_volumes, all_extruders, sorted_extruders, flush_volume, volumes_to_extruder_order);
|
|
||||||
flush_volume -= delta_flush_volume;
|
|
||||||
sorted_extruders.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<unsigned int> get_extruders_order(const std::vector<std::vector<float>> &wipe_volumes, std::vector<unsigned int> all_extruders, unsigned int start_extruder_id)
|
std::vector<unsigned int> get_extruders_order(const std::vector<std::vector<float>> &wipe_volumes, std::vector<unsigned int> all_extruders, unsigned int start_extruder_id)
|
||||||
{
|
{
|
||||||
if (all_extruders.size() > 1) {
|
if (all_extruders.size() > 1) {
|
||||||
std::vector<unsigned int> sorted_extruders;
|
int begin_index = 0;
|
||||||
auto iter = std::find(all_extruders.begin(), all_extruders.end(), start_extruder_id);
|
auto iter = std::find(all_extruders.begin(), all_extruders.end(), start_extruder_id);
|
||||||
if (iter != all_extruders.end()) { sorted_extruders.push_back(start_extruder_id); }
|
if (iter != all_extruders.end()) {
|
||||||
std::map<float, std::vector<unsigned int>> volumes_to_extruder_order;
|
for (int i = 0; i < all_extruders.size(); ++i) {
|
||||||
dfs_get_all_sorted_extruders(wipe_volumes, all_extruders, sorted_extruders, 0, volumes_to_extruder_order);
|
if (all_extruders[i] == start_extruder_id) {
|
||||||
if (volumes_to_extruder_order.size() > 0) return volumes_to_extruder_order.begin()->second;
|
std::swap(all_extruders[i], all_extruders[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
begin_index = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<float, std::vector<unsigned int>> volumes_to_extruder_order;
|
||||||
|
volumes_to_extruder_order.first = 10000 * all_extruders.size();
|
||||||
|
std::sort(all_extruders.begin() + begin_index, all_extruders.end());
|
||||||
|
do {
|
||||||
|
float flush_volume = 0;
|
||||||
|
for (int i = 0; i < all_extruders.size() - 1; ++i) {
|
||||||
|
flush_volume += wipe_volumes[all_extruders[i]][all_extruders[i + 1]];
|
||||||
|
}
|
||||||
|
if (flush_volume < volumes_to_extruder_order.first) {
|
||||||
|
volumes_to_extruder_order = std::pair(flush_volume, all_extruders);
|
||||||
|
}
|
||||||
|
} while (std::next_permutation(all_extruders.begin() + begin_index, all_extruders.end()));
|
||||||
|
|
||||||
|
if (volumes_to_extruder_order.second.size() > 0)
|
||||||
|
return volumes_to_extruder_order.second;
|
||||||
}
|
}
|
||||||
return all_extruders;
|
return all_extruders;
|
||||||
}
|
}
|
||||||
|
@ -737,7 +728,10 @@ void ToolOrdering::reorder_extruders_for_minimum_flush_volume()
|
||||||
for (LayerTools& lt : m_layer_tools) {
|
for (LayerTools& lt : m_layer_tools) {
|
||||||
if (lt.extruders.empty())
|
if (lt.extruders.empty())
|
||||||
continue;
|
continue;
|
||||||
|
// todo: The algorithm complexity is too high(o(n2)), currently only 8 colors are supported
|
||||||
|
if (lt.extruders.size() <= 8) {
|
||||||
lt.extruders = get_extruders_order(wipe_volumes, lt.extruders, current_extruder_id);
|
lt.extruders = get_extruders_order(wipe_volumes, lt.extruders, current_extruder_id);
|
||||||
|
}
|
||||||
current_extruder_id = lt.extruders.back();
|
current_extruder_id = lt.extruders.back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue