mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-01 17:33:37 -05:00
Fix Arachne wall order at pinched holes and next to one wall on top (#16894)
* Arachne wall order pinch and top band * Cover Inner/Outer and Outer/Inner in the one wall on top order test
This commit is contained in:
1 parent
4c7928d8aa
commit
176b1dc63d
2 files changed
+296
-4
No files matched your search
@@ -2377,6 +2377,102 @@ static bool arachne_lines_touch(const Arachne::ExtrusionLine &a, const Arachne::
|
||||
return one_way(a, b) || one_way(b, a);
|
||||
}
|
||||
|
||||
// ORCA: only_one_wall_top without top surface expansion generates the inner walls between the outer walls and the top
|
||||
// surface, numbered from both edges, so a wall along the top surface can be inset 1 with other walls between it and the
|
||||
// outer wall. Wall order follows these numbers: Inner/Outer and Outer/Inner order touching walls by inset,
|
||||
// Inner/Outer/Inner prints inset 2+ before the outer wall and inset 1 after it. Walls chained from the outer walls
|
||||
// (inset 1 touching one, inset k touching inset k - 1) keep their inset; any other wall takes one more than the deepest
|
||||
// wall it touches, if any.
|
||||
// outer_touch / inner_touch: the touching distance to an outer / an inner wall.
|
||||
static void renumber_inner_walls_by_depth(const Arachne::VariableWidthLines &outer_walls, std::vector<Arachne::VariableWidthLines> &inner_walls,
|
||||
coord_t outer_touch, coord_t inner_touch)
|
||||
{
|
||||
std::vector<Arachne::ExtrusionLine> lines;
|
||||
for (Arachne::VariableWidthLines &group : inner_walls)
|
||||
for (Arachne::ExtrusionLine &el : group)
|
||||
if (!el.empty())
|
||||
lines.emplace_back(std::move(el));
|
||||
if (lines.empty())
|
||||
return;
|
||||
|
||||
// Lines whose bounding boxes, grown by the widest bead, do not overlap cannot touch.
|
||||
auto grown_bbox = [](const Arachne::ExtrusionLine &el) {
|
||||
BoundingBox bbox;
|
||||
coord_t widest = 0;
|
||||
for (const Arachne::ExtrusionJunction &j : el.junctions) {
|
||||
bbox.merge(j.p);
|
||||
widest = std::max(widest, j.w);
|
||||
}
|
||||
return bbox.inflated(widest);
|
||||
};
|
||||
std::vector<BoundingBox> line_bboxes;
|
||||
line_bboxes.reserve(lines.size());
|
||||
for (const Arachne::ExtrusionLine &el : lines)
|
||||
line_bboxes.emplace_back(grown_bbox(el));
|
||||
// Integer coordinates put walls generated exactly the touching distance apart up to a few nanometres further.
|
||||
const double rounding = double(scaled<coord_t>(0.001));
|
||||
const double outer_threshold = double(outer_touch) + rounding;
|
||||
const double inner_threshold = double(inner_touch) + rounding;
|
||||
auto touch = [&lines, &line_bboxes, inner_threshold](size_t a, size_t b) {
|
||||
return line_bboxes[a].overlap(line_bboxes[b]) && arachne_lines_touch(lines[a], lines[b], inner_threshold);
|
||||
};
|
||||
|
||||
// Walls numbered from the outer walls.
|
||||
std::vector<size_t> depth(lines.size(), 0);
|
||||
std::vector<size_t> frontier;
|
||||
for (const Arachne::ExtrusionLine &outer : outer_walls) {
|
||||
const BoundingBox outer_bbox = grown_bbox(outer);
|
||||
for (size_t i = 0; i < lines.size(); ++i)
|
||||
if (depth[i] == 0 && lines[i].inset_idx == 1 && outer_bbox.overlap(line_bboxes[i]) && arachne_lines_touch(outer, lines[i], outer_threshold)) {
|
||||
depth[i] = 1;
|
||||
frontier.push_back(i);
|
||||
}
|
||||
}
|
||||
std::vector<size_t> numbered = frontier;
|
||||
for (size_t level = 1; !frontier.empty(); ++level) {
|
||||
std::vector<size_t> next;
|
||||
for (size_t i = 0; i < lines.size(); ++i)
|
||||
if (depth[i] == 0 && lines[i].inset_idx == level + 1)
|
||||
for (size_t f : frontier)
|
||||
if (touch(f, i)) {
|
||||
depth[i] = level + 1;
|
||||
next.push_back(i);
|
||||
break;
|
||||
}
|
||||
numbered.insert(numbered.end(), next.begin(), next.end());
|
||||
frontier = std::move(next);
|
||||
}
|
||||
|
||||
// The other walls, working away from those.
|
||||
frontier = std::move(numbered);
|
||||
while (!frontier.empty()) {
|
||||
std::vector<size_t> next;
|
||||
for (size_t i = 0; i < lines.size(); ++i) {
|
||||
if (depth[i] != 0)
|
||||
continue;
|
||||
size_t deepest = 0;
|
||||
for (size_t f : frontier)
|
||||
if (depth[f] > deepest && touch(f, i))
|
||||
deepest = depth[f];
|
||||
if (deepest > 0) {
|
||||
depth[i] = deepest + 1;
|
||||
next.push_back(i);
|
||||
}
|
||||
}
|
||||
frontier = std::move(next);
|
||||
}
|
||||
|
||||
// Group g holds the walls of inset g + 1, as the caller expects.
|
||||
inner_walls.clear();
|
||||
for (size_t i = 0; i < lines.size(); ++i) {
|
||||
if (depth[i] > 0)
|
||||
lines[i].inset_idx = depth[i];
|
||||
if (inner_walls.size() < lines[i].inset_idx)
|
||||
inner_walls.resize(lines[i].inset_idx);
|
||||
inner_walls[lines[i].inset_idx - 1].emplace_back(std::move(lines[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Finds all perimeters touching a given set of reference lines, given as indexes.
|
||||
*
|
||||
@@ -2430,8 +2526,10 @@ std::vector<PerimeterGeneratorArachneExtrusion> reorderPerimetersByProximity(std
|
||||
|
||||
// Function to reorder perimeters starting from a given reference index
|
||||
auto reorderFromReference = [&](int referenceIndex) {
|
||||
// Find first level touching perimeters. The odd centre line of a wall too narrow for two inner walls is shared
|
||||
// by the outer walls on both sides, so those join this island and are printed before it too, holes first.
|
||||
// Find first level touching perimeters. A first level line touching another outer wall is shared by both: the
|
||||
// odd centre line of a wall too narrow for two inner walls, or an inner wall that turns where a narrow wall
|
||||
// pinches and runs back along the other outer wall. Those outer walls join this island and are printed before
|
||||
// it too, holes first.
|
||||
std::vector<int> outerIndices{referenceIndex};
|
||||
std::vector<int> firstLevelTouchingIndices;
|
||||
for (size_t next = 0; next < outerIndices.size(); ++next)
|
||||
@@ -2439,8 +2537,6 @@ std::vector<PerimeterGeneratorArachneExtrusion> reorderPerimetersByProximity(std
|
||||
if (std::find(firstLevelTouchingIndices.begin(), firstLevelTouchingIndices.end(), idx) != firstLevelTouchingIndices.end())
|
||||
continue;
|
||||
firstLevelTouchingIndices.push_back(idx);
|
||||
if (!entities[idx].extrusion->is_odd)
|
||||
continue;
|
||||
for (size_t i = 0; i < entities.size(); ++i)
|
||||
if (entities[i].extrusion->inset_idx == 0 && includedIndices.count(int(i)) == 0 &&
|
||||
std::find(outerIndices.begin(), outerIndices.end(), int(i)) == outerIndices.end() &&
|
||||
@@ -2763,6 +2859,12 @@ void PerimeterGenerator::process_arachne()
|
||||
for (Arachne::VariableWidthLines &inner_perimeter : inner_perimeters)
|
||||
for (Arachne::ExtrusionLine &el : inner_perimeter)
|
||||
++el.inset_idx;
|
||||
// The not-top region also starts walls at the top surface boundary, numbered from there.
|
||||
if (!clip_walls_over_top && perimeters.size() == 1)
|
||||
renumber_inner_walls_by_depth(perimeters.front(), inner_perimeters,
|
||||
apply_precise_outer_wall ? ext_perimeter_spacing + perimeter_spacing / 2
|
||||
: (ext_perimeter_spacing + perimeter_spacing) / 2,
|
||||
perimeter_spacing);
|
||||
|
||||
perimeters.insert(perimeters.end(), inner_perimeters.begin(), inner_perimeters.end());
|
||||
infill_contour = union_ex(top_expolygons, inner_wall_tool_paths.getInnerContour());
|
||||
|
||||
@@ -1220,6 +1220,196 @@ TEST_CASE("Inner/Outer/Inner prints the hole of a narrow tube wall first and the
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Two 12mm radius cylinders 14mm apart, 2mm tall, with a round hole in the middle 1mm short of the waist on either
|
||||
// side. At the waist the two outer walls touch with nothing between them, so each inner wall turns there and runs back
|
||||
// along the other outer wall: an inner wall of both the contour and the hole.
|
||||
Print &pinched_tube(Print &print, Model &model, const DynamicPrintConfig &config)
|
||||
{
|
||||
ModelObject *object = model.add_object();
|
||||
object->name = "pinched_tube.stl";
|
||||
for (const float y : { 7.f, -7.f }) {
|
||||
TriangleMesh lobe = make_cylinder(12., 2.);
|
||||
lobe.translate(0.f, y, 0.f);
|
||||
object->add_volume(std::move(lobe), ModelVolumeType::MODEL_PART, false);
|
||||
}
|
||||
// The waist is sqrt(12^2 - 7^2) = 9.75mm from the centre.
|
||||
object->add_volume(make_cylinder(8.75, 2.), ModelVolumeType::NEGATIVE_VOLUME, false);
|
||||
object->add_instance();
|
||||
object->ensure_on_bed();
|
||||
|
||||
print.auto_assign_extruders(object);
|
||||
print.apply(model, config);
|
||||
print.validate();
|
||||
print.set_status_silent();
|
||||
print.process();
|
||||
return print;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// The inner walls the contour and the hole share go after both outer walls, and the walls beyond them before, so the
|
||||
// hole's outer wall is sandwiched like the contour's instead of being printed last.
|
||||
TEST_CASE("Inner/Outer/Inner prints both outer walls of a pinched wall before the inner walls they share", "[Perimeters]")
|
||||
{
|
||||
DynamicPrintConfig config = tube_config("arachne", 3);
|
||||
config.set_deserialize_strict("wall_sequence", "inner-outer-inner wall");
|
||||
Print print;
|
||||
Model model;
|
||||
pinched_tube(print, model, config);
|
||||
const auto layers = print.objects().front()->layers();
|
||||
// 2mm at 0.2mm layers.
|
||||
REQUIRE(layers.size() == 10);
|
||||
|
||||
// The first layer is printed Inner/Outer.
|
||||
for (size_t i = 1; i < layers.size(); ++ i) {
|
||||
CAPTURE(i);
|
||||
// The inset of each wall in extrusion order, and where the two outer walls are.
|
||||
std::vector<int> insets;
|
||||
int contour = -1;
|
||||
int hole = -1;
|
||||
for (const LayerRegion *region : layers[i]->regions())
|
||||
for (const ExtrusionEntity *entity : region->perimeters.flatten().entities) {
|
||||
if (entity->inset_idx == 0 && entity->is_loop())
|
||||
(static_cast<const ExtrusionLoop*>(entity)->loop_role() & elrHole ? hole : contour) = int(insets.size());
|
||||
insets.push_back(int(entity->inset_idx));
|
||||
}
|
||||
REQUIRE(contour >= 0);
|
||||
REQUIRE(hole >= 0);
|
||||
REQUIRE(std::count(insets.begin(), insets.end(), 1) > 0);
|
||||
REQUIRE(std::count(insets.begin(), insets.end(), 2) > 0);
|
||||
const int first_outer = std::min(contour, hole);
|
||||
const int last_outer = std::max(contour, hole);
|
||||
CHECK(last_outer == first_outer + 1);
|
||||
for (int k = 0; k < int(insets.size()); ++ k) {
|
||||
CAPTURE(k, insets[k]);
|
||||
if (insets[k] >= 2)
|
||||
CHECK(k < first_outer);
|
||||
else if (insets[k] == 1)
|
||||
CHECK(k > last_outer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// A 24x24x2mm slab with a round hole of 3mm radius, and a 2mm wide collar around the hole rising to 4mm. On the slab's
|
||||
// last layer the collar leaves a band around the hole that is not top surface, wide enough for three walls.
|
||||
Print &collar_slab(Print &print, Model &model, const DynamicPrintConfig &config)
|
||||
{
|
||||
ModelObject *object = model.add_object();
|
||||
object->name = "collar_slab.stl";
|
||||
TriangleMesh slab = make_cube(24., 24., 2.);
|
||||
slab.translate(-12.f, -12.f, 0.f);
|
||||
object->add_volume(std::move(slab), ModelVolumeType::MODEL_PART, false);
|
||||
object->add_volume(make_cylinder(5., 4.), ModelVolumeType::MODEL_PART, false);
|
||||
object->add_volume(make_cylinder(3., 4.), ModelVolumeType::NEGATIVE_VOLUME, false);
|
||||
object->add_instance();
|
||||
object->ensure_on_bed();
|
||||
|
||||
print.auto_assign_extruders(object);
|
||||
print.apply(model, config);
|
||||
print.validate();
|
||||
print.set_status_silent();
|
||||
print.process();
|
||||
return print;
|
||||
}
|
||||
|
||||
// A 6mm radius cup, 3mm tall, with a 2mm wall and a 1.2mm floor. On the floor's last layer the cup's wall is a band
|
||||
// beside the floor's top surface, wide enough for three walls inside the cup's outer wall.
|
||||
Print &floored_cup(Print &print, Model &model, const DynamicPrintConfig &config)
|
||||
{
|
||||
ModelObject *object = model.add_object();
|
||||
object->name = "floored_cup.stl";
|
||||
object->add_volume(make_cylinder(6., 3.), ModelVolumeType::MODEL_PART, false);
|
||||
TriangleMesh inside = make_cylinder(4., 3.);
|
||||
inside.translate(0.f, 0.f, 1.2f);
|
||||
object->add_volume(std::move(inside), ModelVolumeType::NEGATIVE_VOLUME, false);
|
||||
object->add_instance();
|
||||
object->ensure_on_bed();
|
||||
|
||||
print.auto_assign_extruders(object);
|
||||
print.apply(model, config);
|
||||
print.validate();
|
||||
print.set_status_silent();
|
||||
print.process();
|
||||
return print;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// With only one wall on top and no top surface expansion, the inner walls of a layer with a top surface are generated in
|
||||
// the band left beside it, starting from both of its edges. The wall along the top surface is still the third wall from
|
||||
// the outer wall, so every wall sequence orders it by that depth: Inner/Outer prints it before the first inner wall,
|
||||
// Outer/Inner after it, and Inner/Outer/Inner before the outer wall, with the first inner wall after it. Checked for a
|
||||
// hole's outer wall beside a top surface (collar_slab) and for a contour beside one (floored_cup).
|
||||
TEST_CASE("Walls beside a top surface keep their order by depth with only one wall on top", "[Perimeters]")
|
||||
{
|
||||
const std::string shape = GENERATE("hole", "contour");
|
||||
const std::string wall_sequence = GENERATE("inner wall/outer wall", "outer wall/inner wall", "inner-outer-inner wall");
|
||||
CAPTURE(shape, wall_sequence);
|
||||
DynamicPrintConfig config = tube_config("arachne", 3);
|
||||
config.set_deserialize_strict({
|
||||
{ "wall_sequence", wall_sequence },
|
||||
{ "only_one_wall_top", true },
|
||||
{ "top_shell_layers", 3 },
|
||||
{ "top_surface_density", "100%" },
|
||||
{ "top_surface_expansion", 0. },
|
||||
});
|
||||
Print print;
|
||||
Model model;
|
||||
if (shape == "hole")
|
||||
collar_slab(print, model, config);
|
||||
else
|
||||
floored_cup(print, model, config);
|
||||
|
||||
// The slab's last layer at 2mm, or the floor's at 1.2mm. The walls around the axis as their mean distance from it, in
|
||||
// extrusion order.
|
||||
const double print_z = shape == "hole" ? 2. : 1.2;
|
||||
const Layer *layer = nullptr;
|
||||
for (const Layer *l : print.objects().front()->layers())
|
||||
if (std::abs(l->print_z - print_z) < EPSILON)
|
||||
layer = l;
|
||||
REQUIRE(layer != nullptr);
|
||||
std::vector<double> radii;
|
||||
int outer = -1;
|
||||
for (const LayerRegion *region : layer->regions())
|
||||
for (const ExtrusionEntity *entity : region->perimeters.flatten().entities) {
|
||||
const Polyline polyline = entity->as_polyline();
|
||||
double radius = 0.;
|
||||
for (const Point &p : polyline.points)
|
||||
radius += unscaled<double>(p.cast<double>().norm());
|
||||
radius /= double(polyline.points.size());
|
||||
if (radius > 8.)
|
||||
continue; // the slab's own walls
|
||||
if (entity->inset_idx == 0)
|
||||
outer = int(radii.size());
|
||||
radii.push_back(radius);
|
||||
}
|
||||
REQUIRE(outer >= 0);
|
||||
// With 0.5mm walls the first inner wall is about 0.5mm from the outer wall, the third wall about 1mm. The positions
|
||||
// in extrusion order of the first inner walls and of the third walls and beyond.
|
||||
std::vector<int> first_inner;
|
||||
std::vector<int> third_wall;
|
||||
for (int k = 0; k < int(radii.size()); ++ k)
|
||||
if (k != outer)
|
||||
(std::abs(radii[k] - radii[outer]) > 0.75 ? third_wall : first_inner).push_back(k);
|
||||
CAPTURE(radii, outer);
|
||||
REQUIRE(! first_inner.empty());
|
||||
REQUIRE(! third_wall.empty());
|
||||
if (wall_sequence == "inner wall/outer wall") {
|
||||
CHECK(third_wall.back() < first_inner.front());
|
||||
CHECK(first_inner.back() < outer);
|
||||
} else if (wall_sequence == "outer wall/inner wall") {
|
||||
CHECK(outer < first_inner.front());
|
||||
CHECK(first_inner.back() < third_wall.front());
|
||||
} else {
|
||||
CHECK(third_wall.back() < outer);
|
||||
CHECK(outer < first_inner.front());
|
||||
}
|
||||
}
|
||||
|
||||
// The contour's walls run in the wall direction and the hole's against it, except that the walls of a thin wall
|
||||
// hole run with the contour, as does the inner wall Arachne shares between both sides of a 1.5mm tube wall.
|
||||
TEST_CASE("Tube walls run in the wall direction and hole walls against it", "[Perimeters]")
|
||||
|
||||
Reference in new issue
Block a user