From 2f6fbfb3381edcca6f81794c1fd2c76439c89a44 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 4 Apr 2018 11:00:25 +0200 Subject: [PATCH] Fix of SPE-183: Incorrect z values set into GCode Preview sliders. Rework to replace layer top heights with averages of EPSILON intervals. --- xs/src/slic3r/GUI/3DScene.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 95a739353..0db81d99b 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -642,24 +642,25 @@ void GLVolumeCollection::update_outside_state(const DynamicPrintConfig* config, std::vector GLVolumeCollection::get_current_print_zs() const { + // Collect layer top positions of all volumes. std::vector print_zs; - std::vector rounded_print_zs; - for (GLVolume *vol : this->volumes) - { - for (coordf_t z : vol->print_zs) - { - double round_z = ::round(z * 100000.0 + 0.5) / 100000.0; - if (std::find(rounded_print_zs.begin(), rounded_print_zs.end(), round_z) == rounded_print_zs.end()) - { - print_zs.push_back(z); - rounded_print_zs.push_back(round_z); - } - } - } - + append(print_zs, vol->print_zs); std::sort(print_zs.begin(), print_zs.end()); + // Replace intervals of layers with similar top positions with their average value. + int n = int(print_zs.size()); + int k = 0; + for (int i = 0; i < n;) { + int j = i + 1; + coordf_t zmax = print_zs[i] + EPSILON; + for (; j < n && print_zs[j] <= zmax; ++ j) ; + print_zs[k ++] = (j > i + 1) ? (0.5 * (print_zs[i] + print_zs[j - 1])) : print_zs[i]; + i = j; + } + if (k < n) + print_zs.erase(print_zs.begin() + k, print_zs.end()); + return print_zs; }