More constants, less strings => ess memory usage
This commit is contained in:
parent
8fe5d11624
commit
aa9563f00b
10 changed files with 51 additions and 27 deletions
|
@ -1,6 +1,7 @@
|
||||||
package Slic3r::Extruder;
|
package Slic3r::Extruder;
|
||||||
use Moo;
|
use Moo;
|
||||||
|
|
||||||
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(scale unscale);
|
use Slic3r::Geometry qw(scale unscale);
|
||||||
|
|
||||||
has 'layer' => (is => 'rw');
|
has 'layer' => (is => 'rw');
|
||||||
|
@ -33,6 +34,16 @@ has 'speeds' => (
|
||||||
}},
|
}},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my %role_speeds = (
|
||||||
|
&EXTR_ROLE_PERIMETER => 'perimeter',
|
||||||
|
&EXTR_ROLE_SMALLPERIMETER => 'small_perimeter',
|
||||||
|
&EXTR_ROLE_FILL => 'infill',
|
||||||
|
&EXTR_ROLE_SOLIDFILL => 'solid_infill',
|
||||||
|
&EXTR_ROLE_BRIDGE => 'bridge',
|
||||||
|
&EXTR_ROLE_SKIRT => 'perimeter',
|
||||||
|
&EXTR_ROLE_SUPPORTMATERIAL => 'perimeter',
|
||||||
|
);
|
||||||
|
|
||||||
use Slic3r::Geometry qw(points_coincide PI X Y);
|
use Slic3r::Geometry qw(points_coincide PI X Y);
|
||||||
|
|
||||||
sub change_layer {
|
sub change_layer {
|
||||||
|
@ -126,7 +137,7 @@ sub extrude_path {
|
||||||
my $w = ($s - $Slic3r::min_flow_spacing * $Slic3r::overlap_factor) / (1 - $Slic3r::overlap_factor);
|
my $w = ($s - $Slic3r::min_flow_spacing * $Slic3r::overlap_factor) / (1 - $Slic3r::overlap_factor);
|
||||||
|
|
||||||
my $area;
|
my $area;
|
||||||
if ($path->role eq 'bridge') {
|
if ($path->role == EXTR_ROLE_BRIDGE) {
|
||||||
$area = ($s**2) * PI/4;
|
$area = ($s**2) * PI/4;
|
||||||
} elsif ($w >= ($Slic3r::nozzle_diameter + $h)) {
|
} elsif ($w >= ($Slic3r::nozzle_diameter + $h)) {
|
||||||
# rectangle with semicircles at the ends
|
# rectangle with semicircles at the ends
|
||||||
|
@ -142,14 +153,7 @@ sub extrude_path {
|
||||||
* (4 / (($Slic3r::filament_diameter ** 2) * PI));
|
* (4 / (($Slic3r::filament_diameter ** 2) * PI));
|
||||||
|
|
||||||
# extrude arc or line
|
# extrude arc or line
|
||||||
$self->speed(
|
$self->speed( $role_speeds{$path->role} || die "Unknown role: " . $path->role );
|
||||||
$path->role =~ /^(perimeter|skirt|support-material)$/o ? 'perimeter'
|
|
||||||
: $path->role eq 'small-perimeter' ? 'small_perimeter'
|
|
||||||
: $path->role eq 'fill' ? 'infill'
|
|
||||||
: $path->role eq 'solid-fill' ? 'solid_infill'
|
|
||||||
: $path->role eq 'bridge' ? 'bridge'
|
|
||||||
: die "Unknown role: " . $path->role
|
|
||||||
);
|
|
||||||
my $path_length = 0;
|
my $path_length = 0;
|
||||||
if ($path->isa('Slic3r::ExtrusionPath::Arc')) {
|
if ($path->isa('Slic3r::ExtrusionPath::Arc')) {
|
||||||
$path_length = $path->length;
|
$path_length = $path->length;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package Slic3r::ExtrusionLoop;
|
package Slic3r::ExtrusionLoop;
|
||||||
use Moo;
|
use Moo;
|
||||||
|
|
||||||
|
|
||||||
# the underlying Slic3r::Polygon objects holds the geometry
|
# the underlying Slic3r::Polygon objects holds the geometry
|
||||||
has 'polygon' => (
|
has 'polygon' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
|
@ -9,7 +8,7 @@ has 'polygon' => (
|
||||||
handles => [qw(is_printable nearest_point_to)],
|
handles => [qw(is_printable nearest_point_to)],
|
||||||
);
|
);
|
||||||
|
|
||||||
# perimeter/fill/solid-fill/bridge/skirt
|
# see EXTR_ROLE_* constants in ExtrusionPath.pm
|
||||||
has 'role' => (is => 'rw', required => 1);
|
has 'role' => (is => 'rw', required => 1);
|
||||||
|
|
||||||
sub BUILD {
|
sub BUILD {
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
package Slic3r::ExtrusionPath;
|
package Slic3r::ExtrusionPath;
|
||||||
use Moo;
|
use Moo;
|
||||||
|
|
||||||
|
require Exporter;
|
||||||
|
our @ISA = qw(Exporter);
|
||||||
|
our @EXPORT_OK = qw(EXTR_ROLE_PERIMETER EXTR_ROLE_SMALLPERIMETER EXTR_ROLE_FILL EXTR_ROLE_SOLIDFILL
|
||||||
|
EXTR_ROLE_BRIDGE EXTR_ROLE_SKIRT EXTR_ROLE_SUPPORTMATERIAL);
|
||||||
|
our %EXPORT_TAGS = (roles => \@EXPORT_OK);
|
||||||
|
|
||||||
|
|
||||||
use Slic3r::Geometry qw(PI X Y epsilon deg2rad rotate_points);
|
use Slic3r::Geometry qw(PI X Y epsilon deg2rad rotate_points);
|
||||||
|
|
||||||
# the underlying Slic3r::Polyline objects holds the geometry
|
# the underlying Slic3r::Polyline objects holds the geometry
|
||||||
|
@ -16,8 +23,14 @@ has 'depth_layers' => (is => 'ro', default => sub {1});
|
||||||
|
|
||||||
has 'flow_spacing' => (is => 'rw');
|
has 'flow_spacing' => (is => 'rw');
|
||||||
|
|
||||||
# perimeter/fill/solid-fill/bridge/skirt/support-material
|
|
||||||
has 'role' => (is => 'rw', required => 1);
|
has 'role' => (is => 'rw', required => 1);
|
||||||
|
use constant EXTR_ROLE_PERIMETER => 0;
|
||||||
|
use constant EXTR_ROLE_SMALLPERIMETER => 1;
|
||||||
|
use constant EXTR_ROLE_FILL => 2;
|
||||||
|
use constant EXTR_ROLE_SOLIDFILL => 3;
|
||||||
|
use constant EXTR_ROLE_BRIDGE => 4;
|
||||||
|
use constant EXTR_ROLE_SKIRT => 5;
|
||||||
|
use constant EXTR_ROLE_SUPPORTMATERIAL => 6;
|
||||||
|
|
||||||
sub BUILD {
|
sub BUILD {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
|
@ -11,6 +11,7 @@ use Slic3r::Fill::Line;
|
||||||
use Slic3r::Fill::OctagramSpiral;
|
use Slic3r::Fill::OctagramSpiral;
|
||||||
use Slic3r::Fill::PlanePath;
|
use Slic3r::Fill::PlanePath;
|
||||||
use Slic3r::Fill::Rectilinear;
|
use Slic3r::Fill::Rectilinear;
|
||||||
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(X Y scale shortest_path);
|
use Slic3r::Geometry qw(X Y scale shortest_path);
|
||||||
use Slic3r::Geometry::Clipper qw(union_ex diff_ex);
|
use Slic3r::Geometry::Clipper qw(union_ex diff_ex);
|
||||||
|
|
||||||
|
@ -165,7 +166,9 @@ sub make_fill {
|
||||||
paths => [
|
paths => [
|
||||||
map Slic3r::ExtrusionPath->new(
|
map Slic3r::ExtrusionPath->new(
|
||||||
polyline => Slic3r::Polyline->new(@$_),
|
polyline => Slic3r::Polyline->new(@$_),
|
||||||
role => ($is_bridge ? 'bridge' : $is_solid ? 'solid-fill' : 'fill'),
|
role => ($is_bridge ? EXTR_ROLE_BRIDGE
|
||||||
|
: $is_solid ? EXTR_ROLE_SOLIDFILL
|
||||||
|
: EXTR_ROLE_FILL),
|
||||||
depth_layers => $surface->depth_layers,
|
depth_layers => $surface->depth_layers,
|
||||||
flow_spacing => $params->{flow_spacing},
|
flow_spacing => $params->{flow_spacing},
|
||||||
), @paths,
|
), @paths,
|
||||||
|
@ -178,8 +181,8 @@ sub make_fill {
|
||||||
paths => [
|
paths => [
|
||||||
map {
|
map {
|
||||||
$_->isa('Slic3r::Polygon')
|
$_->isa('Slic3r::Polygon')
|
||||||
? Slic3r::ExtrusionLoop->new(polygon => $_, role => 'solid-fill')->split_at($_->[0])
|
? Slic3r::ExtrusionLoop->new(polygon => $_, role => EXTR_ROLE_SOLIDFILL)->split_at($_->[0])
|
||||||
: Slic3r::ExtrusionPath->new(polyline => $_, role => 'solid-fill')
|
: Slic3r::ExtrusionPath->new(polyline => $_, role => EXTR_ROLE_SOLIDFILL)
|
||||||
} @{$layer->thin_fills},
|
} @{$layer->thin_fills},
|
||||||
],
|
],
|
||||||
) if @{$layer->thin_fills};
|
) if @{$layer->thin_fills};
|
||||||
|
|
|
@ -3,6 +3,7 @@ use Moo;
|
||||||
|
|
||||||
extends 'Slic3r::Fill::Base';
|
extends 'Slic3r::Fill::Base';
|
||||||
|
|
||||||
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(scale unscale X1 Y1 X2 Y2);
|
use Slic3r::Geometry qw(scale unscale X1 Y1 X2 Y2);
|
||||||
|
|
||||||
sub fill_surface {
|
sub fill_surface {
|
||||||
|
@ -50,7 +51,7 @@ sub fill_surface {
|
||||||
($bounding_box->[X1] + $bounding_box->[X2]) / 2,
|
($bounding_box->[X1] + $bounding_box->[X2]) / 2,
|
||||||
($bounding_box->[Y1] + $bounding_box->[Y2]) / 2,
|
($bounding_box->[Y1] + $bounding_box->[Y2]) / 2,
|
||||||
);
|
);
|
||||||
foreach my $loop (map Slic3r::ExtrusionLoop->new(polygon => $_, role => 'fill'), @loops) {
|
foreach my $loop (map Slic3r::ExtrusionLoop->new(polygon => $_, role => EXTR_ROLE_FILL), @loops) {
|
||||||
# extrude all loops ccw
|
# extrude all loops ccw
|
||||||
$loop->polygon->make_counter_clockwise;
|
$loop->polygon->make_counter_clockwise;
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ sub fill_surface {
|
||||||
# connect lines
|
# connect lines
|
||||||
{
|
{
|
||||||
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
||||||
paths => [ map Slic3r::ExtrusionPath->new(polyline => Slic3r::Polyline->new(@$_), role => 'bogus'), @paths ],
|
paths => [ map Slic3r::ExtrusionPath->new(polyline => Slic3r::Polyline->new(@$_), role => -1), @paths ],
|
||||||
);
|
);
|
||||||
@paths = ();
|
@paths = ();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package Slic3r::Layer;
|
||||||
use Moo;
|
use Moo;
|
||||||
|
|
||||||
use Math::Clipper ':all';
|
use Math::Clipper ':all';
|
||||||
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(scale unscale collinear X Y A B PI rad2deg_dir bounding_box_center shortest_path);
|
use Slic3r::Geometry qw(scale unscale collinear X Y A B PI rad2deg_dir bounding_box_center shortest_path);
|
||||||
use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex xor_ex is_counter_clockwise);
|
use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex xor_ex is_counter_clockwise);
|
||||||
|
|
||||||
|
@ -283,26 +284,26 @@ sub make_perimeters {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $hole (reverse @holes) {
|
foreach my $hole (reverse @holes) {
|
||||||
push @{ $self->perimeters }, Slic3r::ExtrusionLoop->new(polygon => $hole, role => 'perimeter');
|
push @{ $self->perimeters }, Slic3r::ExtrusionLoop->new(polygon => $hole, role => EXTR_ROLE_PERIMETER);
|
||||||
}
|
}
|
||||||
|
|
||||||
# do contours starting from innermost one
|
# do contours starting from innermost one
|
||||||
foreach my $contour (map $_->contour, map @$_, reverse @$island) {
|
foreach my $contour (map $_->contour, map @$_, reverse @$island) {
|
||||||
push @{ $self->perimeters }, Slic3r::ExtrusionLoop->new(polygon => $contour, role => 'perimeter');
|
push @{ $self->perimeters }, Slic3r::ExtrusionLoop->new(polygon => $contour, role => EXTR_ROLE_PERIMETER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# detect small perimeters by checking their area
|
# detect small perimeters by checking their area
|
||||||
for (@{ $self->perimeters }) {
|
for (@{ $self->perimeters }) {
|
||||||
$_->role('small-perimeter') if abs($_->polygon->length) <= $Slic3r::small_perimeter_length;
|
$_->role(EXTR_ROLE_SMALLPERIMETER) if abs($_->polygon->length) <= $Slic3r::small_perimeter_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
# add thin walls as perimeters
|
# add thin walls as perimeters
|
||||||
for (@{ $self->thin_walls }) {
|
for (@{ $self->thin_walls }) {
|
||||||
if ($_->isa('Slic3r::Polygon')) {
|
if ($_->isa('Slic3r::Polygon')) {
|
||||||
push @{ $self->perimeters }, Slic3r::ExtrusionLoop->new(polygon => $_, role => 'perimeter');
|
push @{ $self->perimeters }, Slic3r::ExtrusionLoop->new(polygon => $_, role => EXTR_ROLE_PERIMETER);
|
||||||
} else {
|
} else {
|
||||||
push @{ $self->perimeters }, Slic3r::ExtrusionPath->new(polyline => $_, role => 'perimeter');
|
push @{ $self->perimeters }, Slic3r::ExtrusionPath->new(polyline => $_, role => EXTR_ROLE_PERIMETER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use Moo;
|
||||||
|
|
||||||
use File::Basename qw(basename fileparse);
|
use File::Basename qw(basename fileparse);
|
||||||
use Math::ConvexHull 1.0.4 qw(convex_hull);
|
use Math::ConvexHull 1.0.4 qw(convex_hull);
|
||||||
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 PI scale unscale move_points);
|
use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 PI scale unscale move_points);
|
||||||
use Slic3r::Geometry::Clipper qw(diff_ex union_ex offset JT_ROUND);
|
use Slic3r::Geometry::Clipper qw(diff_ex union_ex offset JT_ROUND);
|
||||||
use Time::HiRes qw(gettimeofday tv_interval);
|
use Time::HiRes qw(gettimeofday tv_interval);
|
||||||
|
@ -369,7 +370,7 @@ sub make_skirt {
|
||||||
my $outline = offset([$convex_hull], $distance, $Slic3r::scaling_factor * 100, JT_ROUND);
|
my $outline = offset([$convex_hull], $distance, $Slic3r::scaling_factor * 100, JT_ROUND);
|
||||||
push @skirt, Slic3r::ExtrusionLoop->new(
|
push @skirt, Slic3r::ExtrusionLoop->new(
|
||||||
polygon => Slic3r::Polygon->new(@{$outline->[0]}),
|
polygon => Slic3r::Polygon->new(@{$outline->[0]}),
|
||||||
role => 'skirt',
|
role => EXTR_ROLE_SKIRT,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
push @{$self->skirt}, @skirt;
|
push @{$self->skirt}, @skirt;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package Slic3r::Print::Object;
|
package Slic3r::Print::Object;
|
||||||
use Moo;
|
use Moo;
|
||||||
|
|
||||||
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(scale unscale);
|
use Slic3r::Geometry qw(scale unscale);
|
||||||
use Slic3r::Geometry::Clipper qw(diff_ex intersection_ex union_ex);
|
use Slic3r::Geometry::Clipper qw(diff_ex intersection_ex union_ex);
|
||||||
|
|
||||||
|
@ -542,7 +543,7 @@ sub generate_support_material {
|
||||||
push @patterns,
|
push @patterns,
|
||||||
map Slic3r::ExtrusionPath->new(
|
map Slic3r::ExtrusionPath->new(
|
||||||
polyline => Slic3r::Polyline->new(@$_),
|
polyline => Slic3r::Polyline->new(@$_),
|
||||||
role => 'support-material',
|
role => EXTR_ROLE_SUPPORTMATERIAL,
|
||||||
depth_layers => 1,
|
depth_layers => 1,
|
||||||
flow_spacing => $params->{flow_spacing},
|
flow_spacing => $params->{flow_spacing},
|
||||||
), @paths;
|
), @paths;
|
||||||
|
|
7
t/arcs.t
7
t/arcs.t
|
@ -10,6 +10,7 @@ BEGIN {
|
||||||
}
|
}
|
||||||
|
|
||||||
use Slic3r;
|
use Slic3r;
|
||||||
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(epsilon);
|
use Slic3r::Geometry qw(epsilon);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -19,7 +20,7 @@ use Slic3r::Geometry qw(epsilon);
|
||||||
[306517.1,219034.23], [286979.42,248012.49], [258001.16,267550.17], [222515.14,274714.47],
|
[306517.1,219034.23], [286979.42,248012.49], [258001.16,267550.17], [222515.14,274714.47],
|
||||||
[187029.11,267550.17], [158050.85,248012.49], [138513.17,219034.23], [131348.87,183548.2],
|
[187029.11,267550.17], [158050.85,248012.49], [138513.17,219034.23], [131348.87,183548.2],
|
||||||
[86948.77,175149.09], [119825.35,100585],
|
[86948.77,175149.09], [119825.35,100585],
|
||||||
), role => 'fill');
|
), role => EXTR_ROLE_FILL);
|
||||||
|
|
||||||
my $collection = Slic3r::ExtrusionPath::Collection->new(paths => [$path]);
|
my $collection = Slic3r::ExtrusionPath::Collection->new(paths => [$path]);
|
||||||
$collection->detect_arcs(30);
|
$collection->detect_arcs(30);
|
||||||
|
@ -37,10 +38,10 @@ use Slic3r::Geometry qw(epsilon);
|
||||||
[13.8268343236509,19.2387953251129], [14.5399049973955,18.9100652418837],
|
[13.8268343236509,19.2387953251129], [14.5399049973955,18.9100652418837],
|
||||||
[15.2249856471595,18.5264016435409], [15.8778525229247,18.0901699437495],
|
[15.2249856471595,18.5264016435409], [15.8778525229247,18.0901699437495],
|
||||||
[16.4944804833018,17.6040596560003],
|
[16.4944804833018,17.6040596560003],
|
||||||
), role => 'fill');
|
), role => EXTR_ROLE_FILL);
|
||||||
my $path2 = Slic3r::ExtrusionPath->new(
|
my $path2 = Slic3r::ExtrusionPath->new(
|
||||||
polyline => Slic3r::Polyline->new(reverse @{$path1->points}),
|
polyline => Slic3r::Polyline->new(reverse @{$path1->points}),
|
||||||
role => 'fill',
|
role => EXTR_ROLE_FILL,
|
||||||
);
|
);
|
||||||
|
|
||||||
my $collection1 = Slic3r::ExtrusionPath::Collection->new(paths => [$path1]);
|
my $collection1 = Slic3r::ExtrusionPath::Collection->new(paths => [$path1]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue