From 3eecf54d9c375bb37e5488687b7faa48093560e6 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 26 Apr 2019 11:33:33 +0200 Subject: [PATCH] Fixing large memory reservation in the SLA model slicing step. --- src/libslic3r/SLAPrint.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index ecae36cc5..3122beece 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -674,7 +674,7 @@ 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, ilhs, ilh](SLAPrintObject& po) { + auto slice_model = [this, ilhs, ilh, ilhd](SLAPrintObject& po) { const TriangleMesh& mesh = po.transformed_mesh(); // We need to prepare the slice index... @@ -691,13 +691,15 @@ void SLAPrint::process() auto maxZs = coord_t(maxZ / SCALING_FACTOR); po.m_slice_index.clear(); - po.m_slice_index.reserve(size_t(maxZs - (minZs + ilhs) / lhs) + 1); - po.m_slice_index.emplace_back(minZs + ilhs, float(minZ) + ilh / 2.f, ilh); - - for(coord_t h = minZs + ilhs + lhs; h <= maxZs; h += lhs) { - po.m_slice_index.emplace_back(h, float(h*SCALING_FACTOR) - lh / 2.f, lh); - } + + size_t cap = size_t(1 + (maxZs - minZs - ilhs) / lhs); + po.m_slice_index.reserve(cap); + + po.m_slice_index.emplace_back(minZs + ilhs, minZ + ilhd / 2.0, ilh); + for(coord_t h = minZs + ilhs + lhs; h <= maxZs; h += lhs) + po.m_slice_index.emplace_back(h, h*SCALING_FACTOR - lhd / 2.0, lh); + // Just get the first record that is form the model: auto slindex_it = po.closest_slice_record(po.m_slice_index, float(bb3d.min(Z))); @@ -710,11 +712,8 @@ void SLAPrint::process() 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_model_height_levels.emplace_back(it->slice_level()); - } -// mesh.require_shared_vertices(); // TriangleMeshSlicer needs this TriangleMeshSlicer slicer(&mesh); po.m_model_slices.clear();