diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 938f148a30..e12dc7f233 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -30,7 +30,6 @@ public: std::vector support_points; // all the support points (manual/auto) SupportTreePtr support_tree_ptr; // the supports SlicedSupports support_slices; // sliced supports - std::vector level_ids; inline SupportData(const TriangleMesh& trmesh): emesh(trmesh) {} }; @@ -603,25 +602,9 @@ std::string SLAPrint::validate() const return ""; } -std::vector SLAPrint::calculate_heights(const BoundingBoxf3& bb3d, - float elevation, - float initial_layer_height, - float layer_height) const -{ - std::vector heights; - float minZ = float(bb3d.min(Z)) - float(elevation); - float maxZ = float(bb3d.max(Z)); - auto flh = float(layer_height); - auto gnd = float(bb3d.min(Z)); - - for(float h = minZ + initial_layer_height; h < maxZ; h += flh) - if(h >= gnd) heights.emplace_back(h); - - return heights; -} - template -void report_status(SLAPrint& p, int st, const std::string& msg, Args&&...args) { +void report_status(SLAPrint& p, int st, const std::string& msg, Args&&...args) +{ BOOST_LOG_TRIVIAL(info) << st << "% " << msg; p.set_status(st, msg, std::forward(args)...); } @@ -684,15 +667,17 @@ void SLAPrint::process() throw std::runtime_error(L("Slicing had to be stopped " "due to an internal error.")); - po.m_height_levels.clear(); - po.m_height_levels.reserve(po.m_slice_index.size()); + po.m_model_height_levels.clear(); + po.m_model_height_levels.reserve(po.m_slice_index.size()); for(auto it = slindex_it; it != po.m_slice_index.end(); ++it) - po.m_height_levels.emplace_back(it->slice_level()); + { + po.m_model_height_levels.emplace_back(it->slice_level()); + } TriangleMeshSlicer slicer(&mesh); po.m_model_slices.clear(); - slicer.slice(po.m_height_levels, + slicer.slice(po.m_model_height_levels, float(po.config().slice_closing_radius.value), &po.m_model_slices, [this](){ throw_if_canceled(); }); @@ -725,7 +710,7 @@ void SLAPrint::process() if (mo.sla_points_status != sla::PointsStatus::UserModified) { // calculate heights of slices (slices are calculated already) - const std::vector& heights = po.m_height_levels; + const std::vector& heights = po.m_model_height_levels; this->throw_if_canceled(); SLAAutoSupports::Config config; @@ -1646,10 +1631,17 @@ SliceRange SLAPrintObject::get_slices(SliceOrigin so, float from_level, float to_level) const { - auto from = LevelID(double(from_level) / SCALING_FACTOR); - auto to = LevelID(double(to_level) / SCALING_FACTOR); + auto it_from = search_slice_index(from_level); + auto it_to = search_slice_index(to_level); - return SliceRange(get_slices(so, from), get_slices(so, to)); + SliceRange ret; + + auto endit = so == soModel? get_model_slices().end() : get_support_slices().end(); + + ret.from = it_from == m_slice_index.end() ? endit : it_from->get_slices(*this, so); + ret.to = it_to == m_slice_index.end() ? endit : it_to->get_slices(*this, so); + + return ret; } const std::vector &SLAPrintObject::get_support_slices() const diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 6204628757..e86080963a 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -171,8 +171,9 @@ public: const std::vector& get_model_slices() const; const std::vector& get_support_slices() const; - inline const std::vector& get_height_levels() const { - return m_height_levels; + inline size_t get_slice_count() const { return m_slice_index.size(); } + inline float get_slice_level(size_t idx) const { + return m_slice_index[idx].slice_level(); } protected: @@ -204,8 +205,10 @@ protected: private: // Object specific configuration, pulled from the configuration layer. SLAPrintObjectConfig m_config; + // Translation in Z + Rotation by Y and Z + Scaling / Mirroring. Transform3d m_trafo = Transform3d::Identity(); + std::vector m_instances; // Individual 2d slice polygons from lower z to higher z levels @@ -215,10 +218,7 @@ private: // the index to the model and the support slice vectors. std::vector m_slice_index; - // The height levels corrected and scaled up in integer values. This will - // be used at rasterization. - std::vector m_level_ids; - std::vector m_height_levels; + std::vector m_model_height_levels; // Caching the transformed (m_trafo) raw mesh of the object mutable CachedObject m_transformed_rmesh; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 7bd63aa3c9..90656c93b7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4938,24 +4938,26 @@ void GLCanvas3D::_render_sla_slices() const if ((bottom_obj_triangles.empty() || bottom_sup_triangles.empty() || top_obj_triangles.empty() || top_sup_triangles.empty()) && obj->is_step_done(slaposIndexSlices)) { // FIXME: is this all right (by Tamas)? - SliceRange model_slices = obj->get_slices(soModel, float(min_z), float(max_z)); - SliceRange support_slices = obj->get_slices(soSupport, float(min_z), float(max_z)); + SliceRange obj_range = obj->get_slices(soModel, float(min_z), float(max_z)); + SliceRange sup_range = obj->get_slices(soSupport, float(min_z), float(max_z)); + auto obj_end = obj->get_model_slices().end(); + auto sup_end = obj->get_support_slices().end(); // calculate model bottom cap - if(bottom_obj_triangles.empty() && model_slices.from != obj->get_model_slices().end()) - bottom_obj_triangles = triangulate_expolygons_3d(*model_slices.from, min_z, true); + if(bottom_obj_triangles.empty() && obj_range.from != obj_end) + bottom_obj_triangles = triangulate_expolygons_3d(*obj_range.from, min_z, true); // calculate support bottom cap - if(bottom_sup_triangles.empty() && support_slices.from != obj->get_support_slices().end()) - bottom_sup_triangles = triangulate_expolygons_3d(*support_slices.from, min_z, true); + if(bottom_sup_triangles.empty() && sup_range.from != sup_end) + bottom_sup_triangles = triangulate_expolygons_3d(*sup_range.from, min_z, true); // calculate model top cap - if(top_obj_triangles.empty() && model_slices.to != obj->get_model_slices().end()) - top_obj_triangles = triangulate_expolygons_3d(*model_slices.to, max_z, true); + if(top_obj_triangles.empty() && obj_range.to != obj_end) + top_obj_triangles = triangulate_expolygons_3d(*obj_range.to, max_z, false); // calculate support top cap - if(top_sup_triangles.empty() && support_slices.to != obj->get_support_slices().end()) - top_sup_triangles = triangulate_expolygons_3d(*support_slices.to, max_z, true); + if(top_sup_triangles.empty() && sup_range.to != sup_end) + top_sup_triangles = triangulate_expolygons_3d(*sup_range.to, max_z, false); // const std::vector& model_slices = obj->get_model_slices(); // const std::vector& support_slices = obj->get_support_slices(); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index f691850b42..4776733420 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -776,10 +776,10 @@ void Preview::load_print_as_sla() double shift_z = obj->get_current_elevation(); if (obj->is_step_done(slaposIndexSlices)) { - const std::vector& hlvls = obj->get_height_levels(); - for (float h : hlvls) + size_t cnt = obj->get_slice_count(); + for (size_t i = 0; i < cnt; i++) { - zs.insert(shift_z + double(h)); + zs.insert(shift_z + double(obj->get_slice_level(i))); } } }