Skip to content

Commit 60f5df1

Browse files
authored
CURA-12822 start end infill away from wall (#2263)
2 parents e8f5b32 + 2d46123 commit 60f5df1

22 files changed

+713
-134
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ set(engine_SRCS # Except main.cpp.
184184
src/geometry/Polyline.cpp
185185
src/geometry/ClosedPolyline.cpp
186186
src/geometry/MixedLinesSet.cpp
187+
188+
src/geometry/conversions/Point2D_Point2LL.cpp
187189
)
188190

189191
add_library(_CuraEngine STATIC ${engine_SRCS} ${engine_PB_SRCS})
@@ -235,9 +237,9 @@ find_package(fmt REQUIRED)
235237
find_package(range-v3 REQUIRED)
236238
find_package(scripta REQUIRED)
237239
find_package(PNG REQUIRED)
238-
if(NOT EMSCRIPTEN)
240+
if (NOT EMSCRIPTEN)
239241
find_package(TBB REQUIRED)
240-
endif()
242+
endif ()
241243

242244
if (ENABLE_SENTRY)
243245
find_package(sentry REQUIRED)

include/FffGcodeWriter.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,18 @@ class FffGcodeWriter : public NoCopy
417417
* mesh which should be printed with this extruder.
418418
* \param mesh_config The line config with which to print a print feature.
419419
* \param part The part for which to create gcode.
420+
* \param start_move_inwards_length The length of the extra inwards moves to be added at the start of each infill line
421+
* \param end_move_inwards_length The length of the extra inwards moves to be added at the end of each infill line
420422
* \return Whether this function added anything to the layer plan.
421423
*/
422-
bool processMultiLayerInfill(LayerPlan& gcodeLayer, const SliceMeshStorage& mesh, const size_t extruder_nr, const MeshPathConfigs& mesh_config, const SliceLayerPart& part)
423-
const;
424+
bool processMultiLayerInfill(
425+
LayerPlan& gcodeLayer,
426+
const SliceMeshStorage& mesh,
427+
const size_t extruder_nr,
428+
const MeshPathConfigs& mesh_config,
429+
const SliceLayerPart& part,
430+
const coord_t start_move_inwards_length = 0,
431+
const coord_t end_move_inwards_length = 0) const;
424432

425433
/*!
426434
* \brief Add normal sparse infill for a given part in a layer.
@@ -430,6 +438,8 @@ class FffGcodeWriter : public NoCopy
430438
* mesh which should be printed with this extruder
431439
* \param mesh_config The line config with which to print a print feature.
432440
* \param part The part for which to create gcode.
441+
* \param start_move_inwards_length The length of the extra inwards moves to be added at the start of each infill line
442+
* \param end_move_inwards_length The length of the extra inwards moves to be added at the end of each infill line
433443
* \return Whether this function added anything to the layer plan.
434444
*/
435445
bool processSingleLayerInfill(
@@ -438,7 +448,9 @@ class FffGcodeWriter : public NoCopy
438448
const SliceMeshStorage& mesh,
439449
const size_t extruder_nr,
440450
const MeshPathConfigs& mesh_config,
441-
const SliceLayerPart& part) const;
451+
const SliceLayerPart& part,
452+
const coord_t start_move_inwards_length = 0,
453+
const coord_t end_move_inwards_length = 0) const;
442454

443455
/*!
444456
* Generate the insets for the walls of a given layer part.

include/LayerPlan.h

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace cura
3737
class Comb;
3838
class SliceDataStorage;
3939
class LayerPlanBuffer;
40+
class STHalfEdge;
4041

4142
template<typename PathType>
4243
class PathAdapter;
@@ -525,9 +526,30 @@ class LayerPlan : public NoCopy
525526
bool reverse_order = false,
526527
const std::optional<Point2LL> start_near_location = std::optional<Point2LL>(),
527528
bool scarf_seam = false,
528-
bool smooth_acceleration = false,
529+
bool smooth_speed = false,
529530
const std::shared_ptr<TextureDataProvider>& texture_data_provider = nullptr);
530531

532+
/*!
533+
* Adds infill polygons to the gcode with optimized order.
534+
*
535+
* In case we need to generate extra inwards moves for the infill, we cannot treat them as polygons anymore, since the lines will be un-closed. Thus, the resulting open
536+
* polylines are returned in \p remaining_lines and should be re-added to the gcode, e.g. by using addLinesByOptimizer().
537+
*
538+
* @param polygons The infill polygons to be added
539+
* @param[out] remaining_lines The list to be filled with generates open polylines. The given list may be non-empty, only new lines will be appended. * @param config The
540+
* config with which to print the polygon lines
541+
* @param settings The current settings to retrieve values from
542+
* @param add_extra_inwards_move Indicates whether extra start/end inwards extrusion moves will be generated
543+
* @param near_start_location Optional: Location near where to add the first line. If not provided the last position is used.
544+
*/
545+
void addInfillPolygonsByOptimizer(
546+
const Shape& polygons,
547+
OpenLinesSet& remaining_lines,
548+
const GCodePathConfig& config,
549+
const Settings& settings,
550+
const bool add_extra_inwards_move = false,
551+
const std::optional<Point2LL>& near_start_location = std::optional<Point2LL>());
552+
531553
/*!
532554
* Add a single line that is part of a wall to the gcode.
533555
* \param p0 The start vertex of the line.
@@ -687,6 +709,9 @@ class LayerPlan : public NoCopy
687709
* \param fan_speed optional fan speed override for this path
688710
* \param reverse_print_direction Whether to reverse the optimized order and their printing direction.
689711
* \param order_requirements Pairs where first needs to be printed before second. Pointers are pointing to elements of \p lines
712+
* \param extra_inwards_start_move_length The length of the extra inwards moves to be added at the start of each infill line
713+
* \param extra_inwards_end_move_length The length of the extra inwards moves to be added at the end of each infill line
714+
* \param extra_inwards_move_contour The contour to be considered in order to add the inwards moves
690715
*/
691716
template<class LineType>
692717
void addLinesByOptimizer(
@@ -699,7 +724,10 @@ class LayerPlan : public NoCopy
699724
const std::optional<Point2LL> near_start_location = std::optional<Point2LL>(),
700725
const double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT,
701726
const bool reverse_print_direction = false,
702-
const std::unordered_multimap<const Polyline*, const Polyline*>& order_requirements = PathOrderOptimizer<const Polyline*>::no_order_requirements_);
727+
const std::unordered_multimap<const Polyline*, const Polyline*>& order_requirements = PathOrderOptimizer<const Polyline*>::no_order_requirements_,
728+
const coord_t extra_inwards_start_move_length = 0,
729+
const coord_t extra_inwards_end_move_length = 0,
730+
const Shape& extra_inwards_move_contour = Shape());
703731

704732
/*!
705733
* Add lines to the gcode with optimized order.
@@ -870,14 +898,55 @@ class LayerPlan : public NoCopy
870898
* \param wipe_dist (optional) the distance wiped without extruding after laying down a line.
871899
* \param flow_ratio The ratio with which to multiply the extrusion amount
872900
* \param fan_speed optional fan speed override for this path
901+
* \param extra_inwards_start_move_length The length of the extra inwards moves to be added at the start of each infill line
902+
* \param extra_inwards_end_move_length The length of the extra inwards moves to be added at the end of each infill line
903+
* \param extra_inwards_move_contour The contour to be considered in order to add the inwards moves
873904
*/
874905
void addLinesInGivenOrder(
875906
const std::vector<PathOrdering<const Polyline*>>& lines,
876907
const GCodePathConfig& config,
877908
const SpaceFillType space_fill_type,
878909
const coord_t wipe_dist,
879910
const Ratio flow_ratio,
880-
const double fan_speed);
911+
const double fan_speed,
912+
const coord_t extra_inwards_start_move_length = 0,
913+
const coord_t extra_inwards_end_move_length = 0,
914+
const Shape& extra_inwards_move_contour = Shape());
915+
916+
/*!
917+
* Add order optimized polygons to the gcode.
918+
* Add polygons to the gcode with optimized order.
919+
*
920+
* \param polygons The polygons.
921+
* \param config The config with which to print the polygon lines.
922+
* for each given segment (optionally nullptr).
923+
* \param settings The settings which should apply to these polygons added to the layer plan
924+
* \param z_seam_config Optional configuration for z-seam.
925+
* \param wall_0_wipe_dist The distance to travel along each polygon after
926+
* it has been laid down, in order to wipe the start and end of the wall
927+
* together.
928+
* \param spiralize Whether to gradually increase the z height from the
929+
* normal layer height to the height of the next layer over each polygon
930+
* printed.
931+
* \param flow_ratio The ratio with which to multiply the extrusion amount.
932+
* \param always_retract Whether to force a retraction when moving to the
933+
* start of the polygon (used for outer walls).
934+
* \param reverse_order Adds polygons in reverse order.
935+
* \param scarf_seam Indicates whether we may use a scarf seam for the path
936+
* \param smooth_speed Indicates whether we may use a speed gradient for the path
937+
*/
938+
void addPolygonsInGivenOrder(
939+
const std::vector<PathOrdering<const Polygon*>>& polygons,
940+
const GCodePathConfig& config,
941+
const Settings& settings,
942+
const ZSeamConfig& z_seam_config = ZSeamConfig(),
943+
coord_t wall_0_wipe_dist = 0,
944+
bool spiralize = false,
945+
const Ratio flow_ratio = 1.0_r,
946+
bool always_retract = false,
947+
bool reverse_order = false,
948+
bool scarf_seam = false,
949+
bool smooth_speed = false);
881950

882951
/*!
883952
* @brief Send a GCodePath line to the communication object, applying proper Z offsets
@@ -1150,6 +1219,16 @@ class LayerPlan : public NoCopy
11501219
const std::optional<TravelAntiOozing>& priming_amounts,
11511220
const Velocity& speed,
11521221
const size_t point_index);
1222+
1223+
/*!
1224+
* Generates an extrusion move that goes as inwards as possible given a skeletized contour, starting from the given point
1225+
* @param trapezoidal_edges The edges of the skeletal trapezoidation for the contour
1226+
* @param start_point The point to start generating the move from
1227+
* @param move_inwards_length The length of the move to be generated
1228+
* @return Extrusion path to be started from the given start point, going further inwards. It may be empty if not possible or if the start point is
1229+
* already inwards the contour enough.
1230+
*/
1231+
static OpenPolyline makeInwardsMove(const std::list<STHalfEdge>& trapezoidal_edges, const Point2LL& start_point, const coord_t move_inwards_length);
11531232
};
11541233

11551234
} // namespace cura

include/SkeletalTrapezoidationGraph.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ class STHalfEdge : public HalfEdge<SkeletalTrapezoidationJoint, SkeletalTrapezoi
3333
/*!
3434
* Check whether the edge goes from a lower to a higher distance_to_boundary.
3535
* Effectively deals with equidistant edges by looking beyond this edge.
36+
*
37+
* \param strict Whether equidistant edges can count as going upwards
3638
*/
37-
bool isUpward() const;
39+
bool isUpward(const bool strict = false) const;
3840

3941
/*!
4042
* Calculate the traversed distance until we meet an upward edge.

include/geometry/ClosedPolyline.h

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@ class OpenPolyline;
1515
* @sa https://github.com/Ultimaker/CuraEngine/wiki/Geometric-Base-Types#closedpolyline
1616
*
1717
* The path may be closed:
18-
* * Explicitely, which means the last point is at the same position as the first point.
18+
* * Explicitly, which means the last point is at the same position as the first point.
1919
* In this case, in order to iterate over the segments, you just have to iterate over
2020
* the actual points.
21-
* * Implicitely, which means the last and first point are at different positions. In this
21+
* * Implicitly, which means the last and first point are at different positions. In this
2222
* case, to iterate over the segments, you have to consider an additional segment
2323
* between the last and first point
2424
*
2525
* The difference is made because it is easier to iterate over segments when the path is
26-
* explicitely closed, but ClipperLib uses implicitely closed paths. It is also a bit healthier
27-
* to use implicitely closed because there is no risk that the first and last point become different
26+
* explicitly closed, but ClipperLib uses implicitly closed paths. It is also a bit healthier
27+
* to use implicitly closed because there is no risk that the first and last point become different
2828
*/
2929
class ClosedPolyline : public Polyline
3030
{
3131
private:
32-
bool explicitely_closed_{ false };
32+
bool explicitly_closed_{ false };
3333

3434
public:
3535
/*!
3636
* \brief Builds an empty closed polyline
37-
* \warning By default, the line is tagged as non explicitely closed. We need this default
37+
* \warning By default, the line is tagged as non explicitly closed. We need this default
3838
* constructor in various places, but be careful that the interpretation of the points
3939
* added later will depend on this.
4040
*/
4141
ClosedPolyline() = default;
4242

4343
/*!
4444
* \brief Builds an empty closed polyline
45-
* \param explicitely_closed Indicates whether the line will be explicitely closed
45+
* \param explicitly_closed Indicates whether the line will be explicitly closed
4646
*/
47-
explicit ClosedPolyline(const bool explicitely_closed)
48-
: explicitely_closed_{ explicitely_closed }
47+
explicit ClosedPolyline(const bool explicitly_closed)
48+
: explicitly_closed_{ explicitly_closed }
4949
{
5050
}
5151

@@ -57,31 +57,31 @@ class ClosedPolyline : public Polyline
5757

5858
/*!
5959
* \brief Constructor with a points initializer list, provided for convenience
60-
* \param explicitely_closed Specify whether the given points form an explicitely closed line
60+
* \param explicitly_closed Specify whether the given points form an explicitly closed line
6161
*/
62-
ClosedPolyline(const std::initializer_list<Point2LL>& initializer, bool explicitely_closed)
62+
ClosedPolyline(const std::initializer_list<Point2LL>& initializer, bool explicitly_closed)
6363
: Polyline{ initializer }
64-
, explicitely_closed_{ explicitely_closed }
64+
, explicitly_closed_{ explicitly_closed }
6565
{
6666
}
6767

6868
/*!
6969
* \brief Constructor with an existing list of points
70-
* \param explicitely_closed Specify whether the given points form an explicitely closed line
70+
* \param explicitly_closed Specify whether the given points form an explicitly closed line
7171
*/
72-
explicit ClosedPolyline(const ClipperLib::Path& points, bool explicitely_closed)
72+
explicit ClosedPolyline(const ClipperLib::Path& points, bool explicitly_closed)
7373
: Polyline{ points }
74-
, explicitely_closed_{ explicitely_closed }
74+
, explicitly_closed_{ explicitly_closed }
7575
{
7676
}
7777

7878
/*!
7979
* \brief Constructor that takes ownership of the given list of points
80-
* \param explicitely_closed Specify whether the given points form an explicitely closed line
80+
* \param explicitly_closed Specify whether the given points form an explicitly closed line
8181
*/
82-
explicit ClosedPolyline(ClipperLib::Path&& points, bool explicitely_closed)
82+
explicit ClosedPolyline(ClipperLib::Path&& points, bool explicitly_closed)
8383
: Polyline{ std::move(points) }
84-
, explicitely_closed_{ explicitely_closed }
84+
, explicitly_closed_{ explicitly_closed }
8585
{
8686
}
8787

@@ -90,7 +90,7 @@ class ClosedPolyline : public Polyline
9090
/*! @see Polyline::hasClosingSegment() */
9191
[[nodiscard]] bool hasClosingSegment() const override
9292
{
93-
return ! explicitely_closed_;
93+
return ! explicitly_closed_;
9494
}
9595

9696
/*! @see Polyline::addClosingSegment() */
@@ -103,19 +103,19 @@ class ClosedPolyline : public Polyline
103103

104104
ClosedPolyline& operator=(ClosedPolyline&& other) = default;
105105

106-
[[nodiscard]] bool isExplicitelyClosed() const
106+
[[nodiscard]] bool isExplicitlyClosed() const
107107
{
108-
return explicitely_closed_;
108+
return explicitly_closed_;
109109
}
110110

111111
/*!
112-
* \brief Sets whether the points set is to be treated as explicitely or implicitely closed
112+
* \brief Sets whether the points set is to be treated as explicitly or implicitly closed
113113
* \warning This does not actually changes the points set, only the interpretation of it will
114114
* change. So use this method only if you really know what you are doing.
115115
*/
116-
void setExplicitelyClosed(bool explicitely_closed)
116+
void setExplicitlyClosed(bool explicitly_closed)
117117
{
118-
explicitely_closed_ = explicitely_closed;
118+
explicitly_closed_ = explicitly_closed;
119119
}
120120

121121
/*!
@@ -136,6 +136,9 @@ class ClosedPolyline : public Polyline
136136
* \return An open polyline instance, with the end point at the same position of the start point
137137
*/
138138
[[nodiscard]] OpenPolyline toPseudoOpenPolyline() const;
139+
140+
/*! Shifts the points of the line so that it will now start at the point with the given index */
141+
void shiftVerticesToStartPoint(const size_t start_index);
139142
};
140143

141144
} // namespace cura

0 commit comments

Comments
 (0)