Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into CURA-12078_inconsiste…
Browse files Browse the repository at this point in the history
…nt-wall-speed-besides-overhang
  • Loading branch information
wawanbreton committed Oct 7, 2024
2 parents be7344e + 662f20e commit 3541f2d
Show file tree
Hide file tree
Showing 34 changed files with 892 additions and 484 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ set(engine_SRCS # Except main.cpp.
src/utils/ListPolyIt.cpp
src/utils/Matrix4x3D.cpp
src/utils/MinimumSpanningTree.cpp
src/utils/Point3LL.cpp
src/utils/PolygonConnector.cpp
src/utils/PolygonsPointIndex.cpp
src/utils/PolygonsSegmentIndex.cpp
Expand All @@ -157,6 +156,8 @@ set(engine_SRCS # Except main.cpp.
src/utils/VoxelUtils.cpp
src/utils/MixedPolylineStitcher.cpp

src/geometry/Point2LL.cpp
src/geometry/Point3LL.cpp
src/geometry/Polygon.cpp
src/geometry/Shape.cpp
src/geometry/PointsSet.cpp
Expand Down
2 changes: 1 addition & 1 deletion include/ExtruderPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class ExtruderPlan
/*!
* @return distance between p0 and p1 as well as the time spend on the segment
*/
std::pair<double, double> getPointToPointTime(const Point2LL& p0, const Point2LL& p1, const GCodePath& path);
std::pair<double, double> getPointToPointTime(const Point3LL& p0, const Point3LL& p1, const GCodePath& path);

/*!
* Compute naive time estimates (without accounting for slow down at corners etc.) and naive material estimates.
Expand Down
2 changes: 1 addition & 1 deletion include/GCodePathConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct GCodePathConfig
{
static constexpr double FAN_SPEED_DEFAULT = -1.0;

coord_t z_offset{}; //<! vertical offset from 'full' layer height
coord_t z_offset{}; //<! vertical offset from 'full' layer height, to be applied to the whole path
PrintFeatureType type{}; //!< name of the feature type
coord_t line_width{}; //!< width of the line extruded
coord_t layer_thickness{}; //!< current layer height in micron
Expand Down
6 changes: 5 additions & 1 deletion include/InsetOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class InsetOrderOptimizer
const ZSeamConfig& z_seam_config,
const std::vector<VariableWidthLines>& paths,
const Point2LL& model_center_point,
const Shape& disallowed_areas_for_seams = {});
const Shape& disallowed_areas_for_seams = {},
const bool scarf_seam = false,
const bool smooth_speed = false);

/*!
* Adds the insets to the given layer plan.
Expand Down Expand Up @@ -110,6 +112,8 @@ class InsetOrderOptimizer
const LayerIndex layer_nr_;
const Point2LL model_center_point_; // Center of the model (= all meshes) axis-aligned bounding-box.
Shape disallowed_areas_for_seams_;
const bool scarf_seam_;
const bool smooth_speed_;

std::vector<std::vector<const Polygon*>> inset_polys_; // vector of vectors holding the inset polygons
Shape retraction_region_; // After printing an outer wall, move into this region so that retractions do not leave visible blobs. Calculated lazily if needed (see
Expand Down
146 changes: 134 additions & 12 deletions include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class LayerPlan : public NoCopy
#endif

public:
// 'AdjustCoasting'; because split-up paths from the same extruder (with no travel moves between them) should count as the same path w.r.t. coasting.
enum class AdjustCoasting
{
AsNormal,
CoastEntirePath,
ContinueCoasting
};

const PathConfigStorage configs_storage_; //!< The line configs for this layer for each feature type
const coord_t z_;
coord_t final_travel_z_;
Expand Down Expand Up @@ -360,14 +368,15 @@ class LayerPlan : public NoCopy
* \param fan_speed Fan speed override for this path.
*/
void addExtrusionMove(
const Point2LL p,
const Point3LL& p,
const GCodePathConfig& config,
const SpaceFillType space_fill_type,
const Ratio& flow = 1.0_r,
const Ratio width_factor = 1.0_r,
const bool spiralize = false,
const Ratio speed_factor = 1.0_r,
const double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT);
const double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT,
const bool travel_to_z = true);

/*!
* Add polygon to the gcode starting at vertex \p startIdx
Expand Down Expand Up @@ -452,8 +461,8 @@ class LayerPlan : public NoCopy
* the first bridge segment.
*/
void addWallLine(
const Point2LL& p0,
const Point2LL& p1,
const Point3LL& p0,
const Point3LL& p1,
const Settings& settings,
const GCodePathConfig& default_config,
const GCodePathConfig& roofing_config,
Expand All @@ -462,7 +471,8 @@ class LayerPlan : public NoCopy
const Ratio width_factor,
double& non_bridge_line_volume,
Ratio speed_factor,
double distance_to_bridge_start);
double distance_to_bridge_start,
const bool travel_to_z = true);

/*!
* Add a wall to the g-code starting at vertex \p start_idx
Expand All @@ -481,7 +491,7 @@ class LayerPlan : public NoCopy
*/
void addWall(
const Polygon& wall,
int start_idx,
size_t start_idx,
const Settings& settings,
const GCodePathConfig& default_config,
const GCodePathConfig& roofing_config,
Expand Down Expand Up @@ -513,7 +523,7 @@ class LayerPlan : public NoCopy
*/
void addWall(
const ExtrusionLine& wall,
int start_idx,
size_t start_idx,
const Settings& settings,
const GCodePathConfig& default_config,
const GCodePathConfig& roofing_config,
Expand All @@ -523,7 +533,9 @@ class LayerPlan : public NoCopy
bool always_retract,
const bool is_closed,
const bool is_reversed,
const bool is_linked_path);
const bool is_linked_path,
const bool scarf_seam = false,
const bool smooth_speed = false);

/*!
* Add an infill wall to the g-code
Expand Down Expand Up @@ -676,7 +688,7 @@ class LayerPlan : public NoCopy
* \return The index of the first supported vertex - if no vertices are supported, start_idx is returned
*/
template<typename T>
unsigned locateFirstSupportedVertex(const T& wall, const unsigned start_idx) const
size_t locateFirstSupportedVertex(const T& wall, const size_t start_idx) const
{
if (bridge_wall_mask_.empty() && seam_overhang_mask_.empty())
{
Expand All @@ -685,7 +697,7 @@ class LayerPlan : public NoCopy

const auto air_below = bridge_wall_mask_.unionPolygons(seam_overhang_mask_);

unsigned curr_idx = start_idx;
size_t curr_idx = start_idx;

while (true)
{
Expand Down Expand Up @@ -736,14 +748,17 @@ class LayerPlan : public NoCopy
* \param path_idx The index into LayerPlan::paths for the next path to be
* written to GCode.
* \param layer_thickness The height of the current layer.
* \param insertTempOnTime A function that inserts temperature changes at a given time.
* \param coasting_adjust Paths can be split up, so we need to know when to continue coasting from last, or even coast the entire path.
* \return Whether any GCode has been written for the path.
*/
bool writePathWithCoasting(
GCodeExport& gcode,
const size_t extruder_plan_idx,
const size_t path_idx,
const coord_t layer_thickness,
const std::function<void(const double, const int64_t)> insertTempOnTime);
const std::function<void(const double, const int64_t)> insertTempOnTime,
const std::pair<AdjustCoasting, double> coasting_adjust);

/*!
* Applying speed corrections for minimal layer times and determine the fanSpeed.
Expand Down Expand Up @@ -821,12 +836,119 @@ class LayerPlan : public NoCopy
const Ratio flow_ratio,
const double fan_speed);

/*!
* @brief Send a GCodePath line to the communication object, applying proper Z offsets
* @param path The path to be sent
* @param position The start position (which is not included in the path points)
* @param extrude_speed The actual used extrusion speed
*/
void sendLineTo(const GCodePath& path, const Point3LL& position, const double extrude_speed);

/*!
* @brief Write a travel move and properly apply the various Z offsets
* @param gcode The actual GCode exporter
* @param position The position to move to. The Z coordinate is an offset to the current layer position
* @param speed The actual used speed
* @param path_z_offset The global path Z offset to be applied
* @note This function is to be used when dealing with 3D coordinates. If you have 2D coordinates, just call gcode.writeTravel()
*/
void writeTravelRelativeZ(GCodeExport& gcode, const Point3LL& position, const Velocity& speed, const coord_t path_z_offset);

/*!
* \brief Write an extrusion move and properly apply the various Z offsets
* \param gcode The actual GCode exporter
* \param position The position to move to. The Z coordinate is an offset to the current layer position
* \param speed The actual used speed
* \param path_z_offset The global path Z offset to be applied
* \param extrusion_mm3_per_mm The desired flow rate
* \param feature The current feature being printed
* \param update_extrusion_offset whether to update the extrusion offset to match the current flow rate
*/
void writeExtrusionRelativeZ(
GCodeExport& gcode,
const Point3LL& position,
const Velocity& speed,
const coord_t path_z_offset,
double extrusion_mm3_per_mm,
PrintFeatureType feature,
bool update_extrusion_offset = false);

/*!
* \brief Add a wall to the gcode with optimized order, but split into pieces in order to facilitate the scarf seam and/or speed gradient.
* \param wall The full wall to be added
* \param wall_length The pre-calculated full wall length
* \param start_idx The index of the point where to start printing the wall
* \param direction The direction along which to print the wall, which should be 1 or -1
* \param max_index The last index to be used when iterating over the wall segments
* \param settings The settings which should apply to this wall added to the layer plan
* \param default_config The config with which to print the wall lines that are not spanning a bridge or are exposed to air
* \param roofing_config The config with which to print the wall lines that are exposed to air
* \param bridge_config The config with which to print the wall lines that are spanning a bridge
* \param flow_ratio The ratio with which to multiply the extrusion amount
* \param line_width_ratio The line width ratio to be applied
* \param non_bridge_line_volume A pseudo-volume that is derived from the print speed and flow of the non-bridge lines that have preceded this lin
* \param min_bridge_line_len The minimum line width to allow an extrusion move to be processed as a bridge move
* \param always_retract Whether to force a retraction when moving to the start of the polygon (used for outer walls)
* \param is_small_feature Indicates whether the wall is so small that it should be processed differently
* \param small_feature_speed_factor The speed factor to be applied to small feature walls
* \param max_area_deviation The maximum allowed area deviation to split a segment into pieces
* \param max_resolution The maximum resolution to split a segment into pieces
* \param scarf_seam_length The length of the scarf joint seam, which may be 0 if there is none
* \param scarf_seam_start_ratio The ratio of the line thickness to start the scarf seam with
* \param scarf_split_distance The maximum length of a segment to apply the scarf seam gradient, longer segments will be splitted
* \param scarf_max_z_offset The maximum Z offset te be applied at the lowest position of the scarf seam
* \param speed_split_distance The maximum length of a segment to apply the acceleration/deceleration gradient, longer segments will be splitted
* \param start_speed_ratio The ratio of the top speed to be applied when starting the segment, then accelerate gradually to full speed
* \param accelerate_length The pre-calculated length of the acceleration phase
* \param end_speed_ratio The ratio of the top speed to be applied when finishing a segment
* \param decelerate_length The pre-calculated length of the deceleration phase
* \param is_scarf_closure Indicates whether this function is called to make the scarf closure (overlap over the first scarf pass) or the normal first pass of the wall
*/
void addSplitWall(
const ExtrusionLine& wall,
const coord_t wall_length,
size_t start_idx,
const int direction,
const size_t max_index,
const Settings& settings,
const GCodePathConfig& default_config,
const GCodePathConfig& roofing_config,
const GCodePathConfig& bridge_config,
const double flow_ratio,
const Ratio line_width_ratio,
double& non_bridge_line_volume,
const coord_t min_bridge_line_len,
const bool always_retract,
const bool is_small_feature,
Ratio small_feature_speed_factor,
const coord_t max_area_deviation,
const auto max_resolution,
const auto scarf_seam_length,
const auto scarf_seam_start_ratio,
const auto scarf_split_distance,
const coord_t scarf_max_z_offset,
const coord_t speed_split_distance,
const Ratio start_speed_ratio,
const coord_t accelerate_length,
const Ratio end_speed_ratio,
const coord_t decelerate_length,
const bool is_scarf_closure);

/*!
* \brief Helper function to calculate the distance from the start of the current wall line to the first bridge segment
* \param wall The currently processed wall
* \param current_index The index of the currently processed point
* \param min_bridge_line_len The minimum line width to allow an extrusion move to be processed as a bridge move
* \return The distance from the start of the current wall line to the first bridge segment
*/
coord_t computeDistanceToBridgeStart(const ExtrusionLine& wall, const size_t current_index, const coord_t min_bridge_line_len) const;

/*!
* \brief Calculates whether the given segment is to be treated as overhanging
* \param p0 The start point of the segment
* \param p1 The end point of the segment
*/
bool segmentIsOnOverhang(const Point2LL& p0, const Point2LL& p1) const;
bool segmentIsOnOverhang(const Point3LL &p0, const Point3LL &p1) const;
};

} // namespace cura
Expand Down
40 changes: 5 additions & 35 deletions include/communication/ArcusCommunication.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ArcusCommunication : public Communication
* This may indicate the starting position (or any other jump in the path).
* \param position The current position to start the next line at.
*/
void sendCurrentPosition(const Point2LL& position) override;
void sendCurrentPosition(const Point3LL& position) override;

/*
* \brief Sends a message to indicate that all the slicing is done.
Expand All @@ -113,7 +113,7 @@ class ArcusCommunication : public Communication
* visualisation of the layer.
*
* This will be called after all the polygons and lines of this layer are
* sent via sendPolygons, sendPolygon and sendLineTo. This will flush all
* sent via sendLineTo. This will flush all
* visualised data for one layer in one go.
* \param layer_nr The layer that was completed.
* \param z The z-coordinate of the top side of the layer.
Expand All @@ -132,7 +132,7 @@ class ArcusCommunication : public Communication
* \param line_thickness The thickness (in the Z direction) of the line.
* \param velocity The velocity of printing this polygon.
*/
void sendLineTo(const PrintFeatureType& type, const Point2LL& to, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity) override;
void sendLineTo(const PrintFeatureType& type, const Point3LL& to, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity) override;

/*
* \brief Send the sliced layer data to the front-end after the optimisation
Expand All @@ -142,34 +142,6 @@ class ArcusCommunication : public Communication
*/
void sendOptimizedLayerData() override;

/*
* \brief Send a polygon to the front-end to display in layer view.
*
* The polygons are not actually flushed until ``sendLayerComplete`` is
* called.
* \param type The type of print feature the polygon represents (infill,
* wall, support, etc).
* \param polygon The shape to visualise.
* \param line_width The width of the lines in this polygon.
* \param line_thickness The thickness (in the Z direction) of the polygon.
* \param velocity The velocity of printing this polygon.
*/
void sendPolygon(const PrintFeatureType& type, const Polygon& polygon, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity) override;

/*
* \brief Send polygons to the front-end to display in layer view.
*
* The polygons may not actually be flushed until ``sendLayerComplete`` is
* called.
* \param type The type of print feature the polygons represent (infill,
* wall, support, etc).
* \param polygons The shapes to visualise.
* \param line_width The width of the lines in these polygons.
* \param line_thickness The thickness (in the Z direction) of the polygons.
* \param velocity The velocity of printing these polygons.
*/
void sendPolygons(const PrintFeatureType& type, const Shape& polygons, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity) override;

/*
* \brief Send an estimate of how long the print would take and how much
* material it would use.
Expand All @@ -182,15 +154,13 @@ class ArcusCommunication : public Communication
void sendProgress(double progress) const override;

/*
* \brief Set which extruder is being used for the following calls to
* ``sendPolygon``, ``sendPolygons`` and ``sendLineTo``.
* \brief Set which extruder is being used for the following calls to ``sendLineTo``.
* \param extruder The new extruder to send data for.
*/
void setExtruderForSend(const ExtruderTrain& extruder) override;

/*
* \brief Set which layer is being used for the following calls to
* ``sendPolygon``, ``sendPolygons`` and ``sendLineTo``.
* \brief Set which layer is being used for the following calls to ``sendLineTo``.
* \param layer_nr The index of the layer to send data for. This is zero-
* indexed but may be negative for raft layers.
*/
Expand Down
Loading

0 comments on commit 3541f2d

Please sign in to comment.