mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-01 09:22:58 -05:00
Parts and modifiers with matching wall settings share their walls, which are generated with the settings of the first one. The check did not compare the bridge speed and bridge volumetric flow, though overhang walls print at the bridge speed, so a part with its own bridge speed printed its overhang walls at the speed of another part. Only objects whose parts differ in these settings change. Ported from bambulab/BambuStudio@2d6f964e24 Co-authored-by: Colajichi <shubo.nie@bambulab.com>
1783 lines
78 KiB
C++
1783 lines
78 KiB
C++
#include <catch2/catch_all.hpp>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/generators/catch_generators.hpp>
|
|
#include <catch2/catch_message.hpp>
|
|
#include <catch2/matchers/catch_matchers.hpp>
|
|
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
|
#include "libslic3r/ExtrusionEntity.hpp"
|
|
#include "libslic3r/ExtrusionEntityCollection.hpp"
|
|
#include "libslic3r/Layer.hpp"
|
|
#include "libslic3r/Print.hpp"
|
|
#include "libslic3r/GCodeReader.hpp"
|
|
#include "libslic3r/Model.hpp"
|
|
#include "libslic3r/TriangleMesh.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include "libslic3r/PrintConfig.hpp"
|
|
#include <cstddef>
|
|
#include "libslic3r/libslic3r.h"
|
|
#include "libslic3r/BoundingBox.hpp"
|
|
#include "libslic3r/ClipperUtils.hpp"
|
|
#include "libslic3r/Config.hpp"
|
|
#include "libslic3r/ExPolygon.hpp"
|
|
#include "libslic3r/Point.hpp"
|
|
#include "libslic3r/Polygon.hpp"
|
|
#include "libslic3r/Polyline.hpp"
|
|
#include <limits>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "test_helpers.hpp"
|
|
|
|
using namespace Slic3r;
|
|
using namespace Slic3r::Test;
|
|
|
|
namespace {
|
|
|
|
// The layer at this Z is the last one of the base, so its top surface is the ledge.
|
|
const double ledge_z = 5.0;
|
|
|
|
// The first layer, at initial_layer_print_height.
|
|
const double first_layer_z = 0.2;
|
|
|
|
// TestMesh::step scaled 3x in X/Y: a 60x60x5 base carrying a 54x54 column up to z=10, leaving a 3mm
|
|
// top ledge around a feature that keeps rising. That is the geometry both only_one_wall_top and the
|
|
// top surface expansion act on. The ledge has to stay wider than the wall band plus two top-infill
|
|
// lines, or the expansion discards it as a sliver and the tests below assert nothing.
|
|
TriangleMesh step_with_ledge()
|
|
{
|
|
TriangleMesh m = Slic3r::Test::mesh(TestMesh::step);
|
|
m.scale(Vec3f(3.f, 3.f, 1.f));
|
|
return m;
|
|
}
|
|
|
|
// Every setting the assertions depend on, so none of them rests on a default.
|
|
DynamicPrintConfig base_config(const char *wall_generator)
|
|
{
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
config.set_deserialize_strict({
|
|
{ "wall_generator", wall_generator },
|
|
{ "layer_height", 0.2 }, // puts a layer boundary exactly on ledge_z
|
|
{ "initial_layer_print_height", 0.2 },
|
|
{ "wall_loops", 3 },
|
|
{ "sparse_infill_density", "15%" },
|
|
{ "top_shell_layers", 3 },
|
|
{ "bottom_shell_layers", 3 },
|
|
{ "top_surface_density", "100%" },
|
|
{ "top_surface_expansion", 0.0 },
|
|
{ "only_one_wall_top", false },
|
|
{ "only_one_wall_first_layer", false },
|
|
// Do not let the one-wall threshold discard the 3mm ledge before the feature sees it.
|
|
{ "min_width_top_surface", 0.0 },
|
|
});
|
|
return config;
|
|
}
|
|
|
|
double collection_length(const ExtrusionEntityCollection &coll)
|
|
{
|
|
double len = 0.;
|
|
for (const ExtrusionEntity *entity : coll.flatten().entities)
|
|
if (! entity->is_collection())
|
|
len += entity->length();
|
|
return len;
|
|
}
|
|
|
|
// Extruded length per layer. Two slices are compared through this rather than through their G-code,
|
|
// because the G-code carries a config block that differs whenever any setting differs.
|
|
struct SliceLengths {
|
|
std::vector<double> perimeters;
|
|
std::vector<double> fills;
|
|
};
|
|
|
|
SliceLengths slice_lengths(const Print &print)
|
|
{
|
|
SliceLengths out;
|
|
for (const Layer *layer : print.objects().front()->layers()) {
|
|
double perimeters = 0., fills = 0.;
|
|
for (const LayerRegion *region : layer->regions()) {
|
|
perimeters += collection_length(region->perimeters);
|
|
fills += collection_length(region->fills);
|
|
}
|
|
out.perimeters.push_back(perimeters);
|
|
out.fills.push_back(fills);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
double perimeter_length_at(const Print &print, double print_z)
|
|
{
|
|
for (const Layer *layer : print.objects().front()->layers())
|
|
if (std::abs(layer->print_z - print_z) < 1e-4) {
|
|
double len = 0.;
|
|
for (const LayerRegion *region : layer->regions())
|
|
len += collection_length(region->perimeters);
|
|
return len;
|
|
}
|
|
return 0.;
|
|
}
|
|
|
|
// Largest per-layer difference between two series; a negative result means they are not comparable.
|
|
double max_difference(const std::vector<double> &a, const std::vector<double> &b)
|
|
{
|
|
if (a.size() != b.size() || a.empty())
|
|
return -1.;
|
|
double worst = 0.;
|
|
for (size_t i = 0; i < a.size(); ++ i)
|
|
worst = std::max(worst, std::abs(a[i] - b[i]));
|
|
return worst;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// The expansion only retypes area as top solid infill, so it can do nothing where there is no top
|
|
// fill to begin with: zero top shell layers retypes the top surfaces as internal, and a top surface
|
|
// density of 0% leaves the top layer with walls only. The last section is the control - the same
|
|
// expansion on the same model does change the slice once a top fill exists - without which the two
|
|
// equality checks above it would hold for an unrelated reason.
|
|
// Overhang walls print at the bridge speed, so regions that differ in it can't share their walls.
|
|
TEST_CASE("Regions with a different bridge speed or flow get walls of their own", "[Perimeters]")
|
|
{
|
|
const bool flow = GENERATE(false, true);
|
|
CAPTURE(flow);
|
|
Print print;
|
|
Model model;
|
|
init_print({ cube(20) }, print, model);
|
|
const PrintRegionConfig &config = print.objects().front()->printing_region(0).config();
|
|
PrintRegionConfig changed = config;
|
|
if (flow)
|
|
for (FloatOrPercent &value : changed.bridge_volumetric_flow.values)
|
|
value.value += 10.;
|
|
else
|
|
for (double &value : changed.bridge_speed.values)
|
|
value += 10.;
|
|
CHECK(Layer::is_perimeter_compatible(print, PrintRegion(config), PrintRegion(config)));
|
|
CHECK_FALSE(Layer::is_perimeter_compatible(print, PrintRegion(config), PrintRegion(changed)));
|
|
}
|
|
|
|
// The area every layer of the object keeps clear of the walls for gap fill and concentric infill.
|
|
static double no_overlap_fill_area(const Print &print)
|
|
{
|
|
double sum = 0.;
|
|
for (const Layer *layer : print.objects().front()->layers())
|
|
for (const LayerRegion *region : layer->regions())
|
|
sum += area(region->fill_no_overlap_expolygons);
|
|
return sum;
|
|
}
|
|
|
|
TEST_CASE("Generating the walls again leaves the no-overlap fill area of a fresh slice", "[Perimeters][Regression]")
|
|
{
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
config.set_deserialize_strict({ { "wall_loops", 2 }, { "gcode_comments", 1 } });
|
|
Print print;
|
|
Model model;
|
|
init_print({ cube(20) }, print, model, config);
|
|
print.process();
|
|
|
|
// Only the walls are generated again.
|
|
config.set_deserialize_strict({ { "wall_loops", 3 } });
|
|
print.apply(model, config);
|
|
print.process();
|
|
|
|
Print fresh;
|
|
Model fresh_model;
|
|
init_print({ cube(20) }, fresh, fresh_model, config);
|
|
fresh.process();
|
|
REQUIRE(no_overlap_fill_area(fresh) > 0.);
|
|
CHECK_THAT(no_overlap_fill_area(print), Catch::Matchers::WithinRel(no_overlap_fill_area(fresh), 1e-6));
|
|
}
|
|
|
|
TEST_CASE("Top surface expansion only acts where there is a top fill", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
auto lengths_for = [wall_generator](int top_shell_layers, const char *top_surface_density, double expansion) {
|
|
DynamicPrintConfig config = base_config(wall_generator);
|
|
config.set_deserialize_strict({
|
|
{ "top_shell_layers", top_shell_layers },
|
|
{ "top_surface_density", top_surface_density },
|
|
{ "top_surface_expansion", expansion },
|
|
});
|
|
Print print;
|
|
init_and_process_print({ step_with_ledge() }, print, config);
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
return slice_lengths(print);
|
|
};
|
|
|
|
SECTION("no top shell layers") {
|
|
const SliceLengths off = lengths_for(0, "100%", 0.0);
|
|
const SliceLengths on = lengths_for(0, "100%", 2.0);
|
|
REQUIRE(off.perimeters.size() == on.perimeters.size());
|
|
CHECK_THAT(max_difference(off.perimeters, on.perimeters), Catch::Matchers::WithinAbs(0., 1.0));
|
|
CHECK_THAT(max_difference(off.fills, on.fills), Catch::Matchers::WithinAbs(0., 1.0));
|
|
}
|
|
|
|
SECTION("zero top surface density") {
|
|
const SliceLengths off = lengths_for(3, "0%", 0.0);
|
|
const SliceLengths on = lengths_for(3, "0%", 2.0);
|
|
REQUIRE(off.perimeters.size() == on.perimeters.size());
|
|
CHECK_THAT(max_difference(off.perimeters, on.perimeters), Catch::Matchers::WithinAbs(0., 1.0));
|
|
CHECK_THAT(max_difference(off.fills, on.fills), Catch::Matchers::WithinAbs(0., 1.0));
|
|
}
|
|
|
|
SECTION("with a top fill the same expansion does change the slice") {
|
|
const SliceLengths off = lengths_for(3, "100%", 0.0);
|
|
const SliceLengths on = lengths_for(3, "100%", 2.0);
|
|
REQUIRE(off.fills.size() == on.fills.size());
|
|
CHECK(max_difference(off.fills, on.fills) > scale_(0.5));
|
|
}
|
|
}
|
|
|
|
// With no top shell the top surfaces are retyped as internal, so the top surface density has nothing
|
|
// left to control: there is no top fill, and only_one_wall_top - the one route from the density to the
|
|
// perimeters - is itself switched off for want of a top surface to act on.
|
|
TEST_CASE("Top surface density does not affect a slice without a top shell", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
auto lengths_for = [wall_generator](const char *top_surface_density) {
|
|
DynamicPrintConfig config = base_config(wall_generator);
|
|
config.set_deserialize_strict({
|
|
{ "top_shell_layers", 0 },
|
|
{ "only_one_wall_top", true },
|
|
{ "top_surface_density", top_surface_density },
|
|
});
|
|
Print print;
|
|
init_and_process_print({ step_with_ledge() }, print, config);
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
return slice_lengths(print);
|
|
};
|
|
|
|
const SliceLengths solid = lengths_for("100%");
|
|
const SliceLengths none = lengths_for("0%");
|
|
REQUIRE(solid.perimeters.size() == none.perimeters.size());
|
|
CHECK_THAT(max_difference(solid.perimeters, none.perimeters), Catch::Matchers::WithinAbs(0., 1.0));
|
|
CHECK_THAT(max_difference(solid.fills, none.fills), Catch::Matchers::WithinAbs(0., 1.0));
|
|
}
|
|
|
|
// On the ledge layer the inner walls are given up to the top fill, so that layer loses wall length.
|
|
// The handover needs a top fill that reaches the freed space: at a top surface density of 0% there is
|
|
// no top fill at all, and without top_surface_expansion the fill never grows over the walls. Either
|
|
// way the feature still runs, through the original generation, which keeps the inner walls up to the
|
|
// top boundary - putting that layer back between the plain and the one-wall slice.
|
|
TEST_CASE("Only one wall on top surfaces drops inner walls only where a top fill replaces them", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
auto ledge_perimeters_for = [wall_generator](bool only_one_wall_top, const char *top_surface_density, double expansion) {
|
|
DynamicPrintConfig config = base_config(wall_generator);
|
|
config.set_deserialize_strict({
|
|
{ "only_one_wall_top", only_one_wall_top },
|
|
{ "top_surface_density", top_surface_density },
|
|
{ "top_surface_expansion", expansion },
|
|
});
|
|
Print print;
|
|
init_and_process_print({ step_with_ledge() }, print, config);
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
return perimeter_length_at(print, ledge_z);
|
|
};
|
|
|
|
const double plain = ledge_perimeters_for(false, "100%", 2.0);
|
|
const double one_wall = ledge_perimeters_for(true, "100%", 2.0);
|
|
const double one_wall_no_fill = ledge_perimeters_for(true, "0%", 2.0);
|
|
const double one_wall_no_expand = ledge_perimeters_for(true, "100%", 0.0);
|
|
|
|
REQUIRE(plain > 0.);
|
|
CHECK(one_wall < plain);
|
|
// Both fall back to the original generation, which cuts the walls back to the top boundary but not past it.
|
|
CHECK(one_wall_no_fill > one_wall);
|
|
CHECK(one_wall_no_fill < plain);
|
|
CHECK(one_wall_no_expand > one_wall);
|
|
CHECK(one_wall_no_expand < plain);
|
|
}
|
|
|
|
// The bottom counterpart: the first layer is thinned to a single wall only where a bottom shell fills the
|
|
// space behind it. With no bottom shell layers the bottom surfaces are retyped as internal, so that wall
|
|
// would ring sparse infill on the bed - the option is switched off instead, and the GUI hides it in that
|
|
// state so a profile that left it enabled cannot act behind a hidden checkbox.
|
|
TEST_CASE("Only one wall on the first layer needs a bottom shell", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
auto first_layer_perimeters_for = [wall_generator](bool only_one_wall_first_layer, int bottom_shell_layers) {
|
|
DynamicPrintConfig config = base_config(wall_generator);
|
|
config.set_deserialize_strict({
|
|
{ "only_one_wall_first_layer", only_one_wall_first_layer },
|
|
{ "bottom_shell_layers", bottom_shell_layers },
|
|
});
|
|
Print print;
|
|
init_and_process_print({ step_with_ledge() }, print, config);
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
return perimeter_length_at(print, first_layer_z);
|
|
};
|
|
|
|
const double plain = first_layer_perimeters_for(false, 3);
|
|
const double one_wall = first_layer_perimeters_for(true, 3);
|
|
// Both at zero bottom shell layers, so everything else that setting changes cancels out between them.
|
|
const double plain_no_shell = first_layer_perimeters_for(false, 0);
|
|
const double one_wall_no_shell = first_layer_perimeters_for(true, 0);
|
|
|
|
REQUIRE(plain > 0.);
|
|
CHECK(one_wall < plain);
|
|
// No bottom shell: the option is inert, down to the same walls an unchecked box gives.
|
|
CHECK_THAT(one_wall_no_shell, Catch::Matchers::WithinAbs(plain_no_shell, 1.0));
|
|
}
|
|
|
|
namespace {
|
|
|
|
// A 40x40x5 base with a 10x10x10 post in each corner. The inner walls of the base's top layer run along the
|
|
// ledge between two posts, so every vertex of a loop sits inside the posts, which keep rising, while the side
|
|
// between two posts runs over the top surface.
|
|
Print &base_with_corner_posts(Print &print, Model &model, const DynamicPrintConfig &config)
|
|
{
|
|
ModelObject *object = model.add_object();
|
|
object->name = "base_with_corner_posts.stl";
|
|
object->add_volume(make_cube(40., 40., 5.), ModelVolumeType::MODEL_PART, false);
|
|
for (const double x : { 0., 30. })
|
|
for (const double y : { 0., 30. }) {
|
|
TriangleMesh post = make_cube(10., 10., 10.);
|
|
post.translate(float(x), float(y), 0.f);
|
|
object->add_volume(std::move(post), ModelVolumeType::MODEL_PART, 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;
|
|
}
|
|
|
|
const Layer *layer_at(const Print &print, double print_z)
|
|
{
|
|
for (const Layer *layer : print.objects().front()->layers())
|
|
if (std::abs(layer->print_z - print_z) < 1e-4)
|
|
return layer;
|
|
return nullptr;
|
|
}
|
|
|
|
// Length of the top surface fill on a layer.
|
|
double top_fill_length(const Layer &layer)
|
|
{
|
|
double len = 0.;
|
|
for (const LayerRegion *region : layer.regions())
|
|
for (const ExtrusionEntity *entity : region->fills.flatten().entities)
|
|
if (is_top_surface(entity->role()))
|
|
len += entity->length();
|
|
return unscale<double>(len);
|
|
}
|
|
|
|
// Length of the inner-wall centerline lying inside the top surface fill on a layer.
|
|
double inner_wall_over_top_fill(const Layer &layer)
|
|
{
|
|
double over = 0.;
|
|
for (const LayerRegion *region : layer.regions()) {
|
|
Polygons top_fill;
|
|
for (const ExtrusionEntity *entity : region->fills.flatten().entities)
|
|
if (is_top_surface(entity->role()))
|
|
append(top_fill, entity->polygons_covered_by_width());
|
|
if (top_fill.empty())
|
|
continue;
|
|
for (const ExtrusionEntity *entity : region->perimeters.flatten().entities)
|
|
if (is_internal_perimeter(entity->role()))
|
|
over += total_length(intersection_pl(entity->as_polylines(), top_fill));
|
|
}
|
|
return unscale<double>(over);
|
|
}
|
|
|
|
// Length of the inner walls on a layer.
|
|
double inner_wall_length(const Layer &layer)
|
|
{
|
|
double len = 0.;
|
|
for (const LayerRegion *region : layer.regions())
|
|
for (const ExtrusionEntity *entity : region->perimeters.flatten().entities)
|
|
if (is_internal_perimeter(entity->role()))
|
|
len += entity->length();
|
|
return unscale<double>(len);
|
|
}
|
|
|
|
// Length of the inner-wall centerline inside the given area on a layer.
|
|
double inner_wall_length_inside(const Layer &layer, const ExPolygons &area)
|
|
{
|
|
double len = 0.;
|
|
for (const LayerRegion *region : layer.regions())
|
|
for (const ExtrusionEntity *entity : region->perimeters.flatten().entities)
|
|
if (is_internal_perimeter(entity->role()))
|
|
len += total_length(intersection_pl(entity->as_polylines(), area));
|
|
return unscale<double>(len);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// A wall runs over the top surface wherever any part of it is over that surface, which a per-vertex test does
|
|
// not see when the wall crosses the top between two vertices that both sit over the geometry that keeps
|
|
// rising. The inner walls of a base between its corner posts are exactly that: the top fill covers them, so
|
|
// the perimeter generator has to give them up rather than print the fill over them.
|
|
TEST_CASE("Only one wall on top surfaces keeps the top fill off inner walls that cross it between their vertices", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
DynamicPrintConfig config = base_config(wall_generator);
|
|
config.set_deserialize_strict({
|
|
{ "only_one_wall_top", true },
|
|
{ "top_surface_expansion", 2.0 },
|
|
});
|
|
Print print;
|
|
Model model;
|
|
base_with_corner_posts(print, model, config);
|
|
|
|
const Layer *ledge = layer_at(print, ledge_z);
|
|
REQUIRE(ledge != nullptr);
|
|
// The ledge layer has a top fill to keep clear, and the layer below still has the inner walls, so the
|
|
// check below is about which walls survive the ledge and not about the shape lacking either.
|
|
REQUIRE(top_fill_length(*ledge) > 0.);
|
|
const Layer *below = layer_at(print, ledge_z - 0.2);
|
|
REQUIRE(below != nullptr);
|
|
REQUIRE(inner_wall_length(*below) > 0.);
|
|
|
|
CHECK(inner_wall_over_top_fill(*ledge) < 1.0);
|
|
}
|
|
|
|
// Arachne cuts its inner walls at the top surface instead of dropping them, so the walls under the posts stay. Each
|
|
// post sits on two outer sides of the base, each carrying both inner walls of wall_loops 3: 4 x 2 x 2 x 10mm, of
|
|
// which the cut at the inner sides of the posts may take some, but not half.
|
|
TEST_CASE("Only one wall on top surfaces keeps the Arachne inner walls under the geometry that keeps rising", "[Perimeters]")
|
|
{
|
|
DynamicPrintConfig config = base_config("arachne");
|
|
config.set_deserialize_strict({
|
|
{ "only_one_wall_top", true },
|
|
{ "top_surface_expansion", 2.0 },
|
|
});
|
|
Print print;
|
|
Model model;
|
|
base_with_corner_posts(print, model, config);
|
|
|
|
const Layer *ledge = layer_at(print, ledge_z);
|
|
REQUIRE(ledge != nullptr);
|
|
REQUIRE(ledge->upper_layer != nullptr);
|
|
CHECK(inner_wall_length_inside(*ledge, ledge->upper_layer->lslices) > 0.5 * 4 * 2 * 2 * 10.);
|
|
}
|
|
|
|
// With the precise outer wall off and equal wall spacings, the first inner wall lies exactly on the edge of the band
|
|
// next to the outer wall that split_top_surfaces() counts as not top, while the top fill covers it. A ledge along the
|
|
// whole outer wall gives that wall no other crossing to be caught by.
|
|
TEST_CASE("Only one wall on top surfaces keeps the top fill off the inner wall beside the outer wall", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
DynamicPrintConfig config = base_config(wall_generator);
|
|
config.set_deserialize_strict({
|
|
{ "only_one_wall_top", true },
|
|
{ "top_surface_expansion", 2.0 },
|
|
{ "precise_outer_wall", false },
|
|
});
|
|
Print print;
|
|
init_and_process_print({ step_with_ledge() }, print, config);
|
|
|
|
const Layer *ledge = layer_at(print, ledge_z);
|
|
REQUIRE(ledge != nullptr);
|
|
REQUIRE(top_fill_length(*ledge) > 0.);
|
|
CHECK(inner_wall_over_top_fill(*ledge) < 1.0);
|
|
}
|
|
|
|
namespace {
|
|
|
|
// The last layer of the tab, whose top surface shares an island with the tube walls rising past it.
|
|
const double tab_top_z = 5.0;
|
|
|
|
// With the widths below the tube walls are 1.10mm wide once the precise outer wall offset (0.043mm a side) is
|
|
// taken off. That is narrower than 3 outer wall spacings (3 x 0.377 = 1.131mm), so an Arachne pass limited to a
|
|
// single wall fills it by widening its 2 beads, yet wide enough for the full 2 wall pass to add a middle wall
|
|
// (from 1.062mm).
|
|
const double narrow_wall = 1.186;
|
|
|
|
// A 20x30x10 tube with narrow_wall thick walls, and a 20x8x5 tab against its -Y side.
|
|
Print &tube_with_tab(Print &print, Model &model, const DynamicPrintConfig &config)
|
|
{
|
|
ModelObject *object = model.add_object();
|
|
object->name = "tube_with_tab.stl";
|
|
object->add_volume(make_cube(20., 30., 10.), ModelVolumeType::MODEL_PART, false);
|
|
// Overlaps the tube wall by 0.5mm so the two parts slice as one island.
|
|
TriangleMesh tab = make_cube(20., 8.5, 5.);
|
|
tab.translate(0.f, -8.f, 0.f);
|
|
object->add_volume(std::move(tab), ModelVolumeType::MODEL_PART, false);
|
|
TriangleMesh bore = make_cube(20. - 2. * narrow_wall, 30. - 2. * narrow_wall, 12.);
|
|
bore.translate(float(narrow_wall), float(narrow_wall), -1.f);
|
|
object->add_volume(std::move(bore), 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();
|
|
return print;
|
|
}
|
|
|
|
// Every width the narrow_wall arithmetic depends on, so none of them rests on a default.
|
|
DynamicPrintConfig narrow_wall_config(bool only_one_wall_top, double top_surface_expansion)
|
|
{
|
|
DynamicPrintConfig config = base_config("arachne");
|
|
config.set_deserialize_strict({
|
|
{ "wall_loops", 2 },
|
|
{ "nozzle_diameter", "0.4" },
|
|
{ "line_width", 0.42 },
|
|
{ "outer_wall_line_width", 0.42 },
|
|
{ "inner_wall_line_width", 0.45 },
|
|
{ "min_bead_width", "85%" },
|
|
{ "precise_outer_wall", true },
|
|
{ "wall_sequence", "inner wall/outer wall" },
|
|
{ "only_one_wall_top", only_one_wall_top },
|
|
{ "top_surface_expansion", top_surface_expansion },
|
|
});
|
|
return config;
|
|
}
|
|
|
|
// Inner wall length the layer at print_z extrudes within 3mm of its +Y edge: the tube wall facing away from the tab.
|
|
double far_wall_inner_wall_length(const Print &print, double print_z)
|
|
{
|
|
for (const Layer *layer : print.objects().front()->layers()) {
|
|
if (std::abs(layer->print_z - print_z) > EPSILON)
|
|
continue;
|
|
BoundingBox band = get_extents(layer->lslices);
|
|
band.min.y() = band.max.y() - scaled<coord_t>(3.);
|
|
|
|
Polylines inner_walls;
|
|
auto collect = [&inner_walls](const ExtrusionPaths &paths) {
|
|
for (const ExtrusionPath &path : paths)
|
|
if (path.role() == erPerimeter)
|
|
inner_walls.emplace_back(path.as_polyline());
|
|
};
|
|
for (const LayerRegion *region : layer->regions()) {
|
|
const ExtrusionEntityCollection walls = region->perimeters.flatten();
|
|
for (const ExtrusionEntity *entity : walls.entities) {
|
|
if (const auto *loop = dynamic_cast<const ExtrusionLoop*>(entity))
|
|
collect(loop->paths);
|
|
else if (const auto *multi_path = dynamic_cast<const ExtrusionMultiPath*>(entity))
|
|
collect(multi_path->paths);
|
|
else if (const auto *path = dynamic_cast<const ExtrusionPath*>(entity))
|
|
collect({ *path });
|
|
}
|
|
}
|
|
return unscaled<double>(total_length(intersection_pl(inner_walls, band.polygon())));
|
|
}
|
|
return 0.;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// only_one_wall_top first lays out an island with a single Arachne wall and generates the inner walls inside it.
|
|
// On a wall narrower than 3 outer wall spacings that single wall pass widens its 2 beads to fill the wall and leaves
|
|
// no room for the middle wall, which is only intended over the top surface. The tube walls away from the tab are not
|
|
// under the tab's top surface, so on the tab's last layer they keep the inner wall they get with the option off.
|
|
TEST_CASE("Only one wall on top surfaces keeps the inner walls of narrow walls away from the top surface", "[Perimeters]")
|
|
{
|
|
// 0 re-onions the region beside the top surface, 2 clips the inner walls over it.
|
|
const double top_surface_expansion = GENERATE(0.0, 2.0);
|
|
CAPTURE(top_surface_expansion);
|
|
|
|
struct TabTopLayer {
|
|
double perimeters;
|
|
double far_wall_inner_walls;
|
|
};
|
|
auto tab_top_layer_for = [top_surface_expansion](bool only_one_wall_top) {
|
|
Print print;
|
|
Model model;
|
|
tube_with_tab(print, model, narrow_wall_config(only_one_wall_top, top_surface_expansion));
|
|
print.process();
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
return TabTopLayer{ perimeter_length_at(print, tab_top_z), far_wall_inner_wall_length(print, tab_top_z) };
|
|
};
|
|
|
|
const TabTopLayer plain = tab_top_layer_for(false);
|
|
const TabTopLayer one_wall = tab_top_layer_for(true);
|
|
|
|
// The option acts on this layer: the inner walls under the tab's top surface are gone.
|
|
REQUIRE(plain.far_wall_inner_walls > 10.);
|
|
CHECK(one_wall.perimeters < plain.perimeters);
|
|
CHECK_THAT(one_wall.far_wall_inner_walls, Catch::Matchers::WithinAbs(plain.far_wall_inner_walls, 1.0));
|
|
}
|
|
|
|
namespace {
|
|
|
|
// The layer that closes the cavity of box_over_cavity(), the first one printed over air.
|
|
const double cavity_ceiling_z = 6.2;
|
|
|
|
// A cone standing on its tip, flaring by 5mm of radius per mm of height: at a layer height of 0.2 every
|
|
// wall of a layer lands a full millimetre outside the one below, entirely off the layer below but right
|
|
// alongside the walls printed with it.
|
|
TriangleMesh flared_cone()
|
|
{
|
|
TriangleMesh cone = make_cone(20., 4.);
|
|
cone.mirror(Z);
|
|
cone.translate(0., 0., 4.);
|
|
return cone;
|
|
}
|
|
|
|
// A 30mm box holding a 20mm cavity from z=2 to z=6, with a 4mm hole punched down through the ceiling
|
|
// of that cavity. The layer at cavity_ceiling_z bridges the cavity, and the walls of the hole sit in
|
|
// the middle of that bridge, 15mm clear of anything the layer below supports.
|
|
Print &box_over_cavity(Print &print, Model &model, const DynamicPrintConfig &config)
|
|
{
|
|
ModelObject *object = model.add_object();
|
|
object->name = "box_over_cavity.stl";
|
|
object->add_volume(make_cube(30., 30., 8.), ModelVolumeType::MODEL_PART, false);
|
|
TriangleMesh cavity = make_cube(20., 20., 4.);
|
|
cavity.translate(5.f, 5.f, 2.f);
|
|
object->add_volume(std::move(cavity), ModelVolumeType::NEGATIVE_VOLUME, false);
|
|
TriangleMesh hole = make_cube(4., 4., 6.);
|
|
hole.translate(13.f, 13.f, 5.f);
|
|
object->add_volume(std::move(hole), 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();
|
|
return print;
|
|
}
|
|
|
|
// Every setting the assertions below depend on, so none of them rests on a default.
|
|
DynamicPrintConfig unsupported_walls_config(const char *wall_generator, bool unsupported_wall_last)
|
|
{
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
config.set_deserialize_strict({
|
|
{ "wall_generator", wall_generator },
|
|
{ "layer_height", 0.2 },
|
|
{ "initial_layer_print_height", 0.2 },
|
|
{ "wall_loops", 3 },
|
|
{ "detect_overhang_wall", true },
|
|
// Outer wall first, so an unsupported loop only ends up last if the feature puts it there.
|
|
{ "wall_sequence", "outer wall/inner wall" },
|
|
{ "is_infill_first", false },
|
|
{ "sparse_infill_density", "15%" },
|
|
{ "unsupported_wall_last", unsupported_wall_last },
|
|
{ "gcode_comments", true },
|
|
});
|
|
return config;
|
|
}
|
|
|
|
// A loop extruded entirely in mid air: every one of its paths is an overhang.
|
|
bool unsupported_loop(const ExtrusionEntity *entity)
|
|
{
|
|
if (! entity->is_loop())
|
|
return false;
|
|
const ExtrusionPaths &paths = static_cast<const ExtrusionLoop *>(entity)->paths;
|
|
return ! paths.empty() && std::all_of(paths.begin(), paths.end(),
|
|
[](const ExtrusionPath &path) { return path.role() == erOverhangPerimeter; });
|
|
}
|
|
|
|
// The loops of every wall island of the print, island by island, in extrusion order.
|
|
std::vector<std::vector<const ExtrusionLoop*>> wall_islands(const Print &print)
|
|
{
|
|
std::vector<std::vector<const ExtrusionLoop*>> islands;
|
|
for (const Layer *layer : print.objects().front()->layers())
|
|
for (const LayerRegion *region : layer->regions())
|
|
for (const ExtrusionEntity *island : region->perimeters.entities) {
|
|
std::vector<const ExtrusionLoop*> loops;
|
|
for (const ExtrusionEntity *entity : static_cast<const ExtrusionEntityCollection*>(island)->entities)
|
|
if (entity->is_loop())
|
|
loops.push_back(static_cast<const ExtrusionLoop*>(entity));
|
|
islands.push_back(std::move(loops));
|
|
}
|
|
return islands;
|
|
}
|
|
|
|
// Islands where a loop that is anchored is extruded after one that is not.
|
|
int islands_with_a_supported_loop_last(const Print &print)
|
|
{
|
|
int count = 0;
|
|
for (const std::vector<const ExtrusionLoop*> &loops : wall_islands(print)) {
|
|
bool seen_unsupported = false;
|
|
for (const ExtrusionLoop *loop : loops) {
|
|
if (unsupported_loop(loop))
|
|
seen_unsupported = true;
|
|
else if (seen_unsupported) {
|
|
++ count;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
// The unsupported loops of the print, and those of them held back for the infill.
|
|
std::vector<const ExtrusionLoop*> unsupported_loops(const Print &print, double print_z = -1.)
|
|
{
|
|
std::vector<const ExtrusionLoop*> loops;
|
|
for (const Layer *layer : print.objects().front()->layers()) {
|
|
if (print_z >= 0. && std::abs(layer->print_z - print_z) > EPSILON)
|
|
continue;
|
|
for (const LayerRegion *region : layer->regions())
|
|
for (const ExtrusionEntity *island : region->perimeters.entities)
|
|
for (const ExtrusionEntity *entity : static_cast<const ExtrusionEntityCollection*>(island)->entities)
|
|
if (unsupported_loop(entity))
|
|
loops.push_back(static_cast<const ExtrusionLoop*>(entity));
|
|
}
|
|
return loops;
|
|
}
|
|
|
|
int loops_held_back_for_infill(const std::vector<const ExtrusionLoop*> &loops)
|
|
{
|
|
return int(std::count_if(loops.begin(), loops.end(), [](const ExtrusionLoop *loop) { return loop->print_after_infill; }));
|
|
}
|
|
|
|
// The G-code emitted at `print_z`, so the order of one layer can be read on its own.
|
|
std::string layer_gcode(const std::string &gcode, double print_z)
|
|
{
|
|
std::string out;
|
|
GCodeReader reader;
|
|
reader.parse_buffer(gcode, [&out, print_z](GCodeReader &self, const GCodeReader::GCodeLine &line) {
|
|
if (std::abs(self.z() - print_z) < EPSILON)
|
|
out += line.raw() + "\n";
|
|
});
|
|
return out;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// Whatever the wall order asks for, a loop with nothing under it cannot be extruded before the loops it
|
|
// leans on. The flared cone gives every layer an outer wall that lands completely off the one below, and
|
|
// the outer wall first sequence would otherwise put it down before any of them.
|
|
TEST_CASE("Unsupported wall loops are extruded after the walls that anchor them", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
auto slice_cone = [wall_generator](bool unsupported_wall_last, Print &print) {
|
|
init_and_process_print({ flared_cone() }, print, unsupported_walls_config(wall_generator, unsupported_wall_last));
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
};
|
|
|
|
Print on;
|
|
slice_cone(true, on);
|
|
// Without unsupported loops to reorder the rest of the test would pass on an empty print.
|
|
REQUIRE(unsupported_loops(on).size() > 0);
|
|
CHECK(islands_with_a_supported_loop_last(on) == 0);
|
|
|
|
SECTION("the held back loops run innermost first") {
|
|
for (const std::vector<const ExtrusionLoop*> &loops : wall_islands(on)) {
|
|
int previous_inset = std::numeric_limits<int>::max();
|
|
for (const ExtrusionLoop *loop : loops)
|
|
if (unsupported_loop(loop)) {
|
|
CHECK(loop->inset_idx <= previous_inset);
|
|
previous_inset = loop->inset_idx;
|
|
}
|
|
}
|
|
}
|
|
|
|
SECTION("switched off, the configured wall order is left alone") {
|
|
Print off;
|
|
slice_cone(false, off);
|
|
REQUIRE(unsupported_loops(off).size() == unsupported_loops(on).size());
|
|
// Outer wall first puts the unsupported outer wall ahead of the walls behind it.
|
|
CHECK(islands_with_a_supported_loop_last(off) > 0);
|
|
}
|
|
}
|
|
|
|
// A loop the walls cannot reach is a different case: only the bridges of its own layer will ever hold it,
|
|
// so it has to wait for them - while a loop that runs alongside a wall keeps its place, because the
|
|
// bridges anchor on it instead.
|
|
TEST_CASE("A wall loop out of reach of the layer below waits for the infill", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
Print print;
|
|
Model model;
|
|
box_over_cavity(print, model, unsupported_walls_config(wall_generator, true));
|
|
print.process();
|
|
|
|
const std::vector<const ExtrusionLoop*> hole_loops = unsupported_loops(print, cavity_ceiling_z);
|
|
REQUIRE(hole_loops.size() > 0);
|
|
CHECK(loops_held_back_for_infill(hole_loops) == int(hole_loops.size()));
|
|
|
|
SECTION("a loop alongside a supported wall is not held back") {
|
|
Print cone;
|
|
init_and_process_print({ flared_cone() }, cone, unsupported_walls_config(wall_generator, true));
|
|
const std::vector<const ExtrusionLoop*> loops = unsupported_loops(cone);
|
|
REQUIRE(loops.size() > 0);
|
|
CHECK(loops_held_back_for_infill(loops) == 0);
|
|
}
|
|
|
|
SECTION("switched off, no loop is held back") {
|
|
Print off;
|
|
Model off_model;
|
|
box_over_cavity(off, off_model, unsupported_walls_config(wall_generator, false));
|
|
off.process();
|
|
const std::vector<const ExtrusionLoop*> loops = unsupported_loops(off, cavity_ceiling_z);
|
|
REQUIRE(loops.size() == hole_loops.size());
|
|
CHECK(loops_held_back_for_infill(loops) == 0);
|
|
}
|
|
}
|
|
|
|
// The held back loops reach the G-code in a second pass, after the infill of their layer: on the layer
|
|
// that closes the cavity the walls of the hole are extruded once the bridge is down, so the layer emits
|
|
// perimeters, then infill, then the perimeters that were waiting for it.
|
|
TEST_CASE("Loops waiting for the infill are extruded after it", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
auto ceiling_roles = [wall_generator](bool unsupported_wall_last) {
|
|
Print print;
|
|
Model model;
|
|
box_over_cavity(print, model, unsupported_walls_config(wall_generator, unsupported_wall_last));
|
|
const std::string layer = layer_gcode(gcode(print), cavity_ceiling_z);
|
|
REQUIRE_FALSE(layer.empty());
|
|
return role_sequence(layer, { "perimeter", "infill" });
|
|
};
|
|
|
|
CHECK(ceiling_roles(true) == std::vector<std::string>{ "perimeter", "infill", "perimeter" });
|
|
CHECK(ceiling_roles(false) == std::vector<std::string>{ "perimeter", "infill" });
|
|
}
|
|
|
|
namespace {
|
|
|
|
// The rib spans z=[0,5] and the slab z=[5,6], so this is the slab's first layer - the only one whose
|
|
// support comes from the rib rather than from the slab below it.
|
|
const double slab_first_layer_z = 5.2;
|
|
|
|
// Rib widths either side of what the wall generators can print. At a 0.4mm nozzle the classic generator
|
|
// builds nothing thinner than nozzle/3 = 0.133mm and Arachne drops anything below min_feature_size, 25%
|
|
// of the nozzle = 0.1mm. 0.08mm is under both thresholds, 0.3mm over both.
|
|
const double unprintable_rib = 0.08;
|
|
const double printable_rib = 0.3;
|
|
|
|
// A 4x5mm anchor tower carrying a 20x5mm slab at z=[5,6], with a rib `rib_width` wide running the whole
|
|
// length of the slab beneath its y=0 edge; a `rib_width` of 0 leaves the rib out. Nothing else is under
|
|
// that edge, so whether the wall along it is an overhang rests entirely on the rib. Overhang detection
|
|
// grows the lower slices by half the nozzle diameter before it asks, which carries either rib past the
|
|
// 0.21mm from the slab edge to that wall - the unprintable one only fails to reach it once it is filtered
|
|
// out for being unprintable.
|
|
Print &slab_over_rib(Print &print, Model &model, double rib_width, const DynamicPrintConfig &config)
|
|
{
|
|
ModelObject *object = model.add_object();
|
|
object->name = "slab_over_rib.stl";
|
|
object->add_volume(make_cube(4., 5., 6.), ModelVolumeType::MODEL_PART, false);
|
|
if (rib_width > 0.) {
|
|
TriangleMesh rib = make_cube(20., rib_width, 5.);
|
|
rib.translate(4.f, 0.f, 0.f);
|
|
object->add_volume(std::move(rib), ModelVolumeType::MODEL_PART, false);
|
|
}
|
|
TriangleMesh slab = make_cube(20., 5., 1.);
|
|
slab.translate(4.f, 0.f, 5.f);
|
|
object->add_volume(std::move(slab), ModelVolumeType::MODEL_PART, false);
|
|
object->add_instance();
|
|
object->ensure_on_bed();
|
|
|
|
print.auto_assign_extruders(object);
|
|
print.apply(model, config);
|
|
print.validate();
|
|
print.set_status_silent();
|
|
return print;
|
|
}
|
|
|
|
// Every setting the assertions below depend on, so none of them rests on a default. The wall line widths
|
|
// are pinned because the rib widths above are chosen against the distance from the slab edge to its outer
|
|
// wall, and min_feature_size because it is one of the two thresholds under test.
|
|
DynamicPrintConfig printable_rib_config(const char *wall_generator, bool detect_thin_wall)
|
|
{
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
config.set_deserialize_strict({
|
|
{ "wall_generator", wall_generator },
|
|
{ "layer_height", 0.2 }, // puts a layer boundary exactly on the top of the rib
|
|
{ "initial_layer_print_height", 0.2 },
|
|
{ "nozzle_diameter", "0.4" },
|
|
{ "outer_wall_line_width", 0.42 },
|
|
{ "inner_wall_line_width", 0.45 },
|
|
{ "wall_loops", 2 },
|
|
{ "detect_overhang_wall", true },
|
|
{ "detect_thin_wall", detect_thin_wall },
|
|
{ "min_feature_size", "25%" },
|
|
{ "raft_layers", 0 },
|
|
// Anything that adds, drops or reorders walls would move length between the roles being counted.
|
|
{ "extra_perimeters_on_overhangs", false },
|
|
{ "overhang_reverse", false },
|
|
{ "only_one_wall_top", false },
|
|
{ "only_one_wall_first_layer", false },
|
|
{ "unsupported_wall_last", false },
|
|
{ "sparse_infill_density", "15%" },
|
|
});
|
|
return config;
|
|
}
|
|
|
|
// Length of every overhang perimeter path on the layer at `print_z`, loops and open extrusions alike.
|
|
double overhang_length_at(const Print &print, double print_z)
|
|
{
|
|
double len = 0.;
|
|
const auto add_entity = [&len](const ExtrusionEntity *entity, auto &&self) -> void {
|
|
const auto add_paths = [&len](const ExtrusionPaths &paths) {
|
|
for (const ExtrusionPath &path : paths)
|
|
if (path.role() == erOverhangPerimeter)
|
|
len += path.length();
|
|
};
|
|
if (const auto *coll = dynamic_cast<const ExtrusionEntityCollection*>(entity)) {
|
|
for (const ExtrusionEntity *child : coll->entities)
|
|
self(child, self);
|
|
} else if (const auto *loop = dynamic_cast<const ExtrusionLoop*>(entity)) {
|
|
add_paths(loop->paths);
|
|
} else if (const auto *multi = dynamic_cast<const ExtrusionMultiPath*>(entity)) {
|
|
add_paths(multi->paths);
|
|
} else if (const auto *path = dynamic_cast<const ExtrusionPath*>(entity)) {
|
|
if (path->role() == erOverhangPerimeter)
|
|
len += path->length();
|
|
}
|
|
};
|
|
|
|
for (const Layer *layer : print.objects().front()->layers()) {
|
|
if (std::abs(layer->print_z - print_z) > EPSILON)
|
|
continue;
|
|
for (const LayerRegion *region : layer->regions())
|
|
add_entity(®ion->perimeters, add_entity);
|
|
}
|
|
return len;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// A sliver the wall generator prints nothing for holds nothing up, so it cannot be what decides that the
|
|
// wall above it is not an overhang. The rib under the slab is the only thing that edge of the slab could
|
|
// rest on: below the threshold of the active generator the slab has to come out exactly as it does with
|
|
// no rib at all, and the last check is the control - a rib the generator does print anchors that wall,
|
|
// without which the first check would hold for want of any sensitivity to the rib.
|
|
TEST_CASE("A lower layer sliver too thin to print does not support the wall above it", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
const bool detect_thin_wall = GENERATE(true, false);
|
|
CAPTURE(wall_generator, detect_thin_wall);
|
|
|
|
auto overhang_for = [wall_generator, detect_thin_wall](double rib_width) {
|
|
Print print;
|
|
Model model;
|
|
slab_over_rib(print, model, rib_width, printable_rib_config(wall_generator, detect_thin_wall));
|
|
print.process();
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
return overhang_length_at(print, slab_first_layer_z);
|
|
};
|
|
|
|
const double no_rib = overhang_for(0.);
|
|
const double unprintable = overhang_for(unprintable_rib);
|
|
const double printable = overhang_for(printable_rib);
|
|
|
|
// Only where the slab meets the tower is it held up from below, so both of its 20mm walls overhang.
|
|
REQUIRE(no_rib > scale_(30.));
|
|
CHECK_THAT(unprintable, Catch::Matchers::WithinAbs(no_rib, scale_(1.)));
|
|
// A rib that does get printed takes the 20mm outer wall running along it out of the overhangs.
|
|
CHECK(printable < no_rib - scale_(15.));
|
|
}
|
|
|
|
namespace {
|
|
|
|
// Every setting the fuzzy skin assertions below depend on.
|
|
DynamicPrintConfig fuzzy_skin_config(const char *wall_generator)
|
|
{
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
config.set_deserialize_strict({
|
|
{ "wall_generator", wall_generator },
|
|
{ "layer_height", 0.2 },
|
|
{ "initial_layer_print_height", 0.2 },
|
|
// One wall, so every wall point along the long sides belongs to the fuzzed outer wall.
|
|
{ "wall_loops", 1 },
|
|
{ "fuzzy_skin", "external" },
|
|
{ "fuzzy_skin_noise_type", "classic" },
|
|
{ "fuzzy_skin_thickness", 0.3 },
|
|
{ "fuzzy_skin_point_distance", 0.8 },
|
|
});
|
|
return config;
|
|
}
|
|
|
|
// How far the wall points over the middle 60% of the layer's length stray across its width, worst side.
|
|
// A negative result means there is no layer at `print_z`.
|
|
double mid_span_wall_spread(const Print &print, double print_z)
|
|
{
|
|
for (const Layer *layer : print.objects().front()->layers()) {
|
|
if (std::abs(layer->print_z - print_z) > 1e-4)
|
|
continue;
|
|
const BoundingBox bbox = get_extents(layer->lslices);
|
|
const coord_t x_min = bbox.min.x() + bbox.size().x() / 5;
|
|
const coord_t x_max = bbox.max.x() - bbox.size().x() / 5;
|
|
Points points;
|
|
for (const LayerRegion *region : layer->regions())
|
|
region->perimeters.collect_points(points);
|
|
coord_t spread = 0;
|
|
for (const bool south : { true, false }) {
|
|
coord_t lo = bbox.max.y(), hi = bbox.min.y();
|
|
for (const Point &p : points)
|
|
if (p.x() > x_min && p.x() < x_max && (p.y() < bbox.center().y()) == south) {
|
|
lo = std::min(lo, p.y());
|
|
hi = std::max(hi, p.y());
|
|
}
|
|
spread = std::max(spread, hi - lo);
|
|
}
|
|
return unscale<double>(spread);
|
|
}
|
|
return -1.;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// TestMesh::bridge is a 50x10mm deck from z=5 to z=8 on two 5mm-wide pillars, leaving a 40mm span. The deck's
|
|
// first layer (print_z 5.2) crosses the span unsupported; the layers above it rest on the deck.
|
|
TEST_CASE("Fuzzy skin leaves the walls of a bridge smooth", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
Print print;
|
|
init_and_process_print({ TestMesh::bridge }, print, fuzzy_skin_config(wall_generator));
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
|
|
// Control: one deck layer up the same walls rest on the deck, so they are fuzzed.
|
|
CHECK(mid_span_wall_spread(print, 5.6) > 0.1);
|
|
// Over the unsupported span the walls stay straight.
|
|
const double bridged = mid_span_wall_spread(print, 5.2);
|
|
CHECK(bridged >= 0.);
|
|
CHECK(bridged < 0.001);
|
|
}
|
|
|
|
// One object: a 20x20x3mm block on the bed and a second one floating above it from z=5 to z=8. The layers in
|
|
// the gap are empty, so the floating block's first layer (print_z 5.2) has a layer below it with nothing
|
|
// printed on it; the layers above rest on the floating block.
|
|
TEST_CASE("Fuzzy skin leaves the walls over an empty layer smooth", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
TriangleMesh mesh = make_cube(20., 20., 3.);
|
|
TriangleMesh floating = make_cube(20., 20., 3.);
|
|
floating.translate(0.f, 0.f, 5.f);
|
|
mesh.merge(floating);
|
|
|
|
Print print;
|
|
init_and_process_print({ mesh }, print, fuzzy_skin_config(wall_generator));
|
|
REQUIRE_FALSE(print.objects().empty());
|
|
|
|
// Control: one layer up the walls rest on the floating block, so they are fuzzed.
|
|
CHECK(mid_span_wall_spread(print, 5.6) > 0.1);
|
|
// Nothing is printed under the first floating layer, so its walls stay straight.
|
|
const double floating_first_layer = mid_span_wall_spread(print, 5.2);
|
|
CHECK(floating_first_layer >= 0.);
|
|
CHECK(floating_first_layer < 0.001);
|
|
}
|
|
|
|
namespace {
|
|
|
|
// A 20x20x5mm square tube whose walls are `wall` mm thick, except the far one at `far_wall` mm.
|
|
Print &square_tube(Print &print, Model &model, const DynamicPrintConfig &config, double wall, double far_wall)
|
|
{
|
|
ModelObject *object = model.add_object();
|
|
object->name = "square_tube.stl";
|
|
object->add_volume(make_cube(20., 20., 5.), ModelVolumeType::MODEL_PART, false);
|
|
TriangleMesh cavity = make_cube(20. - 2. * wall, 20. - wall - far_wall, 5.);
|
|
cavity.translate(float(wall), float(wall), 0.f);
|
|
object->add_volume(std::move(cavity), 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;
|
|
}
|
|
|
|
// Every setting the wall thicknesses below are measured against. With these widths the two outer walls of
|
|
// a 0.8mm wall touch, a 1mm wall leaves a gap between them for gap fill, and an inner wall needs about 1.5mm.
|
|
// Both one wall options are on, so the first and the last layer have a single wall whatever wall_loops asks.
|
|
DynamicPrintConfig hole_direction_config(int wall_loops, const char *wall_direction)
|
|
{
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
config.set_deserialize_strict({
|
|
{ "wall_generator", "classic" },
|
|
{ "wall_direction", wall_direction },
|
|
{ "wall_loops", wall_loops },
|
|
{ "layer_height", 0.2 },
|
|
{ "initial_layer_print_height", 0.2 },
|
|
{ "outer_wall_line_width", 0.42 },
|
|
{ "inner_wall_line_width", 0.45 },
|
|
{ "detect_thin_wall", false },
|
|
{ "filter_out_gap_fill", 0 },
|
|
{ "top_shell_layers", 3 },
|
|
{ "bottom_shell_layers", 3 },
|
|
{ "only_one_wall_top", true },
|
|
{ "only_one_wall_first_layer", true },
|
|
{ "overhang_reverse", false },
|
|
{ "sparse_infill_density", "15%" },
|
|
});
|
|
return config;
|
|
}
|
|
|
|
// The outer walls of a layer, contours and holes apart, and how many inner walls and gap fills it has.
|
|
struct WallDirections {
|
|
std::vector<bool> contours_ccw;
|
|
std::vector<bool> holes_ccw;
|
|
int inner_walls = 0;
|
|
size_t gap_fills = 0;
|
|
};
|
|
|
|
std::vector<WallDirections> wall_directions(const Print &print)
|
|
{
|
|
std::vector<WallDirections> out;
|
|
for (const Layer *layer : print.objects().front()->layers()) {
|
|
WallDirections &walls = out.emplace_back();
|
|
for (const LayerRegion *region : layer->regions()) {
|
|
walls.gap_fills += region->thin_fills.flatten().entities.size();
|
|
for (const ExtrusionEntity *entity : region->perimeters.flatten().entities) {
|
|
if (! entity->is_loop())
|
|
continue;
|
|
const ExtrusionLoop *loop = static_cast<const ExtrusionLoop*>(entity);
|
|
if (loop->inset_idx > 0)
|
|
++ walls.inner_walls;
|
|
else
|
|
(loop->loop_role() == elrHole ? walls.holes_ccw : walls.contours_ccw).push_back(loop->polygon().is_counter_clockwise());
|
|
}
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// Holes run against the wall direction, so the inside of a hole keeps its direction on the layers where the
|
|
// hole opens into the contour. That holds on every layer, the single wall ones included, as soon as anything
|
|
// fits beside the outer wall of the hole: infill, an inner wall, or only gap fill. The 1mm tube with a 3mm far
|
|
// side is the shape that used to flip, where the far side has an inner wall on most layers and gap fill runs
|
|
// around the rest.
|
|
TEST_CASE("Holes run against the wall direction", "[Perimeters]")
|
|
{
|
|
const auto [wall, far_wall] = GENERATE(std::make_pair(7., 7.), std::make_pair(1., 1.), std::make_pair(1., 3.));
|
|
const int wall_loops = GENERATE(1, 2);
|
|
const char *wall_direction = GENERATE("ccw", "cw");
|
|
CAPTURE(wall, far_wall, wall_loops, wall_direction);
|
|
|
|
Print print;
|
|
Model model;
|
|
square_tube(print, model, hole_direction_config(wall_loops, wall_direction), wall, far_wall);
|
|
const std::vector<WallDirections> layers = wall_directions(print);
|
|
// 5mm at 0.2mm layers.
|
|
REQUIRE(layers.size() == 25);
|
|
// Without gap fill between the outer walls the thin tubes would test the case below instead.
|
|
if (wall < 2.)
|
|
REQUIRE(layers[layers.size() / 2].gap_fills > 0);
|
|
|
|
const bool ccw = std::string(wall_direction) == "ccw";
|
|
for (size_t i = 0; i < layers.size(); ++ i) {
|
|
CAPTURE(i);
|
|
REQUIRE(layers[i].contours_ccw.size() == 1);
|
|
REQUIRE(layers[i].holes_ccw.size() == 1);
|
|
CHECK(layers[i].contours_ccw.front() == ccw);
|
|
CHECK(layers[i].holes_ccw.front() == ! ccw);
|
|
}
|
|
}
|
|
|
|
// A hole whose outer wall touches the contour's all around, with nothing between them, runs with the contour
|
|
// on every layer, so the two walls of a thin tube are laid side by side in the same direction.
|
|
TEST_CASE("A hole whose outer wall touches the contour's runs with it", "[Perimeters]")
|
|
{
|
|
const int wall_loops = GENERATE(1, 2);
|
|
const char *wall_direction = GENERATE("ccw", "cw");
|
|
CAPTURE(wall_loops, wall_direction);
|
|
|
|
Print print;
|
|
Model model;
|
|
square_tube(print, model, hole_direction_config(wall_loops, wall_direction), 0.8, 0.8);
|
|
const std::vector<WallDirections> layers = wall_directions(print);
|
|
REQUIRE(layers.size() == 25);
|
|
// Nothing fits between the two outer walls.
|
|
REQUIRE(layers[layers.size() / 2].gap_fills == 0);
|
|
REQUIRE(layers[layers.size() / 2].inner_walls == 0);
|
|
|
|
const bool ccw = std::string(wall_direction) == "ccw";
|
|
for (size_t i = 0; i < layers.size(); ++ i) {
|
|
CAPTURE(i);
|
|
REQUIRE(layers[i].contours_ccw.size() == 1);
|
|
REQUIRE(layers[i].holes_ccw.size() == 1);
|
|
CHECK(layers[i].contours_ccw.front() == ccw);
|
|
CHECK(layers[i].holes_ccw.front() == ccw);
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
|
|
// The outer radius of round_tube().
|
|
const double tube_radius = 11.5;
|
|
|
|
// Every setting the tube walls below are measured against. With 0.5mm walls a 1mm tube wall holds only the two
|
|
// outer walls, touching, and every further 0.5mm makes room for one more inner wall.
|
|
DynamicPrintConfig tube_config(const char *wall_generator, int wall_loops)
|
|
{
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
config.set_deserialize_strict({
|
|
{ "wall_generator", wall_generator },
|
|
{ "wall_loops", wall_loops },
|
|
{ "wall_sequence", "inner wall/outer wall" },
|
|
{ "wall_direction", "ccw" },
|
|
{ "layer_height", 0.2 },
|
|
{ "initial_layer_print_height", 0.2 },
|
|
{ "nozzle_diameter", "0.4" },
|
|
{ "outer_wall_line_width", 0.5 },
|
|
{ "inner_wall_line_width", 0.5 },
|
|
{ "precise_outer_wall", true },
|
|
{ "detect_thin_wall", false },
|
|
{ "only_one_wall_top", false },
|
|
{ "only_one_wall_first_layer", false },
|
|
{ "brim_type", "no_brim" },
|
|
{ "detect_overhang_wall", true },
|
|
{ "overhang_reverse", false },
|
|
{ "overhang_reverse_threshold", "0%" },
|
|
});
|
|
return config;
|
|
}
|
|
|
|
// A 2mm tall round tube whose wall is `wall` mm thick.
|
|
Print &round_tube(Print &print, Model &model, const DynamicPrintConfig &config, double wall)
|
|
{
|
|
ModelObject *object = model.add_object();
|
|
object->name = "round_tube.stl";
|
|
object->add_volume(make_cylinder(tube_radius, 2.), ModelVolumeType::MODEL_PART, false);
|
|
object->add_volume(make_cylinder(tube_radius - wall, 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;
|
|
}
|
|
|
|
// The side of the tube wall a wall loop lies on. The centre is the middle of the tube wall, where Arachne lays the
|
|
// inner wall both sides share when the tube wall is too narrow for a pair of them.
|
|
enum class TubeSide { Contour, Hole, Centre };
|
|
|
|
struct TubeLoop {
|
|
TubeSide side;
|
|
int inset;
|
|
bool ccw;
|
|
};
|
|
|
|
// The wall loops of every layer of round_tube() in extrusion order.
|
|
std::vector<std::vector<TubeLoop>> tube_loops(const Print &print, double wall)
|
|
{
|
|
const double centre = tube_radius - 0.5 * wall;
|
|
std::vector<std::vector<TubeLoop>> out;
|
|
for (const Layer *layer : print.objects().front()->layers()) {
|
|
const Vec2d axis = get_extents(layer->lslices).center().cast<double>();
|
|
std::vector<TubeLoop> &loops = out.emplace_back();
|
|
for (const LayerRegion *region : layer->regions())
|
|
for (const ExtrusionEntity *entity : region->perimeters.flatten().entities) {
|
|
if (! entity->is_loop())
|
|
continue;
|
|
const ExtrusionLoop *loop = static_cast<const ExtrusionLoop*>(entity);
|
|
const Polygon polygon = loop->polygon();
|
|
double radius = 0.;
|
|
for (const Point &p : polygon.points)
|
|
radius += unscaled<double>((p.cast<double>() - axis).norm());
|
|
radius /= double(polygon.points.size());
|
|
const TubeSide side = radius > centre + 0.1 ? TubeSide::Contour : radius < centre - 0.1 ? TubeSide::Hole : TubeSide::Centre;
|
|
loops.push_back({ side, loop->inset_idx, polygon.is_counter_clockwise() });
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// The insets one side of a wall is printed in, given its deepest inset: inside out for Inner/Outer, outside in for
|
|
// Outer/Inner, and for Inner/Outer/Inner the third wall onwards inside out, then the outer wall, then the first inner
|
|
// wall. Inner/Outer/Inner prints its first layer Inner/Outer, and outside in when there is no third wall.
|
|
std::vector<int> wall_sequence_insets(const std::string &wall_sequence, bool first_layer, int deepest)
|
|
{
|
|
std::vector<int> insets;
|
|
if (wall_sequence == "inner wall/outer wall" || (wall_sequence == "inner-outer-inner wall" && first_layer)) {
|
|
for (int inset = deepest; inset >= 0; -- inset)
|
|
insets.push_back(inset);
|
|
} else if (wall_sequence == "outer wall/inner wall" || deepest < 2) {
|
|
for (int inset = 0; inset <= deepest; ++ inset)
|
|
insets.push_back(inset);
|
|
} else {
|
|
for (int inset = deepest; inset >= 2; -- inset)
|
|
insets.push_back(inset);
|
|
insets.push_back(0);
|
|
insets.push_back(1);
|
|
}
|
|
return insets;
|
|
}
|
|
|
|
// Whether a wall of round_tube() runs with the contour: all but the walls of the hole, and those too when the hole
|
|
// is a thin wall hole, its outer wall touching the contour's with nothing between them.
|
|
bool runs_with_contour(const TubeLoop &loop, bool thin_wall_hole)
|
|
{
|
|
return loop.side != TubeSide::Hole || thin_wall_hole;
|
|
}
|
|
|
|
// The insets of the walls on one side of a round_tube() layer, the shared centre line included, in extrusion order.
|
|
std::vector<int> side_insets(const std::vector<TubeLoop> &loops, TubeSide side)
|
|
{
|
|
std::vector<int> insets;
|
|
for (const TubeLoop &loop : loops)
|
|
if (loop.side == side || loop.side == TubeSide::Centre)
|
|
insets.push_back(loop.inset);
|
|
return insets;
|
|
}
|
|
|
|
// The walls of a round_tube() layer in extrusion order, as side and inset: "c0 c1 h0 h1" is the contour's outer wall,
|
|
// then its first inner wall, then the same for the hole, and "m" marks the wall in the middle both sides share.
|
|
std::string wall_order(const std::vector<TubeLoop> &loops)
|
|
{
|
|
std::string out;
|
|
for (const TubeLoop &loop : loops)
|
|
out += std::string(out.empty() ? "" : " ") + (loop.side == TubeSide::Contour ? "c" : loop.side == TubeSide::Hole ? "h" : "m") +
|
|
std::to_string(loop.inset);
|
|
return out;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// Each side of a tube wall prints its walls in the order the wall sequence asks for, from two walls a side up to
|
|
// four. The inner wall Arachne lays in the middle of a wall too narrow for a pair of them is an inner wall of both
|
|
// sides; Classic fills that middle with gap fill instead, so it has one wall less a side there.
|
|
TEST_CASE("Each side of a tube wall prints its walls in the wall sequence order", "[Perimeters]")
|
|
{
|
|
struct TubeWall {
|
|
double wall;
|
|
int wall_loops;
|
|
// Walls a side, a shared inner wall included.
|
|
int arachne_walls;
|
|
int classic_walls;
|
|
};
|
|
const TubeWall tube = GENERATE(values<TubeWall>({
|
|
{ 1.5, 3, 2, 1 }, { 2.0, 2, 2, 2 }, { 2.5, 3, 3, 2 }, { 3.0, 3, 3, 3 }, { 4.0, 4, 4, 4 } }));
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
const std::string wall_sequence = GENERATE("inner wall/outer wall", "outer wall/inner wall", "inner-outer-inner wall");
|
|
CAPTURE(tube.wall, tube.wall_loops, wall_generator, wall_sequence);
|
|
|
|
DynamicPrintConfig config = tube_config(wall_generator, tube.wall_loops);
|
|
config.set_deserialize_strict("wall_sequence", wall_sequence);
|
|
Print print;
|
|
Model model;
|
|
round_tube(print, model, config, tube.wall);
|
|
const std::vector<std::vector<TubeLoop>> layers = tube_loops(print, tube.wall);
|
|
// 2mm at 0.2mm layers.
|
|
REQUIRE(layers.size() == 10);
|
|
|
|
const int walls = std::string(wall_generator) == "arachne" ? tube.arachne_walls : tube.classic_walls;
|
|
for (size_t i = 0; i < layers.size(); ++ i) {
|
|
for (const TubeSide side : { TubeSide::Contour, TubeSide::Hole }) {
|
|
const bool contour_side = side == TubeSide::Contour;
|
|
CAPTURE(i, contour_side);
|
|
const std::vector<int> insets = side_insets(layers[i], side);
|
|
REQUIRE(int(insets.size()) == walls);
|
|
CHECK(insets == wall_sequence_insets(wall_sequence, i == 0, walls - 1));
|
|
}
|
|
}
|
|
}
|
|
|
|
// The outer wall of a thin wall hole touches the contour's with nothing between them. The hole is printed first, so
|
|
// the contour leans on it, unless the wall sequence puts the outer walls first.
|
|
TEST_CASE("A thin wall hole is printed before the contour unless the outer walls go first", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
const std::string wall_sequence = GENERATE("inner wall/outer wall", "outer wall/inner wall", "inner-outer-inner wall");
|
|
CAPTURE(wall_generator, wall_sequence);
|
|
|
|
DynamicPrintConfig config = tube_config(wall_generator, 3);
|
|
config.set_deserialize_strict("wall_sequence", wall_sequence);
|
|
Print print;
|
|
Model model;
|
|
round_tube(print, model, config, 1.);
|
|
const std::vector<std::vector<TubeLoop>> layers = tube_loops(print, 1.);
|
|
REQUIRE(layers.size() == 10);
|
|
|
|
const TubeSide first = wall_sequence == "outer wall/inner wall" ? TubeSide::Contour : TubeSide::Hole;
|
|
for (size_t i = 0; i < layers.size(); ++ i) {
|
|
CAPTURE(i);
|
|
REQUIRE(layers[i].size() == 2);
|
|
REQUIRE(layers[i][0].side != layers[i][1].side);
|
|
CHECK(layers[i].front().side == first);
|
|
}
|
|
}
|
|
|
|
// A 1.5mm tube wall leaves Inner/Outer/Inner no third wall to sandwich, only the inner wall Arachne lays in the middle
|
|
// for both sides, or Classic's gap fill. Past the first layer it prints the hole first, then the contour, then the
|
|
// middle.
|
|
TEST_CASE("Inner/Outer/Inner prints the hole of a narrow tube wall first and the middle last", "[Perimeters]")
|
|
{
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(wall_generator);
|
|
|
|
DynamicPrintConfig config = tube_config(wall_generator, 3);
|
|
config.set_deserialize_strict("wall_sequence", "inner-outer-inner wall");
|
|
Print print;
|
|
Model model;
|
|
round_tube(print, model, config, 1.5);
|
|
const std::vector<std::vector<TubeLoop>> layers = tube_loops(print, 1.5);
|
|
REQUIRE(layers.size() == 10);
|
|
|
|
// Classic's gap fill is not a wall loop, and goes after the walls.
|
|
const std::string expected = std::string(wall_generator) == "arachne" ? "h0 c0 m1" : "h0 c0";
|
|
for (size_t i = 1; i < layers.size(); ++ i) {
|
|
CAPTURE(i);
|
|
CHECK(wall_order(layers[i]) == expected);
|
|
}
|
|
}
|
|
|
|
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]")
|
|
{
|
|
const double wall = GENERATE(1.0, 1.5, 2.0, 3.0);
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
const std::string wall_direction = GENERATE("ccw", "cw");
|
|
CAPTURE(wall, wall_generator, wall_direction);
|
|
|
|
DynamicPrintConfig config = tube_config(wall_generator, 3);
|
|
config.set_deserialize_strict("wall_direction", wall_direction);
|
|
Print print;
|
|
Model model;
|
|
round_tube(print, model, config, wall);
|
|
const std::vector<std::vector<TubeLoop>> layers = tube_loops(print, wall);
|
|
REQUIRE(layers.size() == 10);
|
|
|
|
const bool thin_wall_hole = wall == 1.;
|
|
for (size_t i = 0; i < layers.size(); ++ i) {
|
|
CAPTURE(i);
|
|
REQUIRE(std::any_of(layers[i].begin(), layers[i].end(), [](const TubeLoop &loop) { return loop.side == TubeSide::Contour; }));
|
|
REQUIRE(std::any_of(layers[i].begin(), layers[i].end(), [](const TubeLoop &loop) { return loop.side == TubeSide::Hole; }));
|
|
for (const TubeLoop &loop : layers[i]) {
|
|
CAPTURE(int(loop.side), loop.inset);
|
|
CHECK(loop.ccw == (runs_with_contour(loop, thin_wall_hole) == (wall_direction == "ccw")));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Reverse on even with no threshold reverses every wall of every other layer, or only the inner walls when it is
|
|
// restricted to them, and leaves the order of the walls alone.
|
|
TEST_CASE("Reverse on even reverses the tube walls of every other layer", "[Perimeters]")
|
|
{
|
|
const double wall = GENERATE(1.0, 1.5, 3.0);
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
const bool reverse_internal_only = GENERATE(false, true);
|
|
CAPTURE(wall, wall_generator, reverse_internal_only);
|
|
|
|
auto slice = [&](bool overhang_reverse) {
|
|
DynamicPrintConfig config = tube_config(wall_generator, 3);
|
|
config.set_deserialize_strict({
|
|
{ "overhang_reverse", overhang_reverse },
|
|
{ "overhang_reverse_internal_only", reverse_internal_only },
|
|
});
|
|
Print print;
|
|
Model model;
|
|
round_tube(print, model, config, wall);
|
|
return tube_loops(print, wall);
|
|
};
|
|
const std::vector<std::vector<TubeLoop>> plain = slice(false);
|
|
const std::vector<std::vector<TubeLoop>> reversed = slice(true);
|
|
REQUIRE(plain.size() == 10);
|
|
REQUIRE(reversed.size() == plain.size());
|
|
|
|
for (size_t i = 0; i < plain.size(); ++ i) {
|
|
CAPTURE(i);
|
|
REQUIRE(reversed[i].size() == plain[i].size());
|
|
for (size_t j = 0; j < plain[i].size(); ++ j) {
|
|
CAPTURE(j);
|
|
CHECK(reversed[i][j].side == plain[i][j].side);
|
|
CHECK(reversed[i][j].inset == plain[i][j].inset);
|
|
const bool flips = i % 2 == 1 && (! reverse_internal_only || plain[i][j].inset > 0);
|
|
CHECK(reversed[i][j].ccw == (plain[i][j].ccw != flips));
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
|
|
DynamicPrintConfig brim_tube_config(const char *wall_generator, const std::string &wall_sequence, const char *brim_type, double brim_width)
|
|
{
|
|
DynamicPrintConfig config = tube_config(wall_generator, 3);
|
|
config.set_deserialize_strict({
|
|
{ "wall_sequence", wall_sequence },
|
|
{ "brim_type", brim_type },
|
|
{ "brim_width", brim_width },
|
|
});
|
|
return config;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// A brim against the outer walls makes the first layer print them first, whatever the wall sequence, so the brim runs
|
|
// straight on into the outer wall: each side of the tube wall outside in, and the contour before a thin wall hole.
|
|
// Brims that may leave the outer walls bare keep the wall sequence, and so do the layers above.
|
|
TEST_CASE("A brim against the outer walls makes the first layer print them first", "[Perimeters]")
|
|
{
|
|
struct Brim {
|
|
const char *type;
|
|
double width;
|
|
bool outer_walls_first;
|
|
};
|
|
const Brim brim = GENERATE(values<Brim>({
|
|
{ "no_brim", 5., false }, { "inner_only", 5., false }, { "auto_brim", 5., false }, { "outer_only", 0., false },
|
|
{ "outer_only", 5., true }, { "outer_and_inner", 5., true }, { "leading_edge_only", 5., true } }));
|
|
const double wall = GENERATE(1.0, 3.0);
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
const std::string wall_sequence = GENERATE("inner wall/outer wall", "inner-outer-inner wall");
|
|
CAPTURE(brim.type, brim.width, wall, wall_generator, wall_sequence);
|
|
|
|
Print print;
|
|
Model model;
|
|
round_tube(print, model, brim_tube_config(wall_generator, wall_sequence, brim.type, brim.width), wall);
|
|
const std::vector<std::vector<TubeLoop>> layers = tube_loops(print, wall);
|
|
REQUIRE(layers.size() == 10);
|
|
|
|
// The thin wall hole has its outer wall a side, the 3mm tube wall three walls a side.
|
|
const size_t walls = wall == 1. ? 1 : 3;
|
|
for (const size_t i : { size_t(0), size_t(1) }) {
|
|
const bool outer_walls_first = brim.outer_walls_first && i == 0;
|
|
for (const TubeSide side : { TubeSide::Contour, TubeSide::Hole }) {
|
|
const bool contour_side = side == TubeSide::Contour;
|
|
CAPTURE(i, contour_side);
|
|
const std::vector<int> insets = side_insets(layers[i], side);
|
|
REQUIRE(insets.size() == walls);
|
|
CHECK(insets == wall_sequence_insets(outer_walls_first ? "outer wall/inner wall" : wall_sequence, i == 0, int(walls) - 1));
|
|
}
|
|
if (wall == 1.)
|
|
CHECK(layers[i].front().side == (outer_walls_first ? TubeSide::Contour : TubeSide::Hole));
|
|
}
|
|
}
|
|
|
|
// Changing the brim of a sliced print regenerates the walls when the first layer's wall order changes with it, so
|
|
// the print gets the walls a slice from scratch with the new brim gets.
|
|
TEST_CASE("Changing the brim updates the wall order of the first layer", "[Perimeters]")
|
|
{
|
|
struct BrimChange {
|
|
const char *from_type;
|
|
double from_width;
|
|
const char *to_type;
|
|
double to_width;
|
|
};
|
|
const BrimChange change = GENERATE(values<BrimChange>({
|
|
{ "outer_only", 0., "outer_only", 5. }, { "outer_only", 5., "outer_only", 0. },
|
|
{ "no_brim", 5., "outer_and_inner", 5. }, { "outer_and_inner", 5., "inner_only", 5. } }));
|
|
const char *wall_generator = GENERATE("classic", "arachne");
|
|
CAPTURE(change.from_type, change.from_width, change.to_type, change.to_width, wall_generator);
|
|
|
|
const std::string wall_sequence = "inner wall/outer wall";
|
|
Print print;
|
|
Model model;
|
|
round_tube(print, model, brim_tube_config(wall_generator, wall_sequence, change.from_type, change.from_width), 3.);
|
|
const std::string before = wall_order(tube_loops(print, 3.).front());
|
|
print.apply(model, brim_tube_config(wall_generator, wall_sequence, change.to_type, change.to_width));
|
|
print.process();
|
|
const std::string after = wall_order(tube_loops(print, 3.).front());
|
|
|
|
Print fresh_print;
|
|
Model fresh_model;
|
|
round_tube(fresh_print, fresh_model, brim_tube_config(wall_generator, wall_sequence, change.to_type, change.to_width), 3.);
|
|
const std::string fresh = wall_order(tube_loops(fresh_print, 3.).front());
|
|
|
|
// The change does turn the first layer around.
|
|
REQUIRE(before != fresh);
|
|
CHECK(after == fresh);
|
|
}
|