Skip to content

Commit

Permalink
Merge branch 'CURA-9830_consolidate_polygon_classes' into CURA-11830_…
Browse files Browse the repository at this point in the history
…smart_seam_unretract
  • Loading branch information
saumyaj3 authored May 2, 2024
2 parents a368605 + 5a2c243 commit ae6c9e3
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 85 deletions.
4 changes: 3 additions & 1 deletion include/FffGcodeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,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
8 changes: 5 additions & 3 deletions include/PrimeTower.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class LayerPlan;
class PrimeTower
{
private:
using MovesByExtruder = std::vector<Shape>;
using MovesByLayer = std::vector<MovesByExtruder>;
using MovesByExtruder = std::map<size_t, Shape>;
using MovesByLayer = std::map<size_t, std::vector<Shape>>;

size_t extruder_count_; //!< Number of extruders

Expand Down Expand Up @@ -79,10 +79,12 @@ class PrimeTower
*/
PrimeTower();

void initializeExtruders(const std::vector<bool>& used_extruders);

/*!
* Check whether we actually use the prime tower.
*/
void checkUsed(const SliceDataStorage& storage);
void checkUsed();

/*!
* Generate the prime tower area to be used on each layer
Expand Down
2 changes: 1 addition & 1 deletion include/infill/NoZigZagConnectorProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class NoZigZagConnectorProcessor : public ZigzagConnectorProcessor
}

void registerVertex(const Point2LL& vertex);
void registerScanlineSegmentIntersection(const Point2LL& intersection, int scanline_index);
void registerScanlineSegmentIntersection(const Point2LL& intersection, int scanline_index, coord_t min_distance_to_scanline);
void registerPolyFinished();
};

Expand Down
15 changes: 3 additions & 12 deletions include/infill/ZigzagConnectorProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class ZigzagConnectorProcessor
* \param intersection The intersection
* \param scanline_index Index of the current scanline
*/
virtual void registerScanlineSegmentIntersection(const Point2LL& intersection, int scanline_index);
virtual void registerScanlineSegmentIntersection(const Point2LL& intersection, int scanline_index, coord_t min_distance_to_scanline);

/*!
* Handle the end of a polygon and prepare for the next.
Expand Down Expand Up @@ -173,17 +173,6 @@ class ZigzagConnectorProcessor
*/
bool shouldAddCurrentConnector(int start_scanline_idx, int end_scanline_idx) const;

/*!
* Checks whether two points are separated at least by "threshold" microns.
* If they are far away from each other enough, the line represented by the two points
* will be added; In case they are close, the second point will be set to be the same
* as the first and this line won't be added.
*
* \param first_point The first of the points
* \param second_point The second of the points
*/
void checkAndAddZagConnectorLine(Point2LL* first_point, Point2LL* second_point);

/*!
* Adds a Zag connector represented by the given points. The last line of the connector will not be
* added if the given connector is an end piece and "connected_endpieces" is not enabled.
Expand All @@ -193,6 +182,8 @@ class ZigzagConnectorProcessor
*/
void addZagConnector(std::vector<Point2LL>& points, bool is_endpiece);

bool handleConnectorTooCloseToSegment(const coord_t scanline_x, const coord_t min_distance_to_scanline);

protected:
const PointMatrix& rotation_matrix_; //!< The rotation matrix used to enforce the infill angle
OpenLinesSet& result_; //!< The result of the computation
Expand Down
3 changes: 1 addition & 2 deletions include/plugins/converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ struct infill_generate_request : public details::converter<infill_generate_reque
};

struct infill_generate_response
: public details::
converter<infill_generate_response, slots::infill::v0::generate::CallResponse, std::tuple<std::vector<std::vector<ExtrusionLine>>, Shape, OpenLinesSet>>
: public details::converter<infill_generate_response, slots::infill::v0::generate::CallResponse, std::tuple<std::vector<std::vector<ExtrusionLine>>, Shape, OpenLinesSet>>
{
native_value_type operator()(const value_type& message) const;
};
Expand Down
14 changes: 10 additions & 4 deletions src/FffGcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <limits> // numeric_limits
#include <list>
#include <memory>
#include <numbers>
#include <numeric>
#include <optional>
#include <unordered_set>
Expand Down Expand Up @@ -1537,12 +1538,13 @@ void FffGcodeWriter::calculateExtruderOrderPerLayer(const SliceDataStorage& stor
}

size_t extruder_count = Application::getInstance().current_slice_->scene.extruders.size();
const std::vector<bool> extruders_used = storage.getExtrudersUsed();
const Settings& mesh_group_settings = Application::getInstance().current_slice_->scene.current_mesh_group->settings;
PrimeTowerMethod prime_tower_mode = mesh_group_settings.get<PrimeTowerMethod>("prime_tower_mode");
for (LayerIndex layer_nr = -Raft::getTotalExtraLayers(); layer_nr < static_cast<LayerIndex>(storage.print_layer_count); layer_nr++)
{
std::vector<std::vector<ExtruderUse>>& extruder_order_per_layer_here = (layer_nr < 0) ? extruder_order_per_layer_negative_layers : extruder_order_per_layer;
std::vector<ExtruderUse> extruder_order = getUsedExtrudersOnLayer(storage, last_extruder, layer_nr);
std::vector<ExtruderUse> extruder_order = getUsedExtrudersOnLayer(storage, last_extruder, layer_nr, extruders_used);
extruder_order_per_layer_here.push_back(extruder_order);

if (! extruder_order.empty())
Expand All @@ -1567,10 +1569,14 @@ void FffGcodeWriter::calculatePrimeLayerPerExtruder(const SliceDataStorage& stor
}
}

std::vector<ExtruderUse> FffGcodeWriter::getUsedExtrudersOnLayer(const SliceDataStorage& storage, const size_t start_extruder, const LayerIndex& layer_nr) const
std::vector<ExtruderUse> FffGcodeWriter::getUsedExtrudersOnLayer(
const SliceDataStorage& storage,
const size_t start_extruder,
const LayerIndex& layer_nr,
const std::vector<bool>& global_extruders_used) const
{
const Settings& mesh_group_settings = Application::getInstance().current_slice_->scene.current_mesh_group->settings;
size_t extruder_count = Application::getInstance().current_slice_->scene.extruders.size();
size_t extruder_count = global_extruders_used.size();
assert(static_cast<int>(extruder_count) > 0);
std::vector<ExtruderUse> ret;
std::vector<bool> extruder_is_used_on_this_layer = storage.getExtrudersUsed(layer_nr);
Expand All @@ -1595,7 +1601,7 @@ std::vector<ExtruderUse> FffGcodeWriter::getUsedExtrudersOnLayer(const SliceData
ordered_extruders.push_back(start_extruder);
for (size_t extruder_nr = 0; extruder_nr < extruder_count; extruder_nr++)
{
if (extruder_nr != start_extruder)
if (extruder_nr != start_extruder && global_extruders_used[extruder_nr])
{
ordered_extruders.push_back(extruder_nr);
}
Expand Down
2 changes: 2 additions & 0 deletions src/FffPolygonGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ void FffPolygonGenerator::slices2polygons(SliceDataStorage& storage, TimeKeeper&

Progress::messageProgressStage(Progress::Stage::SUPPORT, &time_keeper);

storage.primeTower.initializeExtruders(storage.getExtrudersUsed());

AreaSupport::generateOverhangAreas(storage);
AreaSupport::generateSupportAreas(storage);
TreeSupport tree_support_generator(storage);
Expand Down
2 changes: 2 additions & 0 deletions src/Mold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "Mold.h"

#include <numbers>

#include "Application.h" //To get settings.
#include "ExtruderTrain.h"
#include "Scene.h"
Expand Down
62 changes: 33 additions & 29 deletions src/PrimeTower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <algorithm>
#include <limits>
#include <numbers>

#include <spdlog/spdlog.h>

Expand Down Expand Up @@ -52,35 +53,37 @@ PrimeTower::PrimeTower()
&& scene.current_mesh_group->settings.get<coord_t>("prime_tower_size") > 10;

would_have_actual_tower_ = enabled_; // Assume so for now.
}

extruder_count_ = scene.extruders.size();
extruder_order_.resize(extruder_count_);
for (unsigned int extruder_nr = 0; extruder_nr < extruder_count_; extruder_nr++)
void PrimeTower::initializeExtruders(const std::vector<bool>& used_extruders)
{
// Add used extruders in default order, then sort.
for (unsigned int extruder_nr = 0; extruder_nr < used_extruders.size(); extruder_nr++)
{
extruder_order_[extruder_nr] = extruder_nr; // Start with default order, then sort.
if (used_extruders[extruder_nr])
{
extruder_order_.push_back(extruder_nr);
}
}

extruder_count_ = extruder_order_.size();

// Sort from high adhesion to low adhesion.
const Scene* scene_pointer = &scene; // Communicate to lambda via pointer to prevent copy.
const Scene& scene = Application::getInstance().current_slice_->scene;
std::stable_sort(
extruder_order_.begin(),
extruder_order_.end(),
[scene_pointer](const unsigned int& extruder_nr_a, const unsigned int& extruder_nr_b) -> bool
[&scene](const unsigned int& extruder_nr_a, const unsigned int& extruder_nr_b) -> bool
{
const Ratio adhesion_a = scene_pointer->extruders[extruder_nr_a].settings_.get<Ratio>("material_adhesion_tendency");
const Ratio adhesion_b = scene_pointer->extruders[extruder_nr_b].settings_.get<Ratio>("material_adhesion_tendency");
const Ratio adhesion_a = scene.extruders[extruder_nr_a].settings_.get<Ratio>("material_adhesion_tendency");
const Ratio adhesion_b = scene.extruders[extruder_nr_b].settings_.get<Ratio>("material_adhesion_tendency");
return adhesion_a < adhesion_b;
});
}

void PrimeTower::checkUsed(const SliceDataStorage& storage)
void PrimeTower::checkUsed()
{
std::vector<bool> extruder_is_used = storage.getExtrudersUsed();
size_t used_extruder_count = 0;
for (bool is_used : extruder_is_used)
{
used_extruder_count += is_used;
}
if (used_extruder_count <= 1)
if (extruder_count_ <= 1)
{
enabled_ = false;
}
Expand Down Expand Up @@ -108,7 +111,7 @@ void PrimeTower::generateGroundpoly()

void PrimeTower::generatePaths(const SliceDataStorage& storage)
{
checkUsed(storage);
checkUsed();

const int raft_total_extra_layers = Raft::getTotalExtraLayers();
would_have_actual_tower_ = storage.max_print_height_second_to_last_extruder
Expand Down Expand Up @@ -138,9 +141,13 @@ void PrimeTower::generatePaths_denseInfill(std::vector<coord_t>& cumulative_inse
const coord_t base_height = std::max(scene.settings.get<coord_t>("prime_tower_base_height"), has_raft ? layer_height : 0);
const double base_curve_magnitude = mesh_group_settings.get<double>("prime_tower_base_curve_magnitude");

prime_moves_.resize(extruder_count_);
base_extra_moves_.resize(extruder_count_);
inset_extra_moves_.resize(extruder_count_);
for (size_t extruder_nr : extruder_order_)
{
// By default, add empty moves for every extruder
prime_moves_[extruder_nr];
base_extra_moves_[extruder_nr];
inset_extra_moves_[extruder_nr];
}

coord_t cumulative_inset = 0; // Each tower shape is going to be printed inside the other. This is the inset we're doing for each extruder.
for (size_t extruder_nr : extruder_order_)
Expand Down Expand Up @@ -180,7 +187,6 @@ void PrimeTower::generatePaths_denseInfill(std::vector<coord_t>& cumulative_inse
}
extra_radius = line_width * extra_rings;
outer_poly_base_.push_back(outer_poly_.offset(extra_radius));

base_extra_moves_[extruder_nr].push_back(PolygonUtils::generateOutset(outer_poly_, extra_rings, line_width));
}
}
Expand Down Expand Up @@ -226,8 +232,6 @@ void PrimeTower::generatePaths_sparseInfill(const std::vector<coord_t>& cumulati

if (method == PrimeTowerMethod::INTERLEAVED || method == PrimeTowerMethod::NORMAL)
{
const size_t nb_extruders = scene.extruders.size();

// Pre-compute radiuses of each extruder ring
std::vector<coord_t> rings_radii;
const coord_t tower_size = mesh_group_settings.get<coord_t>("prime_tower_size");
Expand All @@ -242,9 +246,9 @@ void PrimeTower::generatePaths_sparseInfill(const std::vector<coord_t>& cumulati
// Generate all possible extruders combinations, e.g. if there are 4 extruders, we have combinations
// 0 / 0-1 / 0-1-2 / 0-1-2-3 / 1 / 1-2 / 1-2-3 / 2 / 2-3 / 3
// A combination is represented by a bitmask
for (size_t first_extruder_idx = 0; first_extruder_idx < nb_extruders; ++first_extruder_idx)
for (size_t first_extruder_idx = 0; first_extruder_idx < extruder_count_; ++first_extruder_idx)
{
size_t nb_extruders_sparse = method == PrimeTowerMethod::NORMAL ? first_extruder_idx + 1 : nb_extruders;
size_t nb_extruders_sparse = method == PrimeTowerMethod::NORMAL ? first_extruder_idx + 1 : extruder_count_;

for (size_t last_extruder_idx = first_extruder_idx; last_extruder_idx < nb_extruders_sparse; ++last_extruder_idx)
{
Expand Down Expand Up @@ -444,7 +448,7 @@ void PrimeTower::addToGcode_denseInfill(LayerPlan& gcode_layer, const size_t ext
{
// Actual prime pattern
const GCodePathConfig& config = gcode_layer.configs_storage_.prime_tower_config_per_extruder[extruder_nr];
const Shape& pattern = prime_moves_[extruder_nr];
const Shape& pattern = prime_moves_.at(extruder_nr);
gcode_layer.addPolygonsByOptimizer(pattern, config);
}
}
Expand All @@ -454,11 +458,11 @@ bool PrimeTower::addToGcode_base(LayerPlan& gcode_layer, const size_t extruder_n
const size_t raft_total_extra_layers = Raft::getTotalExtraLayers();
LayerIndex absolute_layer_number = gcode_layer.getLayerNr() + raft_total_extra_layers;

const std::vector<Shape>& pattern_extra_brim = base_extra_moves_[extruder_nr];
const auto& pattern_extra_brim = base_extra_moves_.at(extruder_nr);
if (absolute_layer_number < pattern_extra_brim.size())
{
// Extra rings for stronger base
const Shape& pattern = pattern_extra_brim[absolute_layer_number];
const auto& pattern = pattern_extra_brim[absolute_layer_number];
if (! pattern.empty())
{
const GCodePathConfig& config = gcode_layer.configs_storage_.prime_tower_config_per_extruder[extruder_nr];
Expand All @@ -477,7 +481,7 @@ bool PrimeTower::addToGcode_inset(LayerPlan& gcode_layer, const size_t extruder_

if (absolute_layer_number == 0) // Extra-adhesion on very first layer only
{
const Shape& pattern_extra_inset = inset_extra_moves_[extruder_nr];
const Shape& pattern_extra_inset = inset_extra_moves_.at(extruder_nr);
if (! pattern_extra_inset.empty())
{
const GCodePathConfig& config = gcode_layer.configs_storage_.prime_tower_config_per_extruder[extruder_nr];
Expand Down
1 change: 1 addition & 0 deletions src/SkeletalTrapezoidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "SkeletalTrapezoidation.h"

#include <functional>
#include <numbers>
#include <queue>
#include <sstream>
#include <stack>
Expand Down
7 changes: 4 additions & 3 deletions src/TreeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,9 +2023,10 @@ void TreeSupport::filterFloatingLines(std::vector<Shape>& support_layer_storage)
return;
}

Shape outer_walls
= TreeSupportUtils::toPolylines(support_layer_storage[layer_idx - 1].getOutsidePolygons())
.createTubeShape(closing_dist, 0); //.unionPolygons(volumes_.getCollision(0, layer_idx - 1, true).offset(-(config.support_line_width+config.xy_min_distance)));
Shape outer_walls = TreeSupportUtils::toPolylines(support_layer_storage[layer_idx - 1].getOutsidePolygons())
.createTubeShape(
closing_dist,
0); //.unionPolygons(volumes_.getCollision(0, layer_idx - 1, true).offset(-(config.support_line_width+config.xy_min_distance)));

Shape holes_below;

Expand Down
1 change: 1 addition & 0 deletions src/TreeSupportTipGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <chrono>
#include <fstream>
#include <numbers>
#include <stdio.h>
#include <string>

Expand Down
7 changes: 4 additions & 3 deletions src/gcodeExport.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) 2023 UltiMaker
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#include "gcodeExport.h"

#include <assert.h>
#include <cassert>
#include <cmath>
#include <cstdarg>
#include <iomanip>
#include <stdarg.h>
#include <numbers>

#include <spdlog/spdlog.h>

Expand Down
7 changes: 4 additions & 3 deletions src/infill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <algorithm> //For std::sort.
#include <functional>
#include <numbers>
#include <unordered_set>

#include <scripta/logger.h>
Expand Down Expand Up @@ -738,12 +739,12 @@ void Infill::generateLinearBasedInfill(

for (int scanline_idx = scanline_idx0; scanline_idx != scanline_idx1 + direction; scanline_idx += direction)
{
int x = scanline_idx * line_distance + shift;
int y = p1.Y + (p0.Y - p1.Y) * (x - p1.X) / (p0.X - p1.X);
const int x = scanline_idx * line_distance + shift;
const int y = p1.Y + (p0.Y - p1.Y) * (x - p1.X) / (p0.X - p1.X);
assert(scanline_idx - scanline_min_idx >= 0 && scanline_idx - scanline_min_idx < int(cut_list.size()) && "reading infill cutlist index out of bounds!");
cut_list[scanline_idx - scanline_min_idx].push_back(y);
Point2LL scanline_linesegment_intersection(x, y);
zigzag_connector_processor.registerScanlineSegmentIntersection(scanline_linesegment_intersection, scanline_idx);
zigzag_connector_processor.registerScanlineSegmentIntersection(scanline_linesegment_intersection, scanline_idx, line_distance / 4);
crossings_per_scanline[scanline_idx - min_scanline_index].emplace_back(scanline_linesegment_intersection, poly_idx, point_idx);
}
zigzag_connector_processor.registerVertex(p1);
Expand Down
4 changes: 3 additions & 1 deletion src/infill/GyroidInfill.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) 2022 Ultimaker B.V.
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher.

#include "infill/GyroidInfill.h"

#include <numbers>

#include "geometry/OpenPolyline.h"
#include "geometry/Polygon.h"
#include "geometry/Shape.h"
Expand Down
Loading

0 comments on commit ae6c9e3

Please sign in to comment.