Skip to content

Commit

Permalink
Re implement wall roofing (#2021)
Browse files Browse the repository at this point in the history
  • Loading branch information
saumyaj3 authored Jan 29, 2024
2 parents 94543ac + 0ad6a45 commit 8085fd0
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 61 deletions.
14 changes: 9 additions & 5 deletions include/InsetOrderOptimizer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Ultimaker B.V.
// Copyright (c) 2024 Ultimaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher

#ifndef INSET_ORDER_OPTIMIZER_H
Expand Down Expand Up @@ -43,8 +43,10 @@ class InsetOrderOptimizer
LayerPlan& gcode_layer,
const Settings& settings,
const int extruder_nr,
const GCodePathConfig& inset_0_non_bridge_config,
const GCodePathConfig& inset_X_non_bridge_config,
const GCodePathConfig& inset_0_default_config,
const GCodePathConfig& inset_X_default_config,
const GCodePathConfig& inset_0_roofing_config,
const GCodePathConfig& inset_X_roofing_config,
const GCodePathConfig& inset_0_bridge_config,
const GCodePathConfig& inset_X_bridge_config,
const bool retract_before_outer_wall,
Expand Down Expand Up @@ -90,8 +92,10 @@ class InsetOrderOptimizer
LayerPlan& gcode_layer_;
const Settings& settings_;
const size_t extruder_nr_;
const GCodePathConfig& inset_0_non_bridge_config_;
const GCodePathConfig& inset_X_non_bridge_config_;
const GCodePathConfig& inset_0_default_config_;
const GCodePathConfig& inset_X_default_config_;
const GCodePathConfig& inset_0_roofing_config_;
const GCodePathConfig& inset_X_roofing_config_;
const GCodePathConfig& inset_0_bridge_config_;
const GCodePathConfig& inset_X_bridge_config_;
const bool retract_before_outer_wall_;
Expand Down
49 changes: 34 additions & 15 deletions include/LayerPlan.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 UltiMaker
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#ifndef LAYER_PLAN_H
Expand Down Expand Up @@ -96,6 +96,7 @@ class LayerPlan : public NoCopy
coord_t comb_move_inside_distance_; //!< Whenever using the minimum boundary for combing it tries to move the coordinates inside by this distance after calculating the combing.
Polygons bridge_wall_mask_; //!< The regions of a layer part that are not supported, used for bridging
Polygons overhang_mask_; //!< The regions of a layer part where the walls overhang
Polygons roofing_mask_; //!< The regions of a layer part where the walls are exposed to the air

const std::vector<FanSpeedLayerTimeSettings> fan_speed_layer_time_settings_per_extruder_;

Expand Down Expand Up @@ -257,6 +258,13 @@ class LayerPlan : public NoCopy
*/
void setOverhangMask(const Polygons& polys);

/*!
* Set roofing_mask.
*
* \param polys The areas of the part currently being processed that will require roofing.
*/
void setRoofingMask(const Polygons& polys);

/*!
* Travel to a certain point, with all of the procedures necessary to do so.
*
Expand Down Expand Up @@ -395,8 +403,10 @@ class LayerPlan : public NoCopy
* \param p1 The end vertex of the line.
* \param settings The settings which should apply to this line added to the
* layer plan.
* \param non_bridge_config The config with which to print the wall lines
* that are not spanning a bridge.
* \param default_config The config with which to print the wall lines
* that are not spanning a bridge or are exposed to air.
* \param roofing_config The config with which to print the wall lines
* that are exposed to air.
* \param bridge_config The config with which to print the wall lines that
* are spanning a bridge.
* \param flow The ratio with which to multiply the extrusion amount.
Expand All @@ -413,7 +423,8 @@ class LayerPlan : public NoCopy
const Point2LL& p0,
const Point2LL& p1,
const Settings& settings,
const GCodePathConfig& non_bridge_config,
const GCodePathConfig& default_config,
const GCodePathConfig& roofing_config,
const GCodePathConfig& bridge_config,
double flow,
const Ratio width_factor,
Expand All @@ -426,10 +437,10 @@ class LayerPlan : public NoCopy
* \param wall The vertices of the wall to add.
* \param start_idx The index of the starting vertex to start at.
* \param settings The settings which should apply to this wall added to the layer plan.
* \param non_bridge_config The config with which to print the wall lines
* that are not spanning a bridge.
* \param bridge_config The config with which to print the wall lines that
* are spanning a bridge.
* \param default_config The config with which to print the wall lines
* that are not spanning a bridge or are exposed to air.
* \param roofing_config The config with which to print the wall lines
* that are exposed to air.
* \param wall_0_wipe_dist The distance to travel along the wall after it
* has been laid down, in order to wipe the start and end of the wall
* \param flow_ratio The ratio with which to multiply the extrusion amount.
Expand All @@ -440,7 +451,8 @@ class LayerPlan : public NoCopy
ConstPolygonRef wall,
int start_idx,
const Settings& settings,
const GCodePathConfig& non_bridge_config,
const GCodePathConfig& default_config,
const GCodePathConfig& roofing_config,
const GCodePathConfig& bridge_config,
coord_t wall_0_wipe_dist,
double flow_ratio,
Expand All @@ -451,8 +463,10 @@ class LayerPlan : public NoCopy
* \param wall The wall of type ExtrusionJunctions
* \param start_idx The index of the starting vertex to start at.
* \param mesh The current mesh being added to the layer plan.
* \param non_bridge_config The config with which to print the wall lines
* that are not spanning a bridge.
* \param default_config The config with which to print the wall lines
* that are not spanning a bridge or are exposed to air.
* \param roofing_config The config with which to print the wall lines
* that are exposed to air.
* \param bridge_config The config with which to print the wall lines that
* are spanning a bridge
* \param wall_0_wipe_dist The distance to travel along the wall after it
Expand All @@ -469,7 +483,8 @@ class LayerPlan : public NoCopy
const ExtrusionLine& wall,
int start_idx,
const Settings& settings,
const GCodePathConfig& non_bridge_config,
const GCodePathConfig& default_config,
const GCodePathConfig& roofing_config,
const GCodePathConfig& bridge_config,
coord_t wall_0_wipe_dist,
double flow_ratio,
Expand All @@ -490,7 +505,10 @@ class LayerPlan : public NoCopy
* Add walls (polygons) to the gcode with optimized order.
* \param walls The walls
* \param settings The settings which should apply to these walls added to the layer plan.
* \param non_bridge_config The config with which to print the wall lines that are not spanning a bridge
* \param default_config The config with which to print the wall lines
* that are not spanning a bridge or are exposed to air.
* \param roofing_config The config with which to print the wall lines
* that are exposed to air.
* \param bridge_config The config with which to print the wall lines that are spanning a bridge
* \param z_seam_config Optional configuration for z-seam
* \param wall_0_wipe_dist The distance to travel along each wall after it has been laid down, in order to wipe the start and end of the wall together
Expand All @@ -501,7 +519,8 @@ class LayerPlan : public NoCopy
void addWalls(
const Polygons& walls,
const Settings& settings,
const GCodePathConfig& non_bridge_config,
const GCodePathConfig& default_config,
const GCodePathConfig& roofing_config,
const GCodePathConfig& bridge_config,
const ZSeamConfig& z_seam_config = ZSeamConfig(),
coord_t wall_0_wipe_dist = 0,
Expand Down Expand Up @@ -625,7 +644,7 @@ class LayerPlan : public NoCopy
return start_idx;
}

Polygons air_below(bridge_wall_mask_.unionPolygons(overhang_mask_));
const auto air_below = bridge_wall_mask_.unionPolygons(overhang_mask_);

unsigned curr_idx = start_idx;

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

#include "FffGcodeWriter.h"
Expand Down Expand Up @@ -690,6 +690,8 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
config,
config,
config,
config,
config,
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down Expand Up @@ -851,6 +853,8 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
config,
config,
config,
config,
config,
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down Expand Up @@ -1043,6 +1047,8 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
config,
config,
config,
config,
config,
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down Expand Up @@ -2239,6 +2245,8 @@ bool FffGcodeWriter::processSingleLayerInfill(
mesh_config.infill_config[0],
mesh_config.infill_config[0],
mesh_config.infill_config[0],
mesh_config.infill_config[0],
mesh_config.infill_config[0],
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down Expand Up @@ -2587,13 +2595,37 @@ bool FffGcodeWriter::processInsets(
Polygons overhang_region = part.outline.offset(-half_outer_wall_width).difference(outlines_below.offset(10 + overhang_width - half_outer_wall_width)).offset(10);
gcode_layer.setOverhangMask(overhang_region);
}

const auto roofing_mask = [&gcode_layer, &mesh, &boundaryBox]() -> Polygons
{
const size_t roofing_layer_count = std::min(mesh.settings.get<size_t>("roofing_layer_count"), mesh.settings.get<size_t>("top_layers"));

if (gcode_layer.getLayerNr() + roofing_layer_count >= mesh.layers.size())
{
return Polygons();
}

auto roofing_mask = Polygons();
for (const auto& layer_part : mesh.layers[gcode_layer.getLayerNr() + roofing_layer_count].parts)
{
if (boundaryBox.hit(layer_part.boundaryBox))
{
roofing_mask.add(layer_part.outline);
}
}
return roofing_mask;
}();

gcode_layer.setRoofingMask(roofing_mask);
}
else
{
// clear to disable use of bridging settings
gcode_layer.setBridgeWallMask(Polygons());
// clear to disable overhang detection
gcode_layer.setOverhangMask(Polygons());
// clear to disable use of roofing settings
gcode_layer.setRoofingMask(Polygons());
}

if (spiralize && extruder_nr == mesh.settings.get<ExtruderTrain&>("wall_0_extruder_nr").extruder_nr_ && ! part.spiral_wall.empty())
Expand All @@ -2611,16 +2643,11 @@ bool FffGcodeWriter::processInsets(
else
{
// Print the spiral walls of other parts as single walls without Z gradient.
gcode_layer.addWalls(part.spiral_wall, mesh.settings, mesh_config.inset0_config, mesh_config.inset0_config);
gcode_layer.addWalls(part.spiral_wall, mesh.settings, mesh_config.inset0_config, mesh_config.inset0_config, mesh_config.inset0_config);
}
}
else
{
// TODO use roofing config for layers-parts that are exposed to air
auto use_roofing_config = false;
const GCodePathConfig& inset0_config = use_roofing_config ? mesh_config.inset0_roofing_config : mesh_config.inset0_config;
const GCodePathConfig& insetX_config = use_roofing_config ? mesh_config.insetX_roofing_config : mesh_config.insetX_config;

// Main case: Optimize the insets with the InsetOrderOptimizer.
const coord_t wall_x_wipe_dist = 0;
const ZSeamConfig z_seam_config(
Expand All @@ -2634,8 +2661,10 @@ bool FffGcodeWriter::processInsets(
gcode_layer,
mesh.settings,
extruder_nr,
inset0_config,
insetX_config,
mesh_config.inset0_config,
mesh_config.insetX_config,
mesh_config.inset0_roofing_config,
mesh_config.insetX_roofing_config,
mesh_config.bridge_inset0_config,
mesh_config.bridge_insetX_config,
mesh.settings.get<bool>("travel_retract_before_outer_wall"),
Expand Down Expand Up @@ -3061,6 +3090,8 @@ void FffGcodeWriter::processSkinPrintFeature(
config,
config,
config,
config,
config,
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down Expand Up @@ -3324,6 +3355,8 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
config,
config,
config,
config,
config,
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down Expand Up @@ -3500,6 +3533,8 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
config,
config,
config,
config,
config,
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down Expand Up @@ -3636,6 +3671,8 @@ bool FffGcodeWriter::addSupportRoofsToGCode(
config,
config,
config,
config,
config,
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down Expand Up @@ -3747,6 +3784,8 @@ bool FffGcodeWriter::addSupportBottomsToGCode(const SliceDataStorage& storage, L
config,
config,
config,
config,
config,
retract_before_outer_wall,
wipe_dist,
wipe_dist,
Expand Down
37 changes: 28 additions & 9 deletions src/InsetOrderOptimizer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 UltiMaker
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#include "InsetOrderOptimizer.h"
Expand Down Expand Up @@ -38,8 +38,10 @@ InsetOrderOptimizer::InsetOrderOptimizer(
LayerPlan& gcode_layer,
const Settings& settings,
const int extruder_nr,
const GCodePathConfig& inset_0_non_bridge_config,
const GCodePathConfig& inset_X_non_bridge_config,
const GCodePathConfig& inset_0_default_config,
const GCodePathConfig& inset_X_default_config,
const GCodePathConfig& inset_0_roofing_config,
const GCodePathConfig& inset_X_roofing_config,
const GCodePathConfig& inset_0_bridge_config,
const GCodePathConfig& inset_X_bridge_config,
const bool retract_before_outer_wall,
Expand All @@ -54,8 +56,10 @@ InsetOrderOptimizer::InsetOrderOptimizer(
, gcode_layer_(gcode_layer)
, settings_(settings)
, extruder_nr_(extruder_nr)
, inset_0_non_bridge_config_(inset_0_non_bridge_config)
, inset_X_non_bridge_config_(inset_X_non_bridge_config)
, inset_0_default_config_(inset_0_default_config)
, inset_X_default_config_(inset_X_default_config)
, inset_0_roofing_config_(inset_0_roofing_config)
, inset_X_roofing_config_(inset_X_roofing_config)
, inset_0_bridge_config_(inset_0_bridge_config)
, inset_X_bridge_config_(inset_X_bridge_config)
, retract_before_outer_wall_(retract_before_outer_wall)
Expand Down Expand Up @@ -114,23 +118,38 @@ bool InsetOrderOptimizer::addToLayer()
for (const PathOrdering<const ExtrusionLine*>& path : order_optimizer.paths_)
{
if (path.vertices_->empty())
{
continue;
}

const bool is_outer_wall = path.vertices_->inset_idx_ == 0; // or thin wall 'gap filler'
const bool is_gap_filler = path.vertices_->is_odd_;
const GCodePathConfig& non_bridge_config = is_outer_wall ? inset_0_non_bridge_config_ : inset_X_non_bridge_config_;
const GCodePathConfig& default_config = is_outer_wall ? inset_0_default_config_ : inset_X_default_config_;
const GCodePathConfig& roofing_config = is_outer_wall ? inset_0_roofing_config_ : inset_X_roofing_config_;
const GCodePathConfig& bridge_config = is_outer_wall ? inset_0_bridge_config_ : inset_X_bridge_config_;
const coord_t wipe_dist = is_outer_wall && ! is_gap_filler ? wall_0_wipe_dist_ : wall_x_wipe_dist_;
const bool retract_before = is_outer_wall ? retract_before_outer_wall_ : false;

const bool revert_inset = alternate_walls && (path.vertices_->inset_idx_ % 2);
const bool revert_layer = alternate_walls && (layer_nr_ % 2);
const bool revert_inset = alternate_walls && (path.vertices_->inset_idx_ % 2 != 0);
const bool revert_layer = alternate_walls && (layer_nr_ % 2 != 0);
const bool backwards = path.backwards_ != (revert_inset != revert_layer);
const size_t start_index = (backwards != path.backwards_) ? path.vertices_->size() - (path.start_vertex_ + 1) : path.start_vertex_;
const bool linked_path = ! path.is_closed_;

gcode_layer_.setIsInside(true); // Going to print walls, which are always inside.
gcode_layer_.addWall(*path.vertices_, start_index, settings_, non_bridge_config, bridge_config, wipe_dist, flow, retract_before, path.is_closed_, backwards, linked_path);
gcode_layer_.addWall(
*path.vertices_,
start_index,
settings_,
default_config,
roofing_config,
bridge_config,
wipe_dist,
flow,
retract_before,
path.is_closed_,
backwards,
linked_path);
added_something = true;
}
return added_something;
Expand Down
Loading

0 comments on commit 8085fd0

Please sign in to comment.