Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CURA-11019] fix slowdown better solution #1951

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions include/FffGcodeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,17 @@ 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<SliceMeshStorage>& mesh_ptr,
const size_t extruder_nr,
const MeshPathConfigs& mesh_config,
LayerPlan& gcode_layer) const;
rburema marked this conversation as resolved.
Show resolved Hide resolved

/*!
* 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.
Expand Down
4 changes: 2 additions & 2 deletions include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LayerPlan : public NoCopy
std::vector<bool> has_prime_tower_planned_per_extruder; //!< For each extruder, whether the prime tower is planned yet or not.
std::optional<Point> last_planned_position; //!< The last planned XY position of the print head (if known)

std::shared_ptr<SliceMeshStorage> current_mesh; //!< The mesh of the last planned move.
std::shared_ptr<const SliceMeshStorage> current_mesh; //!< The mesh of the last planned move.
rburema marked this conversation as resolved.
Show resolved Hide resolved

/*!
* Whether the skirt or brim polygons have been processed into planned paths
Expand Down Expand Up @@ -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<SliceMeshStorage>& mesh);
void setMesh(const std::shared_ptr<const SliceMeshStorage>& mesh);

/*!
* Set bridge_wall_mask.
Expand Down
44 changes: 28 additions & 16 deletions include/SkeletalTrapezoidationEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
#ifndef SKELETAL_TRAPEZOIDATION_EDGE_H
#define SKELETAL_TRAPEZOIDATION_EDGE_H

#include <memory> // smart pointers
#include "utils/ExtrusionJunction.h"

#include <list>
#include <memory> // smart pointers
#include <vector>

#include "utils/ExtrusionJunction.h"

namespace cura
{

class SkeletalTrapezoidationEdge
{
private:
enum class Central : int { UNKNOWN = -1, NO = 0, YES = 1};
enum class Central : int
{
UNKNOWN = -1,
NO = 0,
YES = 1
};

public:
/*!
Expand All @@ -28,9 +33,11 @@ class SkeletalTrapezoidationEdge
int lower_bead_count;
coord_t feature_radius; // The feature radius at which this transition is placed
TransitionMiddle(coord_t pos, int lower_bead_count, coord_t feature_radius)
: pos(pos), lower_bead_count(lower_bead_count)
: pos(pos)
, lower_bead_count(lower_bead_count)
, feature_radius(feature_radius)
{}
{
}
};

/*!
Expand All @@ -42,8 +49,11 @@ class SkeletalTrapezoidationEdge
int lower_bead_count;
bool is_lower_end; // Whether this is the ed of the transition with lower bead count
TransitionEnd(coord_t pos, int lower_bead_count, bool is_lower_end)
: pos(pos), lower_bead_count(lower_bead_count), is_lower_end(is_lower_end)
{}
: pos(pos)
, lower_bead_count(lower_bead_count)
, is_lower_end(is_lower_end)
{
}
};

enum class EdgeType : int
Expand All @@ -55,12 +65,14 @@ class SkeletalTrapezoidationEdge
EdgeType type;

SkeletalTrapezoidationEdge()
: SkeletalTrapezoidationEdge(EdgeType::NORMAL)
{}
: SkeletalTrapezoidationEdge(EdgeType::NORMAL)
{
}
SkeletalTrapezoidationEdge(const EdgeType& type)
: type(type)
, is_central(Central::UNKNOWN)
{}
: type(type)
, is_central(Central::UNKNOWN)
{
}

bool isCentral() const
{
Expand All @@ -80,7 +92,7 @@ class SkeletalTrapezoidationEdge
{
return transitions.use_count() > 0 && (ignore_empty || ! transitions.lock()->empty());
}
void setTransitions(std::shared_ptr<std::list<TransitionMiddle>> storage)
void setTransitions(std::shared_ptr<std::list<TransitionMiddle>>& storage)
{
transitions = storage;
}
Expand All @@ -93,7 +105,7 @@ class SkeletalTrapezoidationEdge
{
return transition_ends.use_count() > 0 && (ignore_empty || ! transition_ends.lock()->empty());
}
void setTransitionEnds(std::shared_ptr<std::list<TransitionEnd>> storage)
void setTransitionEnds(std::shared_ptr<std::list<TransitionEnd>>& storage)
{
transition_ends = storage;
}
Expand All @@ -106,7 +118,7 @@ class SkeletalTrapezoidationEdge
{
return extrusion_junctions.use_count() > 0 && (ignore_empty || ! extrusion_junctions.lock()->empty());
}
void setExtrusionJunctions(std::shared_ptr<LineJunctions> storage)
void setExtrusionJunctions(std::shared_ptr<LineJunctions>& storage)
{
extrusion_junctions = storage;
}
Expand Down
27 changes: 15 additions & 12 deletions include/SkeletalTrapezoidationJoint.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
//Copyright (c) 2020 Ultimaker B.V.
//CuraEngine is released under the terms of the AGPLv3 or higher.
// Copyright (c) 2020 Ultimaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef SKELETAL_TRAPEZOIDATION_JOINT_H
#define SKELETAL_TRAPEZOIDATION_JOINT_H

#include <memory> // smart pointers

#include "BeadingStrategy/BeadingStrategy.h"
#include "utils/IntPoint.h"

#include <memory> // smart pointers

namespace cura
{

class SkeletalTrapezoidationJoint
{
using Beading = BeadingStrategy::Beading;

public:
struct BeadingPropagation
{
Expand All @@ -27,23 +28,26 @@ class SkeletalTrapezoidationJoint
, dist_to_bottom_source(0)
, dist_from_top_source(0)
, is_upward_propagated_only(false)
{}
{
}
};

coord_t distance_to_boundary;
coord_t bead_count;
float transition_ratio; //! The distance near the skeleton to leave free because this joint is in the middle of a transition, as a fraction of the inner bead width of the bead at the higher transition.
float transition_ratio; //! The distance near the skeleton to leave free because this joint is in the middle of a transition, as a fraction of the inner bead width of the bead
//! at the higher transition.
SkeletalTrapezoidationJoint()
: distance_to_boundary(-1)
, bead_count(-1)
, transition_ratio(0)
{}
: distance_to_boundary(-1)
, bead_count(-1)
, transition_ratio(0)
{
}

bool hasBeading() const
{
return beading.use_count() > 0;
}
void setBeading(std::shared_ptr<BeadingPropagation> storage)
void setBeading(std::shared_ptr<BeadingPropagation>& storage)
{
beading = storage;
}
Expand All @@ -53,7 +57,6 @@ class SkeletalTrapezoidationJoint
}

private:

std::weak_ptr<BeadingPropagation> beading;
};

Expand Down
10 changes: 5 additions & 5 deletions include/infill.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ class Infill
const Settings& settings,
int layer_idx,
SectionType section_type,
const std::shared_ptr<SierpinskiFillProvider> cross_fill_provider = nullptr,
const std::shared_ptr<LightningLayer> lightning_layer = nullptr,
const std::shared_ptr<SierpinskiFillProvider>& cross_fill_provider = nullptr,
const std::shared_ptr<LightningLayer>& lightning_layer = nullptr,
const SliceMeshStorage* mesh = nullptr,
const Polygons& prevent_small_exposed_to_air = Polygons(),
const bool is_bridge_skin = false);
Expand Down Expand Up @@ -242,8 +242,8 @@ class Infill
Polygons& result_polygons,
Polygons& result_lines,
const Settings& settings,
const std::shared_ptr<SierpinskiFillProvider> cross_fill_pattern = nullptr,
const std::shared_ptr<LightningLayer> lightning_layer = nullptr,
const std::shared_ptr<SierpinskiFillProvider>& cross_fill_pattern = nullptr,
const std::shared_ptr<LightningLayer>& lightning_layer = nullptr,
const SliceMeshStorage* mesh = nullptr);

/*!
Expand Down Expand Up @@ -402,7 +402,7 @@ class Infill
* see https://hal.archives-ouvertes.fr/hal-02155929/document
* \param result (output) The resulting polygons
*/
void generateLightningInfill(const std::shared_ptr<LightningLayer> lightning_layer, Polygons& result_lines);
void generateLightningInfill(const std::shared_ptr<LightningLayer>& lightning_layer, Polygons& result_lines);

/*!
* Generate sparse concentric infill
Expand Down
2 changes: 1 addition & 1 deletion include/pathPlanning/GCodePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace cura
struct GCodePath
{
GCodePathConfig config{}; //!< The configuration settings of the path.
std::shared_ptr<SliceMeshStorage> 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<const SliceMeshStorage> 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.
Expand Down
2 changes: 1 addition & 1 deletion include/sliceDataStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SliceMeshStorage> meshes;
std::vector<std::shared_ptr<SliceMeshStorage>> meshes;

std::vector<RetractionAndWipeConfig> retraction_wipe_config_per_extruder; //!< Config for retractions, extruder switch retractions, and wipes, per extruder.

Expand Down
39 changes: 22 additions & 17 deletions src/FffGcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ void FffGcodeWriter::writeGCode(SliceDataStorage& storage, TimeKeeper& time_keep
}

size_t total_layers = 0;
for (SliceMeshStorage& mesh : storage.meshes)
for (std::shared_ptr<SliceMeshStorage>& mesh_ptr : storage.meshes)
{
auto& mesh = *mesh_ptr;
size_t mesh_layer_num = mesh.layers.size();

// calculation of _actual_ number of layers in loop.
Expand Down Expand Up @@ -269,7 +270,7 @@ void FffGcodeWriter::findLayerSeamsForSpiralize(SliceDataStorage& storage, size_
const std::vector<size_t>& mesh_order = mesh_order_per_extruder[extruder_nr];
for (unsigned int mesh_idx : mesh_order)
{
SliceMeshStorage& mesh = storage.meshes[mesh_idx];
SliceMeshStorage& 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)
{
Expand Down Expand Up @@ -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 (std::shared_ptr<SliceMeshStorage>& mesh : storage.meshes)
{
retractionAndWipeConfigFromSettings(mesh.settings, &mesh.retraction_wipe_config);
retractionAndWipeConfigFromSettings(mesh->settings, &mesh->retraction_wipe_config);
}
}

Expand Down Expand Up @@ -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<coord_t>(interface_height_setting)
if (mesh->settings.get<coord_t>(interface_height_setting)
>= 2 * Application::getInstance().current_slice->scene.current_mesh_group->settings.get<coord_t>("layer_height"))
{
// Some roofs are quite thick.
Expand Down Expand Up @@ -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 std::shared_ptr<SliceMeshStorage>& mesh_ptr : storage.meshes)
{
const auto& mesh = *mesh_ptr;
if (layer_nr >= static_cast<int>(mesh.layers.size()) || mesh.settings.get<bool>("support_mesh") || mesh.settings.get<bool>("anti_overhang_mesh")
|| mesh.settings.get<bool>("cutting_mesh") || mesh.settings.get<bool>("infill_mesh"))
{
Expand Down Expand Up @@ -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 std::shared_ptr<SliceMeshStorage>& mesh_ptr : storage.meshes)
{
const auto& mesh = *mesh_ptr;
coord_t mesh_inner_wall_width = mesh.settings.get<coord_t>((mesh.settings.get<size_t>("wall_line_count") > 1) ? "wall_line_width_x" : "wall_line_width_0");
if (layer_nr == 0)
{
Expand Down Expand Up @@ -1022,14 +1025,14 @@ LayerPlan& FffGcodeWriter::processLayer(const SliceDataStorage& storage, LayerIn
const std::vector<size_t>& mesh_order = mesh_order_per_extruder[extruder_nr];
for (size_t mesh_idx : mesh_order)
{
const SliceMeshStorage& mesh = storage.meshes[mesh_idx];
const std::shared_ptr<SliceMeshStorage>& mesh = storage.meshes[mesh_idx];
const MeshPathConfigs& mesh_config = gcode_layer.configs_storage.mesh_configs[mesh_idx];
if (mesh.settings.get<ESurfaceMode>("magic_mesh_surface_mode") == ESurfaceMode::SURFACE
if (mesh->settings.get<ESurfaceMode>("magic_mesh_surface_mode") == ESurfaceMode::SURFACE
&& extruder_nr
== mesh.settings.get<ExtruderTrain&>("wall_0_extruder_nr").extruder_nr // mesh surface mode should always only be printed with the outer wall extruder!
== mesh->settings.get<ExtruderTrain&>("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
{
Expand Down Expand Up @@ -1382,7 +1385,7 @@ std::vector<size_t> FffGcodeWriter::calculateMeshOrder(const SliceDataStorage& s
std::vector<MeshGroup>::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 SliceMeshStorage& mesh = *storage.meshes[mesh_idx];
if (mesh.getExtruderIsUsed(extruder_nr))
{
const Mesh& mesh_data = mesh_group->meshes[mesh_idx];
Expand Down Expand Up @@ -1449,11 +1452,12 @@ void FffGcodeWriter::addMeshOpenPolyLinesToGCode(const SliceMeshStorage& mesh, c

void FffGcodeWriter::addMeshLayerToGCode(
const SliceDataStorage& storage,
const SliceMeshStorage& mesh,
const std::shared_ptr<SliceMeshStorage>& 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;
Expand All @@ -1471,7 +1475,7 @@ void FffGcodeWriter::addMeshLayerToGCode(
return;
}

gcode_layer.setMesh(std::make_shared<SliceMeshStorage>(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.
Expand Down Expand Up @@ -2259,8 +2263,9 @@ bool FffGcodeWriter::processInsets(

Polygons outlines_below;
AABB boundaryBox(part.outline);
for (const SliceMeshStorage& m : storage.meshes)
for (const std::shared_ptr<SliceMeshStorage>& mesh_ptr : storage.meshes)
{
const auto& m = *mesh_ptr;
if (m.isPrinted())
{
for (const SliceLayerPart& prevLayerPart : m.layers[gcode_layer.getLayerNr() - 1].parts)
Expand Down
Loading