Skip to content

Commit

Permalink
Avoid seam on overhang positions by checking the area covered below
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Mar 22, 2024
1 parent 19a8a7c commit 0009d17
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
17 changes: 16 additions & 1 deletion include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class PathOrderOptimizer
*/
ZSeamConfig seam_config_;

Polygons model_outline_layer_below_;

static const std::unordered_multimap<Path, Path> no_order_requirements_;

/*!
Expand All @@ -110,14 +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& model_outline_layer_below = Polygons())
: 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)
, model_outline_layer_below_(model_outline_layer_below)
{
}

Expand Down Expand Up @@ -718,6 +722,17 @@ class PathOrderOptimizer
}
}

// TBD: Create the circle once (with a slightly higher res) and translate for every point
Polygons circle;
circle.add(PolygonUtils::makeCircle(here, 200));
Polygons supported_area = model_outline_layer_below_.intersection(circle);
double area = supported_area.area();
static constexpr double max_area = std::numbers::pi * (200 * 200);
if (area > 0.0)
{
score /= 1 - std::pow((area / max_area - 1), 2);
}

constexpr double EPSILON = 5.0;
if (std::abs(best_score - score) <= EPSILON)
{
Expand Down
33 changes: 31 additions & 2 deletions src/InsetOrderOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,37 @@ bool InsetOrderOptimizer::addToLayer()
const auto group_outer_walls = settings_.get<bool>("group_outer_walls");
// 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);

// SVG svg(fmt::format("/tmp/outline_{}.svg", layer_nr_.value), AABB(storage_.getMachineBorder()), 0.001);

Polygons model_outline_layer_below;
if (layer_nr_ == 0)
{
model_outline_layer_below = storage_.getMachineBorder();
}
else
{
for (const std::shared_ptr<SliceMeshStorage>& mesh : storage_.meshes)
{
const SliceLayer& slice_layer = mesh->layers[layer_nr_ - 1];
for (const SliceLayerPart& part : slice_layer.parts)
{
model_outline_layer_below.add(part.print_outline);
}
}
}

// svg.writePolygons(model_outline_layer_below, SVG::Color::BLACK, 0.05);

PathOrderOptimizer<const ExtrusionLine*> order_optimizer(
gcode_layer_.getLastPlannedPositionOrStartingPosition(),
z_seam_config_,
detect_loops,
combing_boundary,
reverse,
order,
group_outer_walls,
model_outline_layer_below);

for (const auto& line : walls_to_be_added)
{
Expand Down

0 comments on commit 0009d17

Please sign in to comment.