From 24d0c3191e39aa37611c8919711671ab01ab0b97 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 29 Feb 2024 11:14:20 +0100 Subject: [PATCH 1/3] Fix remove empty layers when layers do not equal layer height. This shouldn't happen, but neither should the hot-end ram into the build-plate (in fact, you want that even less). part of CURA-11537 --- src/FffPolygonGenerator.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/FffPolygonGenerator.cpp b/src/FffPolygonGenerator.cpp index f2fcbe8910..a8924f0133 100644 --- a/src/FffPolygonGenerator.cpp +++ b/src/FffPolygonGenerator.cpp @@ -769,12 +769,25 @@ bool FffPolygonGenerator::isEmptyLayer(SliceDataStorage& storage, const LayerInd void FffPolygonGenerator::removeEmptyFirstLayers(SliceDataStorage& storage, size_t& total_layers) { + const auto get_highest_z = [&storage](const LayerIndex& layer_idx) + { + coord_t highest_z = 0; + for (std::shared_ptr& mesh_ptr : storage.meshes) + { + auto& mesh = *mesh_ptr; + highest_z = layer_idx >= mesh.layers.size() ? highest_z : std::max(highest_z, mesh.layers[layer_idx].printZ); + } + return highest_z; + }; + size_t n_empty_first_layers = 0; + coord_t hightest_empty_layer = 0; for (size_t layer_idx = 0; layer_idx < total_layers; layer_idx++) { if (isEmptyLayer(storage, layer_idx)) { n_empty_first_layers++; + hightest_empty_layer = get_highest_z(layer_idx); } else { @@ -798,7 +811,7 @@ void FffPolygonGenerator::removeEmptyFirstLayers(SliceDataStorage& storage, size layers.erase(layers.begin(), layers.begin() + n_empty_first_layers); for (SliceLayer& layer : layers) { - layer.printZ -= n_empty_first_layers * layer_height; + layer.printZ -= hightest_empty_layer; } mesh.layer_nr_max_filled_layer -= n_empty_first_layers; } From 70b6447e4be23b8a4aceab1c517f94768b4c5ac0 Mon Sep 17 00:00:00 2001 From: rburema Date: Thu, 29 Feb 2024 10:15:14 +0000 Subject: [PATCH 2/3] Applied clang-format. --- src/FffPolygonGenerator.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/FffPolygonGenerator.cpp b/src/FffPolygonGenerator.cpp index a8924f0133..7c9b188a77 100644 --- a/src/FffPolygonGenerator.cpp +++ b/src/FffPolygonGenerator.cpp @@ -770,15 +770,15 @@ bool FffPolygonGenerator::isEmptyLayer(SliceDataStorage& storage, const LayerInd void FffPolygonGenerator::removeEmptyFirstLayers(SliceDataStorage& storage, size_t& total_layers) { const auto get_highest_z = [&storage](const LayerIndex& layer_idx) + { + coord_t highest_z = 0; + for (std::shared_ptr& mesh_ptr : storage.meshes) { - coord_t highest_z = 0; - for (std::shared_ptr& mesh_ptr : storage.meshes) - { - auto& mesh = *mesh_ptr; - highest_z = layer_idx >= mesh.layers.size() ? highest_z : std::max(highest_z, mesh.layers[layer_idx].printZ); - } - return highest_z; - }; + auto& mesh = *mesh_ptr; + highest_z = layer_idx >= mesh.layers.size() ? highest_z : std::max(highest_z, mesh.layers[layer_idx].printZ); + } + return highest_z; + }; size_t n_empty_first_layers = 0; coord_t hightest_empty_layer = 0; From 258c34e9e491dd1079559f10a639f2407dfddd45 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 29 Feb 2024 17:26:28 +0100 Subject: [PATCH 3/3] Apply review comments. Avoid lambda for just one use, use consts more. done as part of CURA-11537 --- src/FffPolygonGenerator.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/FffPolygonGenerator.cpp b/src/FffPolygonGenerator.cpp index 7c9b188a77..b0d5ff5ff2 100644 --- a/src/FffPolygonGenerator.cpp +++ b/src/FffPolygonGenerator.cpp @@ -769,17 +769,6 @@ bool FffPolygonGenerator::isEmptyLayer(SliceDataStorage& storage, const LayerInd void FffPolygonGenerator::removeEmptyFirstLayers(SliceDataStorage& storage, size_t& total_layers) { - const auto get_highest_z = [&storage](const LayerIndex& layer_idx) - { - coord_t highest_z = 0; - for (std::shared_ptr& mesh_ptr : storage.meshes) - { - auto& mesh = *mesh_ptr; - highest_z = layer_idx >= mesh.layers.size() ? highest_z : std::max(highest_z, mesh.layers[layer_idx].printZ); - } - return highest_z; - }; - size_t n_empty_first_layers = 0; coord_t hightest_empty_layer = 0; for (size_t layer_idx = 0; layer_idx < total_layers; layer_idx++) @@ -787,7 +776,14 @@ void FffPolygonGenerator::removeEmptyFirstLayers(SliceDataStorage& storage, size if (isEmptyLayer(storage, layer_idx)) { n_empty_first_layers++; - hightest_empty_layer = get_highest_z(layer_idx); + + coord_t layer_highest_z = 0; + for (const std::shared_ptr& mesh_ptr : storage.meshes) + { + const auto& mesh = *mesh_ptr; + layer_highest_z = layer_idx >= mesh.layers.size() ? layer_highest_z : std::max(layer_highest_z, mesh.layers[layer_idx].printZ); + } + hightest_empty_layer = std::max(hightest_empty_layer, layer_highest_z); } else {