diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index bbf53ef7e..58386c0bd 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -615,12 +615,19 @@ void SLAPrint::process() using namespace sla; using ExPolygon = Slic3r::ExPolygon; + if(m_objects.empty()) return; + // Assumption: at this point the print objects should be populated only with // the model objects we have to process and the instances are also filtered // shortcut to initial layer height double ilhd = m_material_config.initial_layer_height.getFloat(); auto ilh = float(ilhd); + double lhd = m_objects.front()->m_config.layer_height.getFloat(); + float lh = float(lhd); + + LevelID ilhs = ilhd / SCALING_FACTOR; + LevelID lhs = lhd / SCALING_FACTOR; const size_t objcount = m_objects.size(); const unsigned min_objstatus = 0; // where the per object operations start @@ -641,24 +648,26 @@ void SLAPrint::process() // Slicing the model object. This method is oversimplified and needs to // be compared with the fff slicing algorithm for verification - auto slice_model = [this, ilh](SLAPrintObject& po) { + auto slice_model = [this, ilhs, lhs, ilh, lh](SLAPrintObject& po) { TriangleMesh mesh = po.transformed_mesh(); // We need to prepare the slice index... auto&& bb3d = mesh.bounding_box(); - float minZ = float(bb3d.min(Z)) - float(po.get_elevation()); - float maxZ = float(bb3d.max(Z)); - auto flh = float(po.m_config.layer_height.getFloat()); + double minZ = bb3d.min(Z) - po.get_elevation(); + double maxZ = bb3d.max(Z); + + LevelID minZs = minZ / SCALING_FACTOR; + LevelID maxZs = maxZ / SCALING_FACTOR; auto slh = [](float h) { return LevelID( double(h) / SCALING_FACTOR); }; po.m_slice_index.clear(); - po.m_slice_index.reserve(size_t(maxZ - (minZ + ilh) / flh) + 1); - po.m_slice_index.emplace_back(slh(minZ + ilh), minZ + ilh / 2.f, ilh); + po.m_slice_index.reserve(size_t(maxZs - (minZs + ilhs) / lhs) + 1); + po.m_slice_index.emplace_back(minZs + ilhs, minZ + ilh / 2.f, ilh); - for(float h = minZ + ilh + flh; h <= maxZ; h += flh) { - po.m_slice_index.emplace_back(slh(h), h - flh / 2.f, flh); + for(LevelID h = minZs + ilhs + lhs; h <= maxZs; h += lhs) { + po.m_slice_index.emplace_back(h, h*SCALING_FACTOR - lh / 2.f, lh); } auto slindex_it = po.search_slice_index(float(bb3d.min(Z))); @@ -1337,7 +1346,7 @@ void SLAPrint::fill_statistics() for (SLAPrintObject * po : m_objects) { - const SLAPrintObject::SliceRecord *record = nullptr; + const SLAPrintObject::_SliceRecord *record = nullptr; { const SLAPrintObject::SliceIndex& index = po->get_slice_index(); auto it = po->search_slice_index(layer.slice_level() - float(EPSILON)); @@ -1562,10 +1571,10 @@ const std::vector<sla::SupportPoint>& SLAPrintObject::get_support_points() const SLAPrintObject::SliceIndex::iterator SLAPrintObject::search_slice_index(float slice_level) { - SliceRecord query(0, slice_level, 0); + _SliceRecord query(0, slice_level, 0); auto it = std::lower_bound(m_slice_index.begin(), m_slice_index.end(), query, - [](const SliceRecord& r1, const SliceRecord& r2) + [](const _SliceRecord& r1, const _SliceRecord& r2) { return r1.slice_level() < r2.slice_level(); }); @@ -1576,10 +1585,10 @@ SLAPrintObject::search_slice_index(float slice_level) SLAPrintObject::SliceIndex::const_iterator SLAPrintObject::search_slice_index(float slice_level) const { - SliceRecord query(0, slice_level, 0); + _SliceRecord query(0, slice_level, 0); auto it = std::lower_bound(m_slice_index.cbegin(), m_slice_index.cend(), query, - [](const SliceRecord& r1, const SliceRecord& r2) + [](const _SliceRecord& r1, const _SliceRecord& r2) { return r1.slice_level() < r2.slice_level(); }); @@ -1588,12 +1597,12 @@ SLAPrintObject::search_slice_index(float slice_level) const } SLAPrintObject::SliceIndex::iterator -SLAPrintObject::search_slice_index(SLAPrintObject::SliceRecord::Key key) +SLAPrintObject::search_slice_index(SLAPrintObject::_SliceRecord::Key key) { - SliceRecord query(key, 0.f, 0.f); + _SliceRecord query(key, 0.f, 0.f); auto it = std::lower_bound(m_slice_index.begin(), m_slice_index.end(), query, - [](const SliceRecord& r1, const SliceRecord& r2) + [](const _SliceRecord& r1, const _SliceRecord& r2) { return r1.key() < r2.key(); }); @@ -1605,12 +1614,12 @@ SLAPrintObject::search_slice_index(SLAPrintObject::SliceRecord::Key key) } SLAPrintObject::SliceIndex::const_iterator -SLAPrintObject::search_slice_index(SLAPrintObject::SliceRecord::Key key) const +SLAPrintObject::search_slice_index(SLAPrintObject::_SliceRecord::Key key) const { - SliceRecord query(key, 0.f, 0.f); + _SliceRecord query(key, 0.f, 0.f); auto it = std::lower_bound(m_slice_index.cbegin(), m_slice_index.cend(), query, - [](const SliceRecord& r1, const SliceRecord& r2) + [](const _SliceRecord& r1, const _SliceRecord& r2) { return r1.key() < r2.key(); }); @@ -1645,7 +1654,7 @@ const std::vector<ExPolygons> &SLAPrintObject::get_support_slices() const return m_supportdata->support_slices; } -const std::vector<SLAPrintObject::SliceRecord>& +const std::vector<SLAPrintObject::_SliceRecord>& SLAPrintObject::get_slice_index() const { // assert(is_step_done(slaposIndexSlices)); @@ -1769,7 +1778,7 @@ std::string SLAPrintStatistics::finalize_output_path(const std::string &path_in) return final_path; } -SliceIterator SLAPrintObject::SliceRecord::get_slices(const SLAPrintObject &po, +SliceIterator SLAPrintObject::_SliceRecord::get_slices(const SLAPrintObject &po, SliceOrigin so) const { diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 3e0a0c5e3..b33bfdeb0 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -107,30 +107,21 @@ public: // This method returns the support points of this SLAPrintObject. const std::vector<sla::SupportPoint>& get_support_points() const; -private: - - // An index record referencing the slices - // (get_model_slices(), get_support_slices()) where the keys are the height - // levels of the model in scaled-clipper coordinates. The levels correspond - // to the z coordinate of the object coordinate system. class SliceRecord { public: using Key = LevelID; private: - static const size_t NONE = size_t(-1); // this will be the max limit of size_t - size_t m_model_slices_idx = NONE; - size_t m_support_slices_idx = NONE; - 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 - public: - + protected: SliceRecord(Key key, float slicez, float height): m_print_z(key), m_slice_z(slicez), m_height(height) {} + public: + // The key will be the integer height level of the top of the layer. inline Key key() const { return m_print_z; } @@ -139,8 +130,25 @@ private: // Returns the current layer height inline float layer_height() const { return m_height; } + }; - // Returns the slices for eighter the model or the supports. The return +private: + + // An index record referencing the slices + // (get_model_slices(), get_support_slices()) where the keys are the height + // levels of the model in scaled-clipper coordinates. The levels correspond + // to the z coordinate of the object coordinate system. + class _SliceRecord: public SliceRecord { + private: + static const size_t NONE = size_t(-1); // this will be the max limit of size_t + size_t m_model_slices_idx = NONE; + size_t m_support_slices_idx = NONE; + + public: + _SliceRecord(Key key, float slicez, float height): + SliceRecord(key, slicez, height) {} + + // Returns the slices for either 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; @@ -151,7 +159,7 @@ private: }; // Slice index will be a plain vector sorted by the integer height levels - using SliceIndex = std::vector<SliceRecord>; + using SliceIndex = std::vector<_SliceRecord>; // Retrieve the slice index which is readable only after slaposIndexSlices // is done. @@ -163,8 +171,8 @@ private: // 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; + SliceIndex::iterator search_slice_index(_SliceRecord::Key key); + SliceIndex::const_iterator search_slice_index(_SliceRecord::Key key) const; public: @@ -173,10 +181,6 @@ public: // 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( @@ -194,9 +198,8 @@ public: // 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(); + inline const SliceRecord& get_slice_record(size_t idx) const { + return m_slice_index[idx]; } protected: @@ -239,7 +242,7 @@ private: // Exact (float) height levels mapped to the slices. Each record contains // the index to the model and the support slice vectors. - std::vector<SliceRecord> m_slice_index; + std::vector<_SliceRecord> m_slice_index; std::vector<float> m_model_height_levels; diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 148b83081..10a4a12c7 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -778,7 +778,7 @@ void Preview::load_print_as_sla() size_t cnt = obj->get_slice_count(); for (size_t i = 0; i < cnt; i++) { - zs.insert(shift_z + double(obj->get_slice_level(i))); + zs.insert(shift_z + obj->get_slice_record(i).key() * SCALING_FACTOR); } } }