2021-05-17 18:25:59 +00:00
|
|
|
#ifndef slic3r_TriangleMeshSlicer_hpp_
|
|
|
|
#define slic3r_TriangleMeshSlicer_hpp_
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
#include "Polygon.hpp"
|
|
|
|
#include "ExPolygon.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
struct MeshSlicingParams
|
|
|
|
{
|
2021-05-18 13:05:23 +00:00
|
|
|
enum class SlicingMode : uint32_t {
|
|
|
|
// Regular slicing, maintain all contours and their orientation.
|
2021-06-01 10:33:14 +00:00
|
|
|
// slice_mesh_ex() applies ClipperLib::pftNonZero rule to the result of slice_mesh().
|
2021-05-18 13:05:23 +00:00
|
|
|
Regular,
|
2021-06-01 09:10:12 +00:00
|
|
|
// For slicing 3DLabPrints plane models (aka to be compatible with S3D default strategy).
|
|
|
|
// slice_mesh_ex() applies ClipperLib::pftEvenOdd rule. slice_mesh() slices EvenOdd as Regular.
|
|
|
|
EvenOdd,
|
|
|
|
// Maintain all contours, orient all contours CCW.
|
2021-06-01 10:33:14 +00:00
|
|
|
// slice_mesh_ex() applies ClipperLib::pftNonZero rule, thus holes will be closed.
|
2021-05-18 13:05:23 +00:00
|
|
|
Positive,
|
|
|
|
// Orient all contours CCW and keep only the contour with the largest area.
|
|
|
|
// This mode is useful for slicing complex objects in vase mode.
|
|
|
|
PositiveLargestContour,
|
|
|
|
};
|
|
|
|
|
2021-05-17 18:25:59 +00:00
|
|
|
SlicingMode mode { SlicingMode::Regular };
|
|
|
|
// For vase mode: below this layer a different slicing mode will be used to produce a single contour.
|
|
|
|
// 0 = ignore.
|
|
|
|
size_t slicing_mode_normal_below_layer { 0 };
|
|
|
|
// Mode to apply below slicing_mode_normal_below_layer. Ignored if slicing_mode_nromal_below_layer == 0.
|
|
|
|
SlicingMode mode_below { SlicingMode::Regular };
|
2021-05-18 13:05:23 +00:00
|
|
|
// Transforming faces during the slicing.
|
2021-05-18 14:12:49 +00:00
|
|
|
Transform3d trafo { Transform3d::Identity() };
|
2021-05-17 18:25:59 +00:00
|
|
|
};
|
|
|
|
|
2021-05-18 13:05:23 +00:00
|
|
|
struct MeshSlicingParamsEx : public MeshSlicingParams
|
2021-05-17 18:25:59 +00:00
|
|
|
{
|
2021-05-24 14:55:34 +00:00
|
|
|
// Morphological closing operation when creating output expolygons, unscaled.
|
2021-05-17 18:25:59 +00:00
|
|
|
float closing_radius { 0 };
|
2021-05-24 14:55:34 +00:00
|
|
|
// Positive offset applied when creating output expolygons, unscaled.
|
2021-05-17 18:25:59 +00:00
|
|
|
float extra_offset { 0 };
|
2021-05-24 14:55:34 +00:00
|
|
|
// Resolution for contour simplification, unscaled.
|
2021-05-17 18:25:59 +00:00
|
|
|
// 0 = don't simplify.
|
|
|
|
double resolution { 0 };
|
|
|
|
};
|
|
|
|
|
2021-05-18 13:05:23 +00:00
|
|
|
std::vector<Polygons> slice_mesh(
|
|
|
|
const indexed_triangle_set &mesh,
|
|
|
|
const std::vector<float> &zs,
|
|
|
|
const MeshSlicingParams ¶ms,
|
|
|
|
std::function<void()> throw_on_cancel = []{});
|
|
|
|
|
2021-07-26 15:02:56 +00:00
|
|
|
// Specialized version for a single slicing plane only, running on a single thread.
|
|
|
|
Polygons slice_mesh(
|
|
|
|
const indexed_triangle_set &mesh,
|
|
|
|
const float plane_z,
|
|
|
|
const MeshSlicingParams ¶ms);
|
|
|
|
|
2021-05-18 13:05:23 +00:00
|
|
|
std::vector<ExPolygons> slice_mesh_ex(
|
|
|
|
const indexed_triangle_set &mesh,
|
|
|
|
const std::vector<float> &zs,
|
|
|
|
const MeshSlicingParamsEx ¶ms,
|
|
|
|
std::function<void()> throw_on_cancel = []{});
|
|
|
|
|
|
|
|
inline std::vector<ExPolygons> slice_mesh_ex(
|
|
|
|
const indexed_triangle_set &mesh,
|
|
|
|
const std::vector<float> &zs,
|
|
|
|
std::function<void()> throw_on_cancel = []{})
|
2021-05-17 18:25:59 +00:00
|
|
|
{
|
2021-05-18 13:05:23 +00:00
|
|
|
return slice_mesh_ex(mesh, zs, MeshSlicingParamsEx{}, throw_on_cancel);
|
2021-05-17 18:25:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 13:05:23 +00:00
|
|
|
inline std::vector<ExPolygons> slice_mesh_ex(
|
|
|
|
const indexed_triangle_set &mesh,
|
|
|
|
const std::vector<float> &zs,
|
|
|
|
float closing_radius,
|
|
|
|
std::function<void()> throw_on_cancel = []{})
|
2021-05-17 18:25:59 +00:00
|
|
|
{
|
2021-05-18 13:05:23 +00:00
|
|
|
MeshSlicingParamsEx params;
|
2021-05-17 18:25:59 +00:00
|
|
|
params.closing_radius = closing_radius;
|
2021-05-18 13:05:23 +00:00
|
|
|
return slice_mesh_ex(mesh, zs, params, throw_on_cancel);
|
2021-05-17 18:25:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 13:21:12 +00:00
|
|
|
// Slice a triangle set with a set of Z slabs (thick layers).
|
|
|
|
// The effect is similar to producing the usual top / bottom layers from a sliced mesh by
|
|
|
|
// subtracting layer[i] from layer[i - 1] for the top surfaces resp.
|
|
|
|
// subtracting layer[i] from layer[i + 1] for the bottom surfaces,
|
|
|
|
// with the exception that the triangle set this function processes may not cover the whole top resp. bottom surface.
|
|
|
|
// top resp. bottom surfaces are calculated only if out_top resp. out_bottom is not null.
|
|
|
|
void slice_mesh_slabs(
|
|
|
|
const indexed_triangle_set &mesh,
|
|
|
|
// Unscaled Zs
|
|
|
|
const std::vector<float> &zs,
|
|
|
|
const Transform3d &trafo,
|
|
|
|
std::vector<Polygons> *out_top,
|
|
|
|
std::vector<Polygons> *out_bottom,
|
|
|
|
std::function<void()> throw_on_cancel);
|
|
|
|
|
2021-05-18 13:05:23 +00:00
|
|
|
void cut_mesh(
|
|
|
|
const indexed_triangle_set &mesh,
|
|
|
|
float z,
|
|
|
|
indexed_triangle_set *upper,
|
2021-05-19 11:52:47 +00:00
|
|
|
indexed_triangle_set *lower,
|
|
|
|
bool triangulate_caps = true);
|
2021-05-17 18:25:59 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // slic3r_TriangleMeshSlicer_hpp_
|