ENH: do not consider empty filament

1. Do not consider empty filament when selecting group for ams
2. Function "collect_filaments_in_groups" is frequently called,
optimize memory allocation to speed up.

jira: NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Iad8c9a257bc2dd832c77e650f8c052fb9d8379a0
This commit is contained in:
xun.zhang 2024-10-16 10:54:49 +08:00 committed by lane.wei
parent 65e8b4ee7e
commit 21379e1336
2 changed files with 23 additions and 21 deletions

View File

@ -195,8 +195,10 @@ namespace Slic3r
for (size_t idx = 0; idx < ams_filament_colors_str.size(); ++idx) {
std::vector<Color> tmp;
for (auto& item : ams_filament_colors_str[idx])
for (auto& item : ams_filament_colors_str[idx]) {
if (!item.empty())
tmp.emplace_back(Color(item));
}
ams_filament_colors[idx] = std::move(tmp);
}

View File

@ -421,8 +421,9 @@ namespace Slic3r
template<class T>
static std::vector<T> collect_filaments_in_groups(const std::set<unsigned int>& group, const std::vector<unsigned int>& filament_list) {
static std::vector<T> collect_filaments_in_groups(const std::unordered_set<unsigned int>& group, const std::vector<unsigned int>& filament_list) {
std::vector<T>ret;
ret.reserve(group.size());
for (auto& f : filament_list) {
if (auto iter = group.find(f); iter != group.end())
ret.emplace_back(static_cast<T>(f));
@ -471,7 +472,7 @@ namespace Slic3r
//only when layer filament num <= 5,we do forcast
constexpr int max_n_with_forcast = 5;
int cost = 0;
std::vector<std::set<unsigned int>>groups(2); //save the grouped filaments
std::vector<std::unordered_set<unsigned int>>groups(2); //save the grouped filaments
std::vector<std::vector<std::vector<unsigned int>>> layer_sequences(2); //save the reordered filament sequence by group
std::map<size_t, std::vector<unsigned int>> custom_layer_sequence_map; // save the filament sequences of custom layer
@ -501,7 +502,6 @@ namespace Slic3r
custom_layer_sequence_map[layer] = unsign_custom_extruder_seq;
}
}
using uint128_t = boost::multiprecision::uint128_t;
auto extruders_to_hash_key = [](const std::vector<unsigned int>& curr_layer_extruders,
const std::vector<unsigned int>& next_layer_extruders,