mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-04 14:20:58 +00:00
* Ignore Clipper, libpng, mcut and Boost.Polygon Internals in clang-tidy Each only works through a wrapper or umbrella header: libslic3r/clipper.hpp or clipper_z.hpp configure Clipper before including it, png.h pulls in libpng's config headers, and Boost.Polygon's headers only compile through polygon.hpp or voronoi.hpp. * Ignore minilzo's Config Headers in clang-tidy lzoconf.h and lzodefs.h are internal to minilzo.h, which is what the code includes. * Add Missing Includes Across the Remaining Sources and Tests Covers src/slic3r/Utils, src/slic3r/plugin, src/slic3r/Config, src/libvgcode, src/dev-utils, src/OrcaSlicer.cpp and tests/, the directories left after src/slic3r/GUI and src/libslic3r. Generated with clang-tidy misc-include-cleaner. libvgcode's own headers are included by relative path as in the rest of that library, and Catch2 and pybind11 with angle brackets as elsewhere in the repo. * Make the GUI and Test Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Headers that only compile on one platform, or that nothing built includes, are left alone. * Keep Windows and nanosvg Setup Ahead of the Added Includes OrcaSlicer.cpp and several tests set _WIN32_WINNT, WIN32_LEAN_AND_MEAN or NOMINMAX before including Windows.h, and the profile validator defines NANOSVG_IMPLEMENTATION before any libslic3r header. The added includes had landed above those blocks, which broke the Windows build. * Add the GUI Includes the First Pass Missed Covers headers that only became editable once they compiled on their own, and wx symbols whose suggested header changed as the clang-tidy ignore list grew after the src/slic3r/GUI pass. * Keep the Added Test Includes Below the NOMINMAX Guard test_marchingsquares.cpp and test_texture_displacement.cpp had includes inside #ifndef NOMINMAX, which the tests inherit as defined on Windows from libslic3r, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory, as in #16068.
208 lines
6.0 KiB
C++
208 lines
6.0 KiB
C++
#ifndef SLA_TEST_UTILS_HPP
|
|
#define SLA_TEST_UTILS_HPP
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include "test_utils.hpp"
|
|
|
|
// Debug
|
|
#include <cstddef>
|
|
#include <climits>
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include "libslic3r/SLA/SupportTree.hpp"
|
|
#include "libslic3r/SLA/Hollowing.hpp"
|
|
#include <unordered_map>
|
|
#include <random>
|
|
#include <type_traits>
|
|
#include "libslic3r/SLA/RasterBase.hpp"
|
|
#include "libslic3r/SLA/SupportPoint.hpp"
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
#include <utility>
|
|
|
|
#include "libslic3r/libslic3r.h"
|
|
#include "libslic3r/Format/OBJ.hpp"
|
|
#include "libslic3r/SLAPrint.hpp"
|
|
#include "libslic3r/TriangleMesh.hpp"
|
|
#include "libslic3r/SLA/Pad.hpp"
|
|
#include "libslic3r/SLA/SupportTreeBuilder.hpp"
|
|
#include "libslic3r/SLA/SupportTreeBuildsteps.hpp"
|
|
#include "libslic3r/SLA/SupportPointGenerator.hpp"
|
|
#include "libslic3r/SLA/AGGRaster.hpp"
|
|
#include "libslic3r/SLA/ConcaveHull.hpp"
|
|
#include "libslic3r/MTUtils.hpp"
|
|
|
|
#include "libslic3r/SVG.hpp"
|
|
#include "libslic3r/Format/OBJ.hpp"
|
|
|
|
using namespace Slic3r;
|
|
|
|
enum e_validity {
|
|
ASSUME_NO_EMPTY = 1,
|
|
ASSUME_MANIFOLD = 2,
|
|
ASSUME_NO_REPAIR = 4
|
|
};
|
|
|
|
void check_validity(const TriangleMesh &input_mesh,
|
|
int flags = ASSUME_NO_EMPTY | ASSUME_MANIFOLD |
|
|
ASSUME_NO_REPAIR);
|
|
|
|
struct PadByproducts
|
|
{
|
|
ExPolygons model_contours;
|
|
ExPolygons support_contours;
|
|
TriangleMesh mesh;
|
|
};
|
|
|
|
void test_concave_hull(const ExPolygons &polys);
|
|
|
|
void test_pad(const std::string & obj_filename,
|
|
const sla::PadConfig &padcfg,
|
|
PadByproducts & out);
|
|
|
|
inline void test_pad(const std::string & obj_filename,
|
|
const sla::PadConfig &padcfg = {})
|
|
{
|
|
PadByproducts byproducts;
|
|
test_pad(obj_filename, padcfg, byproducts);
|
|
}
|
|
|
|
struct SupportByproducts
|
|
{
|
|
std::string obj_fname;
|
|
std::vector<float> slicegrid;
|
|
std::vector<ExPolygons> model_slices;
|
|
sla::SupportTreeBuilder supporttree;
|
|
TriangleMesh input_mesh;
|
|
};
|
|
|
|
const constexpr float CLOSING_RADIUS = 0.005f;
|
|
|
|
void check_support_tree_integrity(const sla::SupportTreeBuilder &stree,
|
|
const sla::SupportTreeConfig &cfg);
|
|
|
|
void test_supports(const std::string &obj_filename,
|
|
const sla::SupportTreeConfig &supportcfg,
|
|
const sla::HollowingConfig &hollowingcfg,
|
|
const sla::DrainHoles &drainholes,
|
|
SupportByproducts &out);
|
|
|
|
inline void test_supports(const std::string &obj_filename,
|
|
const sla::SupportTreeConfig &supportcfg,
|
|
SupportByproducts &out)
|
|
{
|
|
sla::HollowingConfig hcfg;
|
|
hcfg.enabled = false;
|
|
test_supports(obj_filename, supportcfg, hcfg, {}, out);
|
|
}
|
|
|
|
inline void test_supports(const std::string &obj_filename,
|
|
const sla::SupportTreeConfig &supportcfg = {})
|
|
{
|
|
SupportByproducts byproducts;
|
|
test_supports(obj_filename, supportcfg, byproducts);
|
|
}
|
|
|
|
void export_failed_case(const std::vector<ExPolygons> &support_slices,
|
|
const SupportByproducts &byproducts);
|
|
|
|
|
|
void test_support_model_collision(
|
|
const std::string &obj_filename,
|
|
const sla::SupportTreeConfig &input_supportcfg,
|
|
const sla::HollowingConfig &hollowingcfg,
|
|
const sla::DrainHoles &drainholes);
|
|
|
|
inline void test_support_model_collision(
|
|
const std::string &obj_filename,
|
|
const sla::SupportTreeConfig &input_supportcfg = {})
|
|
{
|
|
sla::HollowingConfig hcfg;
|
|
hcfg.enabled = false;
|
|
test_support_model_collision(obj_filename, input_supportcfg, hcfg, {});
|
|
}
|
|
|
|
// Test pair hash for 'nums' random number pairs.
|
|
template <class I, class II> void test_pairhash()
|
|
{
|
|
const constexpr size_t nums = 1000;
|
|
I A[nums] = {0}, B[nums] = {0};
|
|
std::unordered_set<I> CH;
|
|
std::unordered_map<II, std::pair<I, I>> ints;
|
|
|
|
std::random_device rd;
|
|
std::mt19937 gen(rd());
|
|
|
|
const I Ibits = int(sizeof(I) * CHAR_BIT);
|
|
const II IIbits = int(sizeof(II) * CHAR_BIT);
|
|
|
|
int bits = IIbits / 2 < Ibits ? Ibits / 2 : Ibits;
|
|
if (std::is_signed<I>::value) bits -= 1;
|
|
const I Imin = 0;
|
|
const I Imax = I(std::pow(2., bits) - 1);
|
|
|
|
std::uniform_int_distribution<I> dis(Imin, Imax);
|
|
|
|
for (size_t i = 0; i < nums;) {
|
|
I a = dis(gen);
|
|
if (CH.find(a) == CH.end()) { CH.insert(a); A[i] = a; ++i; }
|
|
}
|
|
|
|
for (size_t i = 0; i < nums;) {
|
|
I b = dis(gen);
|
|
if (CH.find(b) == CH.end()) { CH.insert(b); B[i] = b; ++i; }
|
|
}
|
|
|
|
for (size_t i = 0; i < nums; ++i) {
|
|
I a = A[i], b = B[i];
|
|
|
|
REQUIRE(a != b);
|
|
|
|
II hash_ab = sla::pairhash<I, II>(a, b);
|
|
II hash_ba = sla::pairhash<I, II>(b, a);
|
|
REQUIRE(hash_ab == hash_ba);
|
|
|
|
auto it = ints.find(hash_ab);
|
|
|
|
if (it != ints.end()) {
|
|
REQUIRE((
|
|
(it->second.first == a && it->second.second == b) ||
|
|
(it->second.first == b && it->second.second == a)
|
|
));
|
|
} else
|
|
ints[hash_ab] = std::make_pair(a, b);
|
|
}
|
|
}
|
|
|
|
// SLA Raster test utils:
|
|
|
|
using TPixel = uint8_t;
|
|
static constexpr const TPixel FullWhite = 255;
|
|
static constexpr const TPixel FullBlack = 0;
|
|
|
|
template <class A, int N> constexpr int arraysize(const A (&)[N]) { return N; }
|
|
|
|
void check_raster_transformations(sla::RasterBase::Orientation o,
|
|
sla::RasterBase::TMirroring mirroring);
|
|
|
|
ExPolygon square_with_hole(double v);
|
|
|
|
inline double pixel_area(TPixel px, const sla::PixelDim &pxdim)
|
|
{
|
|
return (pxdim.h_mm * pxdim.w_mm) * px * 1. / (FullWhite - FullBlack);
|
|
}
|
|
|
|
double raster_white_area(const sla::RasterGrayscaleAA &raster);
|
|
long raster_pxsum(const sla::RasterGrayscaleAA &raster);
|
|
|
|
double predict_error(const ExPolygon &p, const sla::PixelDim &pd);
|
|
|
|
sla::SupportPoints calc_support_pts(
|
|
const TriangleMesh & mesh,
|
|
const sla::SupportPointGenerator::Config &cfg = {});
|
|
|
|
#endif // SLA_TEST_UTILS_HPP
|