From 7c02094b0f16fc0dac9a1bbbb55e32c729d428e8 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Tue, 17 Oct 2023 18:52:28 +0200 Subject: [PATCH] Consolidate duplicated code into 'fillInfillParts'. done as part of CURA-10407 --- include/sliceDataStorage.h | 11 +++++++++++ src/TreeSupport.cpp | 15 ++------------- src/TreeSupportTipGenerator.cpp | 15 +-------------- src/sliceDataStorage.cpp | 16 ++++++++++++++++ src/support.cpp | 14 +------------- 5 files changed, 31 insertions(+), 40 deletions(-) diff --git a/include/sliceDataStorage.h b/include/sliceDataStorage.h index 80b825211a..81d14f24a7 100644 --- a/include/sliceDataStorage.h +++ b/include/sliceDataStorage.h @@ -226,6 +226,17 @@ class SupportLayer * \param exclude_polygons_boundary_box The boundary box for the polygons to exclude */ void excludeAreasFromSupportInfillAreas(const Polygons& exclude_polygons, const AABB& exclude_polygons_boundary_box); + + /* Fill up the infill parts for the support with the given support polygons. The support polygons will be split into parts. This also takes into account fractional-height support layers. + * + * \param layer_nr Current layer index. + * \param support_fill_per_layer All of the (infill) support (since the layer above might be needed). + * \param support_line_width Line width of the support extrusions. + * \param wall_line_count Wall-line count around the fill. + * \param grow_layer_above (optional, default to 0) In cases where support shrinks per layer up, an appropriate offset may be nescesary. + * \param unionAll (optional, default to false) Wether to 'union all' for the split into parts bit. + */ + void fillInfillParts(const LayerIndex layer_nr, const std::vector& support_fill_per_layer, const coord_t support_line_width, const coord_t wall_line_count, const coord_t grow_layer_above = 0, const bool unionAll = false); }; class SupportStorage diff --git a/src/TreeSupport.cpp b/src/TreeSupport.cpp index 8d228ffa71..7c4fcda0a7 100644 --- a/src/TreeSupport.cpp +++ b/src/TreeSupport.cpp @@ -2226,19 +2226,8 @@ void TreeSupport::finalizeInterfaceAndSupportAreas(std::vector& suppor support_layer_storage[layer_idx] = support_layer_storage[layer_idx].difference(floor_layer.offset(10)); // Subtract the support floor from the normal support. } - const Polygons support_layer_storage_above - = (layer_idx + 1) >= support_layer_storage.size() || layer_idx <= 0 ? Polygons() : support_layer_storage[layer_idx + 1].offset(config.maximum_move_distance); - const auto all_support_areas_in_layer - = { support_layer_storage[layer_idx].difference(support_layer_storage_above), support_layer_storage[layer_idx].intersection(support_layer_storage_above) }; - bool use_fractional_config = true; - for (auto& support_areas : all_support_areas_in_layer) - { - for (auto& part : support_areas.splitIntoParts(true)) // Convert every part into a PolygonsPart for the support. - { - storage.support.supportLayers[layer_idx].support_infill_parts.emplace_back(part, config.support_line_width, use_fractional_config, config.support_wall_count); - } - use_fractional_config = false; - } + constexpr bool convert_every_part = true; // Convert every part into a PolygonsPart for the support. + storage.support.supportLayers[layer_idx].fillInfillParts(layer_idx, support_layer_storage, config.support_line_width, config.support_wall_count, config.maximum_move_distance, convert_every_part); { std::lock_guard critical_section_progress(critical_sections); diff --git a/src/TreeSupportTipGenerator.cpp b/src/TreeSupportTipGenerator.cpp index 7d669396c9..552f229dd6 100644 --- a/src/TreeSupportTipGenerator.cpp +++ b/src/TreeSupportTipGenerator.cpp @@ -1164,20 +1164,7 @@ void TreeSupportTipGenerator::generateTips( { if (use_fake_roof) { - const Polygons support_roof_drawn_above - = (layer_idx + 1) >= support_roof_drawn.size() || layer_idx <= 0 ? Polygons() : support_roof_drawn[layer_idx + 1].offset(config.maximum_move_distance); - const auto all_support_areas_in_layer - = { support_roof_drawn[layer_idx].difference(support_roof_drawn_above), support_roof_drawn[layer_idx].intersection(support_roof_drawn_above) }; - bool use_fractional_config = true; - for (auto& support_areas : all_support_areas_in_layer) - { - for (const auto& part : support_areas.splitIntoParts()) - { - storage.support.supportLayers[layer_idx] - .support_infill_parts.emplace_back(part, config.support_line_width, use_fractional_config, 0, support_roof_line_distance); - } - use_fractional_config = false; - } + storage.support.supportLayers[layer_idx].fillInfillParts(layer_idx, support_roof_drawn, config.support_line_width, support_roof_line_distance, config.maximum_move_distance); placed_support_lines_support_areas[layer_idx].add(TreeSupportUtils::generateSupportInfillLines( support_roof_drawn[layer_idx], config, diff --git a/src/sliceDataStorage.cpp b/src/sliceDataStorage.cpp index 4533fbb8be..61c6ff1689 100644 --- a/src/sliceDataStorage.cpp +++ b/src/sliceDataStorage.cpp @@ -705,4 +705,20 @@ void SupportLayer::excludeAreasFromSupportInfillAreas(const Polygons& exclude_po } } +void SupportLayer::fillInfillParts(const LayerIndex layer_nr, const std::vector& support_fill_per_layer, const coord_t support_line_width, const coord_t wall_line_count, const coord_t grow_layer_above /*has default 0*/, const bool unionAll /*has default false*/) +{ + const Polygons& support_this_layer = support_fill_per_layer[layer_nr]; + const Polygons& support_layer_above = (layer_nr + 1) >= support_fill_per_layer.size() || layer_nr <= 0 ? Polygons() : support_fill_per_layer[layer_nr + 1].offset(grow_layer_above); + const auto all_support_areas_in_layer = { support_this_layer.difference(support_layer_above), support_this_layer.intersection(support_layer_above) }; + bool use_fractional_config = true; + for (auto& support_areas : all_support_areas_in_layer) + { + for (const PolygonsPart& island_outline : support_areas.splitIntoParts(unionAll)) + { + support_infill_parts.emplace_back(island_outline, support_line_width, use_fractional_config, wall_line_count); + } + use_fractional_config = false; + } +} + } // namespace cura diff --git a/src/support.cpp b/src/support.cpp index 973b3528e7..a0b049fe04 100644 --- a/src/support.cpp +++ b/src/support.cpp @@ -122,19 +122,7 @@ void AreaSupport::splitGlobalSupportAreasIntoSupportInfillParts( } // We don't generate insets and infill area for the parts yet because later the skirt/brim and prime // tower will remove themselves from the support, so the outlines of the parts can be changed. - - const Polygons& global_support_areas_above - = (layer_nr + 1) >= global_support_areas_per_layer.size() || layer_nr <= 0 ? Polygons() : global_support_areas_per_layer[layer_nr + 1]; - const auto all_support_areas_in_layer = { global_support_areas.difference(global_support_areas_above), global_support_areas.intersection(global_support_areas_above) }; - bool use_fractional_config = true; - for (auto& support_areas : all_support_areas_in_layer) - { - for (const PolygonsPart& island_outline : support_areas.splitIntoParts()) - { - storage.support.supportLayers[layer_nr].support_infill_parts.emplace_back(island_outline, support_line_width_here, use_fractional_config, wall_line_count_this_layer); - } - use_fractional_config = false; - } + storage.support.supportLayers[layer_nr].fillInfillParts(layer_nr, global_support_areas_per_layer, support_line_width_here, wall_line_count_this_layer); } }