From 5e339b3078f0c9d75b6fac28ed3c295ae9fbbef5 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Wed, 10 Feb 2021 14:11:34 +0100 Subject: [PATCH] Fuzzy Skin changes: 1) Moved the parameters to region 2) Removed experimental code. 3) Allowed fuzzyfication of both outer perimeter and holes. --- src/libslic3r/PerimeterGenerator.cpp | 157 +++------------------------ src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 49 ++------- src/libslic3r/PrintConfig.hpp | 60 ++-------- src/libslic3r/PrintObject.cpp | 3 +- src/slic3r/GUI/Field.cpp | 6 +- src/slic3r/GUI/GUI.cpp | 6 +- src/slic3r/GUI/OptionsGroup.cpp | 7 +- src/slic3r/GUI/Tab.cpp | 7 +- 9 files changed, 49 insertions(+), 248 deletions(-) diff --git a/src/libslic3r/PerimeterGenerator.cpp b/src/libslic3r/PerimeterGenerator.cpp index b6929b839f..eef737f971 100644 --- a/src/libslic3r/PerimeterGenerator.cpp +++ b/src/libslic3r/PerimeterGenerator.cpp @@ -5,7 +5,6 @@ #include #include -#include namespace Slic3r { @@ -122,8 +121,8 @@ public: // Children contour, may be both CCW and CW oriented (outer contours or holes). std::vector children; - PerimeterGeneratorLoop(Polygon polygon, unsigned short depth, bool is_contour) : - polygon(polygon), is_contour(is_contour), depth(depth) {} + PerimeterGeneratorLoop(Polygon &&polygon, unsigned short depth, bool is_contour) : + polygon(std::move(polygon)), is_contour(is_contour), depth(depth) {} // External perimeter. It may be CCW or CW oriented (outer contour or hole contour). bool is_external() const { return this->depth == 0; } // An island, which may have holes, but it does not have another internal island. @@ -231,90 +230,9 @@ static ExtrusionEntityCollection traverse_loops(const PerimeterGenerator &perime return out; } -/* -enum class FuzzyShape { - Triangle, - Sawtooth, - Random -}; -*/ - -static void fuzzy_polygon(Polygon &poly, /* FuzzyShape shape, */ double fuzzy_skin_thickness, double fuzzy_skin_point_dist) +// Thanks Cura developers for this function. +static void fuzzy_polygon(Polygon &poly, double fuzzy_skin_thickness, double fuzzy_skin_point_dist) { -#if 0 - Point last = poly.points.at(poly.points.size() - 1); - Point last_processed = last; - - double max_length = scale_(2); - double min_length = scale_(1); - - if (poly.length() < scale_(5)) - return; - - deepness *= 3; - - bool triangle_or_sawtooth = shape == FuzzyShape::Sawtooth; - double length_sum = 0; - Points::iterator it = poly.points.begin(); - while (it != poly.points.end()) { - Point &pt = *it; - - Line line(last, pt); - double length = line.length(); - - // split long line - if (length > max_length) { - auto parts = int(ceil(length / max_length)); - if (parts == 2) { - Point point_to_insert(line.midpoint()); - it = poly.points.insert(it, point_to_insert); - } - else { - Vector part_vector = line.vector() / parts; - - Points points_to_insert; - Point point_to_insert(last); - while (--parts) { - point_to_insert += part_vector; - Point point_to_insert_2(point_to_insert); - points_to_insert.push_back(point_to_insert_2); - } - - it = poly.points.insert(it, points_to_insert.begin(), points_to_insert.end()); - } - continue; - } - - length_sum += length; - - // join short lines - if (length_sum < min_length) { - last = pt; - it = poly.points.erase(it); - continue; - } - - line = Line(last_processed, pt); - last = pt; - last_processed = pt; - - if (shape == FuzzyShape::Random) { - triangle_or_sawtooth = !(rand() % 2); - } - - Point point_to_insert(triangle_or_sawtooth ? pt : line.midpoint()); - - int scale = (rand() % deepness) + 1; - - Vec2d normal = line.normal().cast(); - normal /= line.length() / scale_(1.) / ((double)scale / 20.); - - it = poly.points.insert(it, point_to_insert + normal.cast()) + 2; - - length_sum = 0; - } - -#else const double min_dist_between_points = fuzzy_skin_point_dist * 3. / 4.; // hardcoded: the point distance may vary between 3/4 and 5/4 the supplied value const double range_random_point_dist = fuzzy_skin_point_dist / 2.; double dist_left_over = double(rand()) * (min_dist_between_points / 2) / double(RAND_MAX); // the distance to be traversed on the line before making the first new point @@ -346,15 +264,10 @@ static void fuzzy_polygon(Polygon &poly, /* FuzzyShape shape, */ double fuzzy_sk } if (out.size() >= 3) poly.points = std::move(out); -#endif } void PerimeterGenerator::process() { - // nasty hack! initialize random generator - auto time_us = std::chrono::duration_cast(std::chrono::time_point_cast(std::chrono::high_resolution_clock::now()).time_since_epoch()).count(); - srand(this->layer_id * time_us); - // other perimeters m_mm3_per_mm = this->perimeter_flow.mm3_per_mm(); coord_t perimeter_width = this->perimeter_flow.scaled_width(); @@ -396,30 +309,8 @@ void PerimeterGenerator::process() } // fuzzy skin configuration - double fuzzy_skin_thickness = scale_(this->object_config->fuzzy_skin_thickness); - double fuzzy_skin_point_dist = scale_(this->object_config->fuzzy_skin_point_dist); - //FuzzyShape fuzzy_skin_shape; - if (this->object_config->fuzzy_skin_perimeter_mode != FuzzySkinPerimeterMode::None) { - /* - switch (this->object_config->fuzzy_skin_shape) { - case FuzzySkinShape::Triangle1: - case FuzzySkinShape::Triangle2: - case FuzzySkinShape::Triangle3: - fuzzy_skin_shape = FuzzyShape::Triangle; - break; - case FuzzySkinShape::Sawtooth1: - case FuzzySkinShape::Sawtooth2: - case FuzzySkinShape::Sawtooth3: - fuzzy_skin_shape = FuzzyShape::Sawtooth; - break; - case FuzzySkinShape::Random1: - case FuzzySkinShape::Random2: - case FuzzySkinShape::Random3: - fuzzy_skin_shape = FuzzyShape::Random; - break; - } - */ - } + double fuzzy_skin_thickness = scale_(this->config->fuzzy_skin_thickness); + double fuzzy_skin_point_dist = scale_(this->config->fuzzy_skin_point_dist); // we need to process each island separately because we might have different // extra perimeters for each one @@ -501,39 +392,27 @@ void PerimeterGenerator::process() // If i > loop_number, we were looking just for gaps. break; } - for (ExPolygon &expolygon : offsets) { + const bool fuzzify = this->config->fuzzy_skin != FuzzySkinType::None && i == 0 && this->layer_id > 0; + for (ExPolygon expolygon : offsets) { // Outer contour may overlap with an inner contour, // inner contour may overlap with another inner contour, // outer contour may overlap with itself. //FIXME evaluate the overlaps, annotate each point with an overlap depth, - - bool skip_polygon = false; - - if (this->object_config->fuzzy_skin_perimeter_mode != FuzzySkinPerimeterMode::None) { - if (i == 0 && (this->object_config->fuzzy_skin_perimeter_mode != FuzzySkinPerimeterMode::ExternalSkipFirst || this->layer_id > 0)) { - if ( - this->object_config->fuzzy_skin_perimeter_mode == FuzzySkinPerimeterMode::External || - this->object_config->fuzzy_skin_perimeter_mode == FuzzySkinPerimeterMode::ExternalSkipFirst - ) { - ExPolygon expolygon_fuzzy(expolygon); - fuzzy_polygon(expolygon_fuzzy.contour, /* fuzzy_skin_shape, */ fuzzy_skin_thickness, fuzzy_skin_point_dist); - // compensate for the depth of intersection. - contours[i].emplace_back(PerimeterGeneratorLoop(expolygon_fuzzy.contour, i, true)); - skip_polygon = true; - } else - fuzzy_polygon(expolygon.contour, /* fuzzy_skin_shape, */ fuzzy_skin_thickness, fuzzy_skin_point_dist); - } + if (fuzzify) { + // External perimeter, above the 1st layer. + fuzzy_polygon(expolygon.contour, fuzzy_skin_thickness, fuzzy_skin_point_dist); + if (this->config->fuzzy_skin == FuzzySkinType::All) + for (Polygon &hole : expolygon.holes) + fuzzy_polygon(hole, fuzzy_skin_thickness, fuzzy_skin_point_dist); } - if (!skip_polygon) { - // compensate for the depth of intersection. - contours[i].emplace_back(PerimeterGeneratorLoop(expolygon.contour, i, true)); - } + // compensate for the depth of intersection. + contours[i].emplace_back(std::move(expolygon.contour), i, true); if (! expolygon.holes.empty()) { holes[i].reserve(holes[i].size() + expolygon.holes.size()); - for (const Polygon &hole : expolygon.holes) - holes[i].emplace_back(PerimeterGeneratorLoop(hole, i, false)); + for (Polygon &hole : expolygon.holes) + holes[i].emplace_back(std::move(hole), i, false); } } last = std::move(offsets); diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index b7e966c9e7..476ee81c52 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -411,7 +411,7 @@ const std::vector& Preset::print_options() "solid_infill_below_area", "only_retract_when_crossing_perimeters", "infill_first", "ironing", "ironing_type", "ironing_flowrate", "ironing_speed", "ironing_spacing", "max_print_speed", "max_volumetric_speed", "avoid_crossing_perimeters_max_detour", - "fuzzy_skin_perimeter_mode", /* "fuzzy_skin_shape", */ "fuzzy_skin_thickness", "fuzzy_skin_point_dist", + "fuzzy_skin", "fuzzy_skin_thickness", "fuzzy_skin_point_dist", #ifdef HAS_PRESSURE_EQUALIZER "max_volumetric_extrusion_rate_slope_positive", "max_volumetric_extrusion_rate_slope_negative", #endif /* HAS_PRESSURE_EQUALIZER */ diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 7aaacc4c74..ad1769b497 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1032,51 +1032,20 @@ void PrintConfigDef::init_fff_params() def->mode = comExpert; def->set_default_value(new ConfigOptionInts { 0 }); - def = this->add("fuzzy_skin_perimeter_mode", coEnum); - def->label = L("Fuzzy skin perimeter mode"); + def = this->add("fuzzy_skin", coEnum); + def->label = L("Fuzzy Skin"); def->category = L("Fuzzy Skin"); - def->tooltip = L("Fuzzy skin perimeter mode."); + def->tooltip = L("Fuzzy skin type."); - def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); def->enum_values.push_back("none"); - def->enum_values.push_back("external_only"); - def->enum_values.push_back("external_only_skip_first_layer"); + def->enum_values.push_back("external"); def->enum_values.push_back("all"); def->enum_labels.push_back(L("None")); - def->enum_labels.push_back(L("External")); - def->enum_labels.push_back(L("External (skip first layer)")); + def->enum_labels.push_back(L("External perimeters")); def->enum_labels.push_back(L("All perimeters")); def->mode = comSimple; - def->set_default_value(new ConfigOptionEnum(FuzzySkinPerimeterMode::None)); - -/* - def = this->add("fuzzy_skin_shape", coEnum); - def->label = L("Fuzzy skin shape"); - def->category = L("Fuzzy Skin"); - def->tooltip = L("Fuzzy skin shape."); - - def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); - def->enum_values.push_back("triangle1"); - def->enum_values.push_back("triangle2"); - def->enum_values.push_back("triangle3"); - def->enum_values.push_back("sawtooth1"); - def->enum_values.push_back("sawtooth2"); - def->enum_values.push_back("sawtooth3"); - def->enum_values.push_back("random1"); - def->enum_values.push_back("random2"); - def->enum_values.push_back("random3"); - def->enum_labels.push_back(L("Triangle (1)")); - def->enum_labels.push_back(L("Triangle (2)")); - def->enum_labels.push_back(L("Triangle (3)")); - def->enum_labels.push_back(L("Sawtooth (1)")); - def->enum_labels.push_back(L("Sawtooth (2)")); - def->enum_labels.push_back(L("Sawtooth (3)")); - def->enum_labels.push_back(L("Random (1)")); - def->enum_labels.push_back(L("Random (2)")); - def->enum_labels.push_back(L("Random (3)")); - def->mode = comSimple; - def->set_default_value(new ConfigOptionEnum(FuzzySkinShape::Triangle1)); -*/ + def->set_default_value(new ConfigOptionEnum(FuzzySkinType::None)); def = this->add("fuzzy_skin_thickness", coFloat); def->label = L("Fuzzy skin thickness"); @@ -3350,7 +3319,9 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va #ifndef HAS_PRESSURE_EQUALIZER , "max_volumetric_extrusion_rate_slope_positive", "max_volumetric_extrusion_rate_slope_negative", #endif /* HAS_PRESSURE_EQUALIZER */ - "serial_port", "serial_speed" + "serial_port", "serial_speed", + // Introduced in some PrusaSlicer 2.3.1 alpha, later renamed or removed. + "fuzzy_skin_perimeter_mode", "fuzzy_skin_shape", }; // In PrusaSlicer 2.3.0-alpha0 the "monotonous" infill was introduced, which was later renamed to "monotonic". diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 5189baab2d..84c0c21c3d 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -43,27 +43,12 @@ enum AuthorizationType { atKeyPassword, atUserPassword }; -enum class FuzzySkinPerimeterMode { +enum class FuzzySkinType { None, External, - ExternalSkipFirst, - All + All, }; -/* -enum class FuzzySkinShape { - Triangle1, - Triangle2, - Triangle3, - Sawtooth1, - Sawtooth2, - Sawtooth3, - Random1, - Random2, - Random3 -}; -*/ - enum InfillPattern : int { ipRectilinear, ipMonotonic, ipAlignedRectilinear, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb, ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipAdaptiveCubic, ipSupportCubic, ipCount, @@ -168,35 +153,16 @@ template<> inline const t_config_enum_values& ConfigOptionEnum inline const t_config_enum_values& ConfigOptionEnum::get_enum_values() { +template<> inline const t_config_enum_values& ConfigOptionEnum::get_enum_values() { static t_config_enum_values keys_map; if (keys_map.empty()) { - keys_map["none"] = int(FuzzySkinPerimeterMode::None); - keys_map["external_only"] = int(FuzzySkinPerimeterMode::External); - keys_map["external_only_skip_first_layer"] = int(FuzzySkinPerimeterMode::ExternalSkipFirst); - keys_map["all"] = int(FuzzySkinPerimeterMode::All); + keys_map["none"] = int(FuzzySkinType::None); + keys_map["external"] = int(FuzzySkinType::External); + keys_map["all"] = int(FuzzySkinType::All); } return keys_map; } -/* -template<> inline const t_config_enum_values& ConfigOptionEnum::get_enum_values() { - static t_config_enum_values keys_map; - if (keys_map.empty()) { - keys_map["triangle1"] = int(FuzzySkinShape::Triangle1); - keys_map["triangle2"] = int(FuzzySkinShape::Triangle2); - keys_map["triangle3"] = int(FuzzySkinShape::Triangle3); - keys_map["sawtooth1"] = int(FuzzySkinShape::Sawtooth1); - keys_map["sawtooth2"] = int(FuzzySkinShape::Sawtooth2); - keys_map["sawtooth3"] = int(FuzzySkinShape::Sawtooth3); - keys_map["random1"] = int(FuzzySkinShape::Random1); - keys_map["random2"] = int(FuzzySkinShape::Random2); - keys_map["random3"] = int(FuzzySkinShape::Random3); - } - return keys_map; -} -*/ - template<> inline const t_config_enum_values& ConfigOptionEnum::get_enum_values() { static t_config_enum_values keys_map; if (keys_map.empty()) { @@ -503,10 +469,6 @@ public: ConfigOptionFloat elefant_foot_compensation; ConfigOptionFloatOrPercent extrusion_width; ConfigOptionFloatOrPercent first_layer_height; - ConfigOptionEnum fuzzy_skin_perimeter_mode; -// ConfigOptionEnum fuzzy_skin_shape; - ConfigOptionFloat fuzzy_skin_thickness; - ConfigOptionFloat fuzzy_skin_point_dist; ConfigOptionBool infill_only_where_needed; // Force the generation of solid shells between adjacent materials/volumes. ConfigOptionBool interface_shells; @@ -555,10 +517,6 @@ protected: OPT_PTR(elefant_foot_compensation); OPT_PTR(extrusion_width); OPT_PTR(first_layer_height); - OPT_PTR(fuzzy_skin_perimeter_mode); -// OPT_PTR(fuzzy_skin_shape); - OPT_PTR(fuzzy_skin_thickness); - OPT_PTR(fuzzy_skin_point_dist); OPT_PTR(infill_only_where_needed); OPT_PTR(interface_shells); OPT_PTR(layer_height); @@ -612,6 +570,9 @@ public: ConfigOptionFloat fill_angle; ConfigOptionPercent fill_density; ConfigOptionEnum fill_pattern; + ConfigOptionEnum fuzzy_skin; + ConfigOptionFloat fuzzy_skin_thickness; + ConfigOptionFloat fuzzy_skin_point_dist; ConfigOptionFloat gap_fill_speed; ConfigOptionFloatOrPercent infill_anchor; ConfigOptionFloatOrPercent infill_anchor_max; @@ -665,6 +626,9 @@ protected: OPT_PTR(fill_angle); OPT_PTR(fill_density); OPT_PTR(fill_pattern); + OPT_PTR(fuzzy_skin); + OPT_PTR(fuzzy_skin_thickness); + OPT_PTR(fuzzy_skin_point_dist); OPT_PTR(gap_fill_speed); OPT_PTR(infill_anchor); OPT_PTR(infill_anchor_max); diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 233f693e3c..cadd86e886 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -522,8 +522,7 @@ bool PrintObject::invalidate_state_by_config_options(const std::vector(ret_enum); - else if (m_opt_id.compare("fuzzy_skin_perimeter_mode") == 0) - m_value = static_cast(ret_enum); -// else if (m_opt_id.compare("fuzzy_skin_shape") == 0) -// m_value = static_cast(ret_enum); + else if (m_opt_id.compare("fuzzy_skin") == 0) + m_value = static_cast(ret_enum); else if (m_opt_id.compare("gcode_flavor") == 0) m_value = static_cast(ret_enum); else if (m_opt_id.compare("machine_limits_usage") == 0) diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 3b44f20696..942a50e6b0 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -182,10 +182,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); else if (opt_key.compare("ironing_type") == 0) config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); - else if (opt_key.compare("fuzzy_skin_perimeter_mode") == 0) - config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); -// else if (opt_key.compare("fuzzy_skin_shape") == 0) -// config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); + else if (opt_key.compare("fuzzy_skin") == 0) + config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); else if (opt_key.compare("gcode_flavor") == 0) config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); else if (opt_key.compare("machine_limits_usage") == 0) diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index d077c81f60..d4eeaba48d 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -869,12 +869,9 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config else if (opt_key == "ironing_type") { ret = static_cast(config.option>(opt_key)->value); } - else if (opt_key == "fuzzy_skin_perimeter_mode") { - ret = static_cast(config.option>(opt_key)->value); + else if (opt_key == "fuzzy_skin") { + ret = static_cast(config.option>(opt_key)->value); } -// else if (opt_key == "fuzzy_skin_shape") { -// ret = static_cast(config.option>(opt_key)->value); -// } else if (opt_key == "gcode_flavor") { ret = static_cast(config.option>(opt_key)->value); } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 6f371d1752..bd7cb25854 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1437,14 +1437,9 @@ void TabPrint::build() optgroup->append_single_option_line("external_perimeters_first", category_path + "external-perimeters-first"); optgroup = page->new_optgroup(L("Fuzzy skin (experimental)")); - Option option = optgroup->get_option("fuzzy_skin_perimeter_mode"); + Option option = optgroup->get_option("fuzzy_skin"); option.opt.width = 30; optgroup->append_single_option_line(option); -#if 0 - option = optgroup->get_option("fuzzy_skin_shape"); - option.opt.width = 30; - optgroup->append_single_option_line(option); -#endif optgroup->append_single_option_line(optgroup->get_option("fuzzy_skin_thickness")); optgroup->append_single_option_line(optgroup->get_option("fuzzy_skin_point_dist"));