From 8669291aadb03060a900e0d5add3bea39a33b605 Mon Sep 17 00:00:00 2001 From: "salt.wei" Date: Thu, 2 Mar 2023 20:30:47 +0800 Subject: [PATCH] ENH: optimize speed of gcode export Signed-off-by: salt.wei Change-Id: Ic641352623f26c7241ae5720ad1baa202a1b00c7 --- src/libslic3r/GCode.cpp | 18 +++++++++++++++++- src/libslic3r/Layer.hpp | 11 +++++++++++ src/libslic3r/libslic3r.h | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 483240f40..cb068b8a5 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1461,6 +1461,22 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato m_enable_cooling_markers = true; this->apply_print_config(print.config()); + //BBS: generate simplified_slices if necessary + if (m_config.reduce_infill_retraction) { + for (auto object : print.objects()) { + tbb::parallel_for( + tbb::blocked_range(0, object->layers().size()), + [object](const tbb::blocked_range& range) { + for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++ layer_idx) { + Layer* layer = object->layers()[layer_idx]; + if (layer) + layer->simplify_reagon_final_slices(); + } + } + ); + } + } + //m_volumetric_speed = DoExport::autospeed_volumetric_limit(print); print.throw_if_canceled(); @@ -4048,7 +4064,7 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp } //BBS: need retract when long moving to print perimeter to avoid dropping of material if (!is_perimeter(role) && m_config.reduce_infill_retraction && m_layer != nullptr && - m_config.sparse_infill_density.value > 0 && m_layer->any_internal_region_slice_contains(travel)) + m_config.sparse_infill_density.value > 0 && m_layer->any_internal_region_slmplify_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. diff --git a/src/libslic3r/Layer.hpp b/src/libslic3r/Layer.hpp index 753ffed60..305016a78 100644 --- a/src/libslic3r/Layer.hpp +++ b/src/libslic3r/Layer.hpp @@ -33,6 +33,8 @@ public: // collection of surfaces generated by slicing the original geometry // divided by type top/bottom/internal SurfaceCollection slices; + //BBS: simplifed final slices data to accelerate + SurfaceCollection slices_simplified; // Backed up slices before they are split into top/bottom/internal. // Only backed up for multi-region layers or layers with elephant foot compensation. //FIXME Review whether not to simplify the code by keeping the raw_slices all the time. @@ -73,6 +75,8 @@ public: void slices_to_fill_surfaces_clipped(); void prepare_fill_surfaces(); //BBS + inline void simplify_final_slices() { this->slices_simplified.set(this->slices); this->slices_simplified.simplify(scaled(SIMPLIFY_SLICES_RESOLUTION));} + //BBS void make_perimeters(const SurfaceCollection &slices, SurfaceCollection* fill_surfaces, ExPolygons* fill_no_overlap); void process_external_surfaces(const Layer *lower_layer, const Polygons *lower_layer_covered); double infill_area_threshold() const; @@ -166,6 +170,11 @@ public: for (const LayerRegion *layerm : m_regions) if (layerm->slices.any_internal_contains(item)) return true; return false; } + //BBS: only be used in gcode export when reduce_infill_retraction is enabled + template bool any_internal_region_slmplify_slice_contains(const T& item) const { + for (const LayerRegion* layerm : m_regions) if (layerm->slices_simplified.any_internal_contains(item)) return true; + return false; + } template bool any_bottom_region_slice_contains(const T &item) const { for (const LayerRegion *layerm : m_regions) if (layerm->slices.any_bottom_contains(item)) return true; return false; @@ -189,6 +198,8 @@ public: void simplify_extrusion_path() { for (auto layerm : m_regions) layerm->simplify_extrusion_entity();} //BBS: this function calculate the maximum void grid area of sparse infill of this layer. Just estimated value coordf_t get_sparse_infill_max_void_area(); + //BBS + inline void simplify_reagon_final_slices() { for (auto* region : this->m_regions) region->simplify_final_slices();} protected: friend class PrintObject; diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index 8589d705f..f48218494 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -76,6 +76,8 @@ static constexpr double BRIDGE_INFILL_MARGIN = 1; //inline coord_t scale_(coordf_t v) { return coord_t(floor(v / SCALING_FACTOR + 0.5f)); } #define scale_(val) ((val) / SCALING_FACTOR) #define unscale_(val) ((val) * SCALING_FACTOR) +//BBS +static constexpr double SIMPLIFY_SLICES_RESOLUTION = 0.1; //BBS: BBS only support relative E and can't been changed by user at the moment. because //BBS need to support skip object when printing.