diff options
author | Remco Burema <41987080+rburema@users.noreply.github.com> | 2020-02-20 11:02:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-20 11:02:58 +0300 |
commit | 0ec7eff000772c263cd0e4f55117e0752ec32b77 (patch) | |
tree | 264c9605ec057bdfb6a411aa398dfda51d59b47f | |
parent | 5209537f2b3c5fb4e6bf8f48a07f5a6b008fe273 (diff) | |
parent | f4879b0320238ab57c4e2b6d467dd3e68be5cb7a (diff) |
Fix crash when randomizing infill polygons
-rw-r--r-- | src/FffGcodeWriter.cpp | 24 | ||||
-rw-r--r-- | src/LayerPlan.cpp | 6 | ||||
-rw-r--r-- | src/LayerPlan.h | 46 |
3 files changed, 47 insertions, 29 deletions
diff --git a/src/FffGcodeWriter.cpp b/src/FffGcodeWriter.cpp index de3c771cc..5fc79467a 100644 --- a/src/FffGcodeWriter.cpp +++ b/src/FffGcodeWriter.cpp @@ -1,4 +1,4 @@ -//Copyright (c) 2019 Ultimaker B.V. +//Copyright (c) 2020 Ultimaker B.V. //CuraEngine is released under the terms of the AGPLv3 or higher. #include <list> @@ -1631,18 +1631,26 @@ bool FffGcodeWriter::processSingleLayerInfill(const SliceDataStorage& storage, L added_something = true; setExtruder_addPrime(storage, gcode_layer, extruder_nr); gcode_layer.setIsInside(true); // going to print stuff inside print object + std::optional<Point> near_start_location; + if (mesh.settings.get<bool>("infill_randomize_start_location")) + { + srand(gcode_layer.getLayerNr()); + if(!infill_lines.empty()) + { + near_start_location = infill_lines[rand() % infill_lines.size()][0]; + } + else + { + PolygonRef start_poly = infill_polygons[rand() % infill_polygons.size()]; + near_start_location = start_poly[rand() % start_poly.size()]; + } + } if (!infill_polygons.empty()) { constexpr bool force_comb_retract = false; // start the infill polygons at the nearest vertex to the current location gcode_layer.addTravel(PolygonUtils::findNearestVert(gcode_layer.getLastPlannedPositionOrStartingPosition(), infill_polygons).p(), force_comb_retract); - gcode_layer.addPolygonsByOptimizer(infill_polygons, mesh_config.infill_config[0]); - } - std::optional<Point> near_start_location; - if (mesh.settings.get<bool>("infill_randomize_start_location")) - { - srand(gcode_layer.getLayerNr()); - near_start_location = infill_lines[rand() % infill_lines.size()][0]; + gcode_layer.addPolygonsByOptimizer(infill_polygons, mesh_config.infill_config[0], nullptr, ZSeamConfig(), 0, false, 1.0_r, false, false, near_start_location); } const bool enable_travel_optimization = mesh.settings.get<bool>("infill_enable_travel_optimization"); if (pattern == EFillMethod::GRID || pattern == EFillMethod::LINES || pattern == EFillMethod::TRIANGLES || pattern == EFillMethod::CUBIC || pattern == EFillMethod::TETRAHEDRAL || pattern == EFillMethod::QUARTER_CUBIC || pattern == EFillMethod::CUBICSUBDIV) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index f40104e6d..ffcec63c5 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -1,4 +1,4 @@ -//Copyright (c) 2019 Ultimaker B.V. +//Copyright (c) 2020 Ultimaker B.V. //CuraEngine is released under the terms of the AGPLv3 or higher. #include <cstring> @@ -583,13 +583,13 @@ void LayerPlan::addPolygon(ConstPolygonRef polygon, int start_idx, const GCodePa } } -void LayerPlan::addPolygonsByOptimizer(const Polygons& polygons, const GCodePathConfig& config, WallOverlapComputation* wall_overlap_computation, const ZSeamConfig& z_seam_config, coord_t wall_0_wipe_dist, bool spiralize, const Ratio flow_ratio, bool always_retract, bool reverse_order) +void LayerPlan::addPolygonsByOptimizer(const Polygons& polygons, const GCodePathConfig& config, WallOverlapComputation* wall_overlap_computation, const ZSeamConfig& z_seam_config, coord_t wall_0_wipe_dist, bool spiralize, const Ratio flow_ratio, bool always_retract, bool reverse_order, std::optional<Point> start_near_location) { if (polygons.size() == 0) { return; } - PathOrderOptimizer orderOptimizer(getLastPlannedPositionOrStartingPosition(), z_seam_config); + PathOrderOptimizer orderOptimizer(start_near_location ? start_near_location.value() : getLastPlannedPositionOrStartingPosition(), z_seam_config); for (unsigned int poly_idx = 0; poly_idx < polygons.size(); poly_idx++) { orderOptimizer.addPolygon(polygons[poly_idx]); diff --git a/src/LayerPlan.h b/src/LayerPlan.h index 55052010d..925d13fb3 100644 --- a/src/LayerPlan.h +++ b/src/LayerPlan.h @@ -1,4 +1,4 @@ -//Copyright (c) 2018 Ultimaker B.V. +//Copyright (c) 2020 Ultimaker B.V. //CuraEngine is released under the terms of the AGPLv3 or higher. #ifndef LAYER_PLAN_H @@ -523,23 +523,33 @@ public: /*! * Add polygons to the gcode with optimized order. * - * When \p spiralize is true, each polygon will gradually increase from a z corresponding to this layer to the z corresponding to the next layer. - * Doing this for each polygon means there is a chance for the print head to crash into already printed parts, - * but doing it for the last polygon only would mean you are printing half of the layer in non-spiralize mode, - * while each layer starts with a different part. - * Two towers would result in alternating spiralize and non-spiralize layers. - * - * \param polygons The polygons - * \param config The config with which to print the polygon lines - * \param wall_overlap_computation The wall overlap compensation calculator for each given segment (optionally nullptr) - * \param z_seam_config Optional configuration for z-seam - * \param wall_0_wipe_dist The distance to travel along each polygon after it has been laid down, in order to wipe the start and end of the wall together - * \param spiralize Whether to gradually increase the z height from the normal layer height to the height of the next layer over each polygon printed - * \param flow_ratio The ratio with which to multiply the extrusion amount - * \param always_retract Whether to force a retraction when moving to the start of the polygon (used for outer walls) - * \param reverse_order Adds polygons in reverse order - */ - void addPolygonsByOptimizer(const Polygons& polygons, const GCodePathConfig& config, WallOverlapComputation* wall_overlap_computation = nullptr, const ZSeamConfig& z_seam_config = ZSeamConfig(), coord_t wall_0_wipe_dist = 0, bool spiralize = false, const Ratio flow_ratio = 1.0_r, bool always_retract = false, bool reverse_order = false); + * When \p spiralize is true, each polygon will gradually increase from a z + * corresponding to this layer to the z corresponding to the next layer. + * Doing this for each polygon means there is a chance for the print head to + * crash into already printed parts, but doing it for the last polygon only + * would mean you are printing half of the layer in non-spiralize mode, + * while each layer starts with a different part. Two towers would result in + * alternating spiralize and non-spiralize layers. + * + * \param polygons The polygons. + * \param config The config with which to print the polygon lines. + * \param wall_overlap_computation The wall overlap compensation calculator + * for each given segment (optionally nullptr). + * \param z_seam_config Optional configuration for z-seam. + * \param wall_0_wipe_dist The distance to travel along each polygon after + * it has been laid down, in order to wipe the start and end of the wall + * together. + * \param spiralize Whether to gradually increase the z height from the + * normal layer height to the height of the next layer over each polygon + * printed. + * \param flow_ratio The ratio with which to multiply the extrusion amount. + * \param always_retract Whether to force a retraction when moving to the + * start of the polygon (used for outer walls). + * \param reverse_order Adds polygons in reverse order. + * \param start_near_location Start optimising the path near this location. + * If unset, this causes it to start near the last planned location. + */ + void addPolygonsByOptimizer(const Polygons& polygons, const GCodePathConfig& config, WallOverlapComputation* wall_overlap_computation = nullptr, const ZSeamConfig& z_seam_config = ZSeamConfig(), coord_t wall_0_wipe_dist = 0, bool spiralize = false, const Ratio flow_ratio = 1.0_r, bool always_retract = false, bool reverse_order = false, const std::optional<Point> start_near_location = std::optional<Point>()); /*! * Add a single line that is part of a wall to the gcode. |