Fix islands not being ordered efficiently with the logic that completes each of them before moving to the next one (which is now the default behavior). #1137

This commit is contained in:
Alessandro Ranellucci 2014-04-25 19:11:17 +02:00
parent 2a2ba15665
commit f6897a346a
4 changed files with 17 additions and 4 deletions

View File

@ -149,6 +149,8 @@ sub process_layer {
my @perimeters_by_island = map [], 0..$#{$layer->slices}; # slice idx => @perimeters my @perimeters_by_island = map [], 0..$#{$layer->slices}; # slice idx => @perimeters
my @infill_by_island = map [], 0..$#{$layer->slices}; # slice idx => @fills my @infill_by_island = map [], 0..$#{$layer->slices}; # slice idx => @fills
# NOTE: we assume $layer->slices was already ordered with chained_path()!
PERIMETER: foreach my $perimeter (@{$layerm->perimeters}) { PERIMETER: foreach my $perimeter (@{$layerm->perimeters}) {
for my $i (0 .. $#{$layer->slices}-1) { for my $i (0 .. $#{$layer->slices}-1) {
if ($layer->slices->[$i]->contour->contains_point($perimeter->first_point)) { if ($layer->slices->[$i]->contour->contains_point($perimeter->first_point)) {

View File

@ -2,7 +2,7 @@ package Slic3r::Layer;
use Moo; use Moo;
use List::Util qw(first); use List::Util qw(first);
use Slic3r::Geometry qw(scale); use Slic3r::Geometry qw(scale chained_path);
use Slic3r::Geometry::Clipper qw(union_ex); use Slic3r::Geometry::Clipper qw(union_ex);
has 'id' => (is => 'rw', required => 1); # sequential number of layer, 0-based has 'id' => (is => 'rw', required => 1); # sequential number of layer, 0-based
@ -44,6 +44,10 @@ sub make_slices {
my $self = shift; my $self = shift;
my $slices = union_ex([ map $_->p, map @{$_->slices}, @{$self->regions} ]); my $slices = union_ex([ map $_->p, map @{$_->slices}, @{$self->regions} ]);
# sort slices
$slices = [ @$slices[@{chained_path([ map $_->contour->first_point, @$slices ])}] ];
$self->slices->clear; $self->slices->clear;
$self->slices->append(@$slices); $self->slices->append(@$slices);
} }

View File

@ -284,8 +284,16 @@ sub make_perimeters {
# use a nearest neighbor search to order these children # use a nearest neighbor search to order these children
# TODO: supply second argument to chained_path() too? # TODO: supply second argument to chained_path() too?
my $sorted_collection = $collection->chained_path_indices(0); # Optimization: since islands are going to be sorted by slice anyway in the
my @orig_indices = @{$sorted_collection->orig_indices}; # G-code export process, we skip chained_path here
my ($sorted_collection, @orig_indices);
if ($is_contour && $depth == 0) {
$sorted_collection = $collection;
@orig_indices = (0..$#$sorted_collection);
} else {
$sorted_collection = $collection->chained_path_indices(0);
@orig_indices = @{$sorted_collection->orig_indices};
}
my @loops = (); my @loops = ();
foreach my $loop (@$sorted_collection) { foreach my $loop (@$sorted_collection) {

View File

@ -93,7 +93,6 @@ ExtrusionEntityCollection::chained_path_indices(bool no_reverse)
const char* CLASS = "Slic3r::ExtrusionPath::Collection"; const char* CLASS = "Slic3r::ExtrusionPath::Collection";
CODE: CODE:
RETVAL = new ExtrusionEntityCollection(); RETVAL = new ExtrusionEntityCollection();
std::vector<size_t> indices;
THIS->chained_path(RETVAL, no_reverse, &RETVAL->orig_indices); THIS->chained_path(RETVAL, no_reverse, &RETVAL->orig_indices);
OUTPUT: OUTPUT:
RETVAL RETVAL