Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/upstream/5.9' into fix-enc…
Browse files Browse the repository at this point in the history
…ompassing-hole-alternative
  • Loading branch information
ThomasRahm committed Oct 22, 2024
2 parents 8de3bab + 9a264cb commit 16bfaa4
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 227 deletions.
6 changes: 4 additions & 2 deletions include/InsetOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class InsetOrderOptimizer
const Point2LL& model_center_point,
const Shape& disallowed_areas_for_seams = {},
const bool scarf_seam = false,
const bool smooth_speed = false);
const bool smooth_speed = false,
const Shape& overhang_areas = Shape());

/*!
* Adds the insets to the given layer plan.
Expand Down Expand Up @@ -114,6 +115,7 @@ class InsetOrderOptimizer
Shape disallowed_areas_for_seams_;
const bool scarf_seam_;
const bool smooth_speed_;
Shape overhang_areas_;

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 All @@ -128,7 +130,7 @@ class InsetOrderOptimizer
*
* \param closed_line The polygon to insert the seam point in. (It's assumed to be closed at least.)
*
* \return The index of the inserted seam point, or std::nullopt if no seam point was inserted.
* \return The index of the inserted seam point, or the index of the closest point if an existing one can be used.
*/
std::optional<size_t> insertSeamPoint(ExtrusionLine& closed_line);

Expand Down
49 changes: 5 additions & 44 deletions include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ class LayerPlan : public NoCopy
*/
void setSeamOverhangMask(const Shape& polys);

/*!
* Get the seam overhang mask, which contains the areas where we don't want to place the seam because they are overhanding
*/
const Shape& getSeamOverhangMask() const;

/*!
* Set roofing_mask.
*
Expand Down Expand Up @@ -677,50 +682,6 @@ class LayerPlan : public NoCopy
const bool is_top_layer,
const bool is_bottom_layer);


/*!
* Given a wall polygon and a start vertex index, return the index of the first vertex that is supported (is not above air)
*
* Uses bridge_wall_mask and overhang_mask to determine where there is air below
*
* \param wall The wall polygon
* \param start_idx The index of the starting vertex of \p wall
* \return The index of the first supported vertex - if no vertices are supported, start_idx is returned
*/
template<typename T>
size_t locateFirstSupportedVertex(const T& wall, const size_t start_idx) const
{
if (bridge_wall_mask_.empty() && seam_overhang_mask_.empty())
{
return start_idx;
}

const auto air_below = bridge_wall_mask_.unionPolygons(seam_overhang_mask_);

size_t curr_idx = start_idx;

while (true)
{
const Point2LL& vertex = cura::make_point(wall[curr_idx]);
if (! air_below.inside(vertex, true))
{
// vertex isn't above air so it's OK to use
return curr_idx;
}

if (++curr_idx >= wall.size())
{
curr_idx = 0;
}

if (curr_idx == start_idx)
{
// no vertices are supported so just return the original index
return start_idx;
}
}
}

/*!
* Write the planned paths to gcode
*
Expand Down
278 changes: 178 additions & 100 deletions include/PathOrderOptimizer.h

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions include/path_ordering.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ struct PathOrdering
*/
std::optional<size_t> force_start_index_;

/*!
* The start point calculation strategy to be used for this path
*/
ZSeamConfig seam_config_;

/*!
* Indicates whether this path is an outer (or inner) wall
*/
bool is_outer_wall{ false };

/*!
* Get vertex data from the custom path type.
*
Expand Down
7 changes: 4 additions & 3 deletions include/utils/AABB.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace cura
{

class PointsSet;
class Polygon;
class Shape;

Expand All @@ -21,10 +22,10 @@ class AABB
AABB(); //!< initializes with invalid min and max
AABB(const Point2LL& min, const Point2LL& max); //!< initializes with given min and max
AABB(const Shape& shape); //!< Computes the boundary box for the given shape
AABB(const Polygon& poly); //!< Computes the boundary box for the given polygons
AABB(const PointsSet& poly); //!< Computes the boundary box for the given polygons

void calculate(const Shape& shape); //!< Calculates the aabb for the given shape (throws away old min and max data of this aabb)
void calculate(const Polygon& poly); //!< Calculates the aabb for the given polygon (throws away old min and max data of this aabb)
void calculate(const PointsSet& poly); //!< Calculates the aabb for the given polygon (throws away old min and max data of this aabb)

/*!
* Whether the bounding box contains the specified point.
Expand Down Expand Up @@ -80,7 +81,7 @@ class AABB
*/
void include(const Point2LL& point);

void include(const Polygon& polygon);
void include(const PointsSet& polygon);

/*!
* \brief Includes the specified bounding box in the bounding box.
Expand Down
31 changes: 31 additions & 0 deletions include/utils/CriterionScore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024 Ultimaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef UTILS_CRITERION_SCORE_H
#define UTILS_CRITERION_SCORE_H

namespace cura
{

/*!
* This structure represents a score given by a single crtierion when calculating a global score to select a best
* candidate among a list with multiple criteria.
*/
struct CriterionScore
{
/*!
* The score given by the criterion. To ensure a proper selection, this value must be contained in [0.0, 1.0] and
* the different given scores must be evenly distributed in this range.
*/
double score{ 0.0 };

/*!
* The weight to be given when taking this score into the global score. A score that contributes "normally" to the
* global score should have a weight of 1.0, and others should be adjusted around this value, to give them more or
* less influence.
*/
double weight{ 0.0 };
};

} // namespace cura
#endif // UTILS_CRITERION_SCORE_H
9 changes: 6 additions & 3 deletions include/utils/SVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class SVG : NoCopy
private:
std::string toString(const Color color) const;
std::string toString(const ColorObject& color) const;
void handleFlush(const bool flush) const;

FILE* out_; // the output file
const AABB aabb_; // the boundary box to display
Expand Down Expand Up @@ -122,7 +123,7 @@ class SVG : NoCopy
*/
void writeLines(const std::vector<Point2LL>& polyline, const ColorObject color = Color::BLACK) const;

void writeLine(const Point2LL& a, const Point2LL& b, const ColorObject color = Color::BLACK, const double stroke_width = 1.0) const;
void writeLine(const Point2LL& a, const Point2LL& b, const ColorObject color = Color::BLACK, const double stroke_width = 1.0, const bool flush = true) const;

void writeArrow(const Point2LL& a, const Point2LL& b, const ColorObject color = Color::BLACK, const double stroke_width = 1.0, const double head_size = 5.0) const;

Expand All @@ -148,10 +149,12 @@ class SVG : NoCopy

void writePolygon(Polygon poly, const ColorObject color = Color::BLACK, const double stroke_width = 1.0, const bool flush = true) const;

void writePolylines(const Shape& polys, const ColorObject color = Color::BLACK, const double stroke_width = 1.0) const;
void writePolylines(const Shape& polys, const ColorObject color = Color::BLACK, const double stroke_width = 1.0, const bool flush = true) const;

void writePolyline(const Polygon& poly, const ColorObject color = Color::BLACK, const double stroke_width = 1.0) const;

void writePolyline(const Polyline& poly, const ColorObject color = Color::BLACK, const double stroke_width = 1.0, const bool flush = true) const;

/*!
* Draw variable-width paths into the image.
*
Expand Down Expand Up @@ -183,7 +186,7 @@ class SVG : NoCopy
* \param color The color to draw the line with.
* \param width_factor A multiplicative factor on the line width.
*/
void writeLine(const ExtrusionLine& line, const ColorObject color = Color::BLACK, const double width_factor = 1.0) const;
void writeLine(const ExtrusionLine& line, const ColorObject color = Color::BLACK, const double width_factor = 1.0, const bool flush = true) const;

/*!
* Draws a grid across the image and writes down coordinates.
Expand Down
61 changes: 61 additions & 0 deletions include/utils/Score.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2024 Ultimaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef UTILS_SCORE_H
#define UTILS_SCORE_H

#include <fmt/format.h>

#include "CriterionScore.h"

namespace cura
{

/*!
* This class represents a score to be calculated over different criteria, to select the best candidate among a list.
*/
class Score
{
private:
double value_{ 0.0 };

public:
/*!
* Get the actual score value, should be used for debug purposes only
*/
double getValue() const
{
return value_;
}

/*!
* Add the calculated score of an inidividual criterion to the global score, taking care of its weight
*/
void operator+=(const CriterionScore& criterion_score)
{
value_ += criterion_score.score * criterion_score.weight;
}

/*!
* Comparison operators to allow selecting the best global score
*/
auto operator<=>(const Score&) const = default;
};

} // namespace cura

namespace fmt
{

template<>
struct formatter<cura::Score> : formatter<std::string>
{
auto format(const cura::Score& score, format_context& ctx)
{
return fmt::format_to(ctx.out(), "Score{{{}}}", score.getValue());
}
};

} // namespace fmt

#endif // UTILS_SCORE_H
28 changes: 28 additions & 0 deletions include/utils/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,33 @@ template<utils::multipliable T>
return (dividend + divisor - 1) / divisor;
}

/*!
* \brief Calculates the "inverse linear interpolation" of a value over a range, i.e. given a range [min, max] the
* value "min" would give a result of 0.0 and the value "max" would give a result of 1.0, values in between will
* be interpolated linearly.
* \note The returned value may be out of the [0.0, 1.0] range if the given value is outside the [min, max] range, it is
* up to the caller to clamp the result if required
* \note The range_min value may be greater than the range_max, inverting the interpolation logic
*/
template<utils::numeric T>
[[nodiscard]] inline double inverse_lerp(T range_min, T range_max, T value)
{
if (range_min == range_max)
{
return 0.0;
}

return static_cast<double>(value - range_min) / (range_max - range_min);
}

/*!
* \brief Get a random floating point number in the range [0.0, 1.0]
*/
template<utils::floating_point T>
[[nodiscard]] inline T randf()
{
return static_cast<T>(std::rand()) / static_cast<T>(RAND_MAX);
}

} // namespace cura
#endif // UTILS_MATH_H
Loading

0 comments on commit 16bfaa4

Please sign in to comment.