Merge branch 'new-math'

This commit is contained in:
Alessandro Ranellucci 2011-12-14 16:12:05 +01:00
commit b9d01a32e5
16 changed files with 52 additions and 59 deletions

View File

@ -170,8 +170,6 @@ The author is Alessandro Ranellucci (me).
Calculate the extrusion width as the layer height multiplied by
this value (> 0, default: calculated automatically)
--bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: 1)
--overlap-ratio Overlap between extrusion threads expressed as a ratio over extrusion
width (> 0, default: 0.15)
If you want to change a preset file, just do

View File

@ -66,10 +66,8 @@ our $infill_every_layers = 1;
# flow options
our $extrusion_width_ratio = 0;
our $bridge_flow_ratio = 1;
our $flow_speed_ratio = 1;
our $overlap_factor = 0.15;
our $flow_width;
our $overlap_ratio = 0.15;
our $flow_spacing;
# print options
our $perimeters = 3;

View File

@ -137,11 +137,6 @@ our $Options = {
cli => 'bridge-flow-ratio=f',
type => 'f',
},
'overlap_ratio' => {
label => 'Extrusion overlap (ratio over extrusion width)', # the double space here prevents a bug in WxWidgets (Mac)
cli => 'overlap-ratio=f',
type => 'f',
},
# print options
'perimeters' => {
@ -367,23 +362,21 @@ sub validate {
if $Slic3r::layer_height > $Slic3r::nozzle_diameter;
die "First layer height can't be greater than --nozzle-diameter\n"
if ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) > $Slic3r::nozzle_diameter;
$Slic3r::flow_width = ($Slic3r::nozzle_diameter**2)
* $Slic3r::flow_speed_ratio * PI / (4 * $Slic3r::layer_height);
if ($Slic3r::extrusion_width_ratio) {
$Slic3r::flow_width = $Slic3r::layer_height * $Slic3r::extrusion_width_ratio;
} else {
# here we calculate a sane default by matching the flow speed (at the nozzle)
# and the feed rate
$Slic3r::flow_width = (($Slic3r::nozzle_diameter**2) * PI + ($Slic3r::layer_height**2) * (4 - PI)) / (4 * $Slic3r::layer_height);
my $max_flow_width = $Slic3r::layer_height + $Slic3r::nozzle_diameter;
if ($Slic3r::extrusion_width_ratio) {
my $flow_width = $Slic3r::layer_height * $Slic3r::extrusion_width_ratio;
$Slic3r::flow_speed_ratio = $flow_width / $Slic3r::flow_width;
$Slic3r::flow_width = $flow_width;
} elsif ($Slic3r::flow_width > $max_flow_width) {
$Slic3r::flow_speed_ratio = $max_flow_width / $Slic3r::flow_width;
$Slic3r::flow_width = $max_flow_width;
$Slic3r::flow_width = $max_flow_width if $Slic3r::flow_width > $max_flow_width;
$Slic3r::flow_width = $Slic3r::nozzle_diameter * 1.05
if $Slic3r::flow_width < $Slic3r::nozzle_diameter;
}
$Slic3r::flow_spacing = $Slic3r::flow_width * (1-$Slic3r::overlap_ratio);
Slic3r::debugf "Flow width = $Slic3r::flow_width\n";
Slic3r::debugf "Flow speed ratio = $Slic3r::flow_speed_ratio\n";
Slic3r::debugf "Flow spacing = $Slic3r::flow_spacing\n";
# --perimeters
die "Invalid value for --perimeters\n"

View File

@ -7,7 +7,6 @@ has 'layer' => (is => 'rw');
has 'shift_x' => (is => 'ro', default => sub {0} );
has 'shift_y' => (is => 'ro', default => sub {0} );
has 'z' => (is => 'rw', default => sub {0} );
has 'flow_ratio' => (is => 'rw', default => sub {1});
has 'print_feed_rate' => (is => 'rw');
has 'extrusion_distance' => (is => 'rw', default => sub {0} );
@ -77,7 +76,7 @@ sub extrude_loop {
my $extrusion_path = $loop->split_at($start_at);
# clip the path to avoid the extruder to get exactly on the first point of the loop
$extrusion_path->clip_end(scale $Slic3r::flow_spacing);
$extrusion_path->clip_end(scale $Slic3r::flow_width);
# extrude along the path
return $self->extrude($extrusion_path, $description);
@ -119,13 +118,14 @@ sub extrude {
$gcode .= $self->unretract if $self->retracted;
# calculate extrusion length per distance unit
my $w = $path->flow_width || $Slic3r::flow_width;
my $h = $path->depth_layers * $Slic3r::layer_height;
$h = $w if $path->role eq 'bridge';
my $e = $Slic3r::resolution
* (($Slic3r::nozzle_diameter**2) / ($Slic3r::filament_diameter ** 2))
* $Slic3r::flow_speed_ratio
* $self->flow_ratio
* ($path->flow_ratio || 1)
* ($w * $h + ($Slic3r::layer_height**2) / 4 * (PI - 4) + $Slic3r::overlap_factor * (($Slic3r::layer_height**2) - ($Slic3r::layer_height**2) / 4 * PI))
* $Slic3r::extrusion_multiplier
* $path->depth_layers;
* (4 / (($Slic3r::filament_diameter ** 2) * PI));
# extrude arc or line
$self->print_feed_rate(

View File

@ -7,8 +7,7 @@ extends 'Slic3r::Polyline';
# expressed in layers
has 'depth_layers' => (is => 'ro', default => sub {1});
# multiplier for the flow rate
has 'flow_ratio' => (is => 'rw');
has 'flow_width' => (is => 'rw');
# perimeter/fill/solid-fill/bridge/skirt
has 'role' => (is => 'rw', required => 1);

View File

@ -87,8 +87,7 @@ sub make_fill {
SURFACE: foreach my $surface (@surfaces) {
my $filler = $Slic3r::fill_pattern;
my $density = $Slic3r::fill_density;
my $flow_spacing = $Slic3r::flow_spacing;
my $flow_ratio = 1;
my $flow_width = $Slic3r::flow_width;
my $is_bridge = $layer->id > 0 && $surface->surface_type eq 'bottom';
my $is_solid = $surface->surface_type =~ /^(top|bottom)$/;
@ -98,9 +97,7 @@ sub make_fill {
$filler = $Slic3r::solid_fill_pattern;
if ($is_bridge) {
$filler = 'rectilinear';
$flow_spacing = sqrt($Slic3r::bridge_flow_ratio * ($Slic3r::nozzle_diameter**2))
* (1-$Slic3r::overlap_ratio);
$flow_ratio = $Slic3r::bridge_flow_ratio;
$flow_width = sqrt($Slic3r::bridge_flow_ratio * ($Slic3r::nozzle_diameter**2));
}
} else {
next SURFACE unless $density > 0;
@ -109,7 +106,7 @@ sub make_fill {
my @paths = $self->fillers->{$filler}->fill_surface(
$surface,
density => $density,
flow_spacing => $flow_spacing,
flow_width => $flow_width,
);
my $params = shift @paths;
@ -120,7 +117,7 @@ sub make_fill {
[ @$_ ],
role => ($is_bridge ? 'bridge' : $is_solid ? 'solid-fill' : 'fill'),
depth_layers => $surface->depth_layers,
flow_ratio => $flow_ratio * ($params->{flow_ratio} || 1),
flow_width => $params->{flow_width},
), @paths,
],
) if @paths;

View File

@ -12,8 +12,8 @@ sub fill_surface {
# no rotation is supported for this infill pattern
my $scaled_flow_spacing = scale $params{flow_spacing};
my $distance = $scaled_flow_spacing / $params{density};
my $scaled_flow_width = scale $params{flow_width};
my $distance = $scaled_flow_width / $params{density};
my @contour_loops = ();
my @hole_loops = ();
@ -44,7 +44,7 @@ sub fill_surface {
my $path = $loop->split_at($cur_pos);
# clip the path to avoid the extruder to get exactly on the first point of the loop
$path->clip_end(scale $Slic3r::flow_spacing);
$path->clip_end(scale $Slic3r::flow_width);
push @paths, $path->p;
}

View File

@ -27,7 +27,7 @@ sub fill_surface {
my $rotate_vector = $self->infill_direction($surface);
$self->rotate_points($expolygon, $rotate_vector);
my $distance_between_lines = scale $params{flow_spacing} / $params{density} * $self->multiplier;
my $distance_between_lines = scale $params{flow_width} / $params{density} * $self->multiplier;
my $bounding_box = [ bounding_box(map @$_, $expolygon) ];
my $bounding_box_polygon = Slic3r::Polygon->new([
[ $bounding_box->[X1], $bounding_box->[Y1] ],

View File

@ -3,7 +3,7 @@ use Moo;
extends 'Slic3r::Fill::Base';
use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y scale epsilon);
use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y scale unscale epsilon);
use XXX;
sub fill_surface {
@ -19,14 +19,17 @@ sub fill_surface {
$bounding_box->[X1] += scale 0.1;
$bounding_box->[X2] -= scale 0.1;
my $min_spacing = scale $params{flow_spacing};
my $min_spacing = scale $params{flow_width};
my $distance_between_lines = $min_spacing / $params{density};
my $line_oscillation = $distance_between_lines - $min_spacing;
my $number_of_lines = int(($bounding_box->[X2] - $bounding_box->[X1]) / $distance_between_lines) + 1;
my $flow_width = undef;
if ($params{density} == 1) {
my $extra_space = ($bounding_box->[X2] - $bounding_box->[X1]) % $distance_between_lines;
$distance_between_lines += $extra_space / ($number_of_lines - 1) if $number_of_lines > 1;
my $flow_ratio = $distance_between_lines / ($min_spacing / $params{density});
$flow_width = unscale $distance_between_lines;
}
my @paths = ();
my $x = $bounding_box->[X1];
@ -42,7 +45,7 @@ sub fill_surface {
}
# connect lines
{
if ($params{density} < 1) {
my $collection = Slic3r::ExtrusionPath::Collection->new(
paths => [ map Slic3r::ExtrusionPath->cast([ @$_ ], role => 'bogus'), @paths ],
);
@ -70,7 +73,7 @@ sub fill_surface {
# paths must be rotated back
$self->rotate_points_back(\@paths, $rotate_vector);
return { flow_ratio => $flow_ratio }, @paths;
return { flow_width => $flow_width }, @paths;
}
1;

View File

@ -16,7 +16,7 @@ sub fill_surface {
my $rotate_vector = $self->infill_direction($surface);
$self->rotate_points($polygons, $rotate_vector);
my $distance_between_lines = scale $params{flow_spacing} / $params{density};
my $distance_between_lines = scale $params{flow_width} / $params{density};
my $number_of_lines = int(0.99999999 + $self->max_print_dimension / $distance_between_lines); # ceil
#printf "distance = %f\n", $distance_between_lines;

View File

@ -59,7 +59,7 @@ sub new {
},
extrusion => {
title => 'Extrusion',
options => [qw(extrusion_width_ratio bridge_flow_ratio overlap_ratio)],
options => [qw(extrusion_width_ratio bridge_flow_ratio)],
},
);
$self->{panels} = \%panels;

View File

@ -124,7 +124,14 @@ sub make_surfaces {
# the contours must be offsetted by half extrusion width inwards
{
my $distance = scale $Slic3r::flow_width / 2;
my $distance = $Slic3r::flow_width / 2;
if ($Slic3r::overlap_factor) {
# our overlap is done by increasing the flow; however external perimeters will grow
# outwards, so we offset by the correct amount
$distance = ($Slic3r::flow_width + $Slic3r::overlap_factor * $Slic3r::layer_height * (1 - PI/4)) / 2;
}
$distance = scale $distance;
my @surfaces = @{$self->slices};
@{$self->slices} = ();
foreach my $surface (@surfaces) {
@ -182,7 +189,7 @@ sub prepare_fill_surfaces {
sub remove_small_surfaces {
my $self = shift;
my $distance = scale $Slic3r::flow_spacing / 2;
my $distance = scale $Slic3r::flow_width / 2;
my @surfaces = @{$self->fill_surfaces};
@{$self->fill_surfaces} = ();

View File

@ -45,12 +45,12 @@ sub make_perimeter {
push @{ $perimeters[-1] }, [@last_offsets];
# offset distance for inner loops
$distance = scale $Slic3r::flow_spacing;
$distance = scale $Slic3r::flow_width;
}
# create one more offset to be used as boundary for fill
{
$distance -= scale $Slic3r::flow_spacing;
$distance -= scale $Slic3r::flow_width;
my @fill_boundaries = map Slic3r::Surface->cast_from_expolygon
($_, surface_type => $surface->surface_type),
map $_->offset_ex(-$distance), @last_offsets;

View File

@ -32,7 +32,7 @@ sub is_printable {
# if no offset is possible, then polyline is not printable
my $p = $self->p;
@$p = reverse @$p if !Math::Clipper::is_counter_clockwise($p);
my $offsets = Math::Clipper::offset([$p], -(scale $Slic3r::flow_spacing / 2), $Slic3r::resolution * 100000, JT_MITER, 2);
my $offsets = Math::Clipper::offset([$p], -(scale $Slic3r::flow_width / 2), $Slic3r::resolution * 100000, JT_MITER, 2);
return @$offsets ? 1 : 0;
}

View File

@ -335,7 +335,7 @@ sub extrude_skirt {
# draw outlines from outside to inside
my @skirts = ();
for (my $i = $Slic3r::skirts - 1; $i >= 0; $i--) {
my $distance = scale ($Slic3r::skirt_distance + ($Slic3r::flow_spacing * $i));
my $distance = scale ($Slic3r::skirt_distance + ($Slic3r::flow_width * $i));
my $outline = offset([$convex_hull], $distance, $Slic3r::resolution * 100, JT_ROUND);
push @skirts, Slic3r::ExtrusionLoop->cast([ @{$outline->[0]} ], role => 'skirt');
}

View File

@ -175,8 +175,6 @@ Usage: slic3r.pl [ OPTIONS ] file.stl
Calculate the extrusion width as the layer height multiplied by
this value (> 0, default: calculated automatically)
--bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $Slic3r::bridge_flow_ratio)
--overlap-ratio Overlap between extrusion threads expressed as a ratio over extrusion
width (> 0, default: $Slic3r::overlap_ratio)
EOF
exit ($exit_code || 0);