Skip to content

Commit

Permalink
Refactor "support away from model" to generic "disallowed areas"
Browse files Browse the repository at this point in the history
The specific "support away from model" case has been refactored to a more generic "disallowed areas" in the Insetoptimizer. This adjustment enhances flexibility and allows for potential future utilization in other features.

Related to CURA-11227.
  • Loading branch information
saumyaj3 committed May 2, 2024
1 parent 6777aa0 commit 7229363
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
7 changes: 4 additions & 3 deletions 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 Polygons& disallowed_areas = {});

/*!
* Adds the insets to the given layer plan.
Expand All @@ -64,7 +65,7 @@ class InsetOrderOptimizer
* class, so this optimize function needs no additional information.
* \return Whether anything was added to the layer plan.
*/
bool addToLayer(const bool is_support = false);
bool addToLayer();

/*!
* Get the order constraints of the insets when printing walls per region / hole.
Expand Down Expand Up @@ -106,7 +107,7 @@ class InsetOrderOptimizer
const ZSeamConfig& z_seam_config_;
const std::vector<VariableWidthLines>& paths_;
const LayerIndex layer_nr_;
Polygons mesh_paths_;
Polygons disallowed_areas_;

std::vector<std::vector<ConstPolygonPointer>> inset_polys_; // vector of vectors holding the inset polygons
Polygons 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
7 changes: 4 additions & 3 deletions include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PathOrderOptimizer
public:
using OrderablePath = PathOrdering<Path>;
/* Areas defined here are not allowed to have the start the prints */
Polygons disallowed_area{};
Polygons disallowed_area;
/*!
* After optimizing, this contains the paths that need to be printed in the
* correct order.
Expand Down Expand Up @@ -112,15 +112,16 @@ class PathOrderOptimizer
const Polygons* 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 Polygons& disallowed_areas = {})
: 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{}
, disallowed_area{disallowed_areas}

{
}
Expand Down
23 changes: 20 additions & 3 deletions src/FffGcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3459,7 +3459,23 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
constexpr coord_t wipe_dist = 0;
ZSeamConfig z_seam_config
= ZSeamConfig(EZSeamType::SHORTEST, gcode_layer.getLastPlannedPositionOrStartingPosition(), EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE, false);

Polygons disallowed_area {};
if (infill_extruder.settings_.get<bool>("support_z_seam_away_from_model"))
{
for (std::shared_ptr<SliceMeshStorage> mesh_ptr : storage.meshes)
{
auto& mesh = *mesh_ptr;
for (auto& part : mesh.layers[gcode_layer.getLayerNr()].parts)
{
disallowed_area.add(part.print_outline);
}
}
if (! disallowed_area.empty())
{
coord_t min_distance = infill_extruder.settings_.get<coord_t>("support_z_seam_min_distance");
disallowed_area = disallowed_area.offset(min_distance, ClipperLib::jtRound);
}
}

InsetOrderOptimizer wall_orderer(
*this,
Expand All @@ -3479,8 +3495,9 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
extruder_nr,
extruder_nr,
z_seam_config,
wall_toolpaths);
added_something |= wall_orderer.addToLayer(true);
wall_toolpaths,
disallowed_area);
added_something |= wall_orderer.addToLayer();
}

if ((default_support_line_distance <= 0 && support_structure != ESupportStructure::TREE) || part.infill_area_per_combine_per_density_.empty())
Expand Down
25 changes: 5 additions & 20 deletions src/InsetOrderOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ InsetOrderOptimizer::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 Polygons& disallowed_areas)
: gcode_writer_(gcode_writer)
, storage_(storage)
, gcode_layer_(gcode_layer)
Expand All @@ -70,11 +71,11 @@ InsetOrderOptimizer::InsetOrderOptimizer(
, z_seam_config_(z_seam_config)
, paths_(paths)
, layer_nr_(gcode_layer.getLayerNr())
, mesh_paths_{}
, disallowed_areas_{disallowed_areas}
{
}

bool InsetOrderOptimizer::addToLayer(const bool is_support)
bool InsetOrderOptimizer::addToLayer()
{
// Settings & configs:
const auto pack_by_inset = ! settings_.get<bool>("optimize_wall_printing_order");
Expand All @@ -100,7 +101,7 @@ bool InsetOrderOptimizer::addToLayer(const bool is_support)
// When we alternate walls, also alternate the direction at which the first wall starts in.
// On even layers we start with normal direction, on odd layers with inverted direction.
PathOrderOptimizer<const ExtrusionLine*>
order_optimizer(gcode_layer_.getLastPlannedPositionOrStartingPosition(), z_seam_config_, detect_loops, combing_boundary, reverse, order, group_outer_walls);
order_optimizer(gcode_layer_.getLastPlannedPositionOrStartingPosition(), z_seam_config_, detect_loops, combing_boundary, reverse, order, group_outer_walls, disallowed_areas_);

for (const auto& line : walls_to_be_added)
{
Expand All @@ -113,22 +114,6 @@ bool InsetOrderOptimizer::addToLayer(const bool is_support)
order_optimizer.addPolyline(&line);
}
}
if (is_support && settings_.get<bool>("support_z_seam_away_from_model"))
{
for (std::shared_ptr<SliceMeshStorage> mesh_ptr : storage_.meshes)
{
auto& mesh = *mesh_ptr;
for (auto& part : mesh.layers[layer_nr_].parts)
{
mesh_paths_.add(part.print_outline);
}
}
if (! mesh_paths_.empty())
{
coord_t min_distance = settings_.get<coord_t>("support_z_seam_min_distance");
order_optimizer.disallowed_area = mesh_paths_.offset(min_distance, ClipperLib::jtRound);
}
}

order_optimizer.optimize();

Expand Down

0 comments on commit 7229363

Please sign in to comment.