From 5eaec515bafe7cf20f7dacd37ece59cc154f0ddd Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 7 Nov 2022 20:00:34 +0100 Subject: [PATCH] Follow-up to f24b4e86a9612fcf4cba28a5ae9f24db13f1b171: Refactoring of G-code export to LayerSlices / LayerIslands: Fixed some bugs --- src/libslic3r/GCode/ToolOrdering.cpp | 2 +- src/libslic3r/GCode/ToolOrdering.hpp | 7 ++++++- src/libslic3r/Layer.cpp | 25 +++++++++---------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index fc2e7ae2c..ca4ddf4d5 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -667,7 +667,7 @@ float WipingExtrusions::mark_wiping_extrusions(const Print& print, const LayerTo // we will sort objects so that dedicated for wiping are at the beginning: ConstPrintObjectPtrs object_list(print.objects().begin(), print.objects().end()); - std::sort(object_list.begin(), object_list.end(), [](const PrintObject* a, const PrintObject* b) { return a->config().wipe_into_objects; }); + std::sort(object_list.begin(), object_list.end(), [](const PrintObject* a, const PrintObject* b) { return a->config().wipe_into_objects && ! b->config().wipe_into_objects; }); // We will now iterate through // - first the dedicated objects to mark perimeters or infills (depending on infill_first) diff --git a/src/libslic3r/GCode/ToolOrdering.hpp b/src/libslic3r/GCode/ToolOrdering.hpp index 4aa3dda4e..4fb6e56c0 100644 --- a/src/libslic3r/GCode/ToolOrdering.hpp +++ b/src/libslic3r/GCode/ToolOrdering.hpp @@ -30,7 +30,12 @@ public: } // When allocating extruder overrides of an object's ExtrusionEntity, overrides for maximum 3 copies are allocated in place. - typedef boost::container::small_vector ExtruderPerCopy; + using ExtruderPerCopy = +#ifdef NDEBUG + boost::container::small_vector; +#else // NDEBUG + std::vector; +#endif // NDEBUG // This is called from GCode::process_layer_single_object() // Returns positive number if the extruder is overridden. diff --git a/src/libslic3r/Layer.cpp b/src/libslic3r/Layer.cpp index f785757d0..ebe3b8814 100644 --- a/src/libslic3r/Layer.cpp +++ b/src/libslic3r/Layer.cpp @@ -233,9 +233,9 @@ static void connect_layer_slices( } } for (int32_t islice = 0; islice < above.lslices_ex.size(); ++ islice) { - LayerSlice::Links &links1 = above.lslices_ex[islice].overlaps_above; + LayerSlice::Links &links1 = above.lslices_ex[islice].overlaps_below; for (LayerSlice::Link &link1 : links1) { - LayerSlice::Links &links2 = below.lslices_ex[link1.slice_idx].overlaps_below; + LayerSlice::Links &links2 = below.lslices_ex[link1.slice_idx].overlaps_above; assert(! std::binary_search(links2.begin(), links2.end(), link1, [](auto &l, auto &r){ return l.slice_idx < r.slice_idx; })); } } @@ -688,24 +688,17 @@ void Layer::sort_perimeters_into_islands( std::numeric_limits::max() : (lslices[lslice_idx].point_projection(point) - point).cast().squaredNorm(); }; - for (int lslice_idx = int(lslices_ex.size()) - 1; lslice_idx >= 0 && ! perimeter_slices_queue.empty(); -- lslice_idx) { + for (auto it_source_slice = perimeter_slices_queue.begin(); it_source_slice != perimeter_slices_queue.end(); ++ it_source_slice) { double d2min = std::numeric_limits::max(); - auto it_source_slice = perimeter_slices_queue.end(); - for (auto it = perimeter_slices_queue.begin(); it != perimeter_slices_queue.end(); ++ it) - if (double d2 = point_inside_surface_dist2(lslice_idx, it->second); d2 < d2min) { + int lslice_idx_min = -1; + for (int lslice_idx = int(lslices_ex.size()) - 1; lslice_idx >= 0 && ! perimeter_slices_queue.empty(); -- lslice_idx) + if (double d2 = point_inside_surface_dist2(lslice_idx, it_source_slice->second); d2 < d2min) { d2min = d2; - it_source_slice = it; + lslice_idx_min = lslice_idx; } - assert(it_source_slice != perimeter_slices_queue.end()); - if (it_source_slice != perimeter_slices_queue.end()) { - insert_into_island(lslice_idx, it_source_slice->first); - if (std::next(it_source_slice) != perimeter_slices_queue.end()) - // Remove the current slice & point pair from the queue. - *it_source_slice = perimeter_slices_queue.back(); - perimeter_slices_queue.pop_back(); - } + assert(lslice_idx_min != -1); + insert_into_island(lslice_idx_min, it_source_slice->first); } - assert(perimeter_slices_queue.empty()); } void Layer::export_region_slices_to_svg(const char *path) const