2011-09-05 10:21:27 +00:00
|
|
|
package Slic3r::Fill::Rectilinear;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-05 10:21:27 +00:00
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
extends 'Slic3r::Fill::Base';
|
2014-07-26 14:28:38 +00:00
|
|
|
with qw(Slic3r::Fill::WithDirection);
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2013-04-18 15:34:21 +00:00
|
|
|
has 'cache' => (is => 'rw', default => sub {{}});
|
|
|
|
|
2013-07-29 09:05:04 +00:00
|
|
|
use Slic3r::Geometry qw(A B X Y MIN scale unscale scaled_epsilon);
|
2013-11-21 13:15:38 +00:00
|
|
|
use Slic3r::Geometry::Clipper qw(intersection_pl offset);
|
2011-09-05 10:21:27 +00:00
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
sub fill_surface {
|
2011-09-05 10:21:27 +00:00
|
|
|
my $self = shift;
|
2011-10-06 11:43:32 +00:00
|
|
|
my ($surface, %params) = @_;
|
|
|
|
|
|
|
|
# rotate polygons so that we can work with vertical lines here
|
2012-04-09 20:04:57 +00:00
|
|
|
my $expolygon = $surface->expolygon->clone;
|
2011-10-07 17:07:57 +00:00
|
|
|
my $rotate_vector = $self->infill_direction($surface);
|
2011-11-13 17:14:02 +00:00
|
|
|
$self->rotate_points($expolygon, $rotate_vector);
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2014-01-03 19:02:00 +00:00
|
|
|
my $flow = $params{flow} or die "No flow supplied to fill_surface()";
|
2014-01-03 17:27:46 +00:00
|
|
|
my $min_spacing = $flow->scaled_spacing;
|
2013-07-29 09:05:04 +00:00
|
|
|
my $line_spacing = $min_spacing / $params{density};
|
|
|
|
my $line_oscillation = $line_spacing - $min_spacing;
|
|
|
|
my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
|
|
|
|
my $bounding_box = $expolygon->bounding_box;
|
2011-12-04 15:24:46 +00:00
|
|
|
|
2013-07-29 09:05:04 +00:00
|
|
|
# define flow spacing according to requested density
|
|
|
|
if ($params{density} == 1 && !$params{dont_adjust}) {
|
|
|
|
$line_spacing = $self->adjust_solid_spacing(
|
|
|
|
width => $bounding_box->size->[X],
|
|
|
|
distance => $line_spacing,
|
|
|
|
);
|
2014-01-03 17:27:46 +00:00
|
|
|
$flow = Slic3r::Flow->new_from_spacing(
|
|
|
|
spacing => unscale($line_spacing),
|
|
|
|
nozzle_diameter => $flow->nozzle_diameter,
|
2014-04-05 08:54:24 +00:00
|
|
|
layer_height => ($params{layer_height} or die "No layer_height supplied to fill_surface()"),
|
2014-01-03 17:27:46 +00:00
|
|
|
bridge => $flow->bridge,
|
|
|
|
);
|
2013-07-29 09:05:04 +00:00
|
|
|
} else {
|
|
|
|
# extend bounding box so that our pattern will be aligned with other layers
|
2014-01-07 11:48:09 +00:00
|
|
|
$bounding_box->merge_point(Slic3r::Point->new(
|
|
|
|
$bounding_box->x_min - ($bounding_box->x_min % $line_spacing),
|
|
|
|
$bounding_box->y_min - ($bounding_box->y_min % $line_spacing),
|
|
|
|
));
|
2013-07-29 09:05:04 +00:00
|
|
|
}
|
2011-12-17 19:29:06 +00:00
|
|
|
|
2013-07-29 09:05:04 +00:00
|
|
|
# generate the basic pattern
|
|
|
|
my $i = 0;
|
|
|
|
my $x = $bounding_box->x_min;
|
|
|
|
my $x_max = $bounding_box->x_max + scaled_epsilon;
|
|
|
|
my @vertical_lines = ();
|
|
|
|
while ($x <= $x_max) {
|
2013-08-28 23:36:42 +00:00
|
|
|
my $vertical_line = [ [$x, $bounding_box->y_max], [$x, $bounding_box->y_min] ];
|
2013-07-29 09:05:04 +00:00
|
|
|
if ($is_line_pattern && $i % 2) {
|
|
|
|
$vertical_line->[A][X] += $line_oscillation;
|
|
|
|
$vertical_line->[B][X] -= $line_oscillation;
|
2013-04-18 15:34:21 +00:00
|
|
|
}
|
2013-11-21 13:15:38 +00:00
|
|
|
push @vertical_lines, Slic3r::Polyline->new(@$vertical_line);
|
2013-07-29 09:05:04 +00:00
|
|
|
$i++;
|
|
|
|
$x += $line_spacing;
|
2011-12-04 15:24:46 +00:00
|
|
|
}
|
2012-08-24 16:59:23 +00:00
|
|
|
|
2014-01-11 20:34:26 +00:00
|
|
|
# clip paths against a slightly larger expolygon, so that the first and last paths
|
2012-08-24 16:59:23 +00:00
|
|
|
# are kept even if the expolygon has vertical sides
|
2013-07-29 11:36:22 +00:00
|
|
|
# the minimum offset for preventing edge lines from being clipped is scaled_epsilon;
|
|
|
|
# however we use a larger offset to support expolygons with slightly skewed sides and
|
|
|
|
# not perfectly straight
|
2014-01-11 20:34:26 +00:00
|
|
|
my @polylines = @{intersection_pl(\@vertical_lines, $expolygon->offset(scale 0.02))};
|
2011-12-04 15:24:46 +00:00
|
|
|
|
|
|
|
# connect lines
|
2013-11-21 15:21:42 +00:00
|
|
|
unless ($params{dont_connect} || !@polylines) { # prevent calling leftmost_point() on empty collections
|
2014-01-03 17:27:46 +00:00
|
|
|
my ($expolygon_off) = @{$expolygon->offset_ex($min_spacing/2)};
|
2013-08-29 22:06:10 +00:00
|
|
|
my $collection = Slic3r::Polyline::Collection->new(@polylines);
|
2013-07-16 15:13:01 +00:00
|
|
|
@polylines = ();
|
2011-12-04 15:24:46 +00:00
|
|
|
|
2012-09-12 13:22:43 +00:00
|
|
|
my $tolerance = 10 * scaled_epsilon;
|
2013-07-29 09:05:04 +00:00
|
|
|
my $diagonal_distance = $line_spacing * 2;
|
2012-05-04 18:51:09 +00:00
|
|
|
my $can_connect = $is_line_pattern
|
|
|
|
? sub {
|
2013-07-29 09:05:04 +00:00
|
|
|
($_[X] >= ($line_spacing - $line_oscillation) - $tolerance) && ($_[X] <= ($line_spacing + $line_oscillation) + $tolerance)
|
2012-06-23 18:27:28 +00:00
|
|
|
&& $_[Y] <= $diagonal_distance
|
2012-05-04 18:51:09 +00:00
|
|
|
}
|
2013-06-16 16:05:56 +00:00
|
|
|
: sub { $_[X] <= $diagonal_distance && $_[Y] <= $diagonal_distance };
|
2011-12-04 15:24:46 +00:00
|
|
|
|
2013-11-21 13:15:38 +00:00
|
|
|
foreach my $polyline (@{$collection->chained_path_from($collection->leftmost_point, 0)}) {
|
2013-07-16 15:13:01 +00:00
|
|
|
if (@polylines) {
|
2013-08-28 23:36:42 +00:00
|
|
|
my $first_point = $polyline->first_point;
|
|
|
|
my $last_point = $polylines[-1]->last_point;
|
|
|
|
my @distance = map abs($first_point->$_ - $last_point->$_), qw(x y);
|
2011-12-04 15:24:46 +00:00
|
|
|
|
|
|
|
# TODO: we should also check that both points are on a fill_boundary to avoid
|
|
|
|
# connecting paths on the boundaries of internal regions
|
2013-11-21 13:35:28 +00:00
|
|
|
if ($can_connect->(@distance) && $expolygon_off->contains_line(Slic3r::Line->new($last_point, $first_point))) {
|
2013-08-28 23:36:42 +00:00
|
|
|
$polylines[-1]->append_polyline($polyline);
|
2011-12-04 15:24:46 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
2013-09-02 18:22:20 +00:00
|
|
|
|
|
|
|
# make a clone before $collection goes out of scope
|
|
|
|
push @polylines, $polyline->clone;
|
2011-12-04 15:24:46 +00:00
|
|
|
}
|
2011-09-25 18:09:30 +00:00
|
|
|
}
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
|
|
# paths must be rotated back
|
2013-07-16 15:13:01 +00:00
|
|
|
$self->rotate_points_back(\@polylines, $rotate_vector);
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2014-01-03 17:27:46 +00:00
|
|
|
return { flow => $flow }, @polylines;
|
2011-09-05 10:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|