From 68cf4db58e63334523f8f926b79fa7b3a20c325b Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Wed, 13 Apr 2022 15:46:40 +0200 Subject: [PATCH] interpolate fitted and original position during b spline alignment - push points with large weight more towards their original position --- src/libslic3r/GCode/SeamPlacer.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/GCode/SeamPlacer.cpp b/src/libslic3r/GCode/SeamPlacer.cpp index 85826fc68..3c9009702 100644 --- a/src/libslic3r/GCode/SeamPlacer.cpp +++ b/src/libslic3r/GCode/SeamPlacer.cpp @@ -1206,10 +1206,8 @@ void SeamPlacer::align_seam_points(const PrintObject *po, const SeamPlacerImpl:: observation_points.resize(seam_string.size()); weights.resize(seam_string.size()); - //init min_weight by the first point auto min_weight = std::numeric_limits::max(); - - //gather points positions and weights, update min_weight in each step + //gather points positions and weights (negative value of penalty), update min_weight in each step for (size_t index = 0; index < seam_string.size(); ++index) { Vec3f pos = layers[seam_string[index].first].points[seam_string[index].second].position; observations[index] = pos.head<2>(); @@ -1219,10 +1217,11 @@ void SeamPlacer::align_seam_points(const PrintObject *po, const SeamPlacerImpl:: min_weight = std::min(min_weight, weights[index]); } - //makes all weights positive + //make all weights positive for (float &w : weights) { w = w - min_weight + 0.01; } + float max_weight = -min_weight + 0.01; // Curve Fitting size_t number_of_segments = std::max(size_t(1), @@ -1231,12 +1230,17 @@ void SeamPlacer::align_seam_points(const PrintObject *po, const SeamPlacerImpl:: // Do alignment - compute fitted point for each point in the string from its Z coord, and store the position into // Perimeter structure of the point; also set flag aligned to true - for (const auto &pair : seam_string) { + for (size_t index = 0; index < seam_string.size(); ++index) { + const auto& pair = seam_string[index]; + const float t = weights[index]/max_weight; Vec3f current_pos = layers[pair.first].points[pair.second].position; Vec2f fitted_pos = curve.get_fitted_value(current_pos.z()); + //interpolate between current and fitted position, prefer current pos for large weights. + Vec3f final_position = t*current_pos + (1-t)*to_3d(fitted_pos, current_pos.z()); + Perimeter &perimeter = layers[pair.first].points[pair.second].perimeter; - perimeter.final_seam_position = to_3d(fitted_pos, current_pos.z()); + perimeter.final_seam_position = final_position; perimeter.finalized = true; }