Implemented Slic3r::ExtrusionLoop

This commit is contained in:
Alessandro Ranellucci 2013-07-15 16:21:09 +02:00
parent c9749ca3b3
commit d0701cdcd4
10 changed files with 145 additions and 88 deletions

View file

@ -1,38 +1,20 @@
package Slic3r::ExtrusionLoop;
use Moo;
use strict;
use warnings;
use Slic3r::Geometry qw(same_point);
# the underlying Slic3r::Polygon objects holds the geometry
has 'polygon' => (
is => 'rw',
required => 1,
handles => [qw(is_printable nearest_point_index_to reverse)],
);
has 'flow_spacing' => (is => 'rw', required => 1);
# see EXTR_ROLE_* constants in ExtrusionPath.pm
has 'role' => (is => 'rw', required => 1);
use constant PACK_FMT => 'fca*';
sub polygon { $_[0] }
# class or object method
sub pack {
my $self = shift;
my %args = @_;
if (ref $self) {
%args = map { $_ => $self->$_ } qw(flow_spacing role polygon);
return $self;
} else {
return $self->new(@_);
}
my $o = \ pack PACK_FMT,
$args{flow_spacing} || -1,
$args{role} // (die "Missing mandatory attribute 'role'"), #/
$args{polygon}->serialize;
bless $o, 'Slic3r::ExtrusionLoop::Packed';
return $o;
}
# no-op
@ -42,9 +24,10 @@ sub split_at_index {
my $self = shift;
return Slic3r::ExtrusionPath->new(
polyline => $self->polygon->split_at_index(@_),
polyline => $self->as_polygon->split_at_index(@_),
role => $self->role,
flow_spacing => $self->flow_spacing,
height => $self->height,
);
}
@ -52,9 +35,10 @@ sub split_at {
my $self = shift;
return Slic3r::ExtrusionPath->new(
polyline => $self->polygon->split_at(@_),
polyline => $self->as_polygon->split_at(@_),
role => $self->role,
flow_spacing => $self->flow_spacing,
height => $self->height,
);
}
@ -68,18 +52,4 @@ sub first_point {
return $self->polygon->[0];
}
package Slic3r::ExtrusionLoop::Packed;
sub unpack {
my $self = shift;
my ($flow_spacing, $role, $polygon_s)
= unpack Slic3r::ExtrusionLoop::PACK_FMT, $$self;
return Slic3r::ExtrusionLoop->new(
flow_spacing => ($flow_spacing == -1) ? undef : $flow_spacing,
role => $role,
polygon => Slic3r::Polygon->deserialize($polygon_s),
);
}
1;

View file

@ -142,7 +142,7 @@ sub move_z {
sub extrude {
my $self = shift;
($_[0]->isa('Slic3r::ExtrusionLoop') || $_[0]->isa('Slic3r::ExtrusionLoop::Packed'))
$_[0]->isa('Slic3r::ExtrusionLoop')
? $self->extrude_loop(@_)
: $self->extrude_path(@_);
}
@ -152,14 +152,14 @@ sub extrude_loop {
my ($loop, $description) = @_;
# extrude all loops ccw
$loop = $loop->unpack if $loop->isa('Slic3r::ExtrusionLoop::Packed');
my $was_clockwise = $loop->polygon->make_counter_clockwise;
my $polygon = $loop->as_polygon;
my $was_clockwise = $polygon->make_counter_clockwise;
# find candidate starting points
# start looking for concave vertices not being overhangs
my @concave = ();
if ($Slic3r::Config->start_perimeters_at_concave_points) {
@concave = $loop->polygon->concave_points;
@concave = $polygon->concave_points;
}
my @candidates = ();
if ($Slic3r::Config->start_perimeters_at_non_overhang) {
@ -171,11 +171,11 @@ sub extrude_loop {
if (!@candidates) {
# if none, look for any non-overhang vertex
if ($Slic3r::Config->start_perimeters_at_non_overhang) {
@candidates = grep !Boost::Geometry::Utils::point_covered_by_multi_polygon($_, $self->_layer_overhangs), @{$loop->polygon};
@candidates = grep !Boost::Geometry::Utils::point_covered_by_multi_polygon($_, $self->_layer_overhangs), @{$polygon};
}
if (!@candidates) {
# if none, all points are valid candidates
@candidates = @{$loop->polygon};
@candidates = @{$polygon};
}
}
}

View file

@ -10,6 +10,8 @@ use Slic3r::Geometry qw(polygon_lines polygon_remove_parallel_continuous_edges
PI X1 X2 Y1 Y2 epsilon);
use Slic3r::Geometry::Clipper qw(JT_MITER);
sub arrayref { $_[0] }
sub lines {
my $self = shift;
return polygon_lines($self);
@ -22,7 +24,7 @@ sub wkt {
sub is_counter_clockwise {
my $self = shift;
return Slic3r::Geometry::Clipper::is_counter_clockwise($self);
return Slic3r::Geometry::Clipper::is_counter_clockwise($self->arrayref);
}
sub make_counter_clockwise {

View file

@ -85,7 +85,6 @@ sub _plot {
my @paths =
map { $_->polyline->translate(@$copy); $_ }
map { $_->isa('Slic3r::ExtrusionLoop') ? $_->split_at_first_point : $_ }
map { ref($_) =~ /::Packed$/ ? $_->unpack : $_ }
map { $_->isa('Slic3r::ExtrusionPath::Collection') ? @{$_->paths} : $_ }
grep defined $_,
$filter->($layer);