Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/CURA-9830_consolidate_polygon_cl…
Browse files Browse the repository at this point in the history
…asses' into smaller-prime-tower
  • Loading branch information
wawanbreton committed May 9, 2024
2 parents 7812a0e + 64e94c0 commit dbc1c55
Show file tree
Hide file tree
Showing 186 changed files with 1,958 additions and 2,208 deletions.
5 changes: 3 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Checks: >
-fuchsia-overloaded-operator,
-cppcoreguidelines-avoid-capturing-lambda-coroutines,
-llvm-header-guard,
-bugprone-easily-swappable-parameters
-bugprone-easily-swappable-parameters,
-*-default-arguments-declarations
WarningsAsErrors: '-*'
HeaderFilterRegex: ''
FormatStyle: none
Expand Down Expand Up @@ -52,4 +53,4 @@ CheckOptions:
- key: readability-identifier-length.IgnoredVariableNames
value: '_p|p0|p1|i|j|k|x|X|y|Y|z|Z|a|A|b|B|c|C|d|D|ab|AB|ba|BA|bc|BC|cb|CB|cd|CD|dc|DC|ad|AD|da|DA|ip|os'
- key: readability-identifier-length.IgnoredLoopCounterNames
value: '_p|p0|p1|i|j|k|x|X|y|Y|z|Z|a|A|b|B|c|C|d|D|ab|AB|ba|BA|bc|BC|cb|CB|cd|CD|dc|DC|ad|AD|da|DA|ip|os'
value: '_p|p0|p1|i|j|k|x|X|y|Y|z|Z|a|A|b|B|c|C|d|D|ab|AB|ba|BA|bc|BC|cb|CB|cd|CD|dc|DC|ad|AD|da|DA|ip|os'
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ set(engine_SRCS # Except main.cpp.
src/utils/ToolpathVisualizer.cpp
src/utils/VoronoiUtils.cpp
src/utils/VoxelUtils.cpp
src/utils/mixed_polyline_stitcher.cpp

src/geometry/polygon.cpp
src/geometry/shape.cpp
src/geometry/points_set.cpp
src/geometry/single_shape.cpp
src/geometry/parts_view.cpp
src/geometry/lines_set.cpp
src/geometry/polyline.cpp
src/geometry/closed_polyline.cpp
src/geometry/mixed_lines_set.cpp
src/utils/MixedPolylineStitcher.cpp

src/geometry/Polygon.cpp
src/geometry/Shape.cpp
src/geometry/PointsSet.cpp
src/geometry/SingleShape.cpp
src/geometry/PartsView.cpp
src/geometry/LinesSet.cpp
src/geometry/Polyline.cpp
src/geometry/ClosedPolyline.cpp
src/geometry/MixedLinesSet.cpp
)

add_library(_CuraEngine STATIC ${engine_SRCS} ${engine_PB_SRCS})
Expand Down
6 changes: 4 additions & 2 deletions benchmark/infill_benchmark.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) 2023 UltiMaker
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#ifndef CURAENGINE_INFILL_BENCHMARK_H
#define CURAENGINE_INFILL_BENCHMARK_H

#include <benchmark/benchmark.h>

#include "geometry/open_lines_set.h"
#include "geometry/OpenLinesSet.h"
#include "geometry/OpenPolyline.h"
#include "geometry/LinesSet.h"
#include "infill.h"

namespace cura
Expand Down
2 changes: 1 addition & 1 deletion benchmark/wall_benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "InsetOrderOptimizer.h"
#include "WallsComputation.h"
#include "geometry/polygon.h"
#include "geometry/Polygon.h"
#include "settings/Settings.h"
#include "sliceDataStorage.h"

Expand Down
13 changes: 6 additions & 7 deletions include/BeadingStrategy/BeadingStrategy.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright (c) 2022 Ultimaker B.V.
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#ifndef BEADING_STRATEGY_H
#define BEADING_STRATEGY_H

#include <memory>
#include <numbers>

#include "../settings/types/Angle.h"
#include "../settings/types/Ratio.h" //For the wall transition threshold.
#include "geometry/point2ll.h"
#include "geometry/Point2LL.h"
#include "settings/types/Angle.h"
#include "settings/types/Ratio.h" //For the wall transition threshold.

namespace cura
{
Expand Down Expand Up @@ -45,9 +46,7 @@ class BeadingStrategy

BeadingStrategy(const BeadingStrategy& other);

virtual ~BeadingStrategy()
{
}
virtual ~BeadingStrategy() = default;

/*!
* Retrieve the bead widths with which to cover a given thickness.
Expand Down
6 changes: 4 additions & 2 deletions include/BeadingStrategy/BeadingStrategyFactory.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) 2022 Ultimaker B.V.
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef BEADING_STRATEGY_FACTORY_H
#define BEADING_STRATEGY_FACTORY_H

#include "../settings/types/Ratio.h"
#include <numbers>

#include "BeadingStrategy.h"
#include "settings/types/Ratio.h"

namespace cura
{
Expand Down
4 changes: 2 additions & 2 deletions include/BoostInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <boost/polygon/polygon.hpp>
#include <boost/polygon/voronoi.hpp>

#include "geometry/point2ll.h"
#include "geometry/polygon.h"
#include "geometry/Point2LL.h"
#include "geometry/Polygon.h"
#include "utils/PolygonsSegmentIndex.h"


Expand Down
2 changes: 1 addition & 1 deletion include/ExtruderPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "FanSpeedLayerTime.h"
#include "RetractionConfig.h"
#include "gcodeExport.h"
#include "geometry/point2ll.h"
#include "geometry/Point2LL.h"
#include "pathPlanning/GCodePath.h"
#include "pathPlanning/NozzleTempInsert.h"
#include "pathPlanning/TimeMaterialEstimates.h"
Expand Down
9 changes: 5 additions & 4 deletions include/FffGcodeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

#include "ExtruderUse.h"
#include "FanSpeedLayerTime.h"
#include "GCodePathConfig.h"
#include "LayerPlanBuffer.h"
#include "gcodeExport.h"
#include "settings/MeshPathConfigs.h"
#include "settings/PathConfigStorage.h" //For the MeshPathConfigs subclass.
#include "utils/ExtrusionLine.h" //Processing variable-width paths.
#include "utils/NoCopy.h"
#include "utils/gettime.h"

Expand All @@ -27,6 +25,7 @@ class SliceDataStorage;
class SliceMeshStorage;
class SliceLayer;
class SliceLayerPart;
struct MeshPathConfigs;

/*!
* Secondary stage in Fused Filament Fabrication processing: The generated polygons are used in the gcode generation.
Expand Down Expand Up @@ -299,9 +298,11 @@ class FffGcodeWriter : public NoCopy
*
* \param[in] storage where the slice data is stored.
* \param current_extruder The current extruder with which we last printed
* \param global_extruders_used The extruders that are at some point used for the print job
* \return The order of extruders for a layer beginning with \p current_extruder
*/
std::vector<ExtruderUse> getUsedExtrudersOnLayer(const SliceDataStorage& storage, const size_t start_extruder, const LayerIndex& layer_nr) const;
std::vector<ExtruderUse>
getUsedExtrudersOnLayer(const SliceDataStorage& storage, const size_t start_extruder, const LayerIndex& layer_nr, const std::vector<bool>& global_extruders_used) const;

/*!
* Calculate in which order to plan the meshes of a specific extruder
Expand Down
4 changes: 3 additions & 1 deletion include/InsetOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class InsetOrderOptimizer
const size_t wall_0_extruder_nr,
const size_t wall_x_extruder_nr,
const ZSeamConfig& z_seam_config,
const std::vector<VariableWidthLines>& paths);
const std::vector<VariableWidthLines>& paths,
const Shape& disallowed_areas_for_seams = {});

/*!
* Adds the insets to the given layer plan.
Expand Down Expand Up @@ -106,6 +107,7 @@ class InsetOrderOptimizer
const ZSeamConfig& z_seam_config_;
const std::vector<VariableWidthLines>& paths_;
const LayerIndex layer_nr_;
Shape disallowed_areas_for_seams_;

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
4 changes: 2 additions & 2 deletions include/InterlockingGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <unordered_set>
#include <vector>

#include "geometry/point_matrix.h"
#include "geometry/polygon.h"
#include "geometry/PointMatrix.h"
#include "geometry/Polygon.h"
#include "utils/VoxelUtils.h"

namespace cura
Expand Down
4 changes: 3 additions & 1 deletion include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "PathOrderOptimizer.h"
#include "SpaceFillType.h"
#include "gcodeExport.h"
#include "geometry/polygon.h"
#include "geometry/LinesSet.h"
#include "geometry/OpenLinesSet.h"
#include "geometry/Polygon.h"
#include "pathPlanning/GCodePath.h"
#include "pathPlanning/NozzleTempInsert.h"
#include "pathPlanning/TimeMaterialEstimates.h"
Expand Down
6 changes: 2 additions & 4 deletions include/LayerPlanBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
#include <list>
#include <vector>

#include "ExtruderPlan.h"
#include "LayerPlan.h"
#include "Preheat.h"
#include "gcodeExport.h"
#include "settings/Settings.h"
#include "settings/types/Duration.h"

namespace cura
{


class LayerPlan;
class ExtruderPlan;
class GCodeExport;

/*!
Expand Down
69 changes: 61 additions & 8 deletions include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2023 UltiMaker
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#ifndef PATHORDEROPTIMIZER_H
#define PATHORDEROPTIMIZER_H

#include <numbers>
#include <unordered_set>

#include <range/v3/algorithm/partition_copy.hpp>
Expand All @@ -15,7 +16,6 @@
#include <range/v3/view/reverse.hpp>
#include <spdlog/spdlog.h>

#include "InsetOrderOptimizer.h" // for makeOrderIncludeTransitive
#include "pathPlanning/CombPath.h" //To calculate the combing distance if we want to use combing.
#include "pathPlanning/LinePolygonsCrossings.h" //To prevent calculating combing distances if we don't cross the combing borders.
#include "path_ordering.h"
Expand Down Expand Up @@ -61,6 +61,8 @@ class PathOrderOptimizer
{
public:
using OrderablePath = PathOrdering<Path>;
/* Areas defined here are not allowed to have the start the prints */
Shape disallowed_area_for_seams;
/*!
* After optimizing, this contains the paths that need to be printed in the
* correct order.
Expand Down Expand Up @@ -110,14 +112,17 @@ class PathOrderOptimizer
const Shape* combing_boundary = nullptr,
const bool reverse_direction = false,
const std::unordered_multimap<Path, Path>& order_requirements = no_order_requirements_,
const bool group_outer_walls = false)
const bool group_outer_walls = false,
const Shape& disallowed_areas_for_seams = {})
: start_point_(start_point)
, seam_config_(seam_config)
, combing_boundary_((combing_boundary != nullptr && ! combing_boundary->empty()) ? combing_boundary : nullptr)
, detect_loops_(detect_loops)
, reverse_direction_(reverse_direction)
, _group_outer_walls(group_outer_walls)
, order_requirements_(&order_requirements)
, disallowed_area_for_seams{ disallowed_areas_for_seams }

{
}

Expand Down Expand Up @@ -402,7 +407,7 @@ class PathOrderOptimizer
}

auto local_current_position = current_position;
while (candidates.size() != 0)
while (! candidates.empty())
{
Path best_candidate = findClosestPathVertices(local_current_position, candidates);

Expand Down Expand Up @@ -604,6 +609,52 @@ class PathOrderOptimizer
return best_candidate;
}

/**
* @brief Analyze the positions in a path and determine the next optimal position based on a proximity criterion.
*
* This function iteratively examines positions along the given path, checking if the position is close to 3D model.
* Each position is specified by an index, starting with `best_pos`. If the position is close to the model according to
* `isVertexCloseToPolygonPath` function, the function recursively calls itself with the next position. This process is
* repeated until all positions have been checked or `number_of_paths_analysed` becomes equal to `path_size`.
* If `number_of_paths_analysed` becomes equal to `path_size`, it logs a warning and returns the current best position.
*
* @param best_pos The index of the initial position for analysis in the path.
* @param path An OrderablePath instance containing the path to be examined.
* @param number_of_paths_analysed Optionally, the initial index of paths analysed. Defaults to 0.
* @return The index of the next optimal position in the path sequence. May be the same as the input `best_pos`,
* or may be incremented to a different location based on the proximity criterion.
*
* @note This function uses recursion to evaluate each position in the path.
* @note The process stops prematurely if no start path is found for the support z seam distance.
* This typically happens when the distance of the support seam from the model is bigger than all the support wall points.
*/

size_t pathIfZseamIsInDisallowedArea(size_t best_pos, const OrderablePath& path, size_t number_of_paths_analysed)
{
size_t path_size = path.converted_->size();
if (path_size > number_of_paths_analysed)
{
if (! disallowed_area_for_seams.empty())
{
Point2LL current_candidate = (path.converted_)->at(best_pos);
if (disallowed_area_for_seams.inside(current_candidate, true))
{
size_t next_best_position = (path_size > best_pos + 1) ? best_pos + 1 : 0;
number_of_paths_analysed += 1;
best_pos = pathIfZseamIsInDisallowedArea(next_best_position, path, number_of_paths_analysed);
}
}
}
else
{
spdlog::warn("No start path found for support z seam distance");
// We can also calculate the best point to start at this point.
// This usually happens when the distance of support seam from model is bigger than the whole support wall points.
}
return best_pos;
}


/*!
* Find the vertex which will be the starting point of printing a polygon or
* polyline.
Expand Down Expand Up @@ -633,10 +684,7 @@ class PathOrderOptimizer
{
return path.converted_->size() - 1; // Back end is closer.
}
else
{
return 0; // Front end is closer.
}
return 0; // Front end is closer.
}

// Rest of the function only deals with (closed) polygons. We need to be able to find the seam location of those polygons.
Expand Down Expand Up @@ -674,6 +722,7 @@ class PathOrderOptimizer
// angles > 0 are convex (right turning)

double corner_shift;

if (seam_config_.type_ == EZSeamType::SHORTEST)
{
// the more a corner satisfies our criteria, the closer it appears to be
Expand Down Expand Up @@ -740,6 +789,10 @@ class PathOrderOptimizer
}
}

if (! disallowed_area_for_seams.empty())
{
best_i = pathIfZseamIsInDisallowedArea(best_i, path, 0);
}
return best_i;
}

Expand Down
Loading

0 comments on commit dbc1c55

Please sign in to comment.