Fill gaps using medial axis detection

This commit is contained in:
Alessandro Ranellucci 2012-01-12 22:05:35 +01:00
parent a3a9cf5749
commit 90d10b24a8
7 changed files with 31 additions and 10 deletions

View File

@ -49,14 +49,14 @@ Roadmap includes the following goals:
* support material for internal perimeters;
* new and better GUI;
* cool;
* other fill patterns.
* more fill patterns.
## Is it usable already? Any known limitation?
Sure, it's very usable. Remember that:
* it doesn't generate support material;
* it only works well with manifold models (check them with Meshlab or Netfabb or http://cloud.netfabb.com/).
* it only works well with manifold and clean models (check them with Meshlab or Netfabb or http://cloud.netfabb.com/).
## How to install?

View File

@ -26,7 +26,7 @@ sub split_at {
# find index of point
my $i = -1;
for (my $n = 0; $n <= $#{$self->polygon}; $n++) {ZZZ "here" if ref $self->polygon->[$n] eq 'ARRAY';
for (my $n = 0; $n <= $#{$self->polygon}; $n++) {
if ($point->id eq $self->polygon->[$n]->id) {
$i = $n;
last;

View File

@ -161,6 +161,17 @@ sub make_fill {
],
) if @paths;
}
# add thin fill regions
push @{ $layer->fills }, Slic3r::ExtrusionPath::Collection->new(
paths => [
map {
$_->isa('Slic3r::Polygon')
? Slic3r::ExtrusionLoop->new(polygon => $_, role => 'solid-fill')->split_at($_->[0])
: Slic3r::ExtrusionPath->new(polyline => $_, role => 'solid-fill')
} @{$layer->thin_fills},
],
) if @{$layer->thin_fills};
}
1;

View File

@ -34,6 +34,10 @@ has 'thin_walls' => (is => 'ro', default => sub { [] });
# they represent boundaries of areas to fill
has 'fill_boundaries' => (is => 'ro', default => sub { [] });
# collection of polygons or polylines representing thin infill regions that
# need to be filled with a medial axis
has 'thin_fills' => (is => 'ro', default => sub { [] });
# collection of surfaces generated by clipping the slices to the fill boundaries
has 'surfaces' => (
is => 'rw',

View File

@ -3,6 +3,7 @@ use Moo;
use Math::Clipper ':all';
use Slic3r::Geometry qw(X Y shortest_path scale);
use Slic3r::Geometry::Clipper qw(diff_ex);
use XXX;
sub make_perimeter {
@ -42,6 +43,7 @@ sub make_perimeter {
for (my $loop = 0; $loop < $Slic3r::perimeters; $loop++) {
# offsetting a polygon can result in one or many offset polygons
@last_offsets = map $_->offset_ex(-$distance), @last_offsets if $distance;
last if !@last_offsets;
push @{ $perimeters[-1] }, [@last_offsets];
# offset distance for inner loops
@ -51,12 +53,18 @@ sub make_perimeter {
# create one more offset to be used as boundary for fill
{
my @fill_boundaries = map $_->offset_ex(-$distance), @last_offsets;
push @{ $layer->fill_boundaries }, @fill_boundaries;
# TODO: diff(offset(@last_offsets, -$distance/2), offset(@fill_boundaries, +$distance/2))
# this represents the small gaps that we need to treat like thin polygons,
# detect the small gaps that we need to treat like thin polygons,
# thus generating the skeleton and using it to fill them
push @{ $layer->fill_boundaries }, @fill_boundaries if @fill_boundaries;
my $small_gaps = diff_ex(
[ map @$_, map $_->offset_ex(-$distance/2), map @$_, @{$perimeters[-1]} ],
[ map @$_, map $_->offset_ex(+$distance/2), @fill_boundaries ],
);
push @{ $layer->thin_fills },
grep $_,
map $_->medial_axis(scale $Slic3r::flow_width),
@$small_gaps;
}
}

View File

@ -12,8 +12,6 @@ sub new {
} elsif ($_[0]->isa(__PACKAGE__)) {
return $_[0];
} else {
use XXX;
ZZZ \@_;
die "Invalid arguments for ${class}->new";
}
bless $self, $class;

View File

@ -61,7 +61,7 @@ sub clipper_polygon {
}
sub p {
my $self = shift;use XXX; ZZZ $self->expolygon if !eval { 1 if @{$self->expolygon}; 1 };
my $self = shift;
return @{$self->expolygon};
}