mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-07 07:41:06 +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
99 lines
2.8 KiB
C++
99 lines
2.8 KiB
C++
#include "RasterToPolygons.hpp"
|
|
|
|
#include "AGGRaster.hpp"
|
|
#include "libslic3r/ExPolygon.hpp"
|
|
#include "libslic3r/Point.hpp"
|
|
#include "libslic3r/Polygon.hpp"
|
|
#include "libslic3r/libslic3r.h"
|
|
#include "libslic3r/MarchingSquares.hpp"
|
|
#include "ClipperUtils.hpp"
|
|
#include <cstdint>
|
|
#include <cstddef>
|
|
#include <algorithm>
|
|
#include <vector>
|
|
#include <utility>
|
|
#include "libslic3r/SLA/RasterBase.hpp"
|
|
|
|
namespace marchsq {
|
|
|
|
// Specialize this struct to register a raster type for the Marching squares alg
|
|
template<> struct _RasterTraits<Slic3r::sla::RasterGrayscaleAA> {
|
|
using Rst = Slic3r::sla::RasterGrayscaleAA;
|
|
|
|
// The type of pixel cell in the raster
|
|
using ValueType = uint8_t;
|
|
|
|
// Value at a given position
|
|
static uint8_t get(const Rst &rst, size_t row, size_t col) { return rst.read_pixel(col, row); }
|
|
|
|
// Number of rows and cols of the raster
|
|
static size_t rows(const Rst &rst) { return rst.resolution().height_px; }
|
|
static size_t cols(const Rst &rst) { return rst.resolution().width_px; }
|
|
};
|
|
|
|
} // namespace Slic3r::marchsq
|
|
|
|
namespace Slic3r { namespace sla {
|
|
|
|
template<class Fn> void foreach_vertex(ExPolygon &poly, Fn &&fn)
|
|
{
|
|
for (auto &p : poly.contour.points) fn(p);
|
|
for (auto &h : poly.holes)
|
|
for (auto &p : h.points) fn(p);
|
|
}
|
|
|
|
ExPolygons raster_to_polygons(const RasterGrayscaleAA &rst, Vec2i32 windowsize)
|
|
{
|
|
size_t rows = rst.resolution().height_px, cols = rst.resolution().width_px;
|
|
|
|
if (rows < 2 || cols < 2) return {};
|
|
|
|
Polygons polys;
|
|
long w_rows = std::max(1l, long(windowsize.y()));
|
|
long w_cols = std::max(1l, long(windowsize.x()));
|
|
|
|
std::vector<marchsq::Ring> rings =
|
|
marchsq::execute(rst, 128, {w_rows, w_cols});
|
|
|
|
polys.reserve(rings.size());
|
|
|
|
auto pxd = rst.pixel_dimensions();
|
|
|
|
for (const marchsq::Ring &ring : rings) {
|
|
Polygon poly; Points &pts = poly.points;
|
|
pts.reserve(ring.size());
|
|
|
|
for (const marchsq::Coord &crd : ring)
|
|
pts.emplace_back(scaled(crd.c * pxd.w_mm), scaled(crd.r * pxd.h_mm));
|
|
|
|
polys.emplace_back(poly);
|
|
}
|
|
|
|
// reverse the raster transformations
|
|
ExPolygons unioned = union_ex(polys);
|
|
coord_t width = scaled(cols * pxd.h_mm), height = scaled(rows * pxd.w_mm);
|
|
|
|
auto tr = rst.trafo();
|
|
for (ExPolygon &expoly : unioned) {
|
|
if (tr.mirror_y)
|
|
foreach_vertex(expoly, [height](Point &p) {p.y() = height - p.y(); });
|
|
|
|
if (tr.mirror_x)
|
|
foreach_vertex(expoly, [width](Point &p) {p.x() = width - p.x(); });
|
|
|
|
expoly.translate(-tr.center_x, -tr.center_y);
|
|
|
|
if (tr.flipXY)
|
|
foreach_vertex(expoly, [](Point &p) { std::swap(p.x(), p.y()); });
|
|
|
|
if ((tr.mirror_x + tr.mirror_y + tr.flipXY) % 2) {
|
|
expoly.contour.reverse();
|
|
for (auto &h : expoly.holes) h.reverse();
|
|
}
|
|
}
|
|
|
|
return unioned;
|
|
}
|
|
|
|
}} // namespace Slic3r
|