FIX: modify reorder extruders time

Change-Id: Ib72faf039dee6a08770617c4c2f341079d7e02e9
(cherry picked from commit 5e9d479bd7d7ef54bcafe7181dcdd8c03adaae51)
This commit is contained in:
zhimin.zeng 2022-09-30 11:54:44 +08:00 committed by Lane.Wei
parent c2b2c75bf2
commit d7a8219a8f
3 changed files with 73 additions and 50 deletions

View file

@ -20,6 +20,50 @@ 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)
{
if (all_extruders.size() > 1) {
std::vector<unsigned int> sorted_extruders;
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); }
std::map<float, std::vector<unsigned int>> volumes_to_extruder_order;
dfs_get_all_sorted_extruders(wipe_volumes, all_extruders, sorted_extruders, 0, volumes_to_extruder_order);
if (volumes_to_extruder_order.size() > 0) return volumes_to_extruder_order.begin()->second;
}
return all_extruders;
}
// Returns true in case that extruder a comes before b (b does not have to be present). False otherwise. // Returns true in case that extruder a comes before b (b does not have to be present). False otherwise.
bool LayerTools::is_extruder_order(unsigned int a, unsigned int b) const bool LayerTools::is_extruder_order(unsigned int a, unsigned int b) const
{ {
@ -471,6 +515,9 @@ void ToolOrdering::reorder_extruders(unsigned int last_extruder_id)
assert(extruder_id > 0); assert(extruder_id > 0);
-- extruder_id; -- extruder_id;
} }
// reorder the extruders for minimum flush volume
reorder_extruders_for_minimum_flush_volume();
} }
// BBS // BBS
@ -539,6 +586,9 @@ void ToolOrdering::reorder_extruders(std::vector<unsigned int> tool_order_layer0
assert(extruder_id > 0); assert(extruder_id > 0);
--extruder_id; --extruder_id;
} }
// reorder the extruders for minimum flush volume
reorder_extruders_for_minimum_flush_volume();
} }
void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z, coordf_t max_layer_height) void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z, coordf_t max_layer_height)
@ -670,6 +720,28 @@ void ToolOrdering::collect_extruder_statistics(bool prime_multi_material)
} }
} }
void ToolOrdering::reorder_extruders_for_minimum_flush_volume()
{
if (!m_print_config_ptr || m_layer_tools.empty())
return;
// Get wiping matrix to get number of extruders and convert vector<double> to vector<float>:
std::vector<float> flush_matrix(cast<float>(m_print_config_ptr->flush_volumes_matrix.values));
const unsigned int number_of_extruders = (unsigned int) (sqrt(flush_matrix.size()) + EPSILON);
// Extract purging volumes for each extruder pair:
std::vector<std::vector<float>> wipe_volumes;
for (unsigned int i = 0; i < number_of_extruders; ++i)
wipe_volumes.push_back(std::vector<float>(flush_matrix.begin() + i * number_of_extruders, flush_matrix.begin() + (i + 1) * number_of_extruders));
unsigned int current_extruder_id = -1;
for (LayerTools& lt : m_layer_tools) {
if (lt.extruders.empty())
continue;
lt.extruders = get_extruders_order(wipe_volumes, lt.extruders, current_extruder_id);
current_extruder_id = lt.extruders.back();
}
}
// Layers are marked for infinite skirt aka draft shield. Not all the layers have to be printed. // Layers are marked for infinite skirt aka draft shield. Not all the layers have to be printed.
void ToolOrdering::mark_skirt_layers(const PrintConfig &config, coordf_t max_layer_height) void ToolOrdering::mark_skirt_layers(const PrintConfig &config, coordf_t max_layer_height)
{ {

View file

@ -194,6 +194,7 @@ private:
void fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z, coordf_t max_layer_height); void fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z, coordf_t max_layer_height);
void mark_skirt_layers(const PrintConfig &config, coordf_t max_layer_height); void mark_skirt_layers(const PrintConfig &config, coordf_t max_layer_height);
void collect_extruder_statistics(bool prime_multi_material); void collect_extruder_statistics(bool prime_multi_material);
void reorder_extruders_for_minimum_flush_volume();
// BBS // BBS
std::vector<unsigned int> generate_first_layer_tool_order(const Print& print); std::vector<unsigned int> generate_first_layer_tool_order(const Print& print);

View file

@ -38,54 +38,6 @@ PrintRegion::PrintRegion(PrintRegionConfig &&config) : PrintRegion(std::move(con
//BBS //BBS
float Print::min_skirt_length = 0; float Print::min_skirt_length = 0;
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)
{
if (all_extruders.size() > 1) {
std::vector<unsigned int> sorted_extruders;
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);
}
std::map<float, std::vector<unsigned int>> volumes_to_extruder_order;
dfs_get_all_sorted_extruders(wipe_volumes, all_extruders, sorted_extruders, 0, volumes_to_extruder_order);
if(volumes_to_extruder_order.size() > 0)
return volumes_to_extruder_order.begin()->second;
}
return all_extruders;
}
void Print::clear() void Print::clear()
{ {
std::scoped_lock<std::mutex> lock(this->state_mutex()); std::scoped_lock<std::mutex> lock(this->state_mutex());
@ -1896,8 +1848,6 @@ void Print::_make_wipe_tower()
bool first_layer = &layer_tools == &m_wipe_tower_data.tool_ordering.front(); bool first_layer = &layer_tools == &m_wipe_tower_data.tool_ordering.front();
wipe_tower.plan_toolchange((float)layer_tools.print_z, (float)layer_tools.wipe_tower_layer_height, current_extruder_id, current_extruder_id, false); wipe_tower.plan_toolchange((float)layer_tools.print_z, (float)layer_tools.wipe_tower_layer_height, current_extruder_id, current_extruder_id, false);
layer_tools.extruders = get_extruders_order(wipe_volumes, layer_tools.extruders, current_extruder_id);
for (const auto extruder_id : layer_tools.extruders) { for (const auto extruder_id : layer_tools.extruders) {
// BBS: priming logic is removed, so no need to do toolchange for first extruder // BBS: priming logic is removed, so no need to do toolchange for first extruder
if (/*(first_layer && extruder_id == m_wipe_tower_data.tool_ordering.all_extruders().back()) || */extruder_id != current_extruder_id) { if (/*(first_layer && extruder_id == m_wipe_tower_data.tool_ordering.all_extruders().back()) || */extruder_id != current_extruder_id) {