From 9397da61fcb8efc27894915c11b354094b1a24ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Wed, 31 Jul 2024 14:00:18 +0200 Subject: [PATCH] SPE-2150: Remove top and bottom surfaces that are covered during multi-material segmentation. Co-authored-by: zhimin.zeng Co-authored-by: lane.wei --- src/libslic3r/MultiMaterialSegmentation.cpp | 32 +++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/MultiMaterialSegmentation.cpp b/src/libslic3r/MultiMaterialSegmentation.cpp index 9625cb1dca..12a6341abb 100644 --- a/src/libslic3r/MultiMaterialSegmentation.cpp +++ b/src/libslic3r/MultiMaterialSegmentation.cpp @@ -968,17 +968,39 @@ static inline std::vector> mm_segmentation_top_and_botto } auto filter_out_small_polygons = [&num_extruders, &num_layers](std::vector> &raw_surfaces, double min_area) -> void { - for (size_t extruder_idx = 0; extruder_idx < num_extruders; ++extruder_idx) - if (!raw_surfaces[extruder_idx].empty()) - for (size_t layer_idx = 0; layer_idx < num_layers; ++layer_idx) - if (!raw_surfaces[extruder_idx][layer_idx].empty()) - remove_small(raw_surfaces[extruder_idx][layer_idx], min_area); + for (size_t extruder_idx = 0; extruder_idx < num_extruders; ++extruder_idx) { + if (raw_surfaces[extruder_idx].empty()) + continue; + + for (size_t layer_idx = 0; layer_idx < num_layers; ++layer_idx) { + if (raw_surfaces[extruder_idx][layer_idx].empty()) + continue; + + remove_small(raw_surfaces[extruder_idx][layer_idx], min_area); + } + } }; // Filter out polygons less than 0.1mm^2, because they are unprintable and causing dimples on outer primers (#7104) filter_out_small_polygons(top_raw, Slic3r::sqr(scale_(0.1f))); filter_out_small_polygons(bottom_raw, Slic3r::sqr(scale_(0.1f))); + // Remove top and bottom surfaces that are covered by the previous or next sliced layer. + for (size_t extruder_idx = 0; extruder_idx < num_extruders; ++extruder_idx) { + for (size_t layer_idx = 0; layer_idx < num_layers; ++layer_idx) { + const bool has_top_surface = !top_raw[extruder_idx].empty() && !top_raw[extruder_idx][layer_idx].empty(); + const bool has_bottom_surface = !bottom_raw[extruder_idx].empty() && !bottom_raw[extruder_idx][layer_idx].empty(); + + if (has_top_surface && layer_idx < (num_layers - 1)) { + top_raw[extruder_idx][layer_idx] = diff(top_raw[extruder_idx][layer_idx], input_expolygons[layer_idx + 1]); + } + + if (has_bottom_surface && layer_idx > 0) { + bottom_raw[extruder_idx][layer_idx] = diff(bottom_raw[extruder_idx][layer_idx], input_expolygons[layer_idx - 1]); + } + } + } + #ifdef MM_SEGMENTATION_DEBUG_TOP_BOTTOM { const char* colors[] = { "aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "purple", "red", "silver", "teal", "yellow" };