~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to lib/Slic3r/Fill/Concentric.pm

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Slic3r::Fill::Concentric;
 
2
use Moo;
 
3
 
 
4
extends 'Slic3r::Fill::Base';
 
5
 
 
6
use Slic3r::Geometry qw(scale unscale X);
 
7
use Slic3r::Geometry::Clipper qw(offset offset2 union_pt_chained);
 
8
 
 
9
sub fill_surface {
 
10
    my $self = shift;
 
11
    my ($surface, %params) = @_;
 
12
    
 
13
    # no rotation is supported for this infill pattern
 
14
    
 
15
    my $expolygon = $surface->expolygon;
 
16
    my $bounding_box = $expolygon->bounding_box;
 
17
    
 
18
    my $flow = $params{flow};
 
19
    my $min_spacing = $flow->scaled_spacing;
 
20
    my $distance = $min_spacing / $params{density};
 
21
    
 
22
    my $flow_spacing = $flow->spacing;
 
23
    if ($params{density} == 1 && !$params{dont_adjust}) {
 
24
        $distance = $self->adjust_solid_spacing(
 
25
            width       => $bounding_box->size->[X],
 
26
            distance    => $distance,
 
27
        );
 
28
        $flow = Slic3r::Flow->new_from_spacing(
 
29
            spacing             => unscale($distance),
 
30
            nozzle_diameter     => $flow->nozzle_diameter,
 
31
            layer_height        => ($params{layer_height} or die "No layer_height supplied to fill_surface()"),
 
32
            bridge              => $flow->bridge,
 
33
        );
 
34
    }
 
35
    
 
36
    # compensate the overlap which is good for rectilinear but harmful for concentric
 
37
    # where the perimeter/infill spacing should be equal to any other loop spacing
 
38
    my @loops = my @last = @{offset(\@$expolygon, -&Slic3r::INFILL_OVERLAP_OVER_SPACING * $min_spacing / 2)};
 
39
    while (@last) {
 
40
        push @loops, @last = @{offset2(\@last, -1.5*$distance,  +0.5*$distance)};
 
41
    }
 
42
    
 
43
    # generate paths from the outermost to the innermost, to avoid 
 
44
    # adhesion problems of the first central tiny loops
 
45
    @loops = map Slic3r::Polygon->new(@$_),
 
46
        reverse @{union_pt_chained(\@loops)};
 
47
    
 
48
    # order paths using a nearest neighbor search
 
49
    my @paths = ();
 
50
    my $last_pos = Slic3r::Point->new(0,0);
 
51
    foreach my $loop (@loops) {
 
52
        push @paths, $loop->split_at_index($last_pos->nearest_point_index(\@$loop));
 
53
        $last_pos = $paths[-1]->last_point;
 
54
    }
 
55
    
 
56
    # clip the paths to prevent the extruder from getting exactly on the first point of the loop
 
57
    my $clip_length = scale($flow->nozzle_diameter) * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER;
 
58
    $_->clip_end($clip_length) for @paths;
 
59
    @paths = grep $_->is_valid, @paths;  # remove empty paths (too short, thus eaten by clipping)
 
60
    
 
61
    # TODO: return ExtrusionLoop objects to get better chained paths
 
62
    return { flow => $flow, no_sort => 1 }, @paths;
 
63
}
 
64
 
 
65
1;