Skip to content

Commit

Permalink
Implement functionality to select whether cradle lines should be prin…
Browse files Browse the repository at this point in the history
…ted towards the model, or away from it.
  • Loading branch information
ThomasRahm committed Nov 4, 2024
1 parent 340e70f commit d7d1f71
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 31 deletions.
12 changes: 10 additions & 2 deletions include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class PathOrderOptimizer

// For some Z seam types the start position can be pre-computed.
// This is faster since we don't need to re-compute the start position at each step then.
precompute_start &= seam_config_.type_ == EZSeamType::RANDOM || seam_config_.type_ == EZSeamType::USER_SPECIFIED || seam_config_.type_ == EZSeamType::SHARPEST_CORNER;
precompute_start &= seam_config_.type_ == EZSeamType::RANDOM || seam_config_.type_ == EZSeamType::USER_SPECIFIED || seam_config_.type_ == EZSeamType::INTERNAL_SPECIFIED || seam_config_.type_ == EZSeamType::SHARPEST_CORNER;
if (precompute_start)
{
for (auto& path : paths_)
Expand Down Expand Up @@ -584,7 +584,7 @@ class PathOrderOptimizer
}

const bool precompute_start
= seam_config_.type_ == EZSeamType::RANDOM || seam_config_.type_ == EZSeamType::USER_SPECIFIED || seam_config_.type_ == EZSeamType::SHARPEST_CORNER;
= seam_config_.type_ == EZSeamType::RANDOM || seam_config_.type_ == EZSeamType::USER_SPECIFIED || seam_config_.type_ == EZSeamType::INTERNAL_SPECIFIED ||seam_config_.type_ == EZSeamType::SHARPEST_CORNER;
if (! path->is_closed_ || ! precompute_start) // Find the start location unless we've already precomputed it.
{
path->start_vertex_ = findStartLocation(*path, start_position);
Expand Down Expand Up @@ -676,6 +676,14 @@ class PathOrderOptimizer
{
if (! path.is_closed_)
{
if (seam_config_.type_ == EZSeamType::INTERNAL_SPECIFIED)
{
if(getDirectDistance(path.converted_->back(), seam_config_.pos_) < getDirectDistance(path.converted_->front(), seam_config_.pos_))
{
return path.converted_->size() - 1; // Back end is closer.
}
return 0;
}
// For polylines, the seam settings are not applicable. Simply choose the position closest to target_pos then.
const coord_t back_distance
= (combing_boundary_ == nullptr) ? getDirectDistance(path.converted_->back(), target_pos) : getCombingDistance(path.converted_->back(), target_pos);
Expand Down
11 changes: 10 additions & 1 deletion include/SupportInfillPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef SUPPORT_INFILL_PART_H
#define SUPPORT_INFILL_PART_H

#include <optional>
#include <vector>

#include "geometry/Polygon.h"
Expand Down Expand Up @@ -38,8 +39,16 @@ class SupportInfillPart
coord_t custom_line_distance_; //!< The distance between support infill lines. 0 means use the default line distance instead.
bool use_fractional_config_; //!< Request to use the configuration used to fill a partial layer height here, instead of the normal full layer height configuration.
EFillMethod custom_line_pattern_;
std::optional<Point2LL> start_near_location;

SupportInfillPart(const SingleShape& outline, coord_t support_line_width, bool use_fractional_config, int inset_count_to_generate = 0, coord_t custom_line_distance = 0, EFillMethod custom_line_pattern = EFillMethod::NONE );
SupportInfillPart(const SingleShape& outline,
coord_t support_line_width,
bool use_fractional_config,
int inset_count_to_generate = 0,
coord_t custom_line_distance = 0,
EFillMethod custom_line_pattern = EFillMethod::NONE,
std::optional<Point2LL> start_near_location = std::optional<Point2LL>()
);

const Shape& getInfillArea() const;
};
Expand Down
4 changes: 2 additions & 2 deletions include/TreeSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class TreeSupport
* \param support_roof_extra_wall_storage_fractional[in] Areas of roof that were projected one layer up, but roofs need to have a wall to print correctly.
* \param fake_roof_areas_combined[out] All areas that contain the fake roofs.
* \param cradle_base_areas[out] Copy of all cradle base areas. Already added to correct storage.
* \param cradle_support_line_areas[out] All cradle lines consisting of regular support. Will still have to be added as support (Done in generateSupportSkin)
* \param cradle_support_line_areas[out] All cradle lines consisting of regular support. Already added as support.
* \param storage[in,out] The storage where the support should be stored.
* \param cradle_data[in] All currently existing cradles, with its corresponding cradle lines.
*/
Expand Down Expand Up @@ -371,7 +371,7 @@ class TreeSupport
* \param support_skin_storage[out] Areas where high density support should be generated.
* \param fake_roof_areas_combined[in] All areas that contain the fake roofs.
* \param cradle_base_areas[in] Copy of all cradle base areas. Already added to correct storage.
* \param cradle_support_line_areas[in] All cradle lines consisting of regular support. Will be to be added as support.
* \param cradle_support_line_areas[in] All cradle lines consisting of regular support. Already added as support.
* \param hole_parts[in] Parts of holes, ordered by layer.
* \param valid_holes[in] Indices of holes that rest on outer wall, by layer.
* \param non_removable_holes[in] Indices of holes that can not be removed, by layer.
Expand Down
1 change: 1 addition & 0 deletions include/settings/EnumSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum class EZSeamType
SHORTEST,
USER_SPECIFIED,
SHARPEST_CORNER,
INTERNAL_SPECIFIED,

/* The 'Skirt/brim' type behaves like shortest, except it doesn't try to do tie-breaking for similar locations to
* the last attempt, as that gives a different result when the seams are next to each other instead of on top.
Expand Down
26 changes: 16 additions & 10 deletions src/FffGcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,8 +3425,10 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
constexpr bool retract_before_outer_wall = false;
constexpr coord_t wipe_dist = 0;
const LayerIndex layer_nr = gcode_layer.getLayerNr();
ZSeamConfig z_seam_config
= ZSeamConfig(EZSeamType::SHORTEST, gcode_layer.getLastPlannedPositionOrStartingPosition(), EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE, false);
const ZSeamConfig z_seam_config(part.start_near_location.has_value() ? EZSeamType::INTERNAL_SPECIFIED : EZSeamType::SHORTEST,
part.start_near_location.has_value() ? part.start_near_location.value() : gcode_layer.getLastPlannedPositionOrStartingPosition(),
EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE,
false);
Shape disallowed_area_for_seams{};
if (infill_extruder.settings_.get<bool>("support_z_seam_away_from_model") && (layer_nr >= 0))
{
Expand Down Expand Up @@ -3580,7 +3582,6 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
constexpr bool spiralize = false;
constexpr Ratio flow_ratio = 1.0_r;
constexpr bool always_retract = false;
const std::optional<Point2LL> start_near_location = std::optional<Point2LL>();

gcode_layer.addPolygonsByOptimizer(
support_polygons,
Expand All @@ -3591,7 +3592,7 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
flow_ratio,
always_retract,
alternate_layer_print_direction,
start_near_location);
part.start_near_location);
added_something = true;
}

Expand All @@ -3600,7 +3601,6 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
constexpr bool enable_travel_optimization = false;
constexpr coord_t wipe_dist = 0;
constexpr Ratio flow_ratio = 1.0;
const std::optional<Point2LL> near_start_location = std::optional<Point2LL>();
constexpr double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT;

gcode_layer.addLinesByOptimizer(
Expand All @@ -3610,7 +3610,7 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
enable_travel_optimization,
wipe_dist,
flow_ratio,
near_start_location,
part.start_near_location,
fan_speed,
alternate_layer_print_direction);

Expand Down Expand Up @@ -3715,6 +3715,10 @@ bool FffGcodeWriter::addSupportRoofsToGCode(
constexpr coord_t pocket_size = 0;
const coord_t max_resolution = roof_extruder.settings_.get<coord_t>("meshfix_maximum_resolution");
const coord_t max_deviation = roof_extruder.settings_.get<coord_t>("meshfix_maximum_deviation");
const ZSeamConfig z_seam_config(roof_part.start_near_location.has_value() ? EZSeamType::INTERNAL_SPECIFIED : EZSeamType::SHORTEST,
roof_part.start_near_location.has_value() ? roof_part.start_near_location.value() : gcode_layer.getLastPlannedPositionOrStartingPosition(),
EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE,
false);

coord_t support_roof_line_distance = roof_part.custom_line_distance_ == 0 ? roof_extruder.settings_.get<coord_t>("support_roof_line_distance") : roof_part.custom_line_distance_;
const coord_t support_roof_line_width = roof_extruder.settings_.get<coord_t>("support_roof_line_width");
Expand Down Expand Up @@ -3772,20 +3776,19 @@ bool FffGcodeWriter::addSupportRoofsToGCode(
gcode_layer.setIsInside(false); // going to print stuff outside print object, i.e. support
if (gcode_layer.getLayerNr() == 0)
{
gcode_layer.addPolygonsByOptimizer(wall, current_roof_config);
gcode_layer.addPolygonsByOptimizer(wall, current_roof_config, z_seam_config);
}
if (! roof_polygons.empty())
{
constexpr bool force_comb_retract = false;
gcode_layer.addTravel(roof_polygons[0][0], force_comb_retract);
gcode_layer.addPolygonsByOptimizer(roof_polygons, current_roof_config);
gcode_layer.addPolygonsByOptimizer(roof_polygons, current_roof_config, z_seam_config);
}
if (! roof_paths.empty())
{
const GCodePathConfig& config = current_roof_config;
constexpr bool retract_before_outer_wall = false;
constexpr coord_t wipe_dist = 0;
const ZSeamConfig z_seam_config(EZSeamType::SHORTEST, gcode_layer.getLastPlannedPositionOrStartingPosition(), EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE, false);

InsetOrderOptimizer wall_orderer(
*this,
Expand All @@ -3808,7 +3811,10 @@ bool FffGcodeWriter::addSupportRoofsToGCode(
roof_paths,
storage.getModelBoundingBox().flatten().getMiddle());wall_orderer.addToLayer();
}
gcode_layer.addLinesByOptimizer(roof_lines, current_roof_config, (pattern == EFillMethod::ZIG_ZAG) ? SpaceFillType::PolyLines : SpaceFillType::Lines);
constexpr bool enable_travel_optimization = false;
constexpr coord_t wipe_dist = 0;
constexpr Ratio flow_ratio = 1.0;
gcode_layer.addLinesByOptimizer(roof_lines, current_roof_config, (pattern == EFillMethod::ZIG_ZAG) ? SpaceFillType::PolyLines : SpaceFillType::Lines, enable_travel_optimization, wipe_dist, flow_ratio, roof_part.start_near_location);
}
}
return added_support;
Expand Down
5 changes: 4 additions & 1 deletion src/InsetOrderOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ std::optional<size_t> InsetOrderOptimizer::insertSeamPoint(ExtrusionLine& closed
case EZSeamType::USER_SPECIFIED:
request_point = z_seam_config_.pos_;
break;
case EZSeamType::INTERNAL_SPECIFIED:
request_point = z_seam_config_.pos_;
break;
case EZSeamType::SHORTEST:
request_point = gcode_layer_.getLastPlannedPositionOrStartingPosition();
break;
Expand All @@ -195,7 +198,7 @@ std::optional<size_t> InsetOrderOptimizer::insertSeamPoint(ExtrusionLine& closed
size_t closest_junction_idx = 0;
coord_t closest_distance_sqd = std::numeric_limits<coord_t>::max();
bool should_reclaculate_closest = false;
if (z_seam_config_.type_ == EZSeamType::USER_SPECIFIED)
if (z_seam_config_.type_ == EZSeamType::USER_SPECIFIED || z_seam_config_.type_ == EZSeamType::INTERNAL_SPECIFIED)
{
// For user-defined seams you usually don't _actually_ want the _closest_ point, per-se,
// since you want the seam-line to be continuous in 3D space.
Expand Down
4 changes: 2 additions & 2 deletions src/SupportInfillPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
using namespace cura;


SupportInfillPart::SupportInfillPart(const SingleShape& outline, coord_t support_line_width, bool use_fractional_config, int inset_count_to_generate, coord_t custom_line_distance, EFillMethod custom_line_pattern)
SupportInfillPart::SupportInfillPart(const SingleShape& outline, coord_t support_line_width, bool use_fractional_config, int inset_count_to_generate, coord_t custom_line_distance, EFillMethod custom_line_pattern, std::optional<Point2LL> start_near_location)
: outline_(outline)
, outline_boundary_box_(outline)
, support_line_width_(support_line_width)
, inset_count_to_generate_(inset_count_to_generate)
, custom_line_distance_(custom_line_distance)
, custom_line_pattern_(custom_line_pattern)
, use_fractional_config_(use_fractional_config)

, start_near_location(start_near_location)

{
infill_area_per_combine_per_density_.clear();
Expand Down
Loading

0 comments on commit d7d1f71

Please sign in to comment.