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-12175 Fix scarf seam and coasting interaction #2155

Merged
merged 6 commits into from
Oct 31, 2024
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
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 Point3LL& p0, const Point3LL& p1, const GCodePath& path);
std::pair<double, double> getPointToPointTime(const Point3LL& p0, const Point3LL& p1, const GCodePath& path) const;

/*!
* Compute naive time estimates (without accounting for slow down at corners etc.) and naive material estimates.
Expand Down
76 changes: 46 additions & 30 deletions include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,27 @@ 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_;
bool mode_skip_agressive_merge_; //!< Whether to give every new path the 'skip_agressive_merge_hint' property (see GCodePath); default is false.

private:
// Indicates how coasting should be processed on the given path.
enum class ApplyCoasting
{
NoCoasting, // Do not apply coasting on this path, extrude it normally
CoastEntirePath, // Fully coast this path, i.e. replace it by travel moves
PartialCoasting // Extrude the first part of the path and coast the end
};

struct PathCoasting
{
ApplyCoasting apply_coasting{ ApplyCoasting::NoCoasting };
size_t coasting_start_index{ 0 };
Point3LL coasting_start_pos;
};

const SliceDataStorage& storage_; //!< The polygon data obtained from FffPolygonProcessor
const LayerIndex layer_nr_; //!< The layer number of this layer plan
const bool is_initial_layer_; //!< Whether this is the first layer (which might be raft)
Expand Down Expand Up @@ -714,28 +721,6 @@ class LayerPlan : public NoCopy
*/
bool makeRetractSwitchRetract(unsigned int extruder_plan_idx, unsigned int path_idx);

/*!
* Writes a path to GCode and performs coasting, or returns false if it did nothing.
*
* Coasting replaces the last piece of an extruded path by move commands and uses the oozed material to lay down lines.
*
* \param gcode The gcode to write the planned paths to.
* \param extruder_plan_idx The index of the current extruder plan.
* \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::pair<AdjustCoasting, double> coasting_adjust);

/*!
* Applying speed corrections for minimal layer times and determine the fanSpeed.
*
Expand Down Expand Up @@ -957,6 +942,37 @@ class LayerPlan : public NoCopy
const bool smooth_speed,
const AddExtrusionSegmentFunction& func_add_segment);

/*!
* Pre-calculates the coasting to be applied on the paths
*
* \param extruder_settings The current extruder settings
* \param paths The current set of paths to be written to GCode
* \param current_position The last position set in the gcode writer
* \return The list of coasting settings to be applied on the paths. It will always have the same size as paths.
*/
std::vector<PathCoasting> calculatePathsCoasting(const Settings& extruder_settings, const std::vector<GCodePath>& paths, const Point3LL& current_position) const;

/*!
* Writes a path to GCode and performs coasting, or returns false if it did nothing.
*
* Coasting replaces the last piece of an extruded path by move commands and uses the oozed material to lay down lines.
*
* \param gcode The gcode to write the planned paths to.
* \param extruder_plan_idx The index of the current extruder plan.
* \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 path_coasting The actual coasting to be applied to the 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 std::function<void(const double, const int64_t)> insertTempOnTime,
const PathCoasting& path_coasting);

/*!
* \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
Expand Down
5 changes: 5 additions & 0 deletions include/geometry/Point3LL.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ inline Point3LL operator*(const T i, const Point3LL& rhs)
return rhs * i;
}

inline Point3LL lerp(const Point3LL& a, const Point3LL& b, const double t)
{
return Point3LL(cura::lerp(a.x_, b.x_, t), cura::lerp(a.y_, b.y_, t), cura::lerp(a.z_, b.z_, t));
}

} // namespace cura


Expand Down
11 changes: 10 additions & 1 deletion include/utils/Coord_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@


// Include Clipper to get the ClipperLib::IntPoint definition, which we reuse as Point definition.
#include <cmath>
#include <polyclipping/clipper.hpp>

#include "utils/types/generic.h"

namespace cura
{

Expand All @@ -16,7 +19,7 @@ using coord_t = ClipperLib::cInt;
static inline coord_t operator"" _mu(unsigned long long i)
{
return static_cast<coord_t>(i);
};
}

#define INT2MM(n) (static_cast<double>(n) / 1000.0)
#define INT2MM2(n) (static_cast<double>(n) / 1000000.0)
Expand All @@ -27,6 +30,12 @@ static inline coord_t operator"" _mu(unsigned long long i)
#define INT2MICRON(n) ((n) / 1)
#define MICRON2INT(n) ((n)*1)

template<utils::floating_point FactorType>
[[nodiscard]] inline coord_t lerp(coord_t a, coord_t b, FactorType t)
{
return std::llrint(std::lerp(static_cast<double>(a), static_cast<double>(b), t));
}

} // namespace cura


Expand Down
Loading
Loading