From 9b5da0ecf482c2d49164b19f1aea7eb2abb4b907 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 14 Sep 2023 21:39:25 +0200 Subject: [PATCH] Fix slowdown issue due to copy of large data. Since `make_shared` is a constructor, the mesh data was copied over each time we started a new layer. Properly fix this by using smart-pointers from the beginning, so we only have the creation overhead, which is nearly nothing. In fact, this solution may be _faster_ than the original, perhaps due to some constness that is now also enforced. fixes internal ticket CURA-11019 --- include/FffGcodeWriter.h | 5 ++-- include/LayerPlan.h | 4 +-- include/pathPlanning/GCodePath.h | 2 +- include/sliceDataStorage.h | 2 +- src/FffGcodeWriter.cpp | 39 +++++++++++++++++------------- src/FffPolygonGenerator.cpp | 30 +++++++++++++---------- src/LayerPlan.cpp | 11 +++++---- src/TreeModelVolumes.cpp | 5 ++-- src/TreeSupport.cpp | 16 ++++++------ src/bridge.cpp | 3 ++- src/plugins/converters.cpp | 2 +- src/settings/PathConfigStorage.cpp | 6 ++--- src/sliceDataStorage.cpp | 22 ++++++++--------- src/support.cpp | 19 ++++++++------- 14 files changed, 90 insertions(+), 76 deletions(-) diff --git a/include/FffGcodeWriter.h b/include/FffGcodeWriter.h index 2d2e7c7162..2cde3c40d4 100644 --- a/include/FffGcodeWriter.h +++ b/include/FffGcodeWriter.h @@ -328,13 +328,12 @@ class FffGcodeWriter : public NoCopy * This adds all features (e.g. walls, skin etc.) of this \p mesh to the gcode which are printed using \p extruder_nr * * \param[in] storage where the slice data is stored. - * \param mesh The mesh to add to the layer plan \p gcode_layer. + * \param mesh_ptr The mesh to add to the layer plan \p gcode_layer. * \param extruder_nr The extruder for which to print all features of the mesh which should be printed with this extruder * \param mesh_config the line config with which to print a print feature * \param gcode_layer The initial planning of the gcode of the layer. */ - void addMeshLayerToGCode(const SliceDataStorage& storage, const SliceMeshStorage& mesh, const size_t extruder_nr, const MeshPathConfigs& mesh_config, LayerPlan& gcode_layer) - const; + void addMeshLayerToGCode(const SliceDataStorage& storage, const std::shared_ptr& mesh_ptr, const size_t extruder_nr, const MeshPathConfigs& mesh_config, LayerPlan& gcode_layer) const; /*! * Add all features of the given extruder from a single part from a given layer of a mesh-volume to the layer plan \p gcode_layer. diff --git a/include/LayerPlan.h b/include/LayerPlan.h index 3eda752178..c894ab2a27 100644 --- a/include/LayerPlan.h +++ b/include/LayerPlan.h @@ -70,7 +70,7 @@ class LayerPlan : public NoCopy std::vector has_prime_tower_planned_per_extruder; //!< For each extruder, whether the prime tower is planned yet or not. std::optional last_planned_position; //!< The last planned XY position of the print head (if known) - std::shared_ptr current_mesh; //!< The mesh of the last planned move. + std::shared_ptr current_mesh; //!< The mesh of the last planned move. /*! * Whether the skirt or brim polygons have been processed into planned paths @@ -238,7 +238,7 @@ class LayerPlan : public NoCopy * Track the currently printing mesh. * \param mesh_id A unique ID indicating the current mesh. */ - void setMesh(const std::shared_ptr& mesh); + void setMesh(const std::shared_ptr& mesh); /*! * Set bridge_wall_mask. diff --git a/include/pathPlanning/GCodePath.h b/include/pathPlanning/GCodePath.h index 8c3c34dcfe..7bbd56c709 100644 --- a/include/pathPlanning/GCodePath.h +++ b/include/pathPlanning/GCodePath.h @@ -30,7 +30,7 @@ namespace cura struct GCodePath { GCodePathConfig config{}; //!< The configuration settings of the path. - std::shared_ptr mesh; //!< Which mesh this path belongs to, if any. If it's not part of any mesh, the mesh should be nullptr; + std::shared_ptr mesh; //!< Which mesh this path belongs to, if any. If it's not part of any mesh, the mesh should be nullptr; SpaceFillType space_fill_type{}; //!< The type of space filling of which this path is a part Ratio flow{}; //!< A type-independent flow configuration Ratio width_factor{}; //!< Adjustment to the line width. Similar to flow, but causes the speed_back_pressure_factor to be adjusted. diff --git a/include/sliceDataStorage.h b/include/sliceDataStorage.h index 32a391c24c..9b0661ed36 100644 --- a/include/sliceDataStorage.h +++ b/include/sliceDataStorage.h @@ -324,7 +324,7 @@ class SliceDataStorage : public NoCopy Point3 model_size, model_min, model_max; AABB3D machine_size; //!< The bounding box with the width, height and depth of the printer. - std::vector meshes; + std::vector> meshes; std::vector retraction_wipe_config_per_extruder; //!< Config for retractions, extruder switch retractions, and wipes, per extruder. diff --git a/src/FffGcodeWriter.cpp b/src/FffGcodeWriter.cpp index 648e9082ce..0d6ea404fd 100644 --- a/src/FffGcodeWriter.cpp +++ b/src/FffGcodeWriter.cpp @@ -106,8 +106,9 @@ void FffGcodeWriter::writeGCode(SliceDataStorage& storage, TimeKeeper& time_keep } size_t total_layers = 0; - for (SliceMeshStorage& mesh : storage.meshes) + for (auto& mesh_ptr : storage.meshes) { + auto& mesh = *mesh_ptr; size_t mesh_layer_num = mesh.layers.size(); // calculation of _actual_ number of layers in loop. @@ -269,7 +270,7 @@ void FffGcodeWriter::findLayerSeamsForSpiralize(SliceDataStorage& storage, size_ const std::vector& mesh_order = mesh_order_per_extruder[extruder_nr]; for (unsigned int mesh_idx : mesh_order) { - SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + auto& mesh = *storage.meshes[mesh_idx]; // if this mesh has layer data for this layer process it if (! done_this_layer && mesh.layers.size() > layer_nr) { @@ -371,9 +372,9 @@ void FffGcodeWriter::setConfigRetractionAndWipe(SliceDataStorage& storage) ExtruderTrain& train = scene.extruders[extruder_index]; retractionAndWipeConfigFromSettings(train.settings, &storage.retraction_wipe_config_per_extruder[extruder_index]); } - for (SliceMeshStorage& mesh : storage.meshes) + for (auto& mesh : storage.meshes) { - retractionAndWipeConfigFromSettings(mesh.settings, &mesh.retraction_wipe_config); + retractionAndWipeConfigFromSettings(mesh->settings, &mesh->retraction_wipe_config); } } @@ -505,9 +506,9 @@ void FffGcodeWriter::setSupportAngles(SliceDataStorage& storage) } else { - for (const SliceMeshStorage& mesh : storage.meshes) + for (const auto& mesh : storage.meshes) { - if (mesh.settings.get(interface_height_setting) + if (mesh->settings.get(interface_height_setting) >= 2 * Application::getInstance().current_slice->scene.current_mesh_group->settings.get("layer_height")) { // Some roofs are quite thick. @@ -913,10 +914,11 @@ LayerPlan& FffGcodeWriter::processLayer(const SliceDataStorage& storage, LayerIn } else { - z = storage.meshes[0].layers[layer_nr].printZ; // stub default + z = storage.meshes[0]->layers[layer_nr].printZ; // stub default // find printZ of first actual printed mesh - for (const SliceMeshStorage& mesh : storage.meshes) + for (const auto& mesh_ptr : storage.meshes) { + const auto& mesh = *mesh_ptr; if (layer_nr >= static_cast(mesh.layers.size()) || mesh.settings.get("support_mesh") || mesh.settings.get("anti_overhang_mesh") || mesh.settings.get("cutting_mesh") || mesh.settings.get("infill_mesh")) { @@ -951,8 +953,9 @@ LayerPlan& FffGcodeWriter::processLayer(const SliceDataStorage& storage, LayerIn } coord_t max_inner_wall_width = 0; - for (const SliceMeshStorage& mesh : storage.meshes) + for (const auto& mesh_ptr : storage.meshes) { + const auto& mesh = *mesh_ptr; coord_t mesh_inner_wall_width = mesh.settings.get((mesh.settings.get("wall_line_count") > 1) ? "wall_line_width_x" : "wall_line_width_0"); if (layer_nr == 0) { @@ -1022,14 +1025,14 @@ LayerPlan& FffGcodeWriter::processLayer(const SliceDataStorage& storage, LayerIn const std::vector& mesh_order = mesh_order_per_extruder[extruder_nr]; for (size_t mesh_idx : mesh_order) { - const SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + const auto& mesh = storage.meshes[mesh_idx]; const MeshPathConfigs& mesh_config = gcode_layer.configs_storage.mesh_configs[mesh_idx]; - if (mesh.settings.get("magic_mesh_surface_mode") == ESurfaceMode::SURFACE + if (mesh->settings.get("magic_mesh_surface_mode") == ESurfaceMode::SURFACE && extruder_nr - == mesh.settings.get("wall_0_extruder_nr").extruder_nr // mesh surface mode should always only be printed with the outer wall extruder! + == mesh->settings.get("wall_0_extruder_nr").extruder_nr // mesh surface mode should always only be printed with the outer wall extruder! ) { - addMeshLayerToGCode_meshSurfaceMode(storage, mesh, mesh_config, gcode_layer); + addMeshLayerToGCode_meshSurfaceMode(storage, *mesh, mesh_config, gcode_layer); } else { @@ -1382,7 +1385,7 @@ std::vector FffGcodeWriter::calculateMeshOrder(const SliceDataStorage& s std::vector::iterator mesh_group = Application::getInstance().current_slice->scene.current_mesh_group; for (unsigned int mesh_idx = 0; mesh_idx < storage.meshes.size(); mesh_idx++) { - const SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + const auto& mesh = *storage.meshes[mesh_idx]; if (mesh.getExtruderIsUsed(extruder_nr)) { const Mesh& mesh_data = mesh_group->meshes[mesh_idx]; @@ -1449,11 +1452,12 @@ void FffGcodeWriter::addMeshOpenPolyLinesToGCode(const SliceMeshStorage& mesh, c void FffGcodeWriter::addMeshLayerToGCode( const SliceDataStorage& storage, - const SliceMeshStorage& mesh, + const std::shared_ptr& mesh_ptr, const size_t extruder_nr, const MeshPathConfigs& mesh_config, LayerPlan& gcode_layer) const { + const auto& mesh = *mesh_ptr; if (gcode_layer.getLayerNr() > mesh.layer_nr_max_filled_layer) { return; @@ -1471,7 +1475,7 @@ void FffGcodeWriter::addMeshLayerToGCode( return; } - gcode_layer.setMesh(std::make_shared(mesh)); + gcode_layer.setMesh(mesh_ptr); ZSeamConfig z_seam_config; if (mesh.isPrinted()) //"normal" meshes with walls, skin, infill, etc. get the traditional part ordering based on the z-seam settings. @@ -2259,8 +2263,9 @@ bool FffGcodeWriter::processInsets( Polygons outlines_below; AABB boundaryBox(part.outline); - for (const SliceMeshStorage& m : storage.meshes) + for (const auto& mesh_ptr : storage.meshes) { + const auto& m = *mesh_ptr; if (m.isPrinted()) { for (const SliceLayerPart& prevLayerPart : m.layers[gcode_layer.getLayerNr() - 1].parts) diff --git a/src/FffPolygonGenerator.cpp b/src/FffPolygonGenerator.cpp index 03c83c0627..942345ccc1 100644 --- a/src/FffPolygonGenerator.cpp +++ b/src/FffPolygonGenerator.cpp @@ -275,8 +275,8 @@ bool FffPolygonGenerator::sliceModel(MeshGroup* meshgroup, TimeKeeper& timeKeepe Mesh& mesh = scene.current_mesh_group->meshes[meshIdx]; // always make a new SliceMeshStorage, so that they have the same ordering / indexing as meshgroup.meshes - storage.meshes.emplace_back(&meshgroup->meshes[meshIdx], slicer->layers.size()); // new mesh in storage had settings from the Mesh - SliceMeshStorage& meshStorage = storage.meshes.back(); + storage.meshes.push_back(std::make_shared(& meshgroup->meshes[meshIdx], slicer->layers.size())); // new mesh in storage had settings from the Mesh + auto& meshStorage = *storage.meshes.back(); // only create layer parts for normal meshes const bool is_support_modifier = AreaSupport::handleSupportModifierMesh(storage, mesh.settings, slicer); @@ -347,8 +347,9 @@ void FffPolygonGenerator::slices2polygons(SliceDataStorage& storage, TimeKeeper& // compute layer count and remove first empty layers // there is no separate progress stage for removeEmptyFisrtLayer (TODO) unsigned int slice_layer_count = 0; - for (SliceMeshStorage& mesh : storage.meshes) + for (auto& mesh_ptr : storage.meshes) { + auto& mesh = *mesh_ptr; if (! mesh.settings.get("infill_mesh") && ! mesh.settings.get("anti_overhang_mesh")) { slice_layer_count = std::max(slice_layer_count, mesh.layers.size()); @@ -369,7 +370,7 @@ void FffPolygonGenerator::slices2polygons(SliceDataStorage& storage, TimeKeeper& std::multimap order_to_mesh_indices; for (size_t mesh_idx = 0; mesh_idx < storage.meshes.size(); mesh_idx++) { - order_to_mesh_indices.emplace(storage.meshes[mesh_idx].settings.get("infill_mesh_order"), mesh_idx); + order_to_mesh_indices.emplace(storage.meshes[mesh_idx]->settings.get("infill_mesh_order"), mesh_idx); } for (std::pair& order_and_mesh_idx : order_to_mesh_indices) { @@ -432,9 +433,9 @@ void FffPolygonGenerator::slices2polygons(SliceDataStorage& storage, TimeKeeper& spdlog::debug("Meshes post-processing"); // meshes post processing - for (SliceMeshStorage& mesh : storage.meshes) + for (auto& mesh : storage.meshes) { - processDerivedWallsSkinInfill(mesh); + processDerivedWallsSkinInfill(*mesh); } spdlog::debug("Processing gradual support"); @@ -449,7 +450,7 @@ void FffPolygonGenerator::processBasicWallsSkinInfill( ProgressStageEstimator& inset_skin_progress_estimate) { size_t mesh_idx = mesh_order[mesh_order_idx]; - SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + SliceMeshStorage& mesh = *storage.meshes[mesh_idx]; size_t mesh_layer_count = mesh.layers.size(); if (mesh.settings.get("infill_mesh")) { @@ -513,7 +514,7 @@ void FffPolygonGenerator::processBasicWallsSkinInfill( for (size_t other_mesh_order_idx = mesh_order_idx + 1; other_mesh_order_idx < mesh_order.size(); ++other_mesh_order_idx) { const size_t other_mesh_idx = mesh_order[other_mesh_order_idx]; - SliceMeshStorage& other_mesh = storage.meshes[other_mesh_idx]; + SliceMeshStorage& other_mesh = *storage.meshes[other_mesh_idx]; if (other_mesh.settings.get("infill_mesh")) { AABB3D aabb = scene.current_mesh_group->meshes[mesh_idx].getAABB(); @@ -553,7 +554,7 @@ void FffPolygonGenerator::processBasicWallsSkinInfill( void FffPolygonGenerator::processInfillMesh(SliceDataStorage& storage, const size_t mesh_order_idx, const std::vector& mesh_order) { size_t mesh_idx = mesh_order[mesh_order_idx]; - SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + SliceMeshStorage& mesh = *storage.meshes[mesh_idx]; coord_t surface_line_width = mesh.settings.get("wall_line_width_0"); mesh.layer_nr_max_filled_layer = -1; @@ -585,7 +586,7 @@ void FffPolygonGenerator::processInfillMesh(SliceDataStorage& storage, const siz { break; // all previous meshes have been processed } - SliceMeshStorage& other_mesh = storage.meshes[other_mesh_idx]; + SliceMeshStorage& other_mesh = *storage.meshes[other_mesh_idx]; if (layer_idx >= static_cast(other_mesh.layers.size())) { // there can be no interaction between the infill mesh and this other non-infill mesh continue; @@ -741,8 +742,9 @@ bool FffPolygonGenerator::isEmptyLayer(SliceDataStorage& storage, const LayerInd return false; } } - for (SliceMeshStorage& mesh : storage.meshes) + for (auto& mesh_ptr : storage.meshes) { + auto& mesh = *mesh_ptr; if (layer_idx >= mesh.layers.size()) { continue; @@ -782,8 +784,9 @@ void FffPolygonGenerator::removeEmptyFirstLayers(SliceDataStorage& storage, size { spdlog::info("Removing {} layers because they are empty", n_empty_first_layers); const coord_t layer_height = Application::getInstance().current_slice->scene.current_mesh_group->settings.get("layer_height"); - for (SliceMeshStorage& mesh : storage.meshes) + for (auto& mesh_ptr : storage.meshes) { + auto& mesh = *mesh_ptr; std::vector& layers = mesh.layers; if (layers.size() > n_empty_first_layers) { @@ -852,8 +855,9 @@ void FffPolygonGenerator::computePrintHeightStatistics(SliceDataStorage& storage max_print_height_per_extruder.resize(extruder_count, -(raft_layers + 1)); // Initialize all as -1 (or lower in case of raft). { // compute max_object_height_per_extruder // Height of the meshes themselves. - for (SliceMeshStorage& mesh : storage.meshes) + for (auto& mesh_ptr : storage.meshes) { + auto& mesh = *mesh_ptr; if (mesh.settings.get("anti_overhang_mesh") || mesh.settings.get("support_mesh")) { continue; // Special type of mesh that doesn't get printed. diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 600869daac..b7d24b1b11 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -159,8 +159,9 @@ Polygons LayerPlan::computeCombBoundary(const CombBoundary boundary_type) } else { - for (const SliceMeshStorage& mesh : storage.meshes) + for (const auto& mesh_ptr : storage.meshes) { + const auto& mesh = *mesh_ptr; const SliceLayer& layer = mesh.layers[static_cast(layer_nr)]; // don't process infill_mesh or anti_overhang_mesh if (mesh.settings.get("infill_mesh") || mesh.settings.get("anti_overhang_mesh")) @@ -282,7 +283,7 @@ bool LayerPlan::setExtruder(const size_t extruder_nr) } return true; } -void LayerPlan::setMesh(const std::shared_ptr& mesh) +void LayerPlan::setMesh(const std::shared_ptr& mesh) { current_mesh = mesh; } @@ -1187,9 +1188,9 @@ void LayerPlan::addLinesByOptimizer( if (layer_nr >= 0) { // determine how much the skin/infill lines overlap the combing boundary - for (const SliceMeshStorage& mesh : storage.meshes) + for (const auto& mesh : storage.meshes) { - const coord_t overlap = std::max(mesh.settings.get("skin_overlap_mm"), mesh.settings.get("infill_overlap_mm")); + const coord_t overlap = std::max(mesh->settings.get("skin_overlap_mm"), mesh->settings.get("infill_overlap_mm")); if (overlap > dist) { dist = overlap; @@ -1846,7 +1847,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) const bool acceleration_travel_enabled = mesh_group_settings.get("acceleration_travel_enabled"); const bool jerk_enabled = mesh_group_settings.get("jerk_enabled"); const bool jerk_travel_enabled = mesh_group_settings.get("jerk_travel_enabled"); - std::shared_ptr current_mesh; + std::shared_ptr current_mesh; for (size_t extruder_plan_idx = 0; extruder_plan_idx < extruder_plans.size(); extruder_plan_idx++) { diff --git a/src/TreeModelVolumes.cpp b/src/TreeModelVolumes.cpp index fef53433e7..6ddcef2c93 100644 --- a/src/TreeModelVolumes.cpp +++ b/src/TreeModelVolumes.cpp @@ -49,8 +49,9 @@ TreeModelVolumes::TreeModelVolumes( coord_t min_maximum_area_deviation = std::numeric_limits::max(); support_rests_on_model = false; - for (auto [mesh_idx, mesh] : storage.meshes | ranges::views::enumerate) + for (auto [mesh_idx, mesh_ptr] : storage.meshes | ranges::views::enumerate) { + auto& mesh = *mesh_ptr; bool added = false; for (auto [idx, layer_outline] : layer_outlines_ | ranges::views::enumerate) { @@ -103,7 +104,7 @@ TreeModelVolumes::TreeModelVolumes( { // Workaround for compiler bug on apple-clang -- Closure won't properly capture variables in capture lists in outer scope. const auto& mesh_idx_l = mesh_idx; - const auto& mesh_l = mesh; + const auto& mesh_l = *mesh; // ^^^ Remove when fixed (and rename accordingly in the below parallel-for). cura::parallel_for( diff --git a/src/TreeSupport.cpp b/src/TreeSupport.cpp index 5c7585cfbb..d9e56458c4 100644 --- a/src/TreeSupport.cpp +++ b/src/TreeSupport.cpp @@ -38,8 +38,9 @@ TreeSupport::TreeSupport(const SliceDataStorage& storage) { size_t largest_printed_mesh_idx = 0; - for (const SliceMeshStorage& mesh : storage.meshes) + for (const auto& mesh_ptr : storage.meshes) { + const auto& mesh = *mesh_ptr; TreeSupportSettings::some_model_contains_thick_roof |= mesh.settings.get("support_roof_height") >= 2 * mesh.settings.get("layer_height"); TreeSupportSettings::has_to_rely_on_min_xy_dist_only |= @@ -48,8 +49,9 @@ TreeSupport::TreeSupport(const SliceDataStorage& storage) // Group all meshes that can be processed together. NOTE this is different from mesh-groups! // Only one setting object is needed per group, as different settings in the same group may only occur in the tip, which uses the original settings objects from the meshes. - for (auto [mesh_idx, mesh] : storage.meshes | ranges::views::enumerate) + for (auto [mesh_idx, mesh_ptr] : storage.meshes | ranges::views::enumerate) { + auto& mesh = *mesh_ptr; const bool non_supportable_mesh = mesh.settings.get("infill_mesh") || mesh.settings.get("anti_overhang_mesh") || mesh.settings.get("support_mesh"); if (mesh.settings.get("support_structure") != ESupportStructure::TREE || ! mesh.settings.get("support_enable") || non_supportable_mesh) { @@ -76,14 +78,14 @@ TreeSupport::TreeSupport(const SliceDataStorage& storage) } // no need to do this per mesh group as adaptive layers and raft setting are not setable per mesh. - if (storage.meshes[largest_printed_mesh_idx].layers.back().printZ < mesh.layers.back().printZ) + if (storage.meshes[largest_printed_mesh_idx]->layers.back().printZ < mesh.layers.back().printZ) { largest_printed_mesh_idx = mesh_idx; } } - std::vector known_z(storage.meshes[largest_printed_mesh_idx].layers.size()); + std::vector known_z(storage.meshes[largest_printed_mesh_idx]->layers.size()); - for (auto [z, layer] : ranges::views::enumerate(storage.meshes[largest_printed_mesh_idx].layers)) + for (auto [z, layer] : ranges::views::enumerate(storage.meshes[largest_printed_mesh_idx]->layers)) { known_z[z] = layer.printZ; } @@ -152,7 +154,7 @@ void TreeSupport::generateSupportAreas(SliceDataStorage& storage) // ### Place tips of the support tree for (size_t mesh_idx : processing.second) { - generateInitialAreas(storage.meshes[mesh_idx], move_bounds, storage); + generateInitialAreas(*storage.meshes[mesh_idx], move_bounds, storage); } const auto t_gen = std::chrono::high_resolution_clock::now(); @@ -206,7 +208,7 @@ void TreeSupport::precalculate(const SliceDataStorage& storage, std::vector("layer_height"); const coord_t z_distance_top = mesh.settings.get("support_top_distance"); const size_t z_distance_top_layers = round_up_divide(z_distance_top, diff --git a/src/bridge.cpp b/src/bridge.cpp index f6f4b41f04..a395f7bd79 100644 --- a/src/bridge.cpp +++ b/src/bridge.cpp @@ -24,8 +24,9 @@ int bridgeAngle(const Settings& settings, const Polygons& skin_outline, const Sl const Ratio sparse_infill_max_density = settings.get("bridge_sparse_infill_max_density"); // include parts from all meshes - for (const SliceMeshStorage& mesh : storage.meshes) + for (const auto& mesh_ptr : storage.meshes) { + const auto& mesh = *mesh_ptr; if (mesh.isPrinted()) { const coord_t infill_line_distance = mesh.settings.get("infill_line_distance"); diff --git a/src/plugins/converters.cpp b/src/plugins/converters.cpp index 33e7d4882e..88a716e47a 100644 --- a/src/plugins/converters.cpp +++ b/src/plugins/converters.cpp @@ -430,7 +430,7 @@ gcode_paths_modify_response::native_value_type gcode_paths_modify_response::operator()(gcode_paths_modify_response::native_value_type& original_value, const gcode_paths_modify_response::value_type& message) const { std::vector paths; - using map_t = std::unordered_map>; + using map_t = std::unordered_map>; auto meshes = original_value | ranges::views::filter( [](const auto& path) diff --git a/src/settings/PathConfigStorage.cpp b/src/settings/PathConfigStorage.cpp index 2f9dd2acea..467b130f5c 100644 --- a/src/settings/PathConfigStorage.cpp +++ b/src/settings/PathConfigStorage.cpp @@ -124,9 +124,9 @@ PathConfigStorage::PathConfigStorage(const SliceDataStorage& storage, const Laye } mesh_configs.reserve(storage.meshes.size()); - for (const SliceMeshStorage& mesh_storage : storage.meshes) + for (const auto& mesh_storage : storage.meshes) { - mesh_configs.emplace_back(mesh_storage, layer_thickness, layer_nr, line_width_factor_per_extruder); + mesh_configs.emplace_back(*mesh_storage, layer_thickness, layer_nr, line_width_factor_per_extruder); } support_infill_config.reserve(MAX_INFILL_COMBINE); @@ -224,7 +224,7 @@ void PathConfigStorage::handleInitialLayerSpeedup(const SliceDataStorage& storag { // meshes for (size_t mesh_idx = 0; mesh_idx < storage.meshes.size(); mesh_idx++) { - const SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + const SliceMeshStorage& mesh = *storage.meshes[mesh_idx]; const SpeedDerivatives initial_layer_speed_config{ .speed = mesh.settings.get("speed_print_layer_0"), .acceleration = mesh.settings.get("acceleration_print_layer_0"), diff --git a/src/sliceDataStorage.cpp b/src/sliceDataStorage.cpp index 788ac2e45a..c890783f8c 100644 --- a/src/sliceDataStorage.cpp +++ b/src/sliceDataStorage.cpp @@ -300,16 +300,16 @@ Polygons Polygons total; if (layer_nr >= 0) { - for (const SliceMeshStorage& mesh : meshes) + for (const auto& mesh : meshes) { - if (mesh.settings.get("infill_mesh") || mesh.settings.get("anti_overhang_mesh") - || (extruder_nr != -1 && extruder_nr != int(mesh.settings.get("wall_0_extruder_nr").extruder_nr))) + if (mesh->settings.get("infill_mesh") || mesh->settings.get("anti_overhang_mesh") + || (extruder_nr != -1 && extruder_nr != int(mesh->settings.get("wall_0_extruder_nr").extruder_nr))) { continue; } - const SliceLayer& layer = mesh.layers[layer_nr]; + const SliceLayer& layer = mesh->layers[layer_nr]; layer.getOutlines(total, external_polys_only); - if (mesh.settings.get("magic_mesh_surface_mode") != ESurfaceMode::NORMAL) + if (mesh->settings.get("magic_mesh_surface_mode") != ESurfaceMode::NORMAL) { total = total.unionPolygons(layer.openPolyLines.offsetPolyLine(MM2INT(0.1))); } @@ -381,9 +381,9 @@ std::vector SliceDataStorage::getExtrudersUsed() const // support // support is presupposed to be present... - for (const SliceMeshStorage& mesh : meshes) + for (const auto& mesh : meshes) { - if (mesh.settings.get("support_enable") || mesh.settings.get("support_mesh")) + if (mesh->settings.get("support_enable") || mesh->settings.get("support_mesh")) { ret[mesh_group_settings.get("support_extruder_nr_layer_0").extruder_nr] = true; ret[mesh_group_settings.get("support_infill_extruder_nr").extruder_nr] = true; @@ -399,11 +399,11 @@ std::vector SliceDataStorage::getExtrudersUsed() const } // all meshes are presupposed to actually have content - for (const SliceMeshStorage& mesh : meshes) + for (const auto& mesh : meshes) { for (unsigned int extruder_nr = 0; extruder_nr < ret.size(); extruder_nr++) { - ret[extruder_nr] = ret[extruder_nr] || mesh.getExtruderIsUsed(extruder_nr); + ret[extruder_nr] = ret[extruder_nr] || mesh->getExtruderIsUsed(extruder_nr); } } return ret; @@ -508,11 +508,11 @@ std::vector SliceDataStorage::getExtrudersUsed(const LayerIndex layer_nr) if (include_models) { - for (const SliceMeshStorage& mesh : meshes) + for (const auto& mesh : meshes) { for (unsigned int extruder_nr = 0; extruder_nr < ret.size(); extruder_nr++) { - ret[extruder_nr] = ret[extruder_nr] || mesh.getExtruderIsUsed(extruder_nr, layer_nr); + ret[extruder_nr] = ret[extruder_nr] || mesh->getExtruderIsUsed(extruder_nr, layer_nr); } } } diff --git a/src/support.cpp b/src/support.cpp index 1adb0b1ae7..a55d21b53f 100644 --- a/src/support.cpp +++ b/src/support.cpp @@ -599,8 +599,9 @@ Polygons AreaSupport::join(const SliceDataStorage& storage, const Polygons& supp void AreaSupport::generateOverhangAreas(SliceDataStorage& storage) { - for (SliceMeshStorage& mesh : storage.meshes) + for (auto& mesh_ptr : storage.meshes) { + auto& mesh = *mesh_ptr; if (mesh.settings.get("infill_mesh") || mesh.settings.get("anti_overhang_mesh")) { continue; @@ -645,14 +646,14 @@ void AreaSupport::generateSupportAreas(SliceDataStorage& storage) const Settings& mesh_group_settings = Application::getInstance().current_slice->scene.current_mesh_group->settings; for (unsigned int mesh_idx = 0; mesh_idx < storage.meshes.size(); mesh_idx++) { - SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + SliceMeshStorage& mesh = *storage.meshes[mesh_idx]; if (mesh.settings.get("infill_mesh") || mesh.settings.get("anti_overhang_mesh")) { continue; } - Settings* infill_settings = &storage.meshes[mesh_idx].settings; - Settings* roof_settings = &storage.meshes[mesh_idx].settings; - Settings* bottom_settings = &storage.meshes[mesh_idx].settings; + Settings* infill_settings = &storage.meshes[mesh_idx]->settings; + Settings* roof_settings = &storage.meshes[mesh_idx]->settings; + Settings* bottom_settings = &storage.meshes[mesh_idx]->settings; if (mesh.settings.get("support_mesh")) { if ((mesh.settings.get("support_mesh_drop_down") && support_meshes_drop_down_handled) @@ -694,7 +695,7 @@ void AreaSupport::generateSupportAreas(SliceDataStorage& storage) // handle support interface for (unsigned int mesh_idx = 0; mesh_idx < storage.meshes.size(); mesh_idx++) { - SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + SliceMeshStorage& mesh = *storage.meshes[mesh_idx]; if (mesh.settings.get("infill_mesh") || mesh.settings.get("anti_overhang_mesh")) { continue; @@ -725,12 +726,12 @@ void AreaSupport::precomputeCrossInfillTree(SliceDataStorage& storage) AABB3D aabb; for (unsigned int mesh_idx = 0; mesh_idx < storage.meshes.size(); mesh_idx++) { - const SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + const SliceMeshStorage& mesh = *storage.meshes[mesh_idx]; if (mesh.settings.get("infill_mesh") || mesh.settings.get("anti_overhang_mesh")) { continue; } - Settings& infill_settings = storage.meshes[mesh_idx].settings; + Settings& infill_settings = storage.meshes[mesh_idx]->settings; if (mesh.settings.get("support_mesh")) { // use extruder train settings rather than the per-object settings of the first support mesh encountered. @@ -1039,7 +1040,7 @@ void AreaSupport::generateSupportAreasForMesh( const size_t layer_count, std::vector& support_areas) { - SliceMeshStorage& mesh = storage.meshes[mesh_idx]; + SliceMeshStorage& mesh = *storage.meshes[mesh_idx]; const ESupportStructure support_structure = mesh.settings.get("support_structure"); const bool is_support_mesh_place_holder