Don't store ->surfaces anymore. Save memory, save time

This commit is contained in:
Alessandro Ranellucci 2012-12-22 23:57:39 +01:00
parent 5930267de9
commit 15f07197d8
3 changed files with 19 additions and 46 deletions

View file

@ -32,13 +32,7 @@ has 'thin_walls' => (is => 'rw', default => sub { [] });
# need to be filled with a medial axis
has 'thin_fills' => (is => 'rw', default => sub { [] });
# collection of expolygons generated by offsetting the innermost perimeter(s)
# they represent boundaries of areas to fill, typed (top/bottom/internal)
has 'surfaces' => (is => 'rw', default => sub { [] });
# collection of surfaces for infill generation. the difference between surfaces
# fill_surfaces is that this one honors fill_density == 0 and turns small internal
# surfaces into solid ones
# collection of surfaces for infill generation
has 'fill_surfaces' => (is => 'rw', default => sub { [] });
# ordered collection of extrusion paths/loops to build all perimeters
@ -160,7 +154,7 @@ sub make_perimeters {
])};
$self->perimeters([]);
$self->surfaces([]);
$self->fill_surfaces([]);
$self->thin_fills([]);
# for each island:
@ -227,9 +221,14 @@ sub make_perimeters {
# create one more offset to be used as boundary for fill
{
my @fill_boundaries = map $_->offset_ex(-$distance), @last_offsets;
my @fill_boundaries = @{union_ex([
Slic3r::Geometry::Clipper::offset(
[Slic3r::Geometry::Clipper::offset([ map @$_, @last_offsets ], -1.5*$distance)],
+0.5*$distance,
),
])};
$_->simplify(&Slic3r::SCALED_RESOLUTION) for @fill_boundaries;
push @{ $self->surfaces }, @fill_boundaries;
push @{ $self->fill_surfaces }, @fill_boundaries;
}
# fill gaps
@ -390,48 +389,26 @@ sub _add_perimeter {
sub prepare_fill_surfaces {
my $self = shift;
my @surfaces = @{$self->surfaces};
# if no solid layers are requested, turn top/bottom surfaces to internal
# note that this modifies $self->surfaces in place
if ($Slic3r::Config->top_solid_layers == 0) {
$_->surface_type(S_TYPE_INTERNAL) for grep $_->surface_type == S_TYPE_TOP, @surfaces;
$_->surface_type(S_TYPE_INTERNAL) for grep $_->surface_type == S_TYPE_TOP, @{$self->fill_surfaces};
}
if ($Slic3r::Config->bottom_solid_layers == 0) {
$_->surface_type(S_TYPE_INTERNAL) for grep $_->surface_type == S_TYPE_BOTTOM, @surfaces;
$_->surface_type(S_TYPE_INTERNAL) for grep $_->surface_type == S_TYPE_BOTTOM, @{$self->fill_surfaces};
}
# if hollow object is requested, remove internal surfaces
if ($Slic3r::Config->fill_density == 0) {
@surfaces = grep $_->surface_type != S_TYPE_INTERNAL, @surfaces;
}
# remove unprintable regions (they would slow down the infill process and also cause
# some weird failures during bridge neighbor detection)
{
my $distance = $self->infill_flow->scaled_spacing / 2;
@surfaces = map {
my $surface = $_;
# offset inwards
my @offsets = $surface->expolygon->offset_ex(-$distance);
@offsets = @{union_ex([ Slic3r::Geometry::Clipper::offset([ map @$_, @offsets ], $distance)] )}; # isn't the union_ex useless?
map Slic3r::Surface->new(
expolygon => $_,
surface_type => $surface->surface_type,
), @offsets;
} @surfaces;
@{$self->fill_surfaces} = grep $_->surface_type != S_TYPE_INTERNAL, @{$self->fill_surfaces};
}
# turn too small internal regions into solid regions
{
my $min_area = scale scale $Slic3r::Config->solid_infill_below_area; # scaling an area requires two calls!
my @small = grep $_->surface_type == S_TYPE_INTERNAL && $_->expolygon->contour->area <= $min_area, @surfaces;
my @small = grep $_->surface_type == S_TYPE_INTERNAL && $_->expolygon->contour->area <= $min_area, @{$self->fill_surfaces};
$_->surface_type(S_TYPE_INTERNALSOLID) for @small;
Slic3r::debugf "identified %d small solid surfaces at layer %d\n", scalar(@small), $self->id if @small > 0;
}
$self->fill_surfaces([@surfaces]);
}
# make bridges printable