diff --git a/src/libslic3r/GCode/SeamPlacer.cpp b/src/libslic3r/GCode/SeamPlacer.cpp index c9c25f519..c7df13c58 100644 --- a/src/libslic3r/GCode/SeamPlacer.cpp +++ b/src/libslic3r/GCode/SeamPlacer.cpp @@ -750,7 +750,7 @@ void debug_export_points(const std::vector())), fill); min_vis = std::min(min_vis, point.visibility); max_vis = std::max(max_vis, point.visibility); @@ -772,31 +772,31 @@ void debug_export_points(const std::vector())), visibility_fill); Vec3i weight_color = value_rgbi(min_weight, max_weight, -comparator.get_penalty(point)); std::string weight_fill = "rgb(" + std::to_string(weight_color.x()) + "," + std::to_string(weight_color.y()) - + "," - + std::to_string(weight_color.z()) + ")"; + + "," + + std::to_string(weight_color.z()) + ")"; weight_svg.draw(scaled(Vec2f(point.position.head<2>())), weight_fill); Vec3i overhang_color = value_rgbi(-0.5, 0.5, std::clamp(point.overhang, -0.5f, 0.5f)); std::string overhang_fill = "rgb(" + std::to_string(overhang_color.x()) + "," - + std::to_string(overhang_color.y()) - + "," - + std::to_string(overhang_color.z()) + ")"; + + std::to_string(overhang_color.y()) + + "," + + std::to_string(overhang_color.z()) + ")"; overhangs_svg.draw(scaled(Vec2f(point.position.head<2>())), overhang_fill); } } @@ -903,18 +903,26 @@ void pick_random_seam_point(std::vector &perimeter_points, size_t } -EdgeGrid::Grid compute_layer_merged_edge_grid(const Layer *layer) { +struct EdgeGridWrapper { + explicit EdgeGridWrapper(ExPolygons ex_polys) : + ex_polys(ex_polys) { + + grid.create(this->ex_polys, distance_field_resolution); + grid.calculate_sdf(); + } + const coord_t distance_field_resolution = coord_t(scale_(1.) + 0.5); + EdgeGrid::Grid grid; + ExPolygons ex_polys; +} +; + +EdgeGridWrapper compute_layer_merged_edge_grid(const Layer *layer) { static const float eps = float(scale_(layer->object()->config().slice_closing_radius.value)); // merge with offset ExPolygons merged = layer->merged(eps); // ofsset back ExPolygons layer_outline = offset_ex(merged, -eps); - - const coord_t distance_field_resolution = coord_t(scale_(1.) + 0.5); - EdgeGrid::Grid result { }; - result.create(layer_outline, distance_field_resolution); - result.calculate_sdf(); - return result; + return EdgeGridWrapper(layer_outline); } } // namespace SeamPlacerImpl @@ -971,9 +979,9 @@ void SeamPlacer::calculate_overhangs_and_layer_embedding(const PrintObject *po) tbb::parallel_for(tbb::blocked_range(0, m_perimeter_points_per_object[po].size()), [&](tbb::blocked_range r) { - std::unique_ptr prev_layer_grid; + std::unique_ptr prev_layer_grid; if (r.begin() > 0) { // previous layer exists - prev_layer_grid = std::make_unique( + prev_layer_grid = std::make_unique( compute_layer_merged_edge_grid(po->layers()[r.begin() - 1])); } @@ -981,21 +989,22 @@ void SeamPlacer::calculate_overhangs_and_layer_embedding(const PrintObject *po) bool layer_has_multiple_loops = m_perimeter_points_per_object[po][layer_idx][0].perimeter->end_index < m_perimeter_points_per_object[po][layer_idx].size() - 1; - std::unique_ptr current_layer_grid = std::make_unique( + std::unique_ptr current_layer_grid = std::make_unique( compute_layer_merged_edge_grid(po->layers()[layer_idx])); for (SeamCandidate &perimeter_point : m_perimeter_points_per_object[po][layer_idx]) { Point point = Point::new_scale(Vec2f { perimeter_point.position.head<2>() }); if (prev_layer_grid.get() != nullptr) { coordf_t overhang_dist; - prev_layer_grid->signed_distance(point, scaled(perimeter_point.perimeter->flow_width), overhang_dist); + prev_layer_grid->grid.signed_distance(point, scaled(perimeter_point.perimeter->flow_width), + overhang_dist); perimeter_point.overhang = unscale(overhang_dist) - perimeter_point.perimeter->flow_width; } if (layer_has_multiple_loops) { // search for embedded perimeter points (points hidden inside the print ,e.g. multimaterial join, best position for seam) coordf_t layer_embedded_distance; - current_layer_grid->signed_distance(point, scaled(1.0f), + current_layer_grid->grid.signed_distance(point, scaled(1.0f), layer_embedded_distance); perimeter_point.embedded_distance = unscale(layer_embedded_distance); } diff --git a/src/libslic3r/Geometry/Bicubic.hpp b/src/libslic3r/Geometry/Bicubic.hpp index 9dc4c0083..98c6f8bb2 100644 --- a/src/libslic3r/Geometry/Bicubic.hpp +++ b/src/libslic3r/Geometry/Bicubic.hpp @@ -78,37 +78,37 @@ struct CubicCatmulRomKernel return 0; } static T a01() { - return (T) -0.5; + return T( -0.5); } static T a02() { - return (T) 1.; + return T( 1.); } static T a03() { - return (T) -0.5; + return T( -0.5); } static T a10() { - return (T) 1.; + return T( 1.); } static T a11() { return 0; } static T a12() { - return (T) -5. / 2.; + return T( -5. / 2.); } static T a13() { - return (T) 3. / 2.; + return T( 3. / 2.); } static T a20() { return 0; } static T a21() { - return (T) 0.5; + return T( 0.5); } static T a22() { - return (T) 2.; + return T( 2.); } static T a23() { - return (T) -3. / 2.; + return T( -3. / 2.); } static T a30() { return 0; @@ -117,10 +117,10 @@ struct CubicCatmulRomKernel return 0; } static T a32() { - return (T) -0.5; + return T( -0.5); } static T a33() { - return (T) 0.5; + return T( 0.5); } }; @@ -131,40 +131,40 @@ struct CubicBSplineKernel typedef T FloatType; static T a00() { - return (T) 1. / 6.; + return T( 1. / 6.); } static T a01() { - return (T) -3. / 6.; + return T( -3. / 6.); } static T a02() { - return (T) 3. / 6.; + return T( 3. / 6.); } static T a03() { - return (T) -1. / 6.; + return T( -1. / 6.); } static T a10() { - return (T) 4. / 6.; + return T( 4. / 6.); } static T a11() { return 0; } static T a12() { - return (T) -6. / 6.; + return T( -6. / 6.); } static T a13() { - return (T) 3. / 6.; + return T( 3. / 6.); } static T a20() { - return (T) 1. / 6.; + return T( 1. / 6.); } static T a21() { - return (T) 3. / 6.; + return T( 3. / 6.); } static T a22() { - return (T) 3. / 6.; + return T( 3. / 6.); } static T a23() { - return (T) -3. / 6.; + return T( -3. / 6.); } static T a30() { return 0; @@ -176,7 +176,7 @@ struct CubicBSplineKernel return 0; } static T a33() { - return (T) 1. / 6.; + return T( 1. / 6.); } }; @@ -241,7 +241,7 @@ static typename KernelWrapper::FloatType cubic_interpolate(const Eigen::ArrayBas typedef typename KernelWrapper::FloatType T; const int w = int(F.size()); const int ix = (int) floor(pt); - const T s = pt - (T) ix; + const T s = pt - T( ix); if (ix > 1 && ix + 2 < w) { // Inside the fully interpolated region. @@ -262,8 +262,8 @@ static float bicubic_interpolate(const Eigen::MatrixBase &F, const int h = F.rows(); const int ix = (int) floor(pt[0]); const int iy = (int) floor(pt[1]); - const T s = pt[0] - (T) ix; - const T t = pt[1] - (T) iy; + const T s = pt[0] - T( ix); + const T t = pt[1] - T( iy); if (ix > 1 && ix + 2 < w && iy > 1 && iy + 2 < h) { // Inside the fully interpolated region. @@ -274,7 +274,7 @@ static float bicubic_interpolate(const Eigen::MatrixBase &F, Kernel::interpolate(F(ix - 1, iy + 2), F(ix, iy + 2), F(ix + 1, iy + 2), F(ix + 2, iy + 2), s), t); } // Transition region. Extend with a constant function. - auto f = [&F, &f, w, h](int x, int y) { + auto f = [&F, w, h](int x, int y) { return F(BicubicInternal::clamp(x, 0, w - 1), BicubicInternal::clamp(y, 0, h - 1)); }; return Kernel::interpolate(