From d20f880124254a160b8ef7907c60f58bf061d6ea Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Wed, 11 Jan 2023 12:44:42 +0100 Subject: [PATCH] local issues support generator fix --- src/libslic3r/GCode/ExtrusionProcessor.hpp | 4 +-- src/libslic3r/Print.hpp | 1 - src/libslic3r/PrintObject.cpp | 3 ++ src/libslic3r/SupportSpotsGenerator.cpp | 34 ++++++++++++---------- src/libslic3r/SupportSpotsGenerator.hpp | 3 +- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/libslic3r/GCode/ExtrusionProcessor.hpp b/src/libslic3r/GCode/ExtrusionProcessor.hpp index b392018cf..5a13e5484 100644 --- a/src/libslic3r/GCode/ExtrusionProcessor.hpp +++ b/src/libslic3r/GCode/ExtrusionProcessor.hpp @@ -67,8 +67,8 @@ public: class CurvatureEstimator { - static const size_t sliders_count = 2; - SlidingWindowCurvatureAccumulator sliders[sliders_count] = {{4.0}, {10.0}}; + static const size_t sliders_count = 3; + SlidingWindowCurvatureAccumulator sliders[sliders_count] = {{1.0},{4.0}, {10.0}}; public: void add_point(float distance, float angle) diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 2f5c4e96b..31e78d714 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -222,7 +222,6 @@ public: all_regions.clear(); layer_ranges.clear(); cached_volume_ids.clear(); - generated_support_points.reset(); } private: diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 5423a3ad1..7381f5f56 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -780,6 +780,9 @@ bool PrintObject::invalidate_state_by_config_options( bool PrintObject::invalidate_step(PrintObjectStep step) { bool invalidated = Inherited::invalidate_step(step); + if (invalidated && step == posSupportSpotsSearch) { + this->m_shared_regions->generated_support_points.reset(); + } // propagate to dependent steps if (step == posPerimeters) { diff --git a/src/libslic3r/SupportSpotsGenerator.cpp b/src/libslic3r/SupportSpotsGenerator.cpp index f20583f9b..ceb06a7d1 100644 --- a/src/libslic3r/SupportSpotsGenerator.cpp +++ b/src/libslic3r/SupportSpotsGenerator.cpp @@ -33,8 +33,8 @@ #include "libslic3r/ClipperUtils.hpp" #include "Geometry/ConvexHull.hpp" -#define DETAILED_DEBUG_LOGS -#define DEBUG_FILES +// #define DETAILED_DEBUG_LOGS +// #define DEBUG_FILES #ifdef DEBUG_FILES #include @@ -265,24 +265,23 @@ std::vector check_extrusion_entity_stability(const ExtrusionEntit float sign = (prev_layer_boundary.distance_from_lines(curr_point.position) + 0.5f * flow_width) < 0.0f ? -1.0f : 1.0f; curr_point.distance *= sign; + + float max_bridge_len = params.bridge_distance / (1.0f + std::abs(curr_point.curvature)); - if (curr_point.distance > 0.9f * flow_width) { - line_out.form_quality = 0.7f; + if (curr_point.distance > 2.0f * flow_width) { + line_out.form_quality = 0.8f; bridged_distance += line_len; - // if unsupported distance is larger than bridge distance linearly decreased by curvature, enforce supports. - bool in_layer_dist_condition = bridged_distance > - params.bridge_distance / (1.0f + std::abs(curr_point.curvature) * - params.bridge_distance_decrease_by_curvature_factor); - if (in_layer_dist_condition) { + if (bridged_distance > max_bridge_len) { line_out.support_point_generated = true; bridged_distance = 0.0f; } - } else if (curr_point.distance > flow_width * (0.8 + std::clamp(curr_point.curvature, -0.2f, 0.2f))) { + } else if (curr_point.distance > flow_width * (1.0 + std::clamp(curr_point.curvature, -0.30f, 0.20f))) { bridged_distance += line_len; - line_out.form_quality = nearest_prev_layer_line.form_quality - std::abs(curr_point.curvature); - if (line_out.form_quality < 0) { + line_out.form_quality = nearest_prev_layer_line.form_quality - 0.3f; + if (line_out.form_quality < 0 && bridged_distance > max_bridge_len) { line_out.support_point_generated = true; - line_out.form_quality = 0.7f; + line_out.form_quality = 0.5f; + bridged_distance = 0.0f; } } else { bridged_distance = 0.0f; @@ -773,14 +772,17 @@ SupportPoints check_stability(const PrintObject *po, const PrintTryCancel& cance // and the support presence grid and add the point to the issues. auto reckon_new_support_point = [&part, &weakest_conn, &supp_points, &supports_presence_grid, ¶ms, &layer_idx](const Vec3f &support_point, float force, const Vec2f &dir) { - if (supports_presence_grid.position_taken(support_point) || layer_idx <= 1) { return; } + if ((supports_presence_grid.position_taken(support_point) && force > 0) || layer_idx <= 1) { + return; + } float area = params.support_points_interface_radius * params.support_points_interface_radius * float(PI); part.add_support_point(support_point, area); float radius = params.support_points_interface_radius; supp_points.emplace_back(support_point, force, radius, dir); - supports_presence_grid.take_position(support_point); - + if (force > 0) { + supports_presence_grid.take_position(support_point); + } if (weakest_conn.area > EPSILON) { // Do not add it to the weakest connection if it is not valid - does not exist weakest_conn.area += area; weakest_conn.centroid_accumulator += support_point * area; diff --git a/src/libslic3r/SupportSpotsGenerator.hpp b/src/libslic3r/SupportSpotsGenerator.hpp index ca62061ff..1c07c1381 100644 --- a/src/libslic3r/SupportSpotsGenerator.hpp +++ b/src/libslic3r/SupportSpotsGenerator.hpp @@ -30,14 +30,13 @@ struct Params { // the algorithm should use the following units for all computations: distance [mm], mass [g], time [s], force [g*mm/s^2] const float bridge_distance = 12.0f; //mm - const float bridge_distance_decrease_by_curvature_factor = 10.0f; // allowed bridge distance = bridge_distance / (1 + this factor * curvature ) const std::pair malformation_distance_factors = std::pair { 0.4, 1.2 }; const float max_curled_height_factor = 10.0f; const float min_distance_between_support_points = 3.0f; //mm const float support_points_interface_radius = 1.5f; // mm const float connections_min_considerable_area = 1.5f; //mm^2 - const float min_distance_to_allow_local_supports = 2.0f; //mm + const float min_distance_to_allow_local_supports = 1.0f; //mm std::string filament_type; const float gravity_constant = 9806.65f; // mm/s^2; gravity acceleration on Earth's surface, algorithm assumes that printer is in upwards position.