From 9d1ac71e55cb97931a2bb76b45618d1e1a483420 Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Fri, 2 Dec 2022 12:52:37 +0100 Subject: [PATCH] added support for multiple objects --- src/libslic3r/GCode.cpp | 7 ++- src/libslic3r/GCode/ExtrusionProcessor.hpp | 62 +++++----------------- 2 files changed, 17 insertions(+), 52 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 176dd48bc..ffdf24b1a 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2169,12 +2169,9 @@ LayerResult GCode::process_layer( } } - std::vector layers_ptrs; - layers_ptrs.reserve(layers.size()); for (const ObjectLayerToPrint &layer_to_print : layers) { - layers_ptrs.push_back(layer_to_print.object_layer); + m_extrusion_quality_estimator.prepare_for_new_layer(layer_to_print.object_layer); } - m_extrusion_quality_estimator.prepare_for_new_layer(layers_ptrs); // Extrude the skirt, brim, support, perimeters, infill ordered by the extruders. for (unsigned int extruder_id : layer_tools.extruders) @@ -2303,6 +2300,8 @@ void GCode::process_layer_single_object( const PrintObject &print_object = print_instance.print_object; const Print &print = *print_object.print(); + m_extrusion_quality_estimator.set_current_object(&print_object); + if (! print_wipe_extrusions && layer_to_print.support_layer != nullptr) if (const SupportLayer &support_layer = *layer_to_print.support_layer; ! support_layer.support_fills.entities.empty()) { ExtrusionRole role = support_layer.support_fills.role(); diff --git a/src/libslic3r/GCode/ExtrusionProcessor.hpp b/src/libslic3r/GCode/ExtrusionProcessor.hpp index f8148eb41..7b5f90bd6 100644 --- a/src/libslic3r/GCode/ExtrusionProcessor.hpp +++ b/src/libslic3r/GCode/ExtrusionProcessor.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace Slic3r { @@ -95,59 +96,22 @@ struct ProcessedPoint class ExtrusionQualityEstimator { - AABBTreeLines::LinesDistancer prev_layer_boundary; - AABBTreeLines::LinesDistancer next_layer_boundary; - CurvatureEstimator cestim; + std::unordered_map> prev_layer_boundaries; + std::unordered_map> next_layer_boundaries; + CurvatureEstimator cestim; + const PrintObject *current_object; public: void reset_for_next_extrusion() { cestim.reset(); } - void prepare_for_new_layer(const std::vector &layers) + void set_current_object(const PrintObject *object) { current_object = object; } + + void prepare_for_new_layer(const Layer *layer) { - std::vector layer_lines; - for (const Layer *layer : layers) { - if (layer == nullptr) continue; - std::vector object_lines = to_unscaled_linesf(layer->lslices); - layer_lines.insert(layer_lines.end(), object_lines.begin(), object_lines.end()); - } - prev_layer_boundary = next_layer_boundary; - next_layer_boundary = AABBTreeLines::LinesDistancer{std::move(layer_lines)}; - -#if 0 // EXPORT DEBUG FILES - Lines scaled_lines; - for (const Linef &lf : layer_lines) { scaled_lines.push_back({Point::new_scale(lf.a), Point::new_scale(lf.b)}); } - BoundingBox bb = get_extents(scaled_lines); - - Points inside; - for (const Layer *layer : layers) { - if (layer == nullptr) continue; - auto in = to_points(to_polygons(offset_ex(layer->lslices, -scale_(0.4)))); - inside.insert(inside.end(), in.begin(), in.end()); - } - - ::Slic3r::SVG svg(debug_out_path(("processing" + std::to_string(rand() % 1000)).c_str()).c_str(), bb); - svg.draw(scaled_lines, "black", scale_(0.10)); - for (Point p : inside) { - auto [distance, line_idx, nearest_point] = next_layer_boundary.signed_distance_from_lines_extra(unscaled(p)); - if (distance > 0) { - svg.draw(p, "red", scale_(0.2)); - svg.draw(Point::new_scale(nearest_point.x(), nearest_point.y()), "blue", scale_(0.2)); - auto li = next_layer_boundary.get_line(line_idx); - Line ls{Point::new_scale(li.a), Point::new_scale(li.b)}; - svg.draw(ls, "yellow", scale_(0.2)); - } - } - - if (inside.size() > 0) { - Line line{inside[0], inside[inside.size() * 0.5]}; - auto inters = next_layer_boundary.intersections_with_line({unscaled(line.a), unscaled(line.b)}); - svg.draw(line, "purple", scale_(0.15)); - for (auto inter : inters) { - svg.draw(Point::new_scale(inter), "red", scale_(0.2)); - } - } - -#endif + if (layer == nullptr) return; + const PrintObject *object = layer->object(); + prev_layer_boundaries[object] = next_layer_boundaries[object]; + next_layer_boundaries[object] = AABBTreeLines::LinesDistancer{to_unscaled_linesf(layer->lslices)}; } std::vector estimate_extrusion_quality(const ExtrusionPath &path) @@ -168,6 +132,8 @@ public: const Points &original_points = path.polyline.points; std::vector points; + const auto& prev_layer_boundary = prev_layer_boundaries[current_object]; + float distance = prev_layer_boundary.signed_distance_from_lines(unscaled(original_points[0])) + 0.5 * flow_width; points.push_back({unscaled(original_points[0]), distance, 1.0f}); for (size_t i = 1; i < original_points.size(); i++) {