From d4d66f11a878852ecb731ad00722de4363df7ea0 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Thu, 4 Jan 2024 17:38:02 +0100 Subject: [PATCH] wall ordering fixing with line width CURA-11388 --- include/InsetOrderOptimizer.h | 2 +- src/InsetOrderOptimizer.cpp | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/InsetOrderOptimizer.h b/include/InsetOrderOptimizer.h index e813a134af..8ad97b1242 100644 --- a/include/InsetOrderOptimizer.h +++ b/include/InsetOrderOptimizer.h @@ -72,7 +72,7 @@ class InsetOrderOptimizer * * \param outer_to_inner Whether the wall polygons with a lower inset_idx should go before those with a higher one. */ - static value_type getRegionOrder(const std::vector& input, const bool outer_to_inner); + static value_type getRegionOrder(const std::vector& input, const bool outer_to_inner, const coord_t line_width); /*! * Get the order constraints of the insets when printing walls per inset. diff --git a/src/InsetOrderOptimizer.cpp b/src/InsetOrderOptimizer.cpp index 448adc26d8..22d41e2690 100644 --- a/src/InsetOrderOptimizer.cpp +++ b/src/InsetOrderOptimizer.cpp @@ -75,6 +75,7 @@ bool InsetOrderOptimizer::addToLayer() const auto pack_by_inset = ! settings_.get("optimize_wall_printing_order"); const auto inset_direction = settings_.get("inset_direction"); const auto alternate_walls = settings_.get("material_alternate_walls"); + const auto line_width = settings_.get("line_width"); const bool outer_to_inner = inset_direction == InsetDirection::OUTSIDE_IN; const bool use_one_extruder = wall_0_extruder_nr_ == wall_x_extruder_nr_; @@ -83,7 +84,7 @@ bool InsetOrderOptimizer::addToLayer() const bool reverse = shouldReversePath(use_one_extruder, current_extruder_is_wall_x, outer_to_inner); auto walls_to_be_added = getWallsToBeAdded(reverse, use_one_extruder); - const auto order = pack_by_inset ? getInsetOrder(walls_to_be_added, outer_to_inner) : getRegionOrder(walls_to_be_added, outer_to_inner); + const auto order = pack_by_inset ? getInsetOrder(walls_to_be_added, outer_to_inner) : getRegionOrder(walls_to_be_added, outer_to_inner, line_width); constexpr Ratio flow = 1.0_r; @@ -136,7 +137,7 @@ bool InsetOrderOptimizer::addToLayer() return added_something; } -InsetOrderOptimizer::value_type InsetOrderOptimizer::getRegionOrder(const std::vector& extrusion_lines, const bool outer_to_inner) +InsetOrderOptimizer::value_type InsetOrderOptimizer::getRegionOrder(const std::vector& extrusion_lines, const bool outer_to_inner, const coord_t line_width) { if (extrusion_lines.empty()) { @@ -185,7 +186,9 @@ InsetOrderOptimizer::value_type InsetOrderOptimizer::getRegionOrder(const std::v // Create a polygon representing the inner area of the extrusion line; any // point inside this polygon is considered to the child of the extrusion line. Polygons hole_polygons; - for (const auto& poly : extrusion_line->toExtrusionPolygons().splitIntoParts()) + Polygons outer_polygons; + outer_polygons.add(extrusion_line->toPolygon()); + for (const auto& poly : outer_polygons.offsetPolyLine(line_width/2, ClipperLib::JoinType::jtRound).splitIntoParts()) { // drop first path, as this is the outer contour for (const auto& hole : poly.paths | ranges::views::drop(1)) @@ -195,7 +198,7 @@ InsetOrderOptimizer::value_type InsetOrderOptimizer::getRegionOrder(const std::v } } // increase the size of the hole polygons by 10um to make sure we don't miss any invariant parents - hole_polygons = hole_polygons.offset(10); + hole_polygons = hole_polygons.offset(line_width/2); // go through all the invariant parents and see if they are inside the hole polygon // if they are, then that means we have found a child for this extrusion line