From 4a179c81d29eaad4dc3b4a107a31809b68615076 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 21 Mar 2018 10:03:10 +0100 Subject: [PATCH] GCode Preview - Added visualization of volumetric flow rate --- lib/Slic3r/GUI/Plater/3DPreview.pm | 1 + xs/src/libslic3r/GCode/Analyzer.cpp | 7 ++++++- xs/src/libslic3r/GCode/PreviewData.cpp | 14 ++++++++++++++ xs/src/libslic3r/GCode/PreviewData.hpp | 3 +++ xs/src/slic3r/GUI/3DScene.cpp | 4 ++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index 8f3fa49f5..537cb0c8f 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -69,6 +69,7 @@ sub new { $choice_view_type->Append(L("Height")); $choice_view_type->Append(L("Width")); $choice_view_type->Append(L("Speed")); + $choice_view_type->Append(L("Volumetric flow rate")); $choice_view_type->Append(L("Tool")); $choice_view_type->SetSelection(0); diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index 15b99b2fb..e20f6589f 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -670,14 +670,16 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ float z = FLT_MAX; Polyline polyline; Pointf3 position(FLT_MAX, FLT_MAX, FLT_MAX); + float volumetric_rate = FLT_MAX; GCodePreviewData::Range height_range; GCodePreviewData::Range width_range; GCodePreviewData::Range feedrate_range; + GCodePreviewData::Range volumetric_rate_range; // constructs the polylines while traversing the moves for (const GCodeMove& move : extrude_moves->second) { - if ((data != move.data) || (data.feedrate != move.data.feedrate) || (z != move.start_position.z) || (position != move.start_position)) + if ((data != move.data) || (z != move.start_position.z) || (position != move.start_position) || (volumetric_rate != move.data.feedrate * (float)move.data.mm3_per_mm)) { // store current polyline polyline.remove_duplicate_points(); @@ -693,9 +695,11 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ // update current values data = move.data; z = move.start_position.z; + volumetric_rate = move.data.feedrate * (float)move.data.mm3_per_mm; height_range.update_from(move.data.height); width_range.update_from(move.data.width); feedrate_range.update_from(move.data.feedrate); + volumetric_rate_range.update_from(volumetric_rate); } else // append end vertex of the move to current polyline @@ -713,6 +717,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ preview_data.ranges.height.set_from(height_range); preview_data.ranges.width.set_from(width_range); preview_data.ranges.feedrate.set_from(feedrate_range); + preview_data.ranges.volumetric_rate.set_from(volumetric_rate_range); } void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) diff --git a/xs/src/libslic3r/GCode/PreviewData.cpp b/xs/src/libslic3r/GCode/PreviewData.cpp index b9be6643b..69fd3524d 100644 --- a/xs/src/libslic3r/GCode/PreviewData.cpp +++ b/xs/src/libslic3r/GCode/PreviewData.cpp @@ -235,6 +235,7 @@ void GCodePreviewData::set_default() ::memcpy((void*)ranges.height.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color)); ::memcpy((void*)ranges.width.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color)); ::memcpy((void*)ranges.feedrate.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color)); + ::memcpy((void*)ranges.volumetric_rate.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color)); extrusion.set_default(); travel.set_default(); @@ -248,6 +249,7 @@ void GCodePreviewData::reset() ranges.width.reset(); ranges.height.reset(); ranges.feedrate.reset(); + ranges.volumetric_rate.reset(); extrusion.layers.clear(); travel.polylines.clear(); retraction.positions.clear(); @@ -279,6 +281,11 @@ const GCodePreviewData::Color& GCodePreviewData::get_feedrate_color(float feedra return ranges.feedrate.get_color_at(feedrate); } +const GCodePreviewData::Color& GCodePreviewData::get_volumetric_rate_color(float rate) const +{ + return ranges.volumetric_rate.get_color_at(rate); +} + void GCodePreviewData::set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha) { for (unsigned int i = 0; i < Extrusion::Num_Extrusion_Roles; ++i) @@ -345,6 +352,8 @@ std::string GCodePreviewData::get_legend_title() const return L("Width (mm)"); case Extrusion::Feedrate: return L("Speed (mm/s)"); + case Extrusion::VolumetricRate: + return L("Volumetric flow rate (mm3/s)"); case Extrusion::Tool: return L("Tool"); } @@ -402,6 +411,11 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: Helper::FillListFromRange(items, ranges.feedrate, 0, 1.0f); break; } + case Extrusion::VolumetricRate: + { + Helper::FillListFromRange(items, ranges.volumetric_rate, 3, 1.0f); + break; + } case Extrusion::Tool: { unsigned int tools_colors_count = tool_colors.size() / 4; diff --git a/xs/src/libslic3r/GCode/PreviewData.hpp b/xs/src/libslic3r/GCode/PreviewData.hpp index 6375af5f0..e9c5f7515 100644 --- a/xs/src/libslic3r/GCode/PreviewData.hpp +++ b/xs/src/libslic3r/GCode/PreviewData.hpp @@ -50,6 +50,7 @@ public: Range height; Range width; Range feedrate; + Range volumetric_rate; }; struct LegendItem @@ -70,6 +71,7 @@ public: Height, Width, Feedrate, + VolumetricRate, Tool, Num_View_Types }; @@ -190,6 +192,7 @@ public: const Color& get_height_color(float height) const; const Color& get_width_color(float width) const; const Color& get_feedrate_color(float feedrate) const; + const Color& get_volumetric_rate_color(float rate) const; void set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha); void set_extrusion_paths_colors(const std::vector& colors); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 4762fa54c..eafca6cd1 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -2039,6 +2039,8 @@ void _3DScene::_load_gcode_extrusion_paths(const GCodePreviewData& preview_data, return path.width; case GCodePreviewData::Extrusion::Feedrate: return path.feedrate; + case GCodePreviewData::Extrusion::VolumetricRate: + return path.feedrate * (float)path.mm3_per_mm; case GCodePreviewData::Extrusion::Tool: return (float)path.extruder_id; } @@ -2058,6 +2060,8 @@ void _3DScene::_load_gcode_extrusion_paths(const GCodePreviewData& preview_data, return data.get_width_color(value); case GCodePreviewData::Extrusion::Feedrate: return data.get_feedrate_color(value); + case GCodePreviewData::Extrusion::VolumetricRate: + return data.get_volumetric_rate_color(value); case GCodePreviewData::Extrusion::Tool: { static GCodePreviewData::Color color;