mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-13 02:08:59 +08:00
Change enumerations to make them bitmask items as well (reduce iterations through SurfaceCollections)
This commit is contained in:
parent
2f5722a492
commit
053242f9de
@ -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,
|
||||
};
|
||||
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -100,6 +100,19 @@ SurfaceCollection::filter_by_type(SurfaceType type)
|
||||
return ss;
|
||||
}
|
||||
|
||||
SurfacesPtr
|
||||
SurfaceCollection::filter_by_type(std::initializer_list<SurfaceType> 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
|
||||
|
@ -22,6 +22,7 @@ class SurfaceCollection
|
||||
template <class T> bool any_internal_contains(const T &item) const;
|
||||
template <class T> bool any_bottom_contains(const T &item) const;
|
||||
SurfacesPtr filter_by_type(SurfaceType type);
|
||||
SurfacesPtr filter_by_type(std::initializer_list<SurfaceType> types);
|
||||
void filter_by_type(SurfaceType type, Polygons* polygons);
|
||||
|
||||
/// deletes all surfaces that match the supplied type.
|
||||
|
Loading…
x
Reference in New Issue
Block a user