From 3a1e112d498d04d43715c1a2be5cc51bf833f4b4 Mon Sep 17 00:00:00 2001 From: "salt.wei" Date: Wed, 31 May 2023 14:05:59 +0800 Subject: [PATCH] ENH: separate the simplifying of infill and wall This can avoid to simplify wall twice when the only invalid step is infill. Signed-off-by: salt.wei Change-Id: Ie5a9ccc10d5331c29c716aece08cdb195352cfe3 --- src/libslic3r/Layer.hpp | 6 ++++-- src/libslic3r/LayerRegion.cpp | 7 ------- src/libslic3r/Print.cpp | 9 ++++++--- src/libslic3r/Print.hpp | 3 ++- src/libslic3r/PrintObject.cpp | 38 ++++++++++++++++++++++++++--------- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/libslic3r/Layer.hpp b/src/libslic3r/Layer.hpp index 968aeae9e..54fbb1fe6 100644 --- a/src/libslic3r/Layer.hpp +++ b/src/libslic3r/Layer.hpp @@ -95,7 +95,8 @@ public: // Is there any valid extrusion assigned to this LayerRegion? bool has_extrusions() const { return ! this->perimeters.entities.empty() || ! this->fills.entities.empty(); } //BBS - void simplify_extrusion_entity(); + void simplify_infill_extrusion_entity() { simplify_entity_collection(&fills); } + void simplify_wall_extrusion_entity() { simplify_entity_collection(&perimeters); } private: void simplify_entity_collection(ExtrusionEntityCollection* entity_collection); void simplify_path(ExtrusionPath* path); @@ -190,7 +191,8 @@ public: virtual bool has_extrusions() const { for (auto layerm : m_regions) if (layerm->has_extrusions()) return true; return false; } //BBS - void simplify_extrusion_path() { for (auto layerm : m_regions) layerm->simplify_extrusion_entity();} + void simplify_wall_extrusion_path() { for (auto layerm : m_regions) layerm->simplify_wall_extrusion_entity();} + void simplify_infill_extrusion_path() { for (auto layerm : m_regions) layerm->simplify_infill_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(); diff --git a/src/libslic3r/LayerRegion.cpp b/src/libslic3r/LayerRegion.cpp index 63e32a8a9..a1b069a7d 100644 --- a/src/libslic3r/LayerRegion.cpp +++ b/src/libslic3r/LayerRegion.cpp @@ -526,13 +526,6 @@ void LayerRegion::export_region_fill_surfaces_to_svg_debug(const char *name) con this->export_region_fill_surfaces_to_svg(debug_out_path("LayerRegion-fill_surfaces-%s-%d.svg", name, idx ++).c_str()); } -//BBS -void LayerRegion::simplify_extrusion_entity() -{ - simplify_entity_collection(&perimeters); - simplify_entity_collection(&fills); -} - void LayerRegion::simplify_entity_collection(ExtrusionEntityCollection* entity_collection) { for (size_t i = 0; i < entity_collection->entities.size(); i++) { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index d930a48f0..7d6ed1275 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -228,7 +228,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n osteps.emplace_back(posPerimeters); osteps.emplace_back(posInfill); osteps.emplace_back(posSupportMaterial); - osteps.emplace_back(posSimplifyPath); + osteps.emplace_back(posSimplifyWall); + osteps.emplace_back(posSimplifyInfill); osteps.emplace_back(posSimplifySupportPath); steps.emplace_back(psSkirtBrim); } @@ -1682,8 +1683,10 @@ void Print::process(bool use_cache) obj->simplify_extrusion_path(); } else { - if (obj->set_started(posSimplifyPath)) - obj->set_done(posSimplifyPath); + if (obj->set_started(posSimplifyWall)) + obj->set_done(posSimplifyWall); + if (obj->set_started(posSimplifyInfill)) + obj->set_done(posSimplifyInfill); if (obj->set_started(posSimplifySupportPath)) obj->set_done(posSimplifySupportPath); } diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index a16858181..9a28718a3 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -87,8 +87,9 @@ enum PrintStep { enum PrintObjectStep { posSlice, posPerimeters, posPrepareInfill, - posInfill, posIroning, posSupportMaterial, posSimplifyPath, posSimplifySupportPath, + posInfill, posIroning, posSupportMaterial, // BBS + posSimplifyWall, posSimplifyInfill, posSimplifySupportPath, posDetectOverhangsForLift, posCount, }; diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index b2f948fbd..c6c38c658 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -495,22 +495,40 @@ void PrintObject::generate_support_material() void PrintObject::simplify_extrusion_path() { - if (this->set_started(posSimplifyPath)) { + if (this->set_started(posSimplifyWall)) { m_print->set_status(75, L("Optimizing toolpath")); - BOOST_LOG_TRIVIAL(debug) << "Simplify extrusion path of object in parallel - start"; - //BBS: infill and walls + BOOST_LOG_TRIVIAL(debug) << "Simplify wall extrusion path of object in parallel - start"; + //BBS: walls tbb::parallel_for( tbb::blocked_range(0, m_layers.size()), [this](const tbb::blocked_range& range) { for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++ layer_idx) { m_print->throw_if_canceled(); - m_layers[layer_idx]->simplify_extrusion_path(); + m_layers[layer_idx]->simplify_wall_extrusion_path(); } } ); m_print->throw_if_canceled(); - BOOST_LOG_TRIVIAL(debug) << "Simplify extrusion path of object in parallel - end"; - this->set_done(posSimplifyPath); + BOOST_LOG_TRIVIAL(debug) << "Simplify wall extrusion path of object in parallel - end"; + this->set_done(posSimplifyWall); + } + + if (this->set_started(posSimplifyInfill)) { + m_print->set_status(75, L("Optimizing toolpath")); + BOOST_LOG_TRIVIAL(debug) << "Simplify infill extrusion path of object in parallel - start"; + //BBS: infills + tbb::parallel_for( + tbb::blocked_range(0, m_layers.size()), + [this](const tbb::blocked_range& range) { + for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) { + m_print->throw_if_canceled(); + m_layers[layer_idx]->simplify_infill_extrusion_path(); + } + } + ); + m_print->throw_if_canceled(); + BOOST_LOG_TRIVIAL(debug) << "Simplify infill extrusion path of object in parallel - end"; + this->set_done(posSimplifyInfill); } if (this->set_started(posSimplifySupportPath)) { @@ -911,15 +929,15 @@ bool PrintObject::invalidate_step(PrintObjectStep step) // propagate to dependent steps if (step == posPerimeters) { - invalidated |= this->invalidate_steps({ posPrepareInfill, posInfill, posIroning, posSimplifyPath }); + invalidated |= this->invalidate_steps({ posPrepareInfill, posInfill, posIroning, posSimplifyWall, posSimplifyInfill }); invalidated |= m_print->invalidate_steps({ psSkirtBrim }); } else if (step == posPrepareInfill) { - invalidated |= this->invalidate_steps({ posInfill, posIroning, posSimplifyPath }); + invalidated |= this->invalidate_steps({ posInfill, posIroning, posSimplifyWall, posSimplifyInfill }); } else if (step == posInfill) { - invalidated |= this->invalidate_steps({ posIroning, posSimplifyPath }); + invalidated |= this->invalidate_steps({ posIroning, posSimplifyInfill }); invalidated |= m_print->invalidate_steps({ psSkirtBrim }); } else if (step == posSlice) { - invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posIroning, posSupportMaterial, posSimplifyPath }); + invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posIroning, posSupportMaterial, posSimplifyWall, posSimplifyInfill }); invalidated |= m_print->invalidate_steps({ psSkirtBrim }); m_slicing_params.valid = false; } else if (step == posSupportMaterial) {