From 151ea0a39f94d383fdf17802e4e52e787a7bae46 Mon Sep 17 00:00:00 2001 From: supermerill Date: Thu, 29 Oct 2020 19:44:25 +0100 Subject: [PATCH] #612 add soft threshold for big holes XY compensation --- resources/ui_layout/print.ui | 5 ++++- src/libslic3r/PrintConfig.cpp | 16 ++++++++++++++-- src/libslic3r/PrintConfig.hpp | 2 ++ src/libslic3r/PrintObject.cpp | 24 ++++++++++++++++++++---- src/libslic3r/libslic3r.h | 2 ++ src/slic3r/GUI/Preset.cpp | 3 ++- 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/resources/ui_layout/print.ui b/resources/ui_layout/print.ui index 61ce0f3de..b3a5f615f 100644 --- a/resources/ui_layout/print.ui +++ b/resources/ui_layout/print.ui @@ -86,12 +86,15 @@ group:label_width$8:Modifying slices setting:width$6:curve_smoothing_angle_concave setting:width$6:curve_smoothing_cutoff_dist end_line - setting:hole_to_polyhole line:XY compensation setting:width$6:xy_size_compensation setting:width$6:xy_inner_size_compensation setting:width$6:first_layer_size_compensation + end_line + line:Vertical Hole shrinking compensation + setting:hole_to_polyhole setting:width$6:hole_size_compensation + setting:width$6:hole_size_threshold end_line group:Other setting:clip_multipart_objects diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index c7bb30d17..fd1b4c389 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3725,7 +3725,8 @@ void PrintConfigDef::init_fff_params() def->category = OptionCategory::slicing; def->tooltip = L("The object will be grown/shrunk in the XY plane by the configured value " "(negative = inwards, positive = outwards). This might be useful for fine-tuning sizes." - "\nThis one only applies to the 'exterior' shell of the object"); + "\nThis one only applies to the 'exterior' shell of the object." + "\n !!! it's recommended you put the same value into the 'Inner XY size compensation', unless you are sure you don't have horizontal holes. !!! "); def->sidetext = L("mm"); def->mode = comExpert; def->set_default_value(new ConfigOptionFloat(0)); @@ -3736,7 +3737,7 @@ void PrintConfigDef::init_fff_params() def->category = OptionCategory::slicing; def->tooltip = L("The object will be grown/shrunk in the XY plane by the configured value " "(negative = inwards, positive = outwards). This might be useful for fine-tuning sizes." - "\nThis one only applies to the 'inner' shell of the object"); + "\nThis one only applies to the 'inner' shell of the object (!!! horizontal holes break the shell !!!)"); def->sidetext = L("mm"); def->mode = comExpert; def->set_default_value(new ConfigOptionFloat(0)); @@ -3753,6 +3754,17 @@ void PrintConfigDef::init_fff_params() def->mode = comExpert; def->set_default_value(new ConfigOptionFloat(0)); + def = this->add("hole_size_threshold", coFloat); + def->label = L("Holes"); + def->full_label = L("XY holes threshold"); + def->category = OptionCategory::slicing; + def->tooltip = L("Maximum area for the hole where the hole_size_compensation will apply fully." + " After that, it will decraese down to 0 for four time this area." + " Set to 0 to let the hole_size_compensation apply fully for all detected holes"); + def->sidetext = L("mm²"); + def->mode = comExpert; + def->set_default_value(new ConfigOptionFloat(100)); + def = this->add("hole_to_polyhole", coBool); def->label = L("Convert round holes to polyholes"); def->full_label = L("Convert round holes to polyholes"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 79d66e7fa..78cc0974a 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -530,6 +530,7 @@ public: ConfigOptionFloatOrPercent first_layer_height; ConfigOptionFloat first_layer_size_compensation; ConfigOptionFloat hole_size_compensation; + ConfigOptionFloat hole_size_threshold; ConfigOptionBool infill_only_where_needed; // Force the generation of solid shells between adjacent materials/volumes. ConfigOptionBool interface_shells; @@ -592,6 +593,7 @@ protected: OPT_PTR(exact_last_layer_height); OPT_PTR(extrusion_width); OPT_PTR(hole_size_compensation); + OPT_PTR(hole_size_threshold); OPT_PTR(first_layer_height); OPT_PTR(first_layer_size_compensation); OPT_PTR(infill_only_where_needed); diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index bdf797137..eea125c22 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -646,6 +646,7 @@ bool PrintObject::invalidate_state_by_config_options(const std::vector max_hole_area * 4) { + convex_delta_adapted = 0; + }else if (area > max_hole_area) { + // not a hard threshold, to avoid artefacts on slopped holes. + convex_delta_adapted = convex_delta * (max_hole_area * 4 - area) / (max_hole_area * 3); + } + if (convex_delta_adapted != 0) { + for (Polygon &newHole : offset(hole, -convex_delta_adapted)) { + newHole.make_counter_clockwise(); + holes.emplace_back(std::move(newHole)); + } + } else { + holes.push_back(hole); + holes.back().make_counter_clockwise(); } } else { holes.push_back(hole); diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index 0fd3a61d5..17bf5a717 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -100,6 +100,8 @@ inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); } inline double unscaled(double v) { return v * SCALING_FACTOR; } inline coordf_t unscale_(coord_t v) { return v * SCALING_FACTOR; } inline coord_t scale_t(coordf_t v) { return (coord_t)(v / SCALING_FACTOR); } +inline double scale_d(coordf_t v) { return (v / SCALING_FACTOR); } +inline double scale_d(coord_t v) { return ((double)v / SCALING_FACTOR); } enum Axis { X=0, diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index a7ea408fb..fe4da3f14 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -519,7 +519,8 @@ const std::vector& Preset::print_options() "first_layer_size_compensation", "xy_size_compensation", "xy_inner_size_compensation", - "hole_size_compensation", + "hole_size_compensation", + "hole_size_threshold", "hole_to_polyhole", "threads", "resolution", "wipe_tower", "wipe_tower_x", "wipe_tower_y", "wipe_tower_width", "wipe_tower_rotation_angle", "wipe_tower_bridging",