diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp index df9990822d..34dd80cee0 100644 --- a/src/libslic3r/SLA/SLASupportTree.cpp +++ b/src/libslic3r/SLA/SLASupportTree.cpp @@ -2240,6 +2240,18 @@ SlicedSupports SLASupportTree::slice(float layerh, float init_layerh) const return ret; } +SlicedSupports SLASupportTree::slice(const std::vector &heights, + float cr) const +{ + TriangleMesh fullmesh = m_impl->merged_mesh(); + fullmesh.merge(get_pad()); + TriangleMeshSlicer slicer(&fullmesh); + SlicedSupports ret; + slicer.slice(heights, cr, &ret, get().ctl().cancelfn); + + return ret; +} + const TriangleMesh &SLASupportTree::add_pad(const SliceLayer& baseplate, const PoolConfig& pcfg) const { diff --git a/src/libslic3r/SLA/SLASupportTree.hpp b/src/libslic3r/SLA/SLASupportTree.hpp index 74d7da9cad..66677e4d7a 100644 --- a/src/libslic3r/SLA/SLASupportTree.hpp +++ b/src/libslic3r/SLA/SLASupportTree.hpp @@ -181,6 +181,8 @@ public: /// Get the sliced 2d layers of the support geometry. SlicedSupports slice(float layerh, float init_layerh = -1.0) const; + SlicedSupports slice(const std::vector&, float closing_radius) const; + /// Adding the "pad" (base pool) under the supports const TriangleMesh& add_pad(const SliceLayer& baseplate, const PoolConfig& pcfg) const; diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index e12dc7f233..bbf53ef7e8 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -856,11 +856,19 @@ void SLAPrint::process() // Slicing the support geometries similarly to the model slicing procedure. // If the pad had been added previously (see step "base_pool" than it will // be part of the slices) - auto slice_supports = [ilh](SLAPrintObject& po) { + auto slice_supports = [](SLAPrintObject& po) { auto& sd = po.m_supportdata; if(sd && sd->support_tree_ptr) { - auto lh = float(po.m_config.layer_height.getFloat()); - sd->support_slices = sd->support_tree_ptr->slice(lh, ilh); + sd->support_slices.clear(); + + std::vector heights; heights.reserve(po.m_slice_index.size()); + + for(auto& rec : po.m_slice_index) { + heights.emplace_back(rec.slice_level()); + } + + sd->support_slices = sd->support_tree_ptr->slice( + heights, float(po.config().slice_closing_radius.value)); } for(size_t i = 0; @@ -1613,20 +1621,6 @@ SLAPrintObject::search_slice_index(SLAPrintObject::SliceRecord::Key key) const return it; } -SliceIterator SLAPrintObject::get_slices(SliceOrigin so, LevelID k) const -{ - SliceIterator ret = so == soModel ? get_model_slices().end() : - get_support_slices().end(); - - auto it = search_slice_index(k); - - if(it != m_slice_index.end()) { - ret = it->get_slices(*this, so); - } - - return ret; -} - SliceRange SLAPrintObject::get_slices(SliceOrigin so, float from_level, float to_level) const @@ -1658,23 +1652,6 @@ SLAPrintObject::get_slice_index() const return m_slice_index; } -//std::vector SLAPrintObject::get_slice_levels(float from_eq) const -//{ -// using SlRec = SLAPrintObject::SliceRecord; -// auto it = std::lower_bound(m_slice_index.begin(), -// m_slice_index.end(), -// from_eq, // model start z -// [](const SlRec& sr1, const SlRec& sr2){ -// return sr1.slice_level() < sr2.slice_level(); -// }); - -// std::vector heights; heights.reserve(m_slice_index.size()); -// for(; it != m_slice_index.end(); ++it) -// heights.emplace_back(it->slice_level()); - - -//} - const std::vector &SLAPrintObject::get_model_slices() const { // assert(is_step_done(slaposObjectSlice)); diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index e86080963a..3e0a0c5e3a 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -122,7 +122,7 @@ private: size_t m_model_slices_idx = NONE; size_t m_support_slices_idx = NONE; - LevelID m_print_z = 0; // Top of the layer + LevelID m_print_z = 0; // Top of the layer float m_slice_z = 0.f; // Exact level of the slice float m_height = 0.f; // Height of the sliced layer @@ -131,34 +131,54 @@ private: SliceRecord(Key key, float slicez, float height): m_print_z(key), m_slice_z(slicez), m_height(height) {} + // The key will be the integer height level of the top of the layer. inline Key key() const { return m_print_z; } + + // Returns the exact floating point Z coordinate of the slice inline float slice_level() const { return m_slice_z; } + + // Returns the current layer height inline float layer_height() const { return m_height; } - SliceIterator get_slices(const SLAPrintObject& po, - SliceOrigin so) const; - + // Returns the slices for eighter the model or the supports. The return + // value is an iterator to po.get_model_slices() or po.get_support_slices + // depending on the SliceOrigin parameter. + SliceIterator get_slices(const SLAPrintObject& po, SliceOrigin so) const; + // Methods for setting the indixes into the slice vectors. void set_model_slice_idx(size_t id) { m_model_slices_idx = id; } void set_support_slice_idx(size_t id) { m_support_slices_idx = id; } - }; + // Slice index will be a plain vector sorted by the integer height levels using SliceIndex = std::vector; // Retrieve the slice index which is readable only after slaposIndexSlices // is done. const SliceIndex& get_slice_index() const; + // Search slice index for the closest slice to the given level SliceIndex::iterator search_slice_index(float slice_level); SliceIndex::const_iterator search_slice_index(float slice_level) const; + + // Search the slice index for a particular level in integer coordinates. + // If no such layer is present, it will return m_slice_index.end() SliceIndex::iterator search_slice_index(SliceRecord::Key key); SliceIndex::const_iterator search_slice_index(SliceRecord::Key key) const; public: - SliceIterator get_slices(SliceOrigin so, LevelID k) const; + // ///////////////////////////////////////////////////////////////////////// + // The following methods can be used after the model and the support slicing + // steps have been succesfully finished. + // ///////////////////////////////////////////////////////////////////////// + // Getting slices for either the model or the supports for a particular + // height ID. +// SliceIterator get_slices(SliceOrigin so, LevelID k) const; + + // Getting slices (model or supports) for a Z coordinate range. The returned + // iterators should include the slices for the given boundaries as well. SliceRange get_slices( SliceOrigin so, float from_level, @@ -171,7 +191,10 @@ public: const std::vector& get_model_slices() const; const std::vector& get_support_slices() const; + // Returns the total number of slices in the slice grid (model and supports) inline size_t get_slice_count() const { return m_slice_index.size(); } + + // One can query the Z coordinate of the slice for a given inline float get_slice_level(size_t idx) const { return m_slice_index[idx].slice_level(); }