From f7967414e01da19597fdfe938bbfce770f1dee4b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 7 Jul 2013 12:54:20 +0200 Subject: [PATCH] Store layer slices and region slices as XS data to save memory and make them shared across threads --- lib/Slic3r/ExPolygon.pm | 3 +++ lib/Slic3r/Layer.pm | 4 +++- lib/Slic3r/Layer/Region.pm | 2 +- lib/Slic3r/Print/Object.pm | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index c58af979f..85a31faef 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -299,6 +299,9 @@ sub medial_axis { return @result; } +package Slic3r::ExPolygon::XS; +use base 'Slic3r::ExPolygon'; + package Slic3r::ExPolygon::Collection; use Moo; use Slic3r::Geometry qw(X1 Y1); diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 77dd4ad90..8fcf87c02 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -78,7 +78,9 @@ sub region { # merge all regions' slices to get islands sub make_slices { my $self = shift; - $self->slices(union_ex([ map $_->p, map @{$_->slices}, @{$self->regions} ])); + + my $slices = union_ex([ map $_->p, map @{$_->slices}, @{$self->regions} ]); + $self->slices([ map Slic3r::ExPolygon::XS->new(@$_), @$slices ]); } sub make_perimeters { diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index 6d1d4745e..b10adc60c 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -147,7 +147,7 @@ sub _merge_loops { Slic3r::debugf " %d surface(s) having %d holes detected from %d polylines\n", scalar(@$expolygons), scalar(map $_->holes, @$expolygons), scalar(@$loops); - return map Slic3r::Surface->new(expolygon => $_, surface_type => S_TYPE_INTERNAL), @$expolygons; + return map Slic3r::Surface->new(expolygon => Slic3r::ExPolygon::XS->new(@$_), surface_type => S_TYPE_INTERNAL), @$expolygons; } sub make_perimeters { diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index ae7228ff3..d40350bc4 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -292,8 +292,8 @@ sub make_perimeters { # of our slice $extra_perimeters++; my $hypothetical_perimeter = diff( - [ offset($slice->expolygon, -($perimeter_spacing * ($Slic3r::Config->perimeters + $extra_perimeters-1))) ], - [ offset($slice->expolygon, -($perimeter_spacing * ($Slic3r::Config->perimeters + $extra_perimeters))) ], + [ offset($slice->expolygon->arrayref, -($perimeter_spacing * ($Slic3r::Config->perimeters + $extra_perimeters-1))) ], + [ offset($slice->expolygon->arrayref, -($perimeter_spacing * ($Slic3r::Config->perimeters + $extra_perimeters))) ], ); last CYCLE if !@$hypothetical_perimeter; # no extra perimeter is possible