Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVojtech Bubnik <bubnikv@gmail.com>2021-12-20 16:47:43 +0300
committerVojtech Bubnik <bubnikv@gmail.com>2021-12-20 16:47:51 +0300
commit942c6ea7d89a0473b4f2b5529c516316b0b44b6b (patch)
tree955d4670a54ee0d1e7859c83e287f37aeff977a3 /src/slic3r/GUI
parentcce960673f437e88999321ab2fb3dab36f95fc31 (diff)
Follow-up to 2e250c1463c5d8e8bc94d0769e3e82d648e99e3b
2f638058570197aa2832d0343148741ad6dbba6b The issue was caused by 2e250c1463c5d8e8bc94d0769e3e82d648e99e3b that did not do the binning of floating values well for small numbers, small numbers were rounded to zero. The new code now rounds to two significant digits similarly to sprintf(buf, "%.2g", value)
Diffstat (limited to 'src/slic3r/GUI')
-rw-r--r--src/slic3r/GUI/GCodeViewer.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp
index 8b887bd3d..d3a2e784b 100644
--- a/src/slic3r/GUI/GCodeViewer.cpp
+++ b/src/slic3r/GUI/GCodeViewer.cpp
@@ -73,14 +73,19 @@ static std::vector<std::array<float, 4>> decode_colors(const std::vector<std::st
return output;
}
-static float round_to_nearest_percent(float value)
+// Round to a bin with minimum two digits resolution.
+// Equivalent to conversion to string with sprintf(buf, "%.2g", value) and conversion back to float, but faster.
+static float round_to_bin(const float value)
{
- return std::round(value * 100.f) * 0.01f;
-}
-
-static float round_to_nearest_perthousand(float value)
-{
- return std::round(value * 1000.f) * 0.001f;
+ assert(value > 0);
+ constexpr float const scale [5] = { 100.f, 1000.f, 10000.f, 100000.f, 1000000.f };
+ constexpr float const invscale [5] = { 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f };
+ constexpr float const threshold[5] = { 0.095f, 0.0095f, 0.00095f, 0.000095f, 0.0000095f };
+ // Scaling factor, pointer to the tables above.
+ int i = 0;
+ // While the scaling factor is not yet large enough to get two integer digits after scaling and rounding:
+ for (; value < threshold[i] && i < 4; ++ i) ;
+ return std::round(value * scale[i]) * invscale[i];
}
void GCodeViewer::VBuffer::reset()
@@ -143,7 +148,7 @@ bool GCodeViewer::Path::matches(const GCodeProcessorResult::MoveVertex& move) co
// use rounding to reduce the number of generated paths
return type == move.type && extruder_id == move.extruder_id && cp_color_id == move.cp_color_id && role == move.extrusion_role &&
move.position.z() <= sub_paths.front().first.position.z() && feedrate == move.feedrate && fan_speed == move.fan_speed &&
- height == round_to_nearest_perthousand(move.height) && width == round_to_nearest_percent(move.width) &&
+ height == round_to_bin(move.height) && width == round_to_bin(move.width) &&
matches_percent(volumetric_rate, move.volumetric_rate(), 0.05f);
}
case EMoveType::Travel: {
@@ -176,7 +181,7 @@ void GCodeViewer::TBuffer::add_path(const GCodeProcessorResult::MoveVertex& move
Path::Endpoint endpoint = { b_id, i_id, s_id, move.position };
// use rounding to reduce the number of generated paths
paths.push_back({ move.type, move.extrusion_role, move.delta_extruder,
- round_to_nearest_perthousand(move.height), round_to_nearest_percent(move.width),
+ round_to_bin(move.height), round_to_bin(move.width),
move.feedrate, move.fan_speed, move.temperature,
move.volumetric_rate(), move.extruder_id, move.cp_color_id, { { endpoint, endpoint } } });
}
@@ -751,12 +756,12 @@ void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::v
{
case EMoveType::Extrude:
{
- m_extrusions.ranges.height.update_from(round_to_nearest_perthousand(curr.height));
- m_extrusions.ranges.width.update_from(round_to_nearest_percent(curr.width));
+ m_extrusions.ranges.height.update_from(round_to_bin(curr.height));
+ m_extrusions.ranges.width.update_from(round_to_bin(curr.width));
m_extrusions.ranges.fan_speed.update_from(curr.fan_speed);
m_extrusions.ranges.temperature.update_from(curr.temperature);
if (curr.extrusion_role != erCustom || is_visible(erCustom))
- m_extrusions.ranges.volumetric_rate.update_from(round_to_nearest_percent(curr.volumetric_rate()));
+ m_extrusions.ranges.volumetric_rate.update_from(round_to_bin(curr.volumetric_rate()));
[[fallthrough]];
}
case EMoveType::Travel: