Skip to content

Commit 4dafaef

Browse files
authored
CURA-12833 improve bridge lines direction (#2266)
2 parents 60f5df1 + e1fb57a commit 4dafaef

28 files changed

+1464
-941
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ set(engine_SRCS # Except main.cpp.
6565
src/multiVolumes.cpp
6666
src/path_ordering.cpp
6767
src/PathAdapter.cpp
68+
src/PathOrderMonotonic.cpp
6869
src/Preheat.cpp
6970
src/PrimeTower/PrimeTower.cpp
7071
src/PrimeTower/PrimeTowerNormal.cpp
@@ -177,6 +178,7 @@ set(engine_SRCS # Except main.cpp.
177178
src/geometry/Point3LL.cpp
178179
src/geometry/Polygon.cpp
179180
src/geometry/Shape.cpp
181+
src/geometry/PointMatrix.cpp
180182
src/geometry/PointsSet.cpp
181183
src/geometry/SingleShape.cpp
182184
src/geometry/PartsView.cpp

include/FffGcodeWriter.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "FanSpeedLayerTime.h"
1212
#include "GCodePathConfig.h"
1313
#include "LayerPlanBuffer.h"
14+
#include "LinesOrderingMethod.h"
1415
#include "gcodeExport.h"
1516
#include "utils/LayerVector.h"
1617
#include "utils/NoCopy.h"
@@ -591,6 +592,7 @@ class FffGcodeWriter : public NoCopy
591592
* minimise travel moves (``false``).
592593
* \param[out] added_something Whether this function added anything to the layer plan
593594
* \param fan_speed fan speed override for this skin area
595+
* \param forced_small_area_width A specific value to be used for small_area_width when generating the infill, or nullopt to use the normal value
594596
*/
595597
void processSkinPrintFeature(
596598
const SliceDataStorage& storage,
@@ -603,10 +605,11 @@ class FffGcodeWriter : public NoCopy
603605
const AngleDegrees skin_angle,
604606
const coord_t skin_overlap,
605607
const Ratio skin_density,
606-
const bool monotonic,
608+
const LinesOrderingMethod ordering,
607609
const bool is_roofing_flooring,
608610
bool& added_something,
609-
double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT) const;
611+
double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT,
612+
std::optional<coord_t> forced_small_area_width = std::nullopt) const;
610613

611614
/*!
612615
* see if we can avoid printing a lines or zig zag style skin part in multiple segments by moving to

include/LayerPlan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,8 @@ class LayerPlan : public NoCopy
785785
const coord_t exclude_distance = 0,
786786
const coord_t wipe_dist = 0,
787787
const Ratio flow_ratio = 1.0_r,
788-
const double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT);
788+
const double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT,
789+
const bool interlaced = false);
789790

790791
/*!
791792
* Add a spiralized slice of wall that is interpolated in X/Y between \p last_wall and \p wall.

include/LinesOrderingMethod.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2025 UltiMaker
2+
// CuraEngine is released under the terms of the AGPLv3 or higher
3+
4+
#ifndef LINES_ORDERING_METHOD_H
5+
#define LINES_ORDERING_METHOD_H
6+
7+
8+
namespace cura
9+
{
10+
11+
enum class LinesOrderingMethod
12+
{
13+
Basic, // Lines are ordered by shortest distance
14+
Monotonic, // Lines are ordered so that they will always form a continuous print along a direction
15+
Interlaced, // Similar to monotonic, but with 2 passes so that adjacent lines will not be printed just after each other
16+
};
17+
18+
} // namespace cura
19+
20+
#endif

include/PathOrderMonotonic.h

Lines changed: 27 additions & 363 deletions
Large diffs are not rendered by default.

include/bridge.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
#ifndef BRIDGE_H
55
#define BRIDGE_H
66

7+
#include <optional>
8+
79
namespace cura
810
{
911

1012
class Shape;
11-
class Settings;
13+
class SliceMeshStorage;
1214
class SliceDataStorage;
1315
class SupportLayer;
16+
class AngleDegrees;
1417

1518
/*!
1619
* \brief Computes the angle that lines have to take to bridge a certain shape
1720
* best.
1821
*
1922
* If the area should not be bridged, an angle of -1 is returned.
20-
* \param settings The settings container to get settings from.
23+
* \param mesh The mesh being processed.
2124
* \param skin_outline The shape to fill with lines.
2225
* \param storage The slice data storage where to find objects that the bridge
2326
* could rest on in previous layers.
@@ -27,8 +30,8 @@ class SupportLayer;
2730
* \param supported_regions Pre-computed regions that the support layer would
2831
* support.
2932
*/
30-
double bridgeAngle(
31-
const Settings& settings,
33+
std::optional<AngleDegrees> bridgeAngle(
34+
const SliceMeshStorage& mesh,
3235
const Shape& skin_outline,
3336
const SliceDataStorage& storage,
3437
const unsigned layer_nr,

include/geometry/Point2D.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ class Point2D
6868
return Point2D(x_ * scale, y_ * scale);
6969
}
7070

71+
Point2D operator-(const Point2D& other) const
72+
{
73+
return Point2D(x_ - other.x_, y_ - other.y_);
74+
}
75+
76+
Point2D operator+(const Point2D& other) const
77+
{
78+
return Point2D(x_ + other.x_, y_ + other.y_);
79+
}
80+
81+
Point2D operator-() const
82+
{
83+
return Point2D(-x_, -y_);
84+
}
85+
7186
static double dot(const Point2D& p0, const Point2D& p1)
7287
{
7388
return p0.x_ * p1.x_ + p0.y_ * p1.y_;

include/geometry/PointMatrix.h

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,41 @@
55
#define GEOMETRY_POINT_MATRIX_H
66

77
#include <array>
8-
#include <numbers>
98

109
#include "geometry/Point2LL.h"
1110

1211

1312
namespace cura
1413
{
1514

15+
class AngleDegrees;
16+
class AngleRadians;
17+
1618
class PointMatrix
1719
{
1820
public:
1921
std::array<double, 4> matrix{ 1, 0, 0, 1 };
2022

2123
PointMatrix() noexcept = default;
2224

23-
explicit PointMatrix(double rotation)
24-
{
25-
rotation = rotation / 180 * std::numbers::pi;
26-
matrix.at(0) = std::cos(rotation);
27-
matrix.at(1) = -std::sin(rotation);
28-
matrix.at(2) = -matrix.at(1);
29-
matrix.at(3) = matrix.at(0);
30-
}
31-
32-
explicit PointMatrix(const Point2LL& p)
33-
{
34-
matrix.at(0) = static_cast<double>(p.X);
35-
matrix.at(1) = static_cast<double>(p.Y);
36-
double f = std::sqrt((matrix.at(0) * matrix.at(0)) + (matrix.at(1) * matrix.at(1)));
37-
matrix.at(0) /= f;
38-
matrix.at(1) /= f;
39-
matrix.at(2) = -matrix.at(1);
40-
matrix.at(3) = matrix.at(0);
41-
}
42-
43-
static PointMatrix scale(double s)
44-
{
45-
PointMatrix ret;
46-
ret.matrix.at(0) = s;
47-
ret.matrix.at(3) = s;
48-
return ret;
49-
}
50-
51-
[[nodiscard]] Point2LL apply(const Point2LL& p) const
52-
{
53-
const auto x = static_cast<double>(p.X);
54-
const auto y = static_cast<double>(p.Y);
55-
return { std::llrint(x * matrix.at(0) + y * matrix.at(1)), std::llrint(x * matrix.at(2) + y * matrix.at(3)) };
56-
}
25+
explicit PointMatrix(double rotation);
26+
27+
explicit PointMatrix(const AngleDegrees& rotation);
28+
29+
explicit PointMatrix(const AngleRadians& rotation);
30+
31+
explicit PointMatrix(const Point2LL& p);
32+
33+
static PointMatrix scale(double s);
34+
35+
[[nodiscard]] Point2LL apply(const Point2LL& p) const;
5736

5837
/*!
5938
* \warning only works on a rotation matrix! Output is incorrect for other types of matrix
6039
*/
61-
[[nodiscard]] Point2LL unapply(const Point2LL& p) const
62-
{
63-
const auto x = static_cast<double>(p.X);
64-
const auto y = static_cast<double>(p.Y);
65-
return { std::llrint(x * matrix.at(0) + y * matrix.at(2)), std::llrint(x * matrix.at(1) + y * matrix.at(3)) };
66-
}
67-
68-
[[nodiscard]] PointMatrix inverse() const
69-
{
70-
PointMatrix ret;
71-
double det = matrix.at(0) * matrix.at(3) - matrix.at(1) * matrix.at(2);
72-
ret.matrix.at(0) = matrix.at(3) / det;
73-
ret.matrix.at(1) = -matrix.at(1) / det;
74-
ret.matrix.at(2) = -matrix.at(2) / det;
75-
ret.matrix.at(3) = matrix.at(0) / det;
76-
return ret;
77-
}
40+
[[nodiscard]] Point2LL unapply(const Point2LL& p) const;
41+
42+
[[nodiscard]] PointMatrix inverse() const;
7843
};
7944

8045
} // namespace cura

include/infill.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ class Infill
214214
const SliceMeshStorage* mesh = nullptr,
215215
const Shape& prevent_small_exposed_to_air = Shape());
216216

217+
coord_t getLineDistance() const
218+
{
219+
return line_distance_;
220+
}
221+
217222
/*!
218223
* Generate the wall toolpaths of an infill area. It will return the inner contour and set the inner-contour.
219224
* This function is called within the generate() function but can also be called stand-alone

include/utils/HalfEdgeGraph.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
//Copyright (c) 2020 Ultimaker B.V.
2-
//CuraEngine is released under the terms of the AGPLv3 or higher.
1+
// Copyright (c) 2020 Ultimaker B.V.
2+
// CuraEngine is released under the terms of the AGPLv3 or higher.
33

44
#ifndef UTILS_HALF_EDGE_GRAPH_H
55
#define UTILS_HALF_EDGE_GRAPH_H
66

77

8-
#include <list>
98
#include <cassert>
10-
11-
9+
#include <list>
1210

1311
#include "HalfEdge.h"
1412
#include "HalfEdgeNode.h"
15-
#include "SVG.h"
1613

1714
namespace cura
1815
{
19-
using namespace cura;
16+
using namespace cura;
2017

2118
template<class node_data_t, class edge_data_t, class derived_node_t, class derived_edge_t> // types of data contained in nodes and edges
2219
class HalfEdgeGraph

0 commit comments

Comments
 (0)