2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r::Layer;
|
2014-06-12 07:23:10 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2012-12-20 17:47:40 +00:00
|
|
|
use List::Util qw(first);
|
2014-04-25 17:11:17 +00:00
|
|
|
use Slic3r::Geometry qw(scale chained_path);
|
2014-07-12 13:28:21 +00:00
|
|
|
use Slic3r::Geometry::Clipper qw(union_ex intersection_ex);
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
# the following two were previously generated by Moo
|
|
|
|
sub print {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->object->print;
|
|
|
|
}
|
2011-11-30 15:28:09 +00:00
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
sub config {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->object->config;
|
|
|
|
}
|
2011-09-04 10:04:01 +00:00
|
|
|
|
2013-11-11 19:37:06 +00:00
|
|
|
# the purpose of this method is to be overridden for ::Support layers
|
2013-08-09 12:55:36 +00:00
|
|
|
sub islands {
|
|
|
|
my $self = shift;
|
2013-11-11 19:37:06 +00:00
|
|
|
return $self->slices;
|
2013-06-03 10:29:45 +00:00
|
|
|
}
|
2013-06-03 10:25:32 +00:00
|
|
|
|
2012-09-23 00:52:31 +00:00
|
|
|
sub region {
|
2012-04-29 10:51:20 +00:00
|
|
|
my $self = shift;
|
2012-09-23 00:52:31 +00:00
|
|
|
my ($region_id) = @_;
|
2012-04-29 10:51:20 +00:00
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
while ($self->region_count <= $region_id) {
|
|
|
|
$self->add_region($self->object->print->get_region($self->region_count));
|
2012-04-29 10:51:20 +00:00
|
|
|
}
|
2012-11-05 14:59:31 +00:00
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
return $self->get_region($region_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub regions {
|
|
|
|
my ($self) = @_;
|
|
|
|
return [ map $self->get_region($_), 0..($self->region_count-1) ];
|
2012-04-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
2014-07-15 17:07:38 +00:00
|
|
|
sub merge_slices {
|
|
|
|
my ($self) = @_;
|
|
|
|
$_->merge_slices for @{$self->regions};
|
|
|
|
}
|
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
sub make_perimeters {
|
2011-10-07 17:07:57 +00:00
|
|
|
my $self = shift;
|
2012-09-22 17:04:36 +00:00
|
|
|
Slic3r::debugf "Making perimeters for layer %d\n", $self->id;
|
2014-07-12 13:28:21 +00:00
|
|
|
|
|
|
|
# keep track of regions whose perimeters we have already generated
|
|
|
|
my %done = (); # region_id => 1
|
|
|
|
|
|
|
|
for my $region_id (0..$#{$self->regions}) {
|
|
|
|
next if $done{$region_id};
|
|
|
|
my $layerm = $self->regions->[$region_id];
|
|
|
|
$done{$region_id} = 1;
|
|
|
|
|
|
|
|
# find compatible regions
|
|
|
|
my @layerms = ($layerm);
|
|
|
|
for my $i (($region_id+1)..$#{$self->regions}) {
|
|
|
|
my $config = $self->regions->[$i]->config;
|
|
|
|
my $layerm_config = $layerm->config;
|
|
|
|
|
|
|
|
if ($config->perimeter_extruder == $layerm_config->perimeter_extruder
|
|
|
|
&& $config->perimeters == $layerm_config->perimeters
|
|
|
|
&& $config->perimeter_speed == $layerm_config->perimeter_speed
|
|
|
|
&& $config->gap_fill_speed == $layerm_config->gap_fill_speed
|
|
|
|
&& $config->overhangs == $layerm_config->overhangs
|
|
|
|
&& $config->perimeter_extrusion_width == $layerm_config->perimeter_extrusion_width
|
|
|
|
&& $config->thin_walls == $layerm_config->thin_walls
|
|
|
|
&& $config->external_perimeters_first == $layerm_config->external_perimeters_first) {
|
|
|
|
push @layerms, $self->regions->[$i];
|
|
|
|
$done{$i} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (@layerms == 1) { # optimization
|
|
|
|
$layerm->fill_surfaces->clear;
|
|
|
|
$layerm->make_perimeters($layerm->slices, $layerm->fill_surfaces);
|
|
|
|
} else {
|
|
|
|
# group slices (surfaces) according to number of extra perimeters
|
|
|
|
my %slices = (); # extra_perimeters => [ surface, surface... ]
|
|
|
|
foreach my $surface (map @{$_->slices}, @layerms) {
|
|
|
|
my $extra = $surface->extra_perimeters;
|
|
|
|
$slices{$extra} ||= [];
|
|
|
|
push @{$slices{$extra}}, $surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
# merge the surfaces assigned to each group
|
|
|
|
my $new_slices = Slic3r::Surface::Collection->new;
|
|
|
|
foreach my $surfaces (values %slices) {
|
|
|
|
$new_slices->append(Slic3r::Surface->new(
|
|
|
|
surface_type => $surfaces->[0]->surface_type,
|
|
|
|
extra_perimeters => $surfaces->[0]->extra_perimeters,
|
|
|
|
expolygon => $_,
|
|
|
|
)) for @{union_ex([ map $_->p, @$surfaces ], 1)};
|
|
|
|
}
|
|
|
|
|
|
|
|
# make perimeters
|
|
|
|
my $fill_surfaces = Slic3r::Surface::Collection->new;
|
|
|
|
$layerm->make_perimeters($new_slices, $fill_surfaces);
|
|
|
|
|
|
|
|
# assign fill_surfaces to each layer
|
|
|
|
if ($fill_surfaces->count > 0) {
|
|
|
|
foreach my $lm (@layerms) {
|
|
|
|
my $expolygons = intersection_ex(
|
|
|
|
[ map $_->p, @$fill_surfaces ],
|
|
|
|
[ map $_->p, @{$lm->slices} ],
|
|
|
|
);
|
|
|
|
$lm->fill_surfaces->clear;
|
|
|
|
$lm->fill_surfaces->append(Slic3r::Surface->new(
|
|
|
|
surface_type => $fill_surfaces->[0]->surface_type,
|
|
|
|
extra_perimeters => $fill_surfaces->[0]->extra_perimeters,
|
|
|
|
expolygon => $_,
|
|
|
|
)) for @$expolygons;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-07 17:07:57 +00:00
|
|
|
}
|
|
|
|
|
2013-07-29 18:49:54 +00:00
|
|
|
package Slic3r::Layer::Support;
|
|
|
|
|
2014-05-19 22:03:29 +00:00
|
|
|
our @ISA = qw(Slic3r::Layer);
|
2013-07-29 18:49:54 +00:00
|
|
|
|
2013-08-09 12:55:36 +00:00
|
|
|
sub islands {
|
|
|
|
my $self = shift;
|
2013-11-11 19:37:06 +00:00
|
|
|
return [ @{$self->slices}, @{$self->support_islands} ];
|
2013-08-09 12:55:36 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|