mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-05 06:44:56 +08:00
Improvements to bridge angle detection: use coverage test for all cases (including two-sided bridges and C-shaped bridges) and check for all angles equal to directions of bridge sides
This commit is contained in:
parent
24571612c7
commit
f7421053cc
@ -55,36 +55,37 @@ sub detect_angle {
|
|||||||
my @edges = @{$self->_edges};
|
my @edges = @{$self->_edges};
|
||||||
my $anchors = $self->_anchors;
|
my $anchors = $self->_anchors;
|
||||||
|
|
||||||
if (@edges == 2) {
|
if (!@$anchors) {
|
||||||
my @chords = map Slic3r::Line->new($_->[0], $_->[-1]), @edges;
|
$self->angle(undef);
|
||||||
my @midpoints = map $_->midpoint, @chords;
|
return undef;
|
||||||
my $line_between_midpoints = Slic3r::Line->new(@midpoints);
|
|
||||||
$self->angle($line_between_midpoints->direction);
|
|
||||||
} elsif (@edges == 1 && !$edges[0][0]->coincides_with($edges[0][-1])) {
|
|
||||||
# Don't use this logic if $edges[0] is actually a closed loop
|
|
||||||
# TODO: this case includes both U-shaped bridges and plain overhangs;
|
|
||||||
# we need a trapezoidation algorithm to detect the actual bridged area
|
|
||||||
# and separate it from the overhang area.
|
|
||||||
# in the mean time, we're treating as overhangs all cases where
|
|
||||||
# our supporting edge is a straight line
|
|
||||||
if (@{$edges[0]} > 2) {
|
|
||||||
my $line = Slic3r::Line->new($edges[0]->[0], $edges[0]->[-1]);
|
|
||||||
$self->angle($line->direction);
|
|
||||||
}
|
}
|
||||||
} elsif (@edges) {
|
|
||||||
# Outset the bridge expolygon by half the amount we used for detecting anchors;
|
# Outset the bridge expolygon by half the amount we used for detecting anchors;
|
||||||
# we'll use this one to clip our test lines and be sure that their endpoints
|
# we'll use this one to clip our test lines and be sure that their endpoints
|
||||||
# are inside the anchors and not on their contours leading to false negatives.
|
# are inside the anchors and not on their contours leading to false negatives.
|
||||||
my $clip_area = $self->expolygon->offset_ex(+$self->extrusion_width/2);
|
my $clip_area = $self->expolygon->offset_ex(+$self->extrusion_width/2);
|
||||||
|
|
||||||
if (@$anchors) {
|
|
||||||
# we'll now try several directions using a rudimentary visibility check:
|
# we'll now try several directions using a rudimentary visibility check:
|
||||||
# bridge in several directions and then sum the length of lines having both
|
# bridge in several directions and then sum the length of lines having both
|
||||||
# endpoints within anchors
|
# endpoints within anchors
|
||||||
|
|
||||||
|
# we test angles according to configured resolution
|
||||||
|
my @angles = map { $_*$self->resolution } 0..(PI/$self->resolution);
|
||||||
|
|
||||||
|
# we also test angles of each bridge contour
|
||||||
|
push @angles, map $_->direction, map @{$_->lines}, @{$self->expolygon};
|
||||||
|
|
||||||
|
# we also test angles of each open supporting edge
|
||||||
|
# (this finds the optimal angle for C-shaped supports)
|
||||||
|
push @angles, map Slic3r::Line->new($_->first_point, $_->last_point)->direction,
|
||||||
|
grep { !$_->first_point->coincides_with($_->last_point) }
|
||||||
|
@edges;
|
||||||
|
|
||||||
my %directions_coverage = (); # angle => score
|
my %directions_coverage = (); # angle => score
|
||||||
my %directions_avg_length = (); # angle => score
|
my %directions_avg_length = (); # angle => score
|
||||||
my $line_increment = $self->extrusion_width;
|
my $line_increment = $self->extrusion_width;
|
||||||
for (my $angle = 0; $angle < PI; $angle += $self->resolution) {
|
my %unique_angles = map { $_ => 1 } @angles;
|
||||||
|
for my $angle (keys %unique_angles) {
|
||||||
my $my_clip_area = [ map $_->clone, @$clip_area ];
|
my $my_clip_area = [ map $_->clone, @$clip_area ];
|
||||||
my $my_anchors = [ map $_->clone, @$anchors ];
|
my $my_anchors = [ map $_->clone, @$anchors ];
|
||||||
|
|
||||||
@ -139,16 +140,12 @@ sub detect_angle {
|
|||||||
} keys %directions_coverage;
|
} keys %directions_coverage;
|
||||||
|
|
||||||
$self->angle($sorted_directions[-1]);
|
$self->angle($sorted_directions[-1]);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defined $self->angle) {
|
|
||||||
if ($self->angle >= PI) {
|
if ($self->angle >= PI) {
|
||||||
$self->angle($self->angle - PI);
|
$self->angle($self->angle - PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
Slic3r::debugf " Optimal infill angle is %d degrees\n", rad2deg($self->angle);
|
Slic3r::debugf " Optimal infill angle is %d degrees\n", rad2deg($self->angle);
|
||||||
}
|
|
||||||
|
|
||||||
return $self->angle;
|
return $self->angle;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user