From 994e4f4840a6734ab479e10d39462cc692bc4d77 Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Wed, 18 Sep 2024 14:10:41 +0800 Subject: [PATCH] ENH: enhance accuracy of weight calculation 1.Use float to store the weight copmputed in the procedure.Avoid the issue where filament weight remains at 0 after changing filaments jira:NONE Signed-off-by: xun.zhang Change-Id: Iff0cfc6e22f34affbc232dbfe196f27ee06d2d9e --- src/libslic3r/GCode/ToolOrdering.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index 9dec86c42..cad3ba67a 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -143,14 +143,14 @@ static double calc_max_layer_height(const PrintConfig &config, double max_object } //calculate the flush weight (first value) and filament change count(second value) -static FilamentChangeStats calc_filament_change_info_by_toolorder(const PrintConfig* config,const std::vector&filament_map,const std::vector&flush_matrix,const std::vector>&layer_sequences) +static FilamentChangeStats calc_filament_change_info_by_toolorder(const PrintConfig* config, const std::vector& filament_map, const std::vector& flush_matrix, const std::vector>& layer_sequences) { FilamentChangeStats ret; - std::map flush_volume_per_filament; + std::unordered_map flush_volume_per_filament; std::vectorlast_filament_per_extruder(2, -1); int total_filament_change_count = 0; - int total_filament_flush_weight = 0; + float total_filament_flush_weight = 0; for (const auto& ls : layer_sequences) { for (const auto& item : ls) { int extruder_id = filament_map[item]; @@ -165,12 +165,12 @@ static FilamentChangeStats calc_filament_change_info_by_toolorder(const PrintCon } for (auto& fv : flush_volume_per_filament) { - int weight = config->filament_density.get_at(fv.first) * 0.001 * fv.second; + float weight = config->filament_density.get_at(fv.first) * 0.001 * fv.second; total_filament_flush_weight += weight; } ret.filament_change_count = total_filament_change_count; - ret.filament_flush_weight = total_filament_flush_weight; + ret.filament_flush_weight = (int)total_filament_flush_weight; return ret; }