mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 08:15:52 +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
|
/// Enumeration for different flow roles
|
||||||
enum FlowRole {
|
enum FlowRole {
|
||||||
frExternalPerimeter,
|
frExternalPerimeter = 0b1,
|
||||||
frPerimeter,
|
frPerimeter = 0b10,
|
||||||
frInfill,
|
frInfill = 0b100,
|
||||||
frSolidInfill,
|
frSolidInfill = 0b1000,
|
||||||
frTopSolidInfill,
|
frTopSolidInfill = 0b10000,
|
||||||
frSupportMaterial,
|
frSupportMaterial = 0b100000,
|
||||||
frSupportMaterialInterface,
|
frSupportMaterialInterface = 0b1000000,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,17 @@
|
|||||||
|
|
||||||
namespace Slic3r {
|
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
|
class Surface
|
||||||
{
|
{
|
||||||
|
@ -100,6 +100,19 @@ SurfaceCollection::filter_by_type(SurfaceType type)
|
|||||||
return ss;
|
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
|
void
|
||||||
SurfaceCollection::filter_by_type(SurfaceType type, Polygons* polygons)
|
SurfaceCollection::filter_by_type(SurfaceType type, Polygons* polygons)
|
||||||
{
|
{
|
||||||
@ -173,15 +186,19 @@ void
|
|||||||
SurfaceCollection::keep_type(const SurfaceType type)
|
SurfaceCollection::keep_type(const SurfaceType type)
|
||||||
{
|
{
|
||||||
// Use stl remove_if to remove
|
// 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());
|
surfaces.erase(ptr, surfaces.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SurfaceCollection::keep_types(const SurfaceType *types, size_t ntypes)
|
SurfaceCollection::keep_types(const SurfaceType *types, size_t ntypes)
|
||||||
{
|
{
|
||||||
|
size_t n {0};
|
||||||
for (size_t i = 0; i < ntypes; ++i)
|
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
|
void
|
||||||
|
@ -22,6 +22,7 @@ class SurfaceCollection
|
|||||||
template <class T> bool any_internal_contains(const T &item) const;
|
template <class T> bool any_internal_contains(const T &item) const;
|
||||||
template <class T> bool any_bottom_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(SurfaceType type);
|
||||||
|
SurfacesPtr filter_by_type(std::initializer_list<SurfaceType> types);
|
||||||
void filter_by_type(SurfaceType type, Polygons* polygons);
|
void filter_by_type(SurfaceType type, Polygons* polygons);
|
||||||
|
|
||||||
/// deletes all surfaces that match the supplied type.
|
/// deletes all surfaces that match the supplied type.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user