From 89beded09e0c507f5d411173bdeca1c8b1306647 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 21 Mar 2024 15:48:44 +0100 Subject: [PATCH] Avoid placing seams on overhang areas calculated by supports CURA-11630 --- include/PathOrderOptimizer.h | 15 ++++++++++++++- src/InsetOrderOptimizer.cpp | 14 +++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/PathOrderOptimizer.h b/include/PathOrderOptimizer.h index df1cc07c7e..0e05fb5138 100644 --- a/include/PathOrderOptimizer.h +++ b/include/PathOrderOptimizer.h @@ -87,6 +87,8 @@ class PathOrderOptimizer */ ZSeamConfig seam_config_; + const std::vector overhang_areas_; + static const std::unordered_multimap no_order_requirements_; /*! @@ -110,8 +112,10 @@ class PathOrderOptimizer const Polygons* combing_boundary = nullptr, const bool reverse_direction = false, const std::unordered_multimap& order_requirements = no_order_requirements_, - const bool group_outer_walls = false) + const bool group_outer_walls = false, + const std::vector& overhang_areas = {}) : start_point_(start_point) + , overhang_areas_(overhang_areas) , seam_config_(seam_config) , combing_boundary_((combing_boundary != nullptr && ! combing_boundary->empty()) ? combing_boundary : nullptr) , detect_loops_(detect_loops) @@ -718,6 +722,15 @@ class PathOrderOptimizer } } + for (const Polygons& overhang_area : overhang_areas_) + { + if (overhang_area.inside(here)) + { + score *= 50; + break; + } + } + constexpr double EPSILON = 5.0; if (std::abs(best_score - score) <= EPSILON) { diff --git a/src/InsetOrderOptimizer.cpp b/src/InsetOrderOptimizer.cpp index 82d4199d01..cb8c8a349e 100644 --- a/src/InsetOrderOptimizer.cpp +++ b/src/InsetOrderOptimizer.cpp @@ -98,8 +98,20 @@ bool InsetOrderOptimizer::addToLayer() const auto group_outer_walls = settings_.get("group_outer_walls"); // When we alternate walls, also alternate the direction at which the first wall starts in. // On even layers we start with normal direction, on odd layers with inverted direction. + + std::vector overhang_areas; + for (const std::shared_ptr& mesh : storage_.meshes) + { + if (layer_nr_ > 0 && layer_nr_ < mesh->overhang_areas.size()) + { + // For the offset we should take the support XY distance plus a few line_widths + overhang_areas.push_back(mesh->overhang_areas[layer_nr_].offset(5000)); + svg.writePolygons(mesh->overhang_areas[layer_nr_].offset(5000), SVG::Color::BLACK, 0.05); + } + } + PathOrderOptimizer - order_optimizer(gcode_layer_.getLastPlannedPositionOrStartingPosition(), z_seam_config_, detect_loops, combing_boundary, reverse, order, group_outer_walls); + order_optimizer(gcode_layer_.getLastPlannedPositionOrStartingPosition(), z_seam_config_, detect_loops, combing_boundary, reverse, order, group_outer_walls, overhang_areas); for (const auto& line : walls_to_be_added) {