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

Prime/purge tower optimisation #1875

Merged
merged 89 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
ac86f2a
Basically working version of the optimized prime tower
wawanbreton Apr 6, 2022
e2526fe
Optimized prime tower takes care of extruders with various lines widts
wawanbreton Apr 7, 2022
0bcd1dc
Merge remote-tracking branch 'origin/master' into optimized-prime-tower
wawanbreton Apr 7, 2022
0323644
Minor fix
wawanbreton May 2, 2022
04246e0
Prime tower now takes care of extruders with different lines widths
wawanbreton Jun 6, 2022
0ab6b16
Fixed optimized prime tower first layer
wawanbreton Jun 6, 2022
9f91619
Fixed wrong prime tower generation
wawanbreton Jun 7, 2022
5e5172b
Merge branch 'main' into optimized-prime-tower
wawanbreton Apr 1, 2023
5ee834e
Fixed wrong inset computation
wawanbreton Apr 1, 2023
dcd15aa
Fixed shields generation
wawanbreton Apr 3, 2023
a01543a
Fixed (maybe) unit tests
wawanbreton Apr 3, 2023
685a526
Fixed optimized-consistent generation
wawanbreton Apr 3, 2023
1aad2e2
Merge branch 'main' into optimized-prime-tower
casperlamboo Aug 22, 2023
135e0a5
Applied clang-format.
casperlamboo Aug 22, 2023
d3cf694
Fix build
wawanbreton Sep 5, 2023
a4dfabe
Applied clang-format.
wawanbreton Sep 5, 2023
898450e
Merge remote-tracking branch 'origin-wawanbreton/master' into optimiz…
wawanbreton Sep 12, 2023
a04d26e
Fixed build
wawanbreton Sep 13, 2023
d6fd172
TO BE DISCUSSED removed assert which crashes
wawanbreton Sep 14, 2023
d2e737d
WIP Implement optimized-consistent prime tower
wawanbreton Sep 15, 2023
7f6dfeb
Merge remote-tracking branch 'origin-wawanbreton/master' into optimiz…
wawanbreton Oct 4, 2023
2ee15d8
Basically working architecture for optimized prime tower
wawanbreton Oct 4, 2023
a1b950d
Applied clang-format.
wawanbreton Oct 4, 2023
74a66b9
All prime tower modes basically working
wawanbreton Oct 18, 2023
679537a
Applied clang-format.
wawanbreton Oct 18, 2023
50c8897
Merge remote-tracking branch 'origin-wawanbreton/master' into optimiz…
wawanbreton Nov 2, 2023
6631919
Applied clang-format.
wawanbreton Nov 2, 2023
871ea5e
Fix build
wawanbreton Nov 2, 2023
9e95df4
Restore first layer behavior (WIP)
wawanbreton Nov 3, 2023
3ab4f69
Fix prime tower base/optimized integration issues
wawanbreton Nov 3, 2023
4cd93b8
Now taking care of extruders ordering
wawanbreton Nov 6, 2023
2747f3b
Minor fixes and optimizations
wawanbreton Nov 6, 2023
b9ca023
Minor optimization
wawanbreton Nov 6, 2023
f4b7328
Fixed issue with last layers of optimized-consistent mode
wawanbreton Nov 6, 2023
0011c1d
Applied clang-format.
wawanbreton Nov 8, 2023
a1b3e66
Last tests and code cleaning
wawanbreton Nov 8, 2023
92f0ec2
Merge remote-tracking branch 'origin/main' into optimized-prime-tower
wawanbreton Nov 8, 2023
0b363c8
Remove accidentally-pushed code changes
wawanbreton Nov 8, 2023
588d44d
Applied clang-format.
wawanbreton Nov 8, 2023
e29f675
Restore removed error check
wawanbreton Nov 8, 2023
7f5b45f
Minor last prime tower layers optimizations
wawanbreton Nov 15, 2023
7b9a723
Restore multi-threading
wawanbreton Nov 30, 2023
41c359c
Merge remote-tracking branch 'origin/main' into optimized-prime-tower
wawanbreton Jan 10, 2024
a79170b
Applied clang-format.
wawanbreton Jan 10, 2024
1cf20c1
Split up raft margin setting per raft-type
casperlamboo Jan 8, 2024
211c7a9
Make remove inside corners configurable per raft type
casperlamboo Jan 8, 2024
dc134e5
Applied clang-format.
casperlamboo Jan 8, 2024
3dc1bd2
Make switch state exhaustive
casperlamboo Jan 9, 2024
c3b6558
Use lambda to avoid code duplication
casperlamboo Jan 9, 2024
75dc0ea
Applied clang-format.
casperlamboo Jan 9, 2024
aa9be38
Fix debug build
wawanbreton Jan 9, 2024
d53d330
Fix debug build
wawanbreton Jan 9, 2024
f5925ff
Avoid re-use of setting getters by storing setting-value in local var…
casperlamboo Jan 9, 2024
140cb1d
Remove unused environment variable attachment in lambda
casperlamboo Jan 9, 2024
770effa
Code cleaning
wawanbreton Jan 9, 2024
f720cee
Add slicing time
jellespijker Jan 9, 2024
c840410
use correct relative path
jellespijker Jan 9, 2024
d7d7ffc
Alert on benchmark regression
jellespijker Jan 9, 2024
d3cbcc0
use .time
jellespijker Jan 9, 2024
6ce5a2e
realistic alert value
jellespijker Jan 9, 2024
49d5ec0
different relative path
jellespijker Jan 9, 2024
284d171
Merge remote-tracking branch 'origin/main' into optimized-prime-tower
wawanbreton Jan 10, 2024
0511c4b
Removed default mode which is no more used
wawanbreton Jan 10, 2024
7c46206
Applied clang-format.
wawanbreton Jan 10, 2024
9d8271a
Settings name consistency
wawanbreton Jan 15, 2024
0141f41
Applied clang-format.
wawanbreton Jan 15, 2024
007c39c
Merge remote-tracking branch 'origin/main' into optimized-prime-tower
wawanbreton Jan 17, 2024
2f87df7
Merge branch 'main' into optimized-prime-tower
wawanbreton Jan 17, 2024
0fef7f0
Add point ordering to convex hull algorithm
casperlamboo Jan 11, 2024
727a54d
Also add raft polygons to gcode layer for raft base and middle
casperlamboo Jan 11, 2024
2b9b140
Applied clang-format.
casperlamboo Jan 11, 2024
6bfc431
Fix LayerPlan unit test
casperlamboo Jan 11, 2024
7241031
Fix Polygon unit test
casperlamboo Jan 11, 2024
e9d17a0
Applied clang-format.
casperlamboo Jan 11, 2024
965974d
Don't include holes in convex hull
casperlamboo Jan 11, 2024
3134eca
Fix convex hull in the case where the convex hull consist of islands
casperlamboo Jan 16, 2024
ae03217
Only remove inside corners for the raft poly-islands
casperlamboo Jan 16, 2024
25bca4d
Warn before assert
casperlamboo Jan 16, 2024
6c23889
Update year
casperlamboo Jan 16, 2024
279c196
Use `__FILE__` in favor of `std::source_location`
casperlamboo Jan 17, 2024
9bd9590
fixing holes.wkt file
saumyaj3 Jan 17, 2024
0db09b4
Merge branch 'main' into optimized-prime-tower
wawanbreton Jan 18, 2024
13d7956
Merge remote-tracking branch 'origin/main' into optimized-prime-tower
wawanbreton Jan 25, 2024
6c534e4
Improve code documentation
wawanbreton Jan 25, 2024
4c4c565
Fix Windows build (remove deprecated use of M_PI)
wawanbreton Jan 25, 2024
8907c38
Rename prime tower mode
wawanbreton Feb 9, 2024
7653914
Merge branch 'main' into optimized-prime-tower
jellespijker Feb 16, 2024
aac2a8a
Improve documentation as suggested
wawanbreton Feb 16, 2024
c767d54
Fix crash when using raft with airgap pseudo-layers
wawanbreton Feb 16, 2024
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
18 changes: 18 additions & 0 deletions include/ExtruderPrime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2023 UltiMaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef EXTRUDERPRIME_H
#define EXTRUDERPRIME_H

namespace cura
{

enum class ExtruderPrime
{
None, // Do not prime at all for this extruder on this layer
Sparse, // Just extrude a sparse priming which purpose is to make the tower stronger
Prime, // Do an actual prime
};

} // namespace cura
#endif // EXTRUDERPRIME_H
21 changes: 21 additions & 0 deletions include/ExtruderUse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2023 UltiMaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef EXTRUDERUSE_H
#define EXTRUDERUSE_H

#include "ExtruderPrime.h"

#include <stddef.h>

namespace cura
{

struct ExtruderUse
{
size_t extruder_nr;
ExtruderPrime prime;
};

} // namespace cura
#endif // EXTRUDERUSE_H
7 changes: 4 additions & 3 deletions include/FffGcodeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fstream>
#include <optional>

#include "ExtruderUse.h"
#include "FanSpeedLayerTime.h"
#include "LayerPlanBuffer.h"
#include "gcodeExport.h"
Expand Down Expand Up @@ -64,9 +65,9 @@ class FffGcodeWriter : public NoCopy
* For each raft/filler layer, the extruders to be used in that layer in the order in which they are going to be used.
* The first number is the first raft layer. Indexing is shifted compared to normal negative layer numbers for raft/filler layers.
*/
std::vector<std::vector<size_t>> extruder_order_per_layer_negative_layers;
std::vector<std::vector<ExtruderUse>> extruder_order_per_layer_negative_layers;

std::vector<std::vector<size_t>> extruder_order_per_layer; //!< For each layer, the extruders to be used in that layer in the order in which they are going to be used
std::vector<std::vector<ExtruderUse>> extruder_order_per_layer; //!< For each layer, the extruders to be used in that layer in the order in which they are going to be used

std::vector<std::vector<size_t>> mesh_order_per_extruder; //!< For each extruder, the order of the meshes (first element is first mesh to be printed)

Expand Down Expand Up @@ -296,7 +297,7 @@ class FffGcodeWriter : public NoCopy
* \param current_extruder The current extruder with which we last printed
* \return The order of extruders for a layer beginning with \p current_extruder
*/
std::vector<size_t> getUsedExtrudersOnLayerExcludingStartingExtruder(const SliceDataStorage& storage, const size_t start_extruder, const LayerIndex& layer_nr) const;
std::vector<ExtruderUse> getUsedExtrudersOnLayerExcludingStartingExtruder(const SliceDataStorage& storage, const size_t start_extruder, const LayerIndex& layer_nr) const;

/*!
* Calculate in which order to plan the meshes of a specific extruder
Expand Down
22 changes: 22 additions & 0 deletions include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class LayerPlan : public NoCopy

std::vector<Point2LL> layer_start_pos_per_extruder_; //!< The starting position of a layer for each extruder
std::vector<bool> has_prime_tower_planned_per_extruder_; //!< For each extruder, whether the prime tower is planned yet or not.
bool has_prime_tower_base_planned_; //!< Whether the prime tower base is planned yet or not.
bool has_prime_tower_inset_planned_; //!< Whether the prime tower inset is planned yet or not.
std::optional<Point2LL> last_planned_position_; //!< The last planned XY position of the print head (if known)

std::shared_ptr<const SliceMeshStorage> current_mesh_; //!< The mesh of the last planned move.
Expand Down Expand Up @@ -205,6 +207,26 @@ class LayerPlan : public NoCopy
*/
void setPrimeTowerIsPlanned(unsigned int extruder_nr);

/*!
* Whether the prime tower extra base is already planned.
*/
bool getPrimeTowerBaseIsPlanned() const;

/*!
* Mark the prime tower extra base as planned.
*/
void setPrimeTowerBaseIsPlanned();

/*!
* Whether the prime tower extra inset is already planned.
*/
bool getPrimeTowerInsetIsPlanned() const;

/*!
* Mark the prime tower extra inset as planned.
*/
void setPrimeTowerInsetIsPlanned();

bool getSkirtBrimIsPlanned(unsigned int extruder_nr) const;

void setSkirtBrimIsPlanned(unsigned int extruder_nr);
Expand Down
1 change: 0 additions & 1 deletion include/LayerPlanBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ class LayerPlanBuffer
void handleStandbyTemp(std::vector<ExtruderPlan*>& extruder_plans, unsigned int extruder_plan_idx, double standby_temp);
};


} // namespace cura

#endif // LAYER_PLAN_BUFFER_H
96 changes: 91 additions & 5 deletions include/PrimeTower.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#ifndef PRIME_TOWER_H
#define PRIME_TOWER_H

#include <map>
#include <vector>

#include "ExtruderUse.h"
#include "settings/EnumSettings.h"
#include "settings/types/LayerIndex.h"
#include "utils/polygon.h" // Polygons
#include "utils/polygonUtils.h"


namespace cura
{

Expand Down Expand Up @@ -40,7 +42,17 @@ class PrimeTower
const unsigned int number_of_prime_tower_start_locations_ = 21; //!< The required size of \ref PrimeTower::wipe_locations

MovesByExtruder prime_moves_; //!< For each extruder, the moves to be processed for actual priming.

/*
* The first index is a bitmask representing an extruder combination, e.g. 0x05 for extruders 1+3.
* The second one is the used extruder index, e.g. 1
wawanbreton marked this conversation as resolved.
Show resolved Hide resolved
* The polygons represent the sparse pattern to be printed when all the given extruders are unused for this layer
* and the given extruder is currently in use
*/
std::map<size_t, std::map<size_t, Polygons>> sparse_pattern_per_extruders_;

MovesByLayer base_extra_moves_; //!< For each layer and each extruder, the extra moves to be processed for better adhesion/strength
MovesByExtruder inset_extra_moves_; //!< For each extruder, the extra inset moves to be processed for better adhesion on initial layer

Polygons outer_poly_; //!< The outline of the outermost prime tower.
std::vector<Polygons> outer_poly_base_; //!< The outline of the layers having extra width for the base
Expand Down Expand Up @@ -89,10 +101,16 @@ class PrimeTower
*
* \param storage where to get settings from; where to get the maximum height of the prime tower from
* \param[in,out] gcode_layer Where to get the current extruder from; where to store the generated layer paths
* \param prev_extruder The previous extruder with which paths were planned; from which extruder a switch was made
* \param new_extruder The switched to extruder with which the prime tower paths should be generated.
* \param required_extruder_prime the extruders which actually required to be primed at this layer
* \param prev_extruder_nr The previous extruder with which paths were planned; from which extruder a switch was made
* \param new_extruder_nr The switched to extruder with which the prime tower paths should be generated.
*/
void addToGcode(const SliceDataStorage& storage, LayerPlan& gcode_layer, const size_t prev_extruder, const size_t new_extruder) const;
void addToGcode(
const SliceDataStorage& storage,
LayerPlan& gcode_layer,
const std::vector<ExtruderUse>& required_extruder_prime,
const size_t prev_extruder_nr,
const size_t new_extruder_nr) const;

/*!
* \brief Subtract the prime tower from the support areas in storage.
Expand Down Expand Up @@ -121,8 +139,33 @@ class PrimeTower
*
* Generate the extrude paths for each extruder on even and odd layers
* Fill the ground poly with dense infill.
* \param cumulative_insets [in, out] The insets added to each extruder to compute the radius of its ring
*/
void generatePaths_denseInfill(std::vector<coord_t>& cumulative_insets);

/*!
* \see WipeTower::generatePaths
*
* \brief Generate the sparse extrude paths for each extruders combination
* \param cumulative_insets The insets added to each extruder to compute the radius of its ring
*/
void generatePaths_sparseInfill(const std::vector<coord_t>& cumulative_insets);

/*!
* \brief Generate the sparse extrude paths for an extruders combination
*
* \param first_extruder_nr The index of the first extruder to be pseudo-primed
* \param last_extruder_nr The index of the last extruder to be pseudo-primed
* \param rings_radii The external radii of each extruder ring, plus the internal radius of the internal ring
* \param line_width The actual line width of the extruder
* \param actual_extruder_nr The number of the actual extruder to be used
*/
void generatePaths_denseInfill();
Polygons generatePath_sparseInfill(
const size_t first_extruder_idx,
const size_t last_extruder_idx,
const std::vector<coord_t>& rings_radii,
const coord_t line_width,
const size_t actual_extruder_nr);

/*!
* Generate start locations on the prime tower. The locations are evenly spread around the prime tower's perimeter.
Expand All @@ -143,6 +186,49 @@ class PrimeTower
*/
void addToGcode_denseInfill(LayerPlan& gcode_layer, const size_t extruder) const;

/*!
* \brief Add path plans for the prime tower extra outer rings to make the stronger base
* \param gcode_layer The gcode export to add the paths plans to
* \param extruder_nr The current extruder number
* \return True if something has actually been added, according to the extruder number
* and current layer.
*/
bool addToGcode_base(LayerPlan& gcode_layer, const size_t extruder_nr) const;

/*!
* \brief Add path plans for the prime tower extra inner rings to increase bed adhesion
* \param gcode_layer The gcode export to add the paths plans to
* \param extruder_nr The current extruder number
* \return True if something has actually been added, according to the extruder number
* and current layer.
*/
bool addToGcode_inset(LayerPlan& gcode_layer, const size_t extruder_nr) const;

/*!
* \brief Add path plans in the case an extruder is not to be actually primed, but we still
* want to print something to make the prime tower consistent.
* \param gcode_layer The gcode export to add the paths plans to
* \param extruders_to_prime_idx The indexes of the extra extruders which also don't require being primed on this layer
* \param current_extruder_nr The extruder currently being used
*/
void addToGcode_sparseInfill(LayerPlan& gcode_layer, const std::vector<size_t>& extruders_to_prime_idx, const size_t current_extruder_nr) const;

/*!
* \brief Find the list of extruders that don't actually need to be primed during this layer, and for which
* we want to print only the sparse infill to keep the prime tower consistent.
* \param gcode_layer The current gcode export
* \param required_extruder_prime The pre-computed list of extruders uses during this layer
* \param method The current prime tower strategy
* \param initial_list_idx A list potentially containing extruders that we already know can be used for
* sparse infill
* \return The indexes of extruders to be used for sparse infill
*/
std::vector<size_t> findExtrudersSparseInfill(
LayerPlan& gcode_layer,
const std::vector<ExtruderUse>& required_extruder_prime,
cura::PrimeTowerMethod method,
const std::vector<size_t>& initial_list_idx = {}) const;

/*!
* For an extruder switch that happens not on the first layer, the extruder needs to be primed on the prime tower.
* This function picks a start location for this extruder on the prime tower's perimeter and travels there to avoid
Expand Down
5 changes: 3 additions & 2 deletions include/TreeSupportBaseCircle.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//CuraEngine is released under the terms of the AGPLv3 or higher.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef TREESUPPORTCIRCLE_H
#define TREESUPPORTCIRCLE_H

#include "utils/Coord_t.h"
#include "utils/polygon.h"

#include <cmath>
#include <range/v3/view/iota.hpp>

#include <cmath>

namespace cura
{

Expand Down
4 changes: 2 additions & 2 deletions include/TreeSupportEnums.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//CuraEngine is released under the terms of the AGPLv3 or higher.
// CuraEngine is released under the terms of the AGPLv3 or higher.
#ifndef CURAENGINE_TREESUPPORTENUMS_H
#define CURAENGINE_TREESUPPORTENUMS_H

Expand Down Expand Up @@ -28,6 +28,6 @@ enum class AvoidanceType
COLLISION
};

}//end namespace
} // namespace cura

#endif // CURAENGINE_TREESUPPORTENUMS_H
24 changes: 23 additions & 1 deletion include/settings/EnumSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,28 @@ enum class InsetDirection
PLUGIN,
};

/*!
* Method used for prime tower generation
*/
enum class PrimeTowerMethod
{
/*!
* No prime tower is generated.
*/
NONE,

/*!
* Prime tower that minimizes time and used filament as much as possible.
*/
INTERLEAVED,

/*!
* Prime tower that minimizes time and used filament, but doesn't allow
* for printing two different filaments over each other.
*/
NORMAL,
};

} // namespace cura

#endif // ENUMSETTINGS_H
#endif // ENUMSETTINGS_H
13 changes: 13 additions & 0 deletions include/utils/polygonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,19 @@ class PolygonUtils
*/
static Polygon makeCircle(const Point2LL mid, const coord_t radius, const AngleRadians a_step = std::numbers::pi / 8);

/*!
* Create a "wheel" shape.
*
* This creates a polygon which represents the shape of a wheel.
* \param mid The center of the circle.
* \param inner_radius The radius of the wheel inner circle.
* \param outer_radius The radius of the wheel outer circle.
* \param semi_nb_spokes The semi number of spokes in the wheel. There will actually be N*2 spokes.
* \param arc_angle_resolution The number of segment on each arc.
* \return A new Polygon containing the circle.
*/
static Polygon makeWheel(const Point2LL& mid, const coord_t inner_radius, const coord_t outer_radius, const size_t semi_nb_spokes, const size_t arc_angle_resolution);

/*!
* Connect all polygons to their holes using zero widths hole channels, so that the polygons and their outlines are connected together
*/
Expand Down
4 changes: 3 additions & 1 deletion include/utils/types/get.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ constexpr auto& get(cura::utils::point3d auto& point) noexcept
{
constexpr std::string_view idx = C.value;
static_assert(idx.size() == 1, "Only one character allowed");
static_assert(idx.starts_with("X") || idx.starts_with("x") || idx.starts_with("Y") || idx.starts_with("y") || idx.starts_with("Z") || idx.starts_with("z"), "Index out of bounds");
static_assert(
idx.starts_with("X") || idx.starts_with("x") || idx.starts_with("Y") || idx.starts_with("y") || idx.starts_with("Z") || idx.starts_with("z"),
"Index out of bounds");
if constexpr (idx.starts_with("X") || idx.starts_with("x"))
{
return std::get<0>(point);
Expand Down
Loading
Loading