diff --git a/xs/src/libslic3r/Flow.hpp b/xs/src/libslic3r/Flow.hpp index cc8f90723..430a6197d 100644 --- a/xs/src/libslic3r/Flow.hpp +++ b/xs/src/libslic3r/Flow.hpp @@ -12,13 +12,13 @@ constexpr auto OVERLAP_FACTOR = 1.0; /// Enumeration for different flow roles enum FlowRole { - frExternalPerimeter, - frPerimeter, - frInfill, - frSolidInfill, - frTopSolidInfill, - frSupportMaterial, - frSupportMaterialInterface, + frExternalPerimeter = 0b1, + frPerimeter = 0b10, + frInfill = 0b100, + frSolidInfill = 0b1000, + frTopSolidInfill = 0b10000, + frSupportMaterial = 0b100000, + frSupportMaterialInterface = 0b1000000, }; diff --git a/xs/src/libslic3r/Surface.hpp b/xs/src/libslic3r/Surface.hpp index 1495d7215..17e232d7c 100644 --- a/xs/src/libslic3r/Surface.hpp +++ b/xs/src/libslic3r/Surface.hpp @@ -6,7 +6,17 @@ namespace Slic3r { -enum SurfaceType { stTop, stBottom, stBottomBridge, stInternal, stInternalSolid, stInternalBridge, stInternalVoid }; +/// Surface type enumerations. +/// As it is very unlikely that there will be more than 32 or 64 of these surface types, pack into a flag +enum SurfaceType { + stTop = 0b1, + stBottom = 0b10, + stBottomBridge = 0b100, + stInternal = 0b1000, + stInternalSolid = 0b10000, + stInternalBridge = 0b100000, + stInternalVoid = 0b1000000 +}; class Surface { diff --git a/xs/src/libslic3r/SurfaceCollection.cpp b/xs/src/libslic3r/SurfaceCollection.cpp index 45f805c73..a629ebffb 100644 --- a/xs/src/libslic3r/SurfaceCollection.cpp +++ b/xs/src/libslic3r/SurfaceCollection.cpp @@ -100,6 +100,19 @@ SurfaceCollection::filter_by_type(SurfaceType type) return ss; } +SurfacesPtr +SurfaceCollection::filter_by_type(std::initializer_list types) +{ + size_t n {0}; + SurfacesPtr ss; + for (const auto& t : types) { + n |= t; + } + for (Surfaces::iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) { + if (surface->surface_type & n == surface->surface_type) ss.push_back(&*surface); + } + return ss; +} void SurfaceCollection::filter_by_type(SurfaceType type, Polygons* polygons) { @@ -173,15 +186,19 @@ void SurfaceCollection::keep_type(const SurfaceType type) { // Use stl remove_if to remove - auto ptr {std::remove_if(surfaces.begin(), surfaces.end(),[type] (Surface& s) { return s.surface_type != type; })}; + auto ptr {std::remove_if(surfaces.begin(), surfaces.end(),[type] (const Surface& s) { return s.surface_type != type; })}; surfaces.erase(ptr, surfaces.end()); } void SurfaceCollection::keep_types(const SurfaceType *types, size_t ntypes) { + size_t n {0}; for (size_t i = 0; i < ntypes; ++i) - this->keep_type(types[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.end()); } void diff --git a/xs/src/libslic3r/SurfaceCollection.hpp b/xs/src/libslic3r/SurfaceCollection.hpp index 085c16b68..1c948aea5 100644 --- a/xs/src/libslic3r/SurfaceCollection.hpp +++ b/xs/src/libslic3r/SurfaceCollection.hpp @@ -22,6 +22,7 @@ class SurfaceCollection template bool any_internal_contains(const T &item) const; template bool any_bottom_contains(const T &item) const; SurfacesPtr filter_by_type(SurfaceType type); + SurfacesPtr filter_by_type(std::initializer_list types); void filter_by_type(SurfaceType type, Polygons* polygons); /// deletes all surfaces that match the supplied type.