From 5d1e01839cdd956db28c6c70a69837329753ef17 Mon Sep 17 00:00:00 2001 From: supermerill Date: Thu, 29 Nov 2018 16:43:41 +0100 Subject: [PATCH] remove bad algo from keep_types --- xs/src/libslic3r/PrintObject.cpp | 2 +- xs/src/libslic3r/SurfaceCollection.cpp | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index e4604782e..bcce57559 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -1641,7 +1641,7 @@ PrintObject::_discover_neighbor_horizontal_shells(LayerRegion* layerm, const siz // assign top and bottom surfaces to layer SurfaceCollection tmp_coll; for (const auto& s : neighbor_fill_surfaces.surfaces) - if (s.surface_type == stTop || s.is_bottom()) + if (s.is_top() || s.is_bottom()) tmp_coll.append(s); for (auto s : tmp_coll.group()) { diff --git a/xs/src/libslic3r/SurfaceCollection.cpp b/xs/src/libslic3r/SurfaceCollection.cpp index 1fb15d023..04f449dc2 100644 --- a/xs/src/libslic3r/SurfaceCollection.cpp +++ b/xs/src/libslic3r/SurfaceCollection.cpp @@ -200,12 +200,23 @@ SurfaceCollection::keep_type(const SurfaceType type) void SurfaceCollection::keep_types(const SurfaceType *types, size_t ntypes) { - size_t n {0}; - for (size_t i = 0; i < ntypes; ++i) - n |= types[i]; // form bitmask. - // Use stl remove_if to remove - auto ptr = std::remove_if(surfaces.begin(), surfaces.end(),[n] (const Surface& s) { return (s.surface_type & n) != s.surface_type; }); - surfaces.erase(ptr, surfaces.cend()); + size_t j = 0; + for (size_t i = 0; i < surfaces.size(); ++ i) { + bool keep = false; + for (int k = 0; k < ntypes; ++ k) { + if (surfaces[i].surface_type == types[k]) { + keep = true; + break; + } + } + if (keep) { + if (j < i) + std::swap(surfaces[i], surfaces[j]); + ++ j; + } + } + if (j < surfaces.size()) + surfaces.erase(surfaces.begin() + j, surfaces.end()); } void