mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-06 23:31:19 +00:00
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes. clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer. * Remove Unused Project Includes From Files With Platform-Specific Code A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block. * Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass The platform-file pass treated pchheader.hpp as an ordinary header and emptied it, and left GUI_Preview.hpp and 14 other files relying on headers they no longer reached directly. * Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call * Include Headers That Files Reached Through Ones the Cleanup Removed * Drop Includes Duplicated by the Cleanup or by Main's Own Additions * Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
266 lines
8.2 KiB
C++
266 lines
8.2 KiB
C++
#include "libslic3r/TriangleMesh.hpp"
|
|
#include "libslic3r/SLA/IndexedMesh.hpp"
|
|
#include "libslic3r/SLA/SupportTree.hpp"
|
|
#include "libslic3r/SLA/SupportPointGenerator.hpp"
|
|
#include "libslic3r/MTUtils.hpp"
|
|
#include "libslic3r/ExPolygon.hpp"
|
|
#include "libslic3r/SLA/SupportPoint.hpp"
|
|
#include "libslic3r/Point.hpp"
|
|
#include <cstddef>
|
|
#include "libslic3r/SLA/Pad.hpp"
|
|
#include "libslic3r/SLA/RasterBase.hpp"
|
|
#include "libslic3r/SLA/AGGRaster.hpp"
|
|
#include <cstdlib>
|
|
#include "libslic3r/SLA/SupportTreeBuilder.hpp"
|
|
#include "libslic3r/Execution/Execution.hpp"
|
|
#include "libslic3r/Execution/ExecutionTBB.hpp"
|
|
#include <unordered_set>
|
|
#include <unordered_map>
|
|
#include <random>
|
|
#include <numeric>
|
|
#include <cstdint>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/catch_approx.hpp>
|
|
#include "sla_test_utils.hpp"
|
|
#include "test_utils.hpp"
|
|
|
|
#include <libslic3r/TriangleMeshSlicer.hpp>
|
|
#include <libslic3r/SLA/SupportTreeMesher.hpp>
|
|
#include <vector>
|
|
#include "libslic3r/BoundingBox.hpp"
|
|
#include "libslic3r/ExtrusionEntity.hpp"
|
|
|
|
namespace {
|
|
|
|
const char *const BELOW_PAD_TEST_OBJECTS[] = {
|
|
"20mm_cube.obj",
|
|
"V.obj",
|
|
};
|
|
|
|
const char *const AROUND_PAD_TEST_OBJECTS[] = {
|
|
"20mm_cube.obj",
|
|
"V.obj",
|
|
"frog_legs.obj",
|
|
"cube_with_concave_hole_enlarged.obj",
|
|
};
|
|
|
|
const char *const SUPPORT_TEST_MODELS[] = {
|
|
"cube_with_concave_hole_enlarged_standing.obj",
|
|
"A_upsidedown.obj",
|
|
"extruder_idler.obj"
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("Pillar pairhash should be unique", "[SLASupportGeneration]") {
|
|
test_pairhash<int, int>();
|
|
test_pairhash<int, long>();
|
|
test_pairhash<unsigned, unsigned>();
|
|
test_pairhash<unsigned, unsigned long>();
|
|
}
|
|
|
|
TEST_CASE("Support point generator should be deterministic if seeded",
|
|
"[SLASupportGeneration], [SLAPointGen]") {
|
|
TriangleMesh mesh = load_model("A_upsidedown.obj");
|
|
|
|
sla::IndexedMesh emesh{mesh};
|
|
|
|
sla::SupportTreeConfig supportcfg;
|
|
sla::SupportPointGenerator::Config autogencfg;
|
|
autogencfg.head_diameter = float(2 * supportcfg.head_front_radius_mm);
|
|
sla::SupportPointGenerator point_gen{emesh, autogencfg, [] {}, [](int) {}};
|
|
|
|
auto bb = mesh.bounding_box();
|
|
double zmin = bb.min.z();
|
|
double zmax = bb.max.z();
|
|
double gnd = zmin - supportcfg.object_elevation_mm;
|
|
auto layer_h = 0.05f;
|
|
|
|
auto slicegrid = grid(float(gnd), float(zmax), layer_h);
|
|
std::vector<ExPolygons> slices = slice_mesh_ex(mesh.its, slicegrid, CLOSING_RADIUS);
|
|
|
|
point_gen.seed(0);
|
|
point_gen.execute(slices, slicegrid);
|
|
|
|
auto get_chksum = [](const std::vector<sla::SupportPoint> &pts){
|
|
int64_t chksum = 0;
|
|
for (auto &pt : pts) {
|
|
auto p = scaled(pt.pos);
|
|
chksum += p.x() + p.y() + p.z();
|
|
}
|
|
|
|
return chksum;
|
|
};
|
|
|
|
int64_t checksum = get_chksum(point_gen.output());
|
|
size_t ptnum = point_gen.output().size();
|
|
REQUIRE(point_gen.output().size() > 0);
|
|
|
|
for (int i = 0; i < 20; ++i) {
|
|
point_gen.output().clear();
|
|
point_gen.seed(0);
|
|
point_gen.execute(slices, slicegrid);
|
|
REQUIRE(point_gen.output().size() == ptnum);
|
|
REQUIRE(checksum == get_chksum(point_gen.output()));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Flat pad geometry is valid", "[SLASupportGeneration]") {
|
|
sla::PadConfig padcfg;
|
|
|
|
// Disable wings
|
|
padcfg.wall_height_mm = .0;
|
|
|
|
for (auto &fname : BELOW_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
|
}
|
|
|
|
TEST_CASE("WingedPadGeometryIsValid", "[SLASupportGeneration]") {
|
|
sla::PadConfig padcfg;
|
|
|
|
// Add some wings to the pad to test the cavity
|
|
padcfg.wall_height_mm = 1.;
|
|
|
|
for (auto &fname : BELOW_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
|
}
|
|
|
|
TEST_CASE("FlatPadAroundObjectIsValid", "[SLASupportGeneration]") {
|
|
sla::PadConfig padcfg;
|
|
|
|
// Add some wings to the pad to test the cavity
|
|
padcfg.wall_height_mm = 0.;
|
|
// padcfg.embed_object.stick_stride_mm = 0.;
|
|
padcfg.embed_object.enabled = true;
|
|
padcfg.embed_object.everywhere = true;
|
|
|
|
for (auto &fname : AROUND_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
|
}
|
|
|
|
TEST_CASE("WingedPadAroundObjectIsValid", "[SLASupportGeneration]") {
|
|
sla::PadConfig padcfg;
|
|
|
|
// Add some wings to the pad to test the cavity
|
|
padcfg.wall_height_mm = 1.;
|
|
padcfg.embed_object.enabled = true;
|
|
padcfg.embed_object.everywhere = true;
|
|
|
|
for (auto &fname : AROUND_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
|
}
|
|
|
|
TEST_CASE("ElevatedSupportGeometryIsValid", "[SLASupportGeneration]") {
|
|
sla::SupportTreeConfig supportcfg;
|
|
supportcfg.object_elevation_mm = 10.;
|
|
|
|
for (auto fname : SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
|
|
}
|
|
|
|
TEST_CASE("FloorSupportGeometryIsValid", "[SLASupportGeneration]") {
|
|
sla::SupportTreeConfig supportcfg;
|
|
supportcfg.object_elevation_mm = 0;
|
|
|
|
for (auto &fname: SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
|
|
}
|
|
|
|
TEST_CASE("ElevatedSupportsDoNotPierceModel", "[SLASupportGeneration]") {
|
|
|
|
sla::SupportTreeConfig supportcfg;
|
|
|
|
for (auto fname : SUPPORT_TEST_MODELS)
|
|
test_support_model_collision(fname, supportcfg);
|
|
}
|
|
|
|
TEST_CASE("FloorSupportsDoNotPierceModel", "[SLASupportGeneration]") {
|
|
|
|
sla::SupportTreeConfig supportcfg;
|
|
supportcfg.object_elevation_mm = 0;
|
|
|
|
for (auto fname : SUPPORT_TEST_MODELS)
|
|
test_support_model_collision(fname, supportcfg);
|
|
}
|
|
|
|
TEST_CASE("InitializedRasterShouldBeNONEmpty", "[SLARasterOutput]") {
|
|
// Default SL1 display parameters
|
|
sla::Resolution res{2560, 1440};
|
|
sla::PixelDim pixdim{120. / res.width_px, 68. / res.height_px};
|
|
|
|
sla::RasterGrayscaleAAGammaPower raster(res, pixdim, {}, 1.);
|
|
REQUIRE(raster.resolution().width_px == res.width_px);
|
|
REQUIRE(raster.resolution().height_px == res.height_px);
|
|
REQUIRE(raster.pixel_dimensions().w_mm == Catch::Approx(pixdim.w_mm));
|
|
REQUIRE(raster.pixel_dimensions().h_mm == Catch::Approx(pixdim.h_mm));
|
|
}
|
|
|
|
TEST_CASE("MirroringShouldBeCorrect", "[SLARasterOutput]") {
|
|
sla::RasterBase::TMirroring mirrorings[] = {sla::RasterBase::NoMirror,
|
|
sla::RasterBase::MirrorX,
|
|
sla::RasterBase::MirrorY,
|
|
sla::RasterBase::MirrorXY};
|
|
|
|
sla::RasterBase::Orientation orientations[] =
|
|
{sla::RasterBase::roLandscape, sla::RasterBase::roPortrait};
|
|
|
|
for (auto orientation : orientations)
|
|
for (auto &mirror : mirrorings)
|
|
check_raster_transformations(orientation, mirror);
|
|
}
|
|
|
|
|
|
TEST_CASE("RasterizedPolygonAreaShouldMatch", "[SLARasterOutput]") {
|
|
double disp_w = 120., disp_h = 68.;
|
|
sla::Resolution res{2560, 1440};
|
|
sla::PixelDim pixdim{disp_w / res.width_px, disp_h / res.height_px};
|
|
|
|
double gamma = 1.;
|
|
sla::RasterGrayscaleAAGammaPower raster(res, pixdim, {}, gamma);
|
|
auto bb = BoundingBox({0, 0}, {scaled(disp_w), scaled(disp_h)});
|
|
|
|
ExPolygon poly = square_with_hole(10.);
|
|
poly.translate(bb.center().x(), bb.center().y());
|
|
raster.draw(poly);
|
|
|
|
double a = poly.area() / (scaled<double>(1.) * scaled(1.));
|
|
double ra = raster_white_area(raster);
|
|
double diff = std::abs(a - ra);
|
|
|
|
REQUIRE(diff <= predict_error(poly, pixdim));
|
|
|
|
raster.clear();
|
|
poly = square_with_hole(60.);
|
|
poly.translate(bb.center().x(), bb.center().y());
|
|
raster.draw(poly);
|
|
|
|
a = poly.area() / (scaled<double>(1.) * scaled(1.));
|
|
ra = raster_white_area(raster);
|
|
diff = std::abs(a - ra);
|
|
|
|
REQUIRE(diff <= predict_error(poly, pixdim));
|
|
|
|
sla::RasterGrayscaleAA raster0(res, pixdim, {}, [](double) { return 0.; });
|
|
REQUIRE(raster_pxsum(raster0) == 0);
|
|
|
|
raster0.draw(poly);
|
|
ra = raster_white_area(raster);
|
|
REQUIRE(raster_pxsum(raster0) == 0);
|
|
}
|
|
|
|
|
|
TEST_CASE("halfcone test", "[halfcone]") {
|
|
sla::DiffBridge br{Vec3d{1., 1., 1.}, Vec3d{10., 10., 10.}, 0.25, 0.5};
|
|
|
|
indexed_triangle_set m = sla::get_mesh(br, 45);
|
|
|
|
its_merge_vertices(m);
|
|
write_debug_obj("sla_print/Halfcone.obj", m);
|
|
}
|
|
|
|
TEST_CASE("Test concurrency")
|
|
{
|
|
std::vector<double> vals = grid(0., 100., 10.);
|
|
|
|
double ref = std::accumulate(vals.begin(), vals.end(), 0.);
|
|
|
|
double s = execution::accumulate(ex_tbb, vals.begin(), vals.end(), 0.);
|
|
|
|
REQUIRE(s == Catch::Approx(ref));
|
|
}
|