From 5a0f4eac8d696c5cb4ff4b3db34e695d831b0613 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 25 Dec 2014 11:37:54 +0100 Subject: [PATCH] One more retraction optimization --- lib/Slic3r/GCode.pm | 9 ++++++--- xs/src/libslic3r/Layer.cpp | 11 +++++++++++ xs/src/libslic3r/Layer.hpp | 1 + xs/xsp/Layer.xsp | 4 ++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index 63cecb3332..7adec05295 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -341,14 +341,17 @@ sub travel_to { # Skip retraction at all in the following cases: # - travel length is shorter than the configured threshold # - user has enabled "Only retract when crossing perimeters" and the travel move is - # contained in a single island of the current layer *and* a single island in the - # upper layer (so that ooze will not be visible) + # contained in a single internal fill_surface (this includes the bottom layer when + # bottom_solid_layers == 0) or in a single internal slice (this would exclude such + # bottom layer but preserve perimeter-to-infill moves in all the other layers) # - the path that will be extruded after this travel move is a support material # extrusion and the travel move is contained in a single support material island if ($travel->length < scale $self->config->get_at('retract_before_travel', $self->writer->extruder->id) || ($self->config->only_retract_when_crossing_perimeters && $self->config->fill_density > 0 - && defined($self->layer) && $self->layer->any_internal_region_fill_surface_contains_line($travel)) + && defined($self->layer) + && ($self->layer->any_internal_region_slice_contains_line($travel) + || $self->layer->any_internal_region_fill_surface_contains_line($travel))) || (defined $role && $role == EXTR_ROLE_SUPPORTMATERIAL && $self->layer->support_islands->contains_line($travel)) ) { # Just perform a straight travel move without any retraction. diff --git a/xs/src/libslic3r/Layer.cpp b/xs/src/libslic3r/Layer.cpp index 8f8334d1f4..47bef81019 100644 --- a/xs/src/libslic3r/Layer.cpp +++ b/xs/src/libslic3r/Layer.cpp @@ -120,6 +120,17 @@ Layer::make_slices() } } +template +bool +Layer::any_internal_region_slice_contains(const T &item) const +{ + FOREACH_LAYERREGION(this, layerm) { + if ((*layerm)->slices.any_internal_contains(item)) return true; + } + return false; +} +template bool Layer::any_internal_region_slice_contains(const Line &item) const; + template bool Layer::any_internal_region_fill_surface_contains(const T &item) const diff --git a/xs/src/libslic3r/Layer.hpp b/xs/src/libslic3r/Layer.hpp index 63e4819c89..6a4e905c3b 100644 --- a/xs/src/libslic3r/Layer.hpp +++ b/xs/src/libslic3r/Layer.hpp @@ -93,6 +93,7 @@ class Layer { LayerRegion* add_region(PrintRegion* print_region); void make_slices(); + template bool any_internal_region_slice_contains(const T &item) const; template bool any_internal_region_fill_surface_contains(const T &item) const; protected: diff --git a/xs/xsp/Layer.xsp b/xs/xsp/Layer.xsp index b2996dc034..cc38b08472 100644 --- a/xs/xsp/Layer.xsp +++ b/xs/xsp/Layer.xsp @@ -69,6 +69,8 @@ %code%{ RETVAL = (int)(intptr_t)THIS; %}; void make_slices(); + bool any_internal_region_slice_contains_line(Line* line) + %code%{ RETVAL = THIS->any_internal_region_slice_contains(*line); %}; bool any_internal_region_fill_surface_contains_line(Line* line) %code%{ RETVAL = THIS->any_internal_region_fill_surface_contains(*line); %}; bool any_internal_region_fill_surface_contains_polyline(Polyline* polyline) @@ -119,6 +121,8 @@ Ref slices() %code%{ RETVAL = &THIS->slices; %}; + bool any_internal_region_slice_contains_line(Line* line) + %code%{ RETVAL = THIS->any_internal_region_slice_contains(*line); %}; bool any_internal_region_fill_surface_contains_line(Line* line) %code%{ RETVAL = THIS->any_internal_region_fill_surface_contains(*line); %}; bool any_internal_region_fill_surface_contains_polyline(Polyline* polyline)