diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index de498fce6..2304fad07 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -1928,8 +1928,7 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string return gcode; } -bool -GCode::needs_retraction(const Polyline &travel, ExtrusionRole role) +bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role) { if (travel.length() < scale_(EXTRUDER_CONFIG(retract_before_travel))) { // skip retraction if the move is shorter than the configured threshold @@ -1946,14 +1945,12 @@ GCode::needs_retraction(const Polyline &travel, ExtrusionRole role) return false; } - if (m_config.only_retract_when_crossing_perimeters && m_layer != nullptr) { - if (m_config.fill_density.value > 0 - && m_layer->any_internal_region_slice_contains(travel)) { - /* skip retraction if travel is contained in an internal slice *and* - internal infill is enabled (so that stringing is entirely not visible) */ - return false; - } - } + if (m_config.only_retract_when_crossing_perimeters && m_layer != nullptr && + m_config.fill_density.value > 0 && m_layer->any_internal_region_slice_contains(travel)) + // Skip retraction if travel is contained in an internal slice *and* + // internal infill is enabled (so that stringing is entirely not visible). + //FIXME any_internal_region_slice_contains() is potentionally very slow, it shall test for the bounding boxes first. + return false; // retract if only_retract_when_crossing_perimeters is disabled or doesn't apply return true; diff --git a/xs/src/libslic3r/Layer.cpp b/xs/src/libslic3r/Layer.cpp index 94413c2bb..cfa66f9eb 100644 --- a/xs/src/libslic3r/Layer.cpp +++ b/xs/src/libslic3r/Layer.cpp @@ -70,27 +70,6 @@ void Layer::merge_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 Polyline &item) const; - -template -bool Layer::any_bottom_region_slice_contains(const T &item) const -{ - FOREACH_LAYERREGION(this, layerm) { - if ((*layerm)->slices.any_bottom_contains(item)) return true; - } - return false; -} -template bool Layer::any_bottom_region_slice_contains(const Polyline &item) const; - - // Here the perimeters are created cummulatively for all layer regions sharing the same parameters influencing the perimeters. // The perimeter paths and the thin fills (ExtrusionEntityCollection) are assigned to the first compatible layer region. // The resulting fill surface is split back among the originating regions. diff --git a/xs/src/libslic3r/Layer.hpp b/xs/src/libslic3r/Layer.hpp index 2f0228453..0bb76fe13 100644 --- a/xs/src/libslic3r/Layer.hpp +++ b/xs/src/libslic3r/Layer.hpp @@ -115,8 +115,14 @@ public: void make_slices(); void merge_slices(); - template bool any_internal_region_slice_contains(const T &item) const; - template bool any_bottom_region_slice_contains(const T &item) const; + template bool any_internal_region_slice_contains(const T &item) const { + for (const LayerRegion *layerm : this->regions) if (layerm->slices.any_internal_contains(item)) return true; + return false; + } + template bool any_bottom_region_slice_contains(const T &item) const { + for (const LayerRegion *layerm : this->regions) if (layerm->slices.any_bottom_contains(item)) return true; + return false; + } void make_perimeters(); void make_fills(); diff --git a/xs/src/libslic3r/SurfaceCollection.cpp b/xs/src/libslic3r/SurfaceCollection.cpp index 70272fede..42ddf9574 100644 --- a/xs/src/libslic3r/SurfaceCollection.cpp +++ b/xs/src/libslic3r/SurfaceCollection.cpp @@ -54,28 +54,6 @@ SurfaceCollection::group(std::vector *retval) } } -template -bool -SurfaceCollection::any_internal_contains(const T &item) const -{ - for (Surfaces::const_iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) { - if (surface->is_internal() && surface->expolygon.contains(item)) return true; - } - return false; -} -template bool SurfaceCollection::any_internal_contains(const Polyline &item) const; - -template -bool -SurfaceCollection::any_bottom_contains(const T &item) const -{ - for (Surfaces::const_iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) { - if (surface->is_bottom() && surface->expolygon.contains(item)) return true; - } - return false; -} -template bool SurfaceCollection::any_bottom_contains(const Polyline &item) const; - SurfacesPtr SurfaceCollection::filter_by_type(const SurfaceType type) { diff --git a/xs/src/libslic3r/SurfaceCollection.hpp b/xs/src/libslic3r/SurfaceCollection.hpp index 41e4c81b9..0edca6a5a 100644 --- a/xs/src/libslic3r/SurfaceCollection.hpp +++ b/xs/src/libslic3r/SurfaceCollection.hpp @@ -19,8 +19,14 @@ public: operator ExPolygons() const; void simplify(double tolerance); void group(std::vector *retval); - template bool any_internal_contains(const T &item) const; - template bool any_bottom_contains(const T &item) const; + template bool any_internal_contains(const T &item) const { + for (const Surface &surface : this->surfaces) if (surface.is_internal() && surface.expolygon.contains(item)) return true; + return false; + } + template bool any_bottom_contains(const T &item) const { + for (const Surface &surface : this->surfaces) if (surface.is_bottom() && surface.expolygon.contains(item)) return true; + return false; + } SurfacesPtr filter_by_type(const SurfaceType type); SurfacesPtr filter_by_types(const SurfaceType *types, int ntypes); void keep_type(const SurfaceType type); diff --git a/xs/xsp/Layer.xsp b/xs/xsp/Layer.xsp index 55e52eca4..896712ffc 100644 --- a/xs/xsp/Layer.xsp +++ b/xs/xsp/Layer.xsp @@ -87,10 +87,6 @@ void make_slices(); void merge_slices(); - bool any_internal_region_slice_contains_polyline(Polyline* polyline) - %code%{ RETVAL = THIS->any_internal_region_slice_contains(*polyline); %}; - bool any_bottom_region_slice_contains_polyline(Polyline* polyline) - %code%{ RETVAL = THIS->any_bottom_region_slice_contains(*polyline); %}; void make_perimeters(); void make_fills();