GCode Preview - Added visualization of volumetric flow rate

This commit is contained in:
Enrico Turri 2018-03-21 10:03:10 +01:00
parent 78d1d83583
commit 4a179c81d2
5 changed files with 28 additions and 1 deletions

View file

@ -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);

View file

@ -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)

View file

@ -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;

View file

@ -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<std::string>& colors);

View file

@ -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;