Large memory savings (down to about 50%) for high-res input files
This commit is contained in:
parent
efdf266df1
commit
34e3dfdb08
3 changed files with 26 additions and 25 deletions
|
@ -207,10 +207,7 @@ sub export_gcode {
|
||||||
# each layer has surfaces with holes
|
# each layer has surfaces with holes
|
||||||
$status_cb->(5, "Processing input file");
|
$status_cb->(5, "Processing input file");
|
||||||
$status_cb->(10, "Processing triangulated mesh");
|
$status_cb->(10, "Processing triangulated mesh");
|
||||||
$_->slice for @{$self->objects};
|
$_->slice(keep_meshes => $params{keep_meshes}) for @{$self->objects};
|
||||||
unless ($params{keep_meshes}) {
|
|
||||||
$_->mesh(undef) for @{$self->objects}; # free memory
|
|
||||||
}
|
|
||||||
|
|
||||||
# make perimeters
|
# make perimeters
|
||||||
# this will add a set of extrusion loops to each layer
|
# this will add a set of extrusion loops to each layer
|
||||||
|
|
|
@ -40,6 +40,7 @@ sub layer {
|
||||||
|
|
||||||
sub slice {
|
sub slice {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my %params = @_;
|
||||||
|
|
||||||
# process facets
|
# process facets
|
||||||
{
|
{
|
||||||
|
@ -78,6 +79,9 @@ sub slice {
|
||||||
}
|
}
|
||||||
die "Invalid input file\n" if !@{$self->layers};
|
die "Invalid input file\n" if !@{$self->layers};
|
||||||
|
|
||||||
|
# free memory
|
||||||
|
$self->mesh(undef) unless $params{keep_meshes};
|
||||||
|
|
||||||
# remove last layer if empty
|
# remove last layer if empty
|
||||||
# (we might have created it because of the $max_layer = ... + 1 code below)
|
# (we might have created it because of the $max_layer = ... + 1 code below)
|
||||||
pop @{$self->layers} if !@{$self->layers->[-1]->surfaces} && !@{$self->layers->[-1]->lines};
|
pop @{$self->layers} if !@{$self->layers->[-1]->surfaces} && !@{$self->layers->[-1]->lines};
|
||||||
|
@ -94,7 +98,7 @@ sub slice {
|
||||||
# inside a closed polyline)
|
# inside a closed polyline)
|
||||||
|
|
||||||
# build surfaces from sparse lines
|
# build surfaces from sparse lines
|
||||||
$layer->make_surfaces($self->mesh->make_loops($layer));
|
$layer->make_surfaces(Slic3r::TriangleMesh::make_loops($layer));
|
||||||
|
|
||||||
# free memory
|
# free memory
|
||||||
$layer->lines(undef);
|
$layer->lines(undef);
|
||||||
|
|
|
@ -136,10 +136,15 @@ sub check_manifoldness {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub make_loops {
|
sub make_loops {
|
||||||
my $self = shift;
|
|
||||||
my ($layer) = @_;
|
my ($layer) = @_;
|
||||||
|
|
||||||
my @lines = @{$layer->lines};
|
my @lines = map {
|
||||||
|
my @data = unpack 'ffLLLLLc', $_;
|
||||||
|
splice @data, 0, 2, [ @data[0,1] ];
|
||||||
|
$data[$_] ||= undef for I_A_ID, I_B_ID;
|
||||||
|
$data[I_FACET_EDGE] = undef if $data[I_FACET_EDGE] == -1;
|
||||||
|
[@data]
|
||||||
|
} @{$layer->lines};
|
||||||
|
|
||||||
# remove tangent edges
|
# remove tangent edges
|
||||||
{
|
{
|
||||||
|
@ -212,7 +217,7 @@ sub make_loops {
|
||||||
Slic3r::SVG::output(undef, "same_point.svg",
|
Slic3r::SVG::output(undef, "same_point.svg",
|
||||||
lines => [ map $_->line, grep !defined $_->[I_FACET_EDGE], @lines ],
|
lines => [ map $_->line, grep !defined $_->[I_FACET_EDGE], @lines ],
|
||||||
red_lines => [ map $_->line, grep defined $_->[I_FACET_EDGE], @lines ],
|
red_lines => [ map $_->line, grep defined $_->[I_FACET_EDGE], @lines ],
|
||||||
points => [ $self->vertices->[$point_id] ],
|
#points => [ $self->vertices->[$point_id] ],
|
||||||
no_arrows => 0,
|
no_arrows => 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -417,8 +422,8 @@ sub intersect_facet {
|
||||||
($a, $b) = ($b, $a);
|
($a, $b) = ($b, $a);
|
||||||
($a_id, $b_id) = ($b_id, $a_id);
|
($a_id, $b_id) = ($b_id, $a_id);
|
||||||
}
|
}
|
||||||
push @lines, [
|
push @lines, pack 'ffLLLLLc', (
|
||||||
[$b->[X], $b->[Y]], # I_B
|
$b->[X], $b->[Y], # I_B
|
||||||
$a_id, # I_A_ID
|
$a_id, # I_A_ID
|
||||||
$b_id, # I_B_ID
|
$b_id, # I_B_ID
|
||||||
$facet_id, # I_FACET_INDEX
|
$facet_id, # I_FACET_INDEX
|
||||||
|
@ -428,7 +433,7 @@ sub intersect_facet {
|
||||||
|
|
||||||
# Unused data:
|
# Unused data:
|
||||||
# a => [$a->[X], $a->[Y]],
|
# a => [$a->[X], $a->[Y]],
|
||||||
];
|
);
|
||||||
#print "Horizontal edge at $z!\n";
|
#print "Horizontal edge at $z!\n";
|
||||||
|
|
||||||
} elsif ($a->[Z] == $z) {
|
} elsif ($a->[Z] == $z) {
|
||||||
|
@ -477,20 +482,15 @@ sub intersect_facet {
|
||||||
$next_facet_index = +(grep $_ != $facet_id, @{$self->edges_facets->[$points[A][3]]})[0]
|
$next_facet_index = +(grep $_ != $facet_id, @{$self->edges_facets->[$points[A][3]]})[0]
|
||||||
if defined $points[A][3];
|
if defined $points[A][3];
|
||||||
|
|
||||||
return [
|
return pack 'ffLLLLLc', (
|
||||||
[$points[A][X], $points[A][Y]], # I_B
|
$points[A][X], $points[A][Y], # I_B
|
||||||
$points[B][2], # I_A_ID
|
$points[B][2] || 0, # I_A_ID
|
||||||
$points[A][2], # I_B_ID
|
$points[A][2] || 0, # I_B_ID
|
||||||
$facet_id, # I_FACET_INDEX
|
$facet_id, # I_FACET_INDEX
|
||||||
$prev_facet_index, # I_PREV_FACET_INDEX
|
$prev_facet_index, # I_PREV_FACET_INDEX
|
||||||
$next_facet_index, # I_NEXT_FACET_INDEX
|
$next_facet_index, # I_NEXT_FACET_INDEX
|
||||||
undef, # I_FACET_EDGE
|
-1, # I_FACET_EDGE
|
||||||
|
);
|
||||||
# Unused data:
|
|
||||||
# a => [$points[B][X], $points[B][Y]],
|
|
||||||
# prev_edge_id => $points[B][3],
|
|
||||||
# next_edge_id => $points[A][3],
|
|
||||||
];
|
|
||||||
#printf " intersection points at z = %f: %f,%f - %f,%f\n", $z, map @$_, @intersection_points;
|
#printf " intersection points at z = %f: %f,%f - %f,%f\n", $z, map @$_, @intersection_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue