OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::ClipperZUtils Namespace Reference

Classes

class  ClipperZIntersectionVisitor

Typedefs

using ZPoint = Vec3crd
using ZPoints = std::vector<ZPoint, PointsAllocator<ZPoint>>
using ZPath = ZPoints
using ZPaths = std::vector<ZPath, PointsAllocator<ZPath>>
using ZFillCallback = std::function<void(const ZPoint &e1bot, const ZPoint &e1top, const ZPoint &e2bot, const ZPoint &e2top, ZPoint &pt)>

Functions

static C2::Paths64 to_paths64 (const ZPaths &paths)
static void append_zpaths (const C2::Paths64 &paths, ZPaths &out)
double area (const ZPath &path)
ZPaths clip_zpaths (ClipType clip_type, const ZPaths &subject, bool subject_open, const ZPaths &clip, const ZFillCallback &zfill, bool preserve_collinear)
bool zpoint_lower (const ZPoint &l, const ZPoint &r)
template<bool Open = false>
ZPath to_zpath (const Points &path, coord_t z)
template<bool Open = false>
ZPaths to_zpaths (const VecOfPoints &paths, coord_t z)
template<bool Open = false>
ZPaths expolygons_to_zpaths (const ExPolygons &src, coord_t &base_idx)
template<bool Open = false>
Points from_zpath (const ZPoints &path)
template<bool Open = false>
void from_zpaths (const ZPaths &paths, VecOfPoints &out)
template<bool Open = false>
VecOfPoints from_zpaths (const ZPaths &paths)

Typedef Documentation

◆ ZFillCallback

using Slic3r::ClipperZUtils::ZFillCallback = std::function<void(const ZPoint &e1bot, const ZPoint &e1top, const ZPoint &e2bot, const ZPoint &e2top, ZPoint &pt)>

◆ ZPath

◆ ZPaths

◆ ZPoint

◆ ZPoints

Function Documentation

◆ append_zpaths()

void Slic3r::ClipperZUtils::append_zpaths ( const C2::Paths64 & paths,
ZPaths & out )
static
27{
28 out.reserve(out.size() + paths.size());
29 for (const C2::Path64 &path : paths) {
30 ZPath &dst = out.emplace_back();
31 dst.reserve(path.size());
32 for (const C2::Point64 &pt : path)
33 dst.emplace_back(pt.x, pt.y, pt.z);
34 }
35}
ZPoints ZPath
Definition ClipperZUtils.hpp:24

Referenced by clip_zpaths().

Here is the caller graph for this function:

◆ area()

double Slic3r::ClipperZUtils::area ( const ZPath & path)
38{
39 const size_t size = path.size();
40 if (size < 3)
41 return 0.;
42 double a = 0.;
43 for (size_t i = 0, j = size - 1; i < size; j = i ++)
44 a += (double(path[j].x()) + path[i].x()) * (double(path[j].y()) - path[i].y());
45 return -a * 0.5;
46}

Referenced by Slic3r::tree_supports_generate_paths().

Here is the caller graph for this function:

◆ clip_zpaths()

ZPaths Slic3r::ClipperZUtils::clip_zpaths ( ClipType clip_type,
const ZPaths & subject,
bool subject_open,
const ZPaths & clip,
const ZFillCallback & zfill,
bool preserve_collinear )
49{
50 C2::Clipper64 clipper;
51 clipper.PreserveCollinear(preserve_collinear);
52 if (zfill)
53 clipper.SetZCallback([&zfill](const C2::Point64 &e1bot, const C2::Point64 &e1top, const C2::Point64 &e2bot, const C2::Point64 &e2top, C2::Point64 &pt) {
54 // Clipper2 already copied Z from a coincident input vertex.
55 auto coincident = [&pt](const C2::Point64 &p) { return p.x == pt.x && p.y == pt.y; };
56 if (coincident(e1bot) || coincident(e1top) || coincident(e2bot) || coincident(e2top))
57 return;
58 ZPoint zpt(pt.x, pt.y, pt.z);
59 zfill(ZPoint(e1bot.x, e1bot.y, e1bot.z), ZPoint(e1top.x, e1top.y, e1top.z),
60 ZPoint(e2bot.x, e2bot.y, e2bot.z), ZPoint(e2top.x, e2top.y, e2top.z), zpt);
61 pt.z = zpt.z();
62 });
63 if (subject_open)
64 clipper.AddOpenSubject(to_paths64(subject));
65 else
66 clipper.AddSubject(to_paths64(subject));
67 clipper.AddClip(to_paths64(clip));
68 const C2::ClipType type = clip_type == ctIntersection ? C2::ClipType::Intersection :
69 clip_type == ctUnion ? C2::ClipType::Union :
70 clip_type == ctDifference ? C2::ClipType::Difference : C2::ClipType::Xor;
71 C2::Paths64 closed, open;
72 clipper.Execute(type, C2::FillRule::NonZero, closed, open);
73 ZPaths out;
74 append_zpaths(closed, out);
75 append_zpaths(open, out);
76 return out;
77}
std::vector< ZPath, PointsAllocator< ZPath > > ZPaths
Definition ClipperZUtils.hpp:25
static void append_zpaths(const C2::Paths64 &paths, ZPaths &out)
Definition ClipperZUtils.cpp:26
Vec3crd ZPoint
Definition ClipperZUtils.hpp:22
static C2::Paths64 to_paths64(const ZPaths &paths)
Definition ClipperZUtils.cpp:13
@ ctUnion
Definition ClipperUtils.hpp:24
@ ctDifference
Definition ClipperUtils.hpp:24
@ ctIntersection
Definition ClipperUtils.hpp:24

References append_zpaths(), Slic3r::ctDifference, Slic3r::ctIntersection, Slic3r::ctUnion, and to_paths64().

Referenced by Slic3r::clip_extrusion(), Slic3r::Algorithm::do_split_line(), Slic3r::tree_supports_generate_paths(), and Slic3r::Algorithm::wave_seeds().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expolygons_to_zpaths()

template<bool Open = false>
ZPaths Slic3r::ClipperZUtils::expolygons_to_zpaths ( const ExPolygons & src,
coord_t & base_idx )
inline
68{
69 ZPaths out;
70 out.reserve(std::accumulate(src.begin(), src.end(), size_t(0),
71 [](const size_t acc, const ExPolygon &expoly) { return acc + expoly.num_contours(); }));
72 for (const ExPolygon &expoly : src) {
73 out.emplace_back(to_zpath<Open>(expoly.contour.points, base_idx));
74 for (const Polygon &hole : expoly.holes)
75 out.emplace_back(to_zpath<Open>(hole.points, base_idx));
76 ++ base_idx;
77 }
78 return out;
79}
Definition ExPolygon.hpp:23
Polygon contour
Definition ExPolygon.hpp:42
Polygons holes
Definition ExPolygon.hpp:43
Points points
Definition MultiPoint.hpp:22
Definition Polygon.hpp:31
ZPath to_zpath(const Points &path, coord_t z)
Definition ClipperZUtils.hpp:38

References Slic3r::ExPolygon::contour, Slic3r::ExPolygon::holes, Slic3r::MultiPoint::points, and to_zpath().

Referenced by Slic3r::Algorithm::wave_seeds().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ from_zpath()

template<bool Open = false>
Points Slic3r::ClipperZUtils::from_zpath ( const ZPoints & path)
inline
85{
86 Points out;
87 if (! path.empty()) {
88 out.reserve((path.size() + Open) ? 1 : 0);
89 for (const ZPoint &p : path)
90 out.emplace_back(p.x(), p.y());
91 if (Open)
92 out.emplace_back(out.front());
93 }
94 return out;
95}
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:73

Referenced by Slic3r::Algorithm::do_split_line(), from_zpaths(), and Slic3r::Algorithm::wave_seeds().

Here is the caller graph for this function:

◆ from_zpaths() [1/2]

template<bool Open = false>
VecOfPoints Slic3r::ClipperZUtils::from_zpaths ( const ZPaths & paths)
inline
108{
109 VecOfPoints out;
110 from_zpaths(paths, out);
111 return out;
112}
void from_zpaths(const ZPaths &paths, VecOfPoints &out)
Definition ClipperZUtils.hpp:100
std::vector< Points, PointsAllocator< Points > > VecOfPoints
Definition Point.hpp:81

References from_zpaths().

Here is the call graph for this function:

◆ from_zpaths() [2/2]

template<bool Open = false>
void Slic3r::ClipperZUtils::from_zpaths ( const ZPaths & paths,
VecOfPoints & out )
inline
101{
102 out.reserve(out.size() + paths.size());
103 for (const ZPoints &path : paths)
104 out.emplace_back(from_zpath<Open>(path));
105}
Points from_zpath(const ZPoints &path)
Definition ClipperZUtils.hpp:84
std::vector< ZPoint, PointsAllocator< ZPoint > > ZPoints
Definition ClipperZUtils.hpp:23

References from_zpath().

Referenced by from_zpaths().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_paths64()

C2::Paths64 Slic3r::ClipperZUtils::to_paths64 ( const ZPaths & paths)
static
14{
15 C2::Paths64 out;
16 out.reserve(paths.size());
17 for (const ZPath &path : paths) {
18 C2::Path64 &dst = out.emplace_back();
19 dst.reserve(path.size());
20 for (const ZPoint &pt : path)
21 dst.emplace_back(pt.x(), pt.y(), pt.z());
22 }
23 return out;
24}

Referenced by clip_zpaths().

Here is the caller graph for this function:

◆ to_zpath()

template<bool Open = false>
ZPath Slic3r::ClipperZUtils::to_zpath ( const Points & path,
coord_t z )
inline
39{
40 ZPath out;
41 if (! path.empty()) {
42 out.reserve((path.size() + Open) ? 1 : 0);
43 for (const Point &p : path)
44 out.emplace_back(p.x(), p.y(), z);
45 if (Open)
46 out.emplace_back(out.front());
47 }
48 return out;
49}
Definition Point.hpp:199

Referenced by Slic3r::Algorithm::do_split_line(), expolygons_to_zpaths(), Slic3r::Algorithm::expolygons_to_zpaths_expanded_opened(), to_zpaths(), and Slic3r::tree_supports_generate_paths().

Here is the caller graph for this function:

◆ to_zpaths()

template<bool Open = false>
ZPaths Slic3r::ClipperZUtils::to_zpaths ( const VecOfPoints & paths,
coord_t z )
inline
55{
56 ZPaths out;
57 out.reserve(paths.size());
58 for (const Points &path : paths)
59 out.emplace_back(to_zpath<Open>(path, z));
60 return out;
61}

References to_zpath().

Here is the call graph for this function:

◆ zpoint_lower()

bool Slic3r::ClipperZUtils::zpoint_lower ( const ZPoint & l,
const ZPoint & r )
inline
31{
32 return l.x() < r.x() || (l.x() == r.x() && (l.y() < r.y() || (l.y() == r.y() && l.z() < r.z())));
33}