From 0440e288f762d7389d631e46c8af1bef1ab9f7bd Mon Sep 17 00:00:00 2001 From: wintergua Date: Thu, 6 Apr 2023 14:52:11 +0800 Subject: [PATCH] ENH: move the volumes grouping process to an indivial function grouping of volumes in the slicing process, which will be used by the brim generation processes, is moved to an indivial function from the fixed_slicing_errors function. Change-Id: I241081823a671829d8cc4e923da5f6f22776c410 (cherry picked from commit 18a7b541ee48f3c01319d5835c05610c3d8ca0ae) --- src/libslic3r/Layer.hpp | 2 +- src/libslic3r/PrintObjectSlice.cpp | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/Layer.hpp b/src/libslic3r/Layer.hpp index 421e33f86..47b0b7817 100644 --- a/src/libslic3r/Layer.hpp +++ b/src/libslic3r/Layer.hpp @@ -197,7 +197,7 @@ public: protected: friend class PrintObject; friend std::vector new_layers(PrintObject*, const std::vector&); - friend std::string fix_slicing_errors(PrintObject* object, LayerPtrs&, const std::function&); + friend std::string fix_slicing_errors(PrintObject* object, LayerPtrs&, const std::function&, int &); Layer(size_t id, PrintObject *object, coordf_t height, coordf_t print_z, coordf_t slice_z) : upper_layer(nullptr), lower_layer(nullptr), slicing_errors(false), diff --git a/src/libslic3r/PrintObjectSlice.cpp b/src/libslic3r/PrintObjectSlice.cpp index fa5aa1e79..382296e16 100644 --- a/src/libslic3r/PrintObjectSlice.cpp +++ b/src/libslic3r/PrintObjectSlice.cpp @@ -608,7 +608,7 @@ void reGroupingLayerPolygons(std::vector& gvss, ExPolygons } } -std::string fix_slicing_errors(PrintObject* object, LayerPtrs &layers, const std::function &throw_if_canceled) +std::string fix_slicing_errors(PrintObject* object, LayerPtrs &layers, const std::function &throw_if_canceled, int &firstLayerReplacedBy) { std::string error_msg;//BBS @@ -720,10 +720,14 @@ std::string fix_slicing_errors(PrintObject* object, LayerPtrs &layers, const std // BBS: first layer slices are sorted by volume group, if the first layer is empty and replaced by the 2nd layer // the later will be stored in "object->firstLayerObjGroupsMod()" - int firstLayerReplacedBy = 0; if (!buggy_layers.empty() && buggy_layers.front() == 0 && layers.size() > 1) firstLayerReplacedBy = 1; + return error_msg; +} + +void groupingVolumesForBrim(PrintObject* object, LayerPtrs& layers, int firstLayerReplacedBy) +{ const auto scaled_resolution = scaled(object->print()->config().resolution.value); auto partsObjSliceByVolume = findPartVolumes(object->firstLayerObjSliceMod(), object->model_object()->volumes); groupingVolumes(partsObjSliceByVolume, object->firstLayerObjGroupsMod(), scaled_resolution, firstLayerReplacedBy); @@ -731,8 +735,6 @@ std::string fix_slicing_errors(PrintObject* object, LayerPtrs &layers, const std // BBS: the actual first layer slices stored in layers are re-sorted by volume group and will be used to generate brim reGroupingLayerPolygons(object->firstLayerObjGroupsMod(), layers.front()->lslices); - - return error_msg; } // Called by make_perimeters() @@ -757,10 +759,12 @@ void PrintObject::slice() m_layers = new_layers(this, generate_object_layers(m_slicing_params, layer_height_profile)); this->slice_volumes(); m_print->throw_if_canceled(); + int firstLayerReplacedBy = 0; + #if 1 // Fix the model. //FIXME is this the right place to do? It is done repeateadly at the UI and now here at the backend. - std::string warning = fix_slicing_errors(this, m_layers, [this](){ m_print->throw_if_canceled(); }); + std::string warning = fix_slicing_errors(this, m_layers, [this](){ m_print->throw_if_canceled(); }, firstLayerReplacedBy); m_print->throw_if_canceled(); //BBS: send warning message to slicing callback if (!warning.empty()) { @@ -768,6 +772,10 @@ void PrintObject::slice() this->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL, warning, PrintStateBase::SlicingReplaceInitEmptyLayers); } #endif + + // BBS: the actual first layer slices stored in layers are re-sorted by volume group and will be used to generate brim + groupingVolumesForBrim(this, m_layers, firstLayerReplacedBy); + // Update bounding boxes, back up raw slices of complex models. tbb::parallel_for( tbb::blocked_range(0, m_layers.size()),