Little refactoring, removing useless methods

This commit is contained in:
Alessandro Ranellucci 2011-11-16 09:52:09 +01:00
parent ed050089d9
commit 55f00fdb35
3 changed files with 19 additions and 53 deletions

View File

@ -4,8 +4,8 @@ use warnings;
require Exporter; require Exporter;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT_OK = qw(explode_expolygon explode_expolygons safety_offset our @EXPORT_OK = qw(explode_expolygon explode_expolygons safety_offset offset
diff_ex diff union_ex intersection_ex PFT_EVENODD); diff_ex diff union_ex intersection_ex PFT_EVENODD JT_MITER JT_ROUND);
use Math::Clipper 1.02 ':all'; use Math::Clipper 1.02 ':all';
our $clipper = Math::Clipper->new; our $clipper = Math::Clipper->new;

View File

@ -1,10 +1,10 @@
package Slic3r::Print; package Slic3r::Print;
use Moo; use Moo;
use Math::Clipper ':all';
use Math::ConvexHull 1.0.4 qw(convex_hull); use Math::ConvexHull 1.0.4 qw(convex_hull);
use Slic3r::Geometry qw(X Y); use Slic3r::Geometry qw(X Y);
use Slic3r::Geometry::Clipper qw(explode_expolygons safety_offset diff_ex intersection_ex); use Slic3r::Geometry::Clipper qw(explode_expolygons safety_offset diff_ex intersection_ex
offset JT_ROUND JT_MITER);
use XXX; use XXX;
has 'x_length' => ( has 'x_length' => (
@ -78,8 +78,6 @@ sub layer {
sub detect_surfaces_type { sub detect_surfaces_type {
my $self = shift; my $self = shift;
my $clipper = Math::Clipper->new;
# prepare a reusable subroutine to make surface differences # prepare a reusable subroutine to make surface differences
my $surface_difference = sub { my $surface_difference = sub {
my ($subject_surfaces, $clip_surfaces, $result_type) = @_; my ($subject_surfaces, $clip_surfaces, $result_type) = @_;
@ -148,10 +146,11 @@ sub detect_surfaces_type {
@{$surface->contour->points} = map Slic3r::Point->new($_), @{ $offset->[0] }; @{$surface->contour->points} = map Slic3r::Point->new($_), @{ $offset->[0] };
} }
#Slic3r::SVG::output(undef, "layer_" . $layer->id . "_diff.svg", use Slic3r::SVG;
# green_polygons => [ map $_->p, @{$layer->surfaces} ], Slic3r::SVG::output(undef, "layer_" . $layer->id . "_diff.svg",
# red_polygons => [ map $_->p, @{$lower_layer->surfaces} ], green_polygons => [ map $_->p, @{$layer->surfaces} ],
#); red_polygons => [ map $_->p, @{$lower_layer->surfaces} ],
);exit if $layer->id == 3;
# offset lower layer's surfaces # offset lower layer's surfaces
my $lower_surfaces_offsetted; my $lower_surfaces_offsetted;
@ -204,8 +203,6 @@ sub discover_horizontal_shells {
Slic3r::debugf "==> DISCOVERING HORIZONTAL SHELLS\n"; Slic3r::debugf "==> DISCOVERING HORIZONTAL SHELLS\n";
my $clipper = Math::Clipper->new;
for (my $i = 0; $i < $self->layer_count; $i++) { for (my $i = 0; $i < $self->layer_count; $i++) {
my $layer = $self->layers->[$i]; my $layer = $self->layers->[$i];
foreach my $type (qw(top bottom)) { foreach my $type (qw(top bottom)) {
@ -225,21 +222,14 @@ sub discover_horizontal_shells {
my $neighbor_polygons = [ map $_->p, grep $_->surface_type =~ /internal/, @$surfaces ]; my $neighbor_polygons = [ map $_->p, grep $_->surface_type =~ /internal/, @$surfaces ];
# find intersection between @surfaces and current layer's surfaces # find intersection between @surfaces and current layer's surfaces
$clipper->add_subject_polygons([ map $_->p, @surfaces ]);
$clipper->add_clip_polygons($neighbor_polygons);
# intersections have contours and holes # intersections have contours and holes
my $intersections = $clipper->ex_execute(CT_INTERSECTION, PFT_NONZERO, PFT_NONZERO); my $intersections = intersection_ex([ map $_->p, @surfaces ], $neighbor_polygons);
$clipper->clear;
next if @$intersections == 0; next if @$intersections == 0;
Slic3r::debugf " %d intersections found\n", scalar @$intersections; Slic3r::debugf " %d intersections found\n", scalar @$intersections;
# subtract intersections from layer surfaces to get resulting inner surfaces # subtract intersections from layer surfaces to get resulting inner surfaces
$clipper->add_subject_polygons($neighbor_polygons); my $internal_polygons = diff_ex($neighbor_polygons, [ map @$_, @$intersections ]);
$clipper->add_clip_polygons([ map { $_->{outer}, @{$_->{holes}} } @$intersections ]);
my $internal_polygons = $clipper->ex_execute(CT_DIFFERENCE, PFT_NONZERO, PFT_NONZERO);
$clipper->clear;
# Note: due to floating point math we're going to get some very small # Note: due to floating point math we're going to get some very small
# polygons as $internal_polygons; they will be removed by removed_small_features() # polygons as $internal_polygons; they will be removed by removed_small_features()
@ -249,9 +239,9 @@ sub discover_horizontal_shells {
foreach my $p (@$internal_polygons) { foreach my $p (@$internal_polygons) {
push @$surfaces, Slic3r::Surface->new( push @$surfaces, Slic3r::Surface->new(
surface_type => 'internal', surface_type => 'internal',
contour => Slic3r::Polyline::Closed->cast($p->{outer}), contour => $p->contour->closed_polyline,
holes => [ holes => [
map Slic3r::Polyline::Closed->cast($_), @{$p->{holes}} map $_->closed_polyline, $p->holes,
], ],
); );
} }
@ -260,9 +250,9 @@ sub discover_horizontal_shells {
foreach my $p (@$intersections) { foreach my $p (@$intersections) {
push @$surfaces, Slic3r::Surface->new( push @$surfaces, Slic3r::Surface->new(
surface_type => 'internal-solid', surface_type => 'internal-solid',
contour => Slic3r::Polyline::Closed->cast($p->{outer}), contour => $p->contour->closed_polyline,
holes => [ holes => [
map Slic3r::Polyline::Closed->cast($_), @{$p->{holes}} map $_->closed_polyline, $p->holes,
], ],
); );
} }
@ -272,24 +262,6 @@ sub discover_horizontal_shells {
} }
} }
# remove surfaces which are too small to be extruded
sub remove_small_surfaces {
my $self = shift;
$_->remove_small_surfaces for @{$self->layers};
}
# remove perimeters which are too small to be extruded
sub remove_small_perimeters {
my $self = shift;
$_->remove_small_perimeters for @{$self->layers};
}
# make bridges printable
sub process_bridges {
my $self = shift;
$_->process_bridges for @{ $self->layers };
}
sub extrude_skirt { sub extrude_skirt {
my $self = shift; my $self = shift;
return unless $Slic3r::skirts > 0; return unless $Slic3r::skirts > 0;
@ -327,12 +299,6 @@ sub extrude_perimeters {
} }
} }
# splits fill_surfaces in internal and bridge surfaces
sub split_bridges_fills {
my $self = shift;
$_->split_bridges_fills for @{$self->layers};
}
# combine fill surfaces across layers # combine fill surfaces across layers
sub infill_every_layers { sub infill_every_layers {
my $self = shift; my $self = shift;

View File

@ -25,11 +25,11 @@ sub go {
# this will remove unprintable surfaces # this will remove unprintable surfaces
# (those that are too tight for extrusion) # (those that are too tight for extrusion)
$print->remove_small_surfaces; $_->remove_small_surfaces for @{$print->layers};
# make bridges printable # make bridges printable
# this will add a set of bridges to each layer # this will add a set of bridges to each layer
$print->process_bridges; $_->process_bridges for @{$print->layers};
# make skirt # make skirt
$print->extrude_skirt; $print->extrude_skirt;
@ -41,10 +41,10 @@ sub go {
# this will remove unprintable perimeter loops # this will remove unprintable perimeter loops
# (those that are too tight for extrusion) # (those that are too tight for extrusion)
$print->remove_small_perimeters; $_->remove_small_perimeters for @{$print->layers};
# split fill_surfaces in internal and bridge surfaces # split fill_surfaces in internal and bridge surfaces
$print->split_bridges_fills; $_->split_bridges_fills for @{$print->layers};
# detect which fill surfaces are near external layers # detect which fill surfaces are near external layers
# they will be split in internal and internal-solid surfaces # they will be split in internal and internal-solid surfaces