diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp index e7f6b1a76e..9fd20cf9f5 100644 --- a/src/libslic3r/Fill/Fill.cpp +++ b/src/libslic3r/Fill/Fill.cpp @@ -403,7 +403,7 @@ static void insert_fills_into_islands(Layer &layer, uint32_t fill_region_id, uin } assert(island); if (island) - island->fills.push_back(LayerExtrusionRange{ fill_region_id, { fill_begin, fill_end }}); + island->add_fill_range(LayerExtrusionRange{ fill_region_id, { fill_begin, fill_end }}); } } } @@ -550,14 +550,14 @@ void Layer::make_fills(FillAdaptive::Octree* adaptive_fill_octree, FillAdaptive: collection.entities.reserve(island.thin_fills.size()); for (uint32_t fill_id : island.thin_fills) collection.entities.push_back(layerm.thin_fills().entities[fill_id]->clone()); - island.fills.push_back({ island.perimeters.region(), { uint32_t(layerm.m_fills.entities.size() - 1), uint32_t(layerm.m_fills.entities.size()) } }); + island.add_fill_range({ island.perimeters.region(), { uint32_t(layerm.m_fills.entities.size() - 1), uint32_t(layerm.m_fills.entities.size()) } }); } // Sort the fills by region ID. std::sort(island.fills.begin(), island.fills.end(), [](auto &l, auto &r){ return l.region() < r.region() || (l.region() == r.region() && *l.begin() < *r.begin()); }); // Compress continuous fill ranges of the same region. { size_t k = 0; - for (size_t i = 0; i < island.fills.size(); ++ i) { + for (size_t i = 0; i < island.fills.size();) { uint32_t region_id = island.fills[i].region(); uint32_t begin = *island.fills[i].begin(); uint32_t end = *island.fills[i].end(); @@ -565,6 +565,7 @@ void Layer::make_fills(FillAdaptive::Octree* adaptive_fill_octree, FillAdaptive: for (; j < island.fills.size() && island.fills[j].region() == region_id && *island.fills[j].begin() == end; ++ j) end = *island.fills[j].end(); island.fills[k ++] = { region_id, { begin, end } }; + i = j; } island.fills.erase(island.fills.begin() + k, island.fills.end()); } diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 5776541ae9..06801b0e48 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2430,12 +2430,13 @@ void GCode::process_layer_single_object( } }; auto process_infill = [&]() { - for (auto it = island.fills.begin(); it != island.fills.end(); ++ it) { + for (auto it = island.fills.begin(); it != island.fills.end();) { // Gather range of fill ranges with the same region. auto it_end = it; for (++ it_end; it_end != island.fills.end() && it->region() == it_end->region(); ++ it_end) ; const LayerRegion &layerm = *layer->get_region(it->region()); extrude_infill_range(layerm, layerm.fills(), it, it_end, false /* normal extrusions, not ironing */); + it = it_end; } }; if (print.config().infill_first) { @@ -2451,12 +2452,13 @@ void GCode::process_layer_single_object( // First Ironing changes extrusion rate quickly, second single ironing may be done over multiple perimeter regions. // Ironing in a second phase is safer, but it may be less efficient. for (const LayerIsland &island : lslice.islands) { - for (auto it = island.fills.begin(); it != island.fills.end(); ++ it) { + for (auto it = island.fills.begin(); it != island.fills.end();) { // Gather range of fill ranges with the same region. auto it_end = it; for (++ it_end; it_end != island.fills.end() && it->region() == it_end->region(); ++ it_end) ; const LayerRegion &layerm = *layer->get_region(it->region()); extrude_infill_range(layerm, layerm.fills(), it, it_end, true /* ironing, not normal extrusions */); + it = it_end; } } } diff --git a/src/libslic3r/GCodeReader.cpp b/src/libslic3r/GCodeReader.cpp index cd6cedf515..a45ea8439e 100644 --- a/src/libslic3r/GCodeReader.cpp +++ b/src/libslic3r/GCodeReader.cpp @@ -70,7 +70,7 @@ const char* GCodeReader::parse_line_internal(const char *ptr, const char *end, G if (axis != NUM_AXES_WITH_UNKNOWN) { // Try to parse the numeric value. double v; - c = skip_whitespaces(++c); + c = skip_whitespaces(++ c); auto [pend, ec] = fast_float::from_chars(c, end, v); if (pend != c && is_end_of_word(*pend)) { // The axis value has been parsed correctly. diff --git a/src/libslic3r/Layer.hpp b/src/libslic3r/Layer.hpp index 869004cd5a..0aa4c2aa31 100644 --- a/src/libslic3r/Layer.hpp +++ b/src/libslic3r/Layer.hpp @@ -256,6 +256,14 @@ public: // Point centroid; bool has_extrusions() const { return ! this->perimeters.empty() || ! this->fills.empty(); } + + void add_fill_range(const LayerExtrusionRange &new_fill_range) { + // Compress ranges. + if (! this->fills.empty() && this->fills.back().region() == new_fill_range.region() && *this->fills.back().end() == *new_fill_range.begin()) + this->fills.back() = { new_fill_range.region(), { *this->fills.back().begin(), *new_fill_range.end() } }; + else + this->fills.push_back(new_fill_range); + } }; static constexpr const size_t LayerIslandsStaticSize = 1;