From bb9a04fc4892efb5742044e0c1e778dc9e765e2f Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 8 Aug 2023 12:00:11 +0200 Subject: [PATCH 1/2] Fixed TextCtrl::value_was_changed() function to respect changes, when type of Field is coPoints. --- src/slic3r/GUI/Field.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 74ad028d36..121493b68b 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -588,6 +588,8 @@ bool TextCtrl::value_was_changed() case coFloatOrPercent: case coFloatsOrPercents: return boost::any_cast(m_value) != boost::any_cast(val); + case coPoints: + return boost::any_cast>(m_value) != boost::any_cast>(val); default: return true; } From 57b2f364e0d839c64d865c0e49f6c73361261393 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 8 Aug 2023 13:12:26 +0200 Subject: [PATCH 2/2] Improve and fix curvature estimation algorithm --- src/libslic3r/GCode/ExtrusionProcessor.hpp | 95 +++++++++++----------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/src/libslic3r/GCode/ExtrusionProcessor.hpp b/src/libslic3r/GCode/ExtrusionProcessor.hpp index 968ba4024f..5314e9afe4 100644 --- a/src/libslic3r/GCode/ExtrusionProcessor.hpp +++ b/src/libslic3r/GCode/ExtrusionProcessor.hpp @@ -146,67 +146,68 @@ std::vector estimate_points_properties(const POINTS std::vector angles_for_curvature(points.size()); std::vector distances_for_curvature(points.size()); - for (int point_idx = 0; point_idx < int(points.size()); ++point_idx) { + for (size_t point_idx = 0; point_idx < points.size(); ++point_idx) { ExtendedPoint &a = points[point_idx]; - ExtendedPoint &prev = points[point_idx > 0 ? point_idx - 1 : point_idx]; + size_t prev = prev_idx_modulo(point_idx, points.size()); + size_t next = next_idx_modulo(point_idx, points.size()); - int prev_point_idx = point_idx; - while (prev_point_idx > 0) { - prev_point_idx--; - if ((a.position - points[prev_point_idx].position).squaredNorm() > EPSILON) { - break; - } + int iter_limit = points.size(); + while ((a.position - points[prev].position).squaredNorm() < 1 && iter_limit > 0) { + prev = prev_idx_modulo(prev, points.size()); + iter_limit--; } - int next_point_index = point_idx; - while (next_point_index < int(points.size()) - 1) { - next_point_index++; - if ((a.position - points[next_point_index].position).squaredNorm() > EPSILON) { - break; - } + while ((a.position - points[next].position).squaredNorm() < 1 && iter_limit > 0) { + next = next_idx_modulo(next, points.size()); + iter_limit--; } - distances_for_curvature[point_idx] = (prev.position - a.position).norm(); - if (prev_point_idx != point_idx && next_point_index != point_idx) { - float alfa = angle(a.position - points[prev_point_idx].position, points[next_point_index].position - a.position); - angles_for_curvature[point_idx] = alfa; - } // else keep zero + distances_for_curvature[point_idx] = (points[prev].position - a.position).norm(); + float alfa = angle(a.position - points[prev].position, points[next].position - a.position); + angles_for_curvature[point_idx] = alfa; } - for (float window_size : {3.0f, 9.0f, 16.0f}) { - size_t tail_point = 0; - float tail_window_acc = 0; - float tail_angle_acc = 0; + if (std::accumulate(distances_for_curvature.begin(), distances_for_curvature.end(), 0) > EPSILON) + for (float window_size : {3.0f, 9.0f, 16.0f}) { + size_t tail_point = 0; + float tail_window_acc = 0; + float tail_angle_acc = 0; - size_t head_point = 0; - float head_window_acc = 0; - float head_angle_acc = 0; + size_t head_point = 0; + float head_window_acc = 0; + float head_angle_acc = 0; - for (int point_idx = 0; point_idx < int(points.size()); ++point_idx) { - if (point_idx > 0) { - tail_window_acc += distances_for_curvature[point_idx - 1]; - tail_angle_acc += angles_for_curvature[point_idx - 1]; - head_window_acc -= distances_for_curvature[point_idx - 1]; - head_angle_acc -= angles_for_curvature[point_idx - 1]; - } - while (tail_window_acc > window_size * 0.5 && int(tail_point) < point_idx) { - tail_window_acc -= distances_for_curvature[tail_point]; - tail_angle_acc -= angles_for_curvature[tail_point]; - tail_point++; - } + for (size_t point_idx = 0; point_idx < points.size(); ++point_idx) { + if (point_idx == 0) { + while (tail_window_acc < window_size * 0.5) { + tail_window_acc += distances_for_curvature[tail_point]; + tail_angle_acc += angles_for_curvature[tail_point]; + tail_point = prev_idx_modulo(tail_point, points.size()); + } + } + while (tail_window_acc - distances_for_curvature[next_idx_modulo(tail_point, points.size())] > window_size * 0.5) { + tail_point = next_idx_modulo(tail_point, points.size()); + tail_window_acc -= distances_for_curvature[tail_point]; + tail_angle_acc -= angles_for_curvature[tail_point]; + } - while (head_window_acc < window_size * 0.5 && int(head_point) < int(points.size()) - 1) { - head_window_acc += distances_for_curvature[head_point]; - head_angle_acc += angles_for_curvature[head_point]; - head_point++; - } + while (head_window_acc < window_size * 0.5) { + head_point = next_idx_modulo(head_point, points.size()); + head_window_acc += distances_for_curvature[head_point]; + head_angle_acc += angles_for_curvature[head_point]; + } - float curvature = (tail_angle_acc + head_angle_acc) / (tail_window_acc + head_window_acc); - if (std::abs(curvature) > std::abs(points[point_idx].curvature)) { - points[point_idx].curvature = curvature; + float curvature = (tail_angle_acc + head_angle_acc) / window_size; + if (std::abs(curvature) > std::abs(points[point_idx].curvature)) { + points[point_idx].curvature = curvature; + } + + tail_window_acc += distances_for_curvature[point_idx]; + tail_angle_acc += angles_for_curvature[point_idx]; + head_window_acc -= distances_for_curvature[point_idx]; + head_angle_acc -= angles_for_curvature[point_idx]; } } - } return points; }