mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-10 01:01:57 +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
147 lines
5.2 KiB
C++
147 lines
5.2 KiB
C++
#include <cstddef>
|
|
#include <cassert>
|
|
#include <numeric>
|
|
|
|
#include "SlicesToTriangleMesh.hpp"
|
|
|
|
//#include "libslic3r/MTUtils.hpp"
|
|
#include "Polygon.hpp"
|
|
#include "Point.hpp"
|
|
#include "TriangleMesh.hpp"
|
|
#include "Execution/Execution.hpp"
|
|
#include "libslic3r/Execution/ExecutionTBB.hpp"
|
|
#include "libslic3r/ClipperUtils.hpp"
|
|
#include "libslic3r/Tesselate.hpp"
|
|
|
|
#include <tbb/parallel_for.h>
|
|
#include <tbb/parallel_reduce.h>
|
|
#include <vector>
|
|
#include "ExPolygon.hpp"
|
|
|
|
namespace Slic3r {
|
|
|
|
inline indexed_triangle_set wall_strip(const Polygon &poly,
|
|
double lower_z_mm,
|
|
double upper_z_mm)
|
|
{
|
|
indexed_triangle_set ret;
|
|
|
|
size_t startidx = ret.vertices.size();
|
|
size_t offs = poly.points.size();
|
|
|
|
ret.vertices.reserve(ret.vertices.size() + 2 *offs);
|
|
|
|
// The expression unscaled(p).cast<float>().eval() is important here
|
|
// as it ensures identical conversion of 2D scaled coordinates to float 3D
|
|
// to that used by the tesselation. This way, the duplicated vertices in the
|
|
// output mesh can be found with the == operator of the points.
|
|
// its_merge_vertices will then reliably remove the duplicates.
|
|
for (const Point &p : poly.points)
|
|
ret.vertices.emplace_back(to_3d(unscaled(p).cast<float>().eval(), float(lower_z_mm)));
|
|
|
|
for (const Point &p : poly.points)
|
|
ret.vertices.emplace_back(to_3d(unscaled(p).cast<float>().eval(), float(upper_z_mm)));
|
|
|
|
for (size_t i = startidx + 1; i < startidx + offs; ++i) {
|
|
ret.indices.emplace_back(i - 1, i, i + offs - 1);
|
|
ret.indices.emplace_back(i, i + offs, i + offs - 1);
|
|
}
|
|
|
|
ret.indices.emplace_back(startidx + offs - 1, startidx, startidx + 2 * offs - 1);
|
|
ret.indices.emplace_back(startidx, startidx + offs, startidx + 2 * offs - 1);
|
|
|
|
return ret;
|
|
}
|
|
|
|
// Same as walls() but with identical higher and lower polygons.
|
|
indexed_triangle_set inline straight_walls(const Polygon &plate,
|
|
double lo_z,
|
|
double hi_z)
|
|
{
|
|
return wall_strip(plate, lo_z, hi_z);
|
|
}
|
|
|
|
indexed_triangle_set inline straight_walls(const ExPolygon &plate,
|
|
double lo_z,
|
|
double hi_z)
|
|
{
|
|
indexed_triangle_set ret = straight_walls(plate.contour, lo_z, hi_z);
|
|
for (auto &h : plate.holes)
|
|
its_merge(ret, straight_walls(h, lo_z, hi_z));
|
|
|
|
return ret;
|
|
}
|
|
|
|
indexed_triangle_set inline straight_walls(const ExPolygons &slice,
|
|
double lo_z,
|
|
double hi_z)
|
|
{
|
|
indexed_triangle_set ret;
|
|
for (const ExPolygon &poly : slice)
|
|
its_merge(ret, straight_walls(poly, lo_z, hi_z));
|
|
|
|
return ret;
|
|
}
|
|
|
|
indexed_triangle_set slices_to_mesh(
|
|
const std::vector<ExPolygons> &slices,
|
|
double zmin,
|
|
const std::vector<float> & grid)
|
|
{
|
|
assert(slices.size() == grid.size());
|
|
|
|
using Layers = std::vector<indexed_triangle_set>;
|
|
Layers layers(slices.size());
|
|
size_t len = slices.size() - 1;
|
|
|
|
tbb::parallel_for(size_t(0), len, [&slices, &layers, &grid](size_t i) {
|
|
const ExPolygons &upper = slices[i + 1];
|
|
const ExPolygons &lower = slices[i];
|
|
|
|
// Small 0 area artefacts can be created by diff_ex, and the
|
|
// tesselation also can create 0 area triangles. These will be removed
|
|
// by its_remove_degenerate_faces.
|
|
ExPolygons free_top = diff_ex(lower, upper);
|
|
ExPolygons overhang = diff_ex(upper, lower);
|
|
its_merge(layers[i], triangulate_expolygons_3d(free_top, grid[i], NORMALS_UP));
|
|
its_merge(layers[i], triangulate_expolygons_3d(overhang, grid[i], NORMALS_DOWN));
|
|
its_merge(layers[i], straight_walls(upper, grid[i], grid[i + 1]));
|
|
});
|
|
|
|
auto merge_fn = []( const indexed_triangle_set &a, const indexed_triangle_set &b ) {
|
|
indexed_triangle_set res{a}; its_merge(res, b); return res;
|
|
};
|
|
|
|
auto ret = execution::reduce(ex_tbb, layers.begin(), layers.end(),
|
|
indexed_triangle_set{}, merge_fn);
|
|
|
|
its_merge(ret, triangulate_expolygons_3d(slices.front(), zmin, NORMALS_DOWN));
|
|
its_merge(ret, straight_walls(slices.front(), zmin, grid.front()));
|
|
its_merge(ret, triangulate_expolygons_3d(slices.back(), grid.back(), NORMALS_UP));
|
|
|
|
// FIXME: these repairs do not fix the mesh entirely. There will be cracks
|
|
// in the output. It is very hard to do the meshing in a way that does not
|
|
// leave errors.
|
|
its_merge_vertices(ret);
|
|
its_remove_degenerate_faces(ret);
|
|
its_compactify_vertices(ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
void slices_to_mesh(indexed_triangle_set & mesh,
|
|
const std::vector<ExPolygons> &slices,
|
|
double zmin,
|
|
double lh,
|
|
double ilh)
|
|
{
|
|
std::vector<float> grid(slices.size(), zmin + ilh);
|
|
|
|
for (size_t i = 1; i < grid.size(); ++i) grid[i] = grid[i - 1] + lh;
|
|
|
|
indexed_triangle_set cntr = slices_to_mesh(slices, zmin, grid);
|
|
its_merge(mesh, cntr);
|
|
}
|
|
|
|
} // namespace Slic3r
|