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

Classes

class  PathsProviderIteratorBase
class  EmptyPathsProvider
class  SinglePathProvider
class  PathsProvider
class  MultiPointsProvider
struct  ExPolygonProvider
struct  ExPolygonsProvider
struct  SurfacesProvider
struct  SurfacesPtrProvider
struct  ExPolygonsTile

Typedefs

using PolygonsProvider = MultiPointsProvider<Polygons>
using PolylinesProvider = MultiPointsProvider<Polylines>
using ZPoint = Vec3i32
using ZPoints = std::vector<Vec3i32>

Functions

template<typename PointsType>
void clip_clipper_polygon_with_subject_bbox_templ (const PointsType &src, const BoundingBox &bbox, PointsType &out, const bool get_entire_polygons=false)
void clip_clipper_polygon_with_subject_bbox (const Points &src, const BoundingBox &bbox, Points &out, const bool get_entire_polygons)
void clip_clipper_polygon_with_subject_bbox (const ZPoints &src, const BoundingBox &bbox, ZPoints &out)
template<typename PointsType>
PointsType clip_clipper_polygon_with_subject_bbox_templ (const PointsType &src, const BoundingBox &bbox)
Points clip_clipper_polygon_with_subject_bbox (const Points &src, const BoundingBox &bbox)
ZPoints clip_clipper_polygon_with_subject_bbox (const ZPoints &src, const BoundingBox &bbox)
void clip_clipper_polygon_with_subject_bbox (const Polygon &src, const BoundingBox &bbox, Polygon &out)
Polygon clip_clipper_polygon_with_subject_bbox (const Polygon &src, const BoundingBox &bbox, const bool get_entire_polygons)
Polygons clip_clipper_polygons_with_subject_bbox (const Polygons &src, const BoundingBox &bbox)
Polygons clip_clipper_polygons_with_subject_bbox (const ExPolygon &src, const BoundingBox &bbox, const bool get_entire_polygons)
Polygons clip_clipper_polygons_with_subject_bbox (const ExPolygons &src, const BoundingBox &bbox, const bool get_entire_polygons)
std::vector< ExPolygonsTile > tile_expolygons (const ExPolygons &expolygons, size_t per_tile)
std::optional< Point > interior_point (const Polygon &polygon)

Class Documentation

◆ Slic3r::ClipperUtils::ExPolygonsTile

struct Slic3r::ClipperUtils::ExPolygonsTile
Collaboration diagram for Slic3r::ClipperUtils::ExPolygonsTile:
Class Members
BoundingBox bbox
vector< size_t > members

Typedef Documentation

◆ PolygonsProvider

◆ PolylinesProvider

◆ ZPoint

◆ ZPoints

using Slic3r::ClipperUtils::ZPoints = std::vector<Vec3i32>

Function Documentation

◆ clip_clipper_polygon_with_subject_bbox() [1/6]

Points Slic3r::ClipperUtils::clip_clipper_polygon_with_subject_bbox ( const Points & src,
const BoundingBox & bbox )
nodiscard
void clip_clipper_polygon_with_subject_bbox_templ(const PointsType &src, const BoundingBox &bbox, PointsType &out, const bool get_entire_polygons=false)
Definition ClipperUtils.cpp:58

References clip_clipper_polygon_with_subject_bbox_templ().

Here is the call graph for this function:

◆ clip_clipper_polygon_with_subject_bbox() [2/6]

void Slic3r::ClipperUtils::clip_clipper_polygon_with_subject_bbox ( const Points & src,
const BoundingBox & bbox,
Points & out,
const bool get_entire_polygons )
108{ clip_clipper_polygon_with_subject_bbox_templ(src, bbox, out, get_entire_polygons); }

References clip_clipper_polygon_with_subject_bbox_templ().

Referenced by clip_clipper_polygon_with_subject_bbox(), clip_clipper_polygon_with_subject_bbox(), clip_clipper_polygon_with_subject_bbox_templ(), clip_clipper_polygons_with_subject_bbox(), clip_clipper_polygons_with_subject_bbox(), and Slic3r::traverse_extrusions().

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

◆ clip_clipper_polygon_with_subject_bbox() [3/6]

Polygon Slic3r::ClipperUtils::clip_clipper_polygon_with_subject_bbox ( const Polygon & src,
const BoundingBox & bbox,
const bool get_entire_polygons )
nodiscard
126{
127 Polygon out;
128 clip_clipper_polygon_with_subject_bbox(src.points, bbox, out.points, get_entire_polygons);
129 return out;
130}
Points points
Definition MultiPoint.hpp:22
Definition Polygon.hpp:31
void clip_clipper_polygon_with_subject_bbox(const Points &src, const BoundingBox &bbox, Points &out, const bool get_entire_polygons)
Definition ClipperUtils.cpp:108

References clip_clipper_polygon_with_subject_bbox(), and Slic3r::MultiPoint::points.

Here is the call graph for this function:

◆ clip_clipper_polygon_with_subject_bbox() [4/6]

void Slic3r::ClipperUtils::clip_clipper_polygon_with_subject_bbox ( const Polygon & src,
const BoundingBox & bbox,
Polygon & out )
121 {
123}

References clip_clipper_polygon_with_subject_bbox(), and Slic3r::MultiPoint::points.

Here is the call graph for this function:

◆ clip_clipper_polygon_with_subject_bbox() [5/6]

ZPoints Slic3r::ClipperUtils::clip_clipper_polygon_with_subject_bbox ( const ZPoints & src,
const BoundingBox & bbox )
nodiscard

References clip_clipper_polygon_with_subject_bbox_templ().

Here is the call graph for this function:

◆ clip_clipper_polygon_with_subject_bbox() [6/6]

void Slic3r::ClipperUtils::clip_clipper_polygon_with_subject_bbox ( const ZPoints & src,
const BoundingBox & bbox,
ZPoints & out )

References clip_clipper_polygon_with_subject_bbox_templ().

Here is the call graph for this function:

◆ clip_clipper_polygon_with_subject_bbox_templ() [1/2]

template<typename PointsType>
PointsType Slic3r::ClipperUtils::clip_clipper_polygon_with_subject_bbox_templ ( const PointsType & src,
const BoundingBox & bbox )
nodiscard
112{
113 PointsType out;
115 return out;
116}

References clip_clipper_polygon_with_subject_bbox().

Here is the call graph for this function:

◆ clip_clipper_polygon_with_subject_bbox_templ() [2/2]

template<typename PointsType>
void Slic3r::ClipperUtils::clip_clipper_polygon_with_subject_bbox_templ ( const PointsType & src,
const BoundingBox & bbox,
PointsType & out,
const bool get_entire_polygons = false )
inline
59{
60 using PointType = typename PointsType::value_type;
61
62 out.clear();
63 const size_t cnt = src.size();
64 if (cnt < 3) return;
65
66 enum class Side { Left = 1, Right = 2, Top = 4, Bottom = 8 };
67
68 auto sides = [bbox](const PointType &p) {
69 return int(p.x() < bbox.min.x()) * int(Side::Left) + int(p.x() > bbox.max.x()) * int(Side::Right) + int(p.y() < bbox.min.y()) * int(Side::Bottom) +
70 int(p.y() > bbox.max.y()) * int(Side::Top);
71 };
72
73 int sides_prev = sides(src.back());
74 int sides_this = sides(src.front());
75 const size_t last = cnt - 1;
76 for (size_t i = 0; i < last; ++i) {
77 int sides_next = sides(src[i + 1]);
78 if ( // This point is inside. Take it.
79 sides_this == 0 ||
80 // Either this point is outside and previous or next is inside, or
81 // the edge possibly cuts corner of the bounding box.
82 (sides_prev & sides_this & sides_next) == 0) {
83 out.emplace_back(src[i]);
84 sides_prev = sides_this;
85 } else {
86 // All the three points (this, prev, next) are outside at the same side.
87 // Ignore this point.
88 }
89 sides_this = sides_next;
90 }
91
92 // Never produce just a single point output polygon.
93 if (!out.empty()) {
94 if (get_entire_polygons) {
95 out=src;
96 } else {
97 if (int sides_next = sides(out.front());
98 // The last point is inside. Take it.
99 sides_this == 0 ||
100 // Either this point is outside and previous or next is inside, or
101 // the edge possibly cuts corner of the bounding box.
102 (sides_prev & sides_this & sides_next) == 0)
103 out.emplace_back(src.back());
104 }
105 }
106}
PointType max
Definition BoundingBox.hpp:21
PointType min
Definition BoundingBox.hpp:20
@ Bottom
Definition GeometryEngine.hpp:16
@ Top
Definition GeometryEngine.hpp:16

References Slic3r::Bottom, Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, and Slic3r::Top.

Referenced by clip_clipper_polygon_with_subject_bbox(), clip_clipper_polygon_with_subject_bbox(), clip_clipper_polygon_with_subject_bbox(), and clip_clipper_polygon_with_subject_bbox().

Here is the caller graph for this function:

◆ clip_clipper_polygons_with_subject_bbox() [1/3]

Polygons Slic3r::ClipperUtils::clip_clipper_polygons_with_subject_bbox ( const ExPolygon & src,
const BoundingBox & bbox,
const bool get_entire_polygons )
nodiscard
141{
142 Polygons out;
143 out.reserve(src.num_contours());
144 out.emplace_back(clip_clipper_polygon_with_subject_bbox(src.contour, bbox, get_entire_polygons));
145 for (const Polygon &p : src.holes) out.emplace_back(clip_clipper_polygon_with_subject_bbox(p, bbox, get_entire_polygons));
146 out.erase(std::remove_if(out.begin(), out.end(), [](const Polygon &polygon) { return polygon.empty(); }), out.end());
147 return out;
148}
Polygon contour
Definition ExPolygon.hpp:42
size_t num_contours() const
Definition ExPolygon.hpp:87
Polygons holes
Definition ExPolygon.hpp:43
std::vector< Polygon, PointsAllocator< Polygon > > Polygons
Definition Polygon.hpp:22

References clip_clipper_polygon_with_subject_bbox(), Slic3r::ExPolygon::contour, Slic3r::ExPolygon::holes, and Slic3r::ExPolygon::num_contours().

Here is the call graph for this function:

◆ clip_clipper_polygons_with_subject_bbox() [2/3]

Polygons Slic3r::ClipperUtils::clip_clipper_polygons_with_subject_bbox ( const ExPolygons & src,
const BoundingBox & bbox,
const bool get_entire_polygons )
nodiscard
150{
151 Polygons out;
152 out.reserve(number_polygons(src));
153 for (const ExPolygon &p : src) {
154 Polygons temp = clip_clipper_polygons_with_subject_bbox(p, bbox, get_entire_polygons);
155 out.insert(out.end(), temp.begin(), temp.end());
156 }
157
158 out.erase(std::remove_if(out.begin(), out.end(), [](const Polygon &polygon) {return polygon.empty(); }), out.end());
159 return out;
160}
Definition ExPolygon.hpp:23
Polygons clip_clipper_polygons_with_subject_bbox(const Polygons &src, const BoundingBox &bbox)
Definition ClipperUtils.cpp:132
size_t number_polygons(const ExPolygons &expolys)
Definition ExPolygon.hpp:116

References clip_clipper_polygons_with_subject_bbox(), and Slic3r::number_polygons().

Here is the call graph for this function:

◆ clip_clipper_polygons_with_subject_bbox() [3/3]

Polygons Slic3r::ClipperUtils::clip_clipper_polygons_with_subject_bbox ( const Polygons & src,
const BoundingBox & bbox )
nodiscard
133{
134 Polygons out;
135 out.reserve(src.size());
136 for (const Polygon &p : src) out.emplace_back(clip_clipper_polygon_with_subject_bbox(p, bbox));
137 out.erase(std::remove_if(out.begin(), out.end(), [](const Polygon &polygon) { return polygon.empty(); }), out.end());
138 return out;
139}

References clip_clipper_polygon_with_subject_bbox().

Referenced by Slic3r::avoid_object_remove_extra_small_parts(), clip_clipper_polygons_with_subject_bbox(), Slic3r::detect_steep_overhang(), Slic3r::diff_clipped(), Slic3r::diff_clipped(), Slic3r::diff_clipped(), Slic3r::generate_extra_perimeters_over_overhangs(), Slic3r::intersection_clipped(), Slic3r::Layer::make_fills(), Slic3r::PerimeterGenerator::process_classic(), Slic3r::Algorithm::propagate_wave_from_boundary(), Slic3r::TreeSupport3D::safe_offset_inc(), Slic3r::PerimeterGenerator::split_top_surfaces(), Slic3r::RetractWhenCrossingPerimeters::travel_inside_internal_regions(), and Slic3r::traverse_loops().

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

◆ interior_point()

std::optional< Point > Slic3r::ClipperUtils::interior_point ( const Polygon & polygon)
nodiscard
936 {
937 std::vector<coord_t> heights;
938 heights.reserve(polygon.size());
939 for (const Point &pt : polygon.points)
940 heights.emplace_back(pt.y());
941 std::sort(heights.begin(), heights.end());
942 heights.erase(std::unique(heights.begin(), heights.end()), heights.end());
943 std::vector<std::pair<coord_t, coord_t>> bands;
944 for (size_t i = 1; i < heights.size(); ++ i)
945 if (heights[i] - heights[i - 1] >= 2)
946 bands.emplace_back(heights[i - 1], heights[i]);
947 std::sort(bands.begin(), bands.end(), [](const auto &a, const auto &b) { return a.second - a.first > b.second - b.first; });
948 std::vector<double> crossings;
949 for (const auto &[low, high] : bands) {
950 const coord_t y = low + (high - low) / 2;
951 crossings.clear();
952 for (size_t i = 0, j = polygon.size() - 1; i < polygon.size(); j = i ++) {
953 const Point &a = polygon.points[j];
954 const Point &b = polygon.points[i];
955 if ((a.y() > y) != (b.y() > y))
956 crossings.emplace_back(double(a.x()) + double(y - a.y()) * double(b.x() - a.x()) / double(b.y() - a.y()));
957 }
958 std::sort(crossings.begin(), crossings.end());
959 // Inside from the first crossing to the second, from the third to the fourth...
960 double left = 0., right = 0.;
961 for (size_t i = 1; i < crossings.size(); i += 2)
962 if (crossings[i] - crossings[i - 1] > right - left) {
963 left = crossings[i - 1];
964 right = crossings[i];
965 }
966 if (const Point pt(coord_t(std::round(0.5 * (left + right))), y); right > left && contains(polygon, pt, false))
967 return pt;
968 }
969 return std::nullopt;
970 }
size_t size() const
Definition MultiPoint.hpp:50
Definition Point.hpp:199
int64_t coord_t
Definition libslic3r.h:48
bool contains(const std::vector< T > &vector, const Point &point)
Definition Geometry.cpp:55

References Slic3r::Geometry::contains(), Slic3r::MultiPoint::points, and Slic3r::MultiPoint::size().

Referenced by Slic3r::anonymous_namespace{ClipperUtils.cpp}::path_encloses().

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

◆ tile_expolygons()

std::vector< ExPolygonsTile > Slic3r::ClipperUtils::tile_expolygons ( const ExPolygons & expolygons,
size_t per_tile )
nodiscard
905 {
906 BoundingBox extent;
907 std::vector<BoundingBox> bboxes;
908 bboxes.reserve(expolygons.size());
909 for (const ExPolygon &expoly : expolygons) {
910 bboxes.emplace_back(get_extents(expoly));
911 extent.merge(bboxes.back());
912 }
913 if (! extent.defined)
914 return {};
915 const int tiles = std::clamp(int(std::sqrt(double(expolygons.size()) / double(std::max<size_t>(per_tile, 1)))), 1, 32);
916 const Point size = extent.size();
917 const coord_t tile_w = std::max<coord_t>(1, size.x() / tiles + 1), tile_h = std::max<coord_t>(1, size.y() / tiles + 1);
918 std::vector<ExPolygonsTile> out(size_t(tiles * tiles));
919 for (size_t i = 0; i < expolygons.size(); ++ i) {
920 const Point c = bboxes[i].center();
921 ExPolygonsTile &tile = out[size_t(std::clamp(int((c.y() - extent.min.y()) / tile_h), 0, tiles - 1) * tiles +
922 std::clamp(int((c.x() - extent.min.x()) / tile_w), 0, tiles - 1))];
923 tile.members.emplace_back(i);
924 tile.bbox.merge(bboxes[i]);
925 }
926 out.erase(std::remove_if(out.begin(), out.end(), [](const ExPolygonsTile &tile) { return tile.members.empty(); }), out.end());
927 return out;
928 }
void merge(const PointType &point)
Definition BoundingBox.cpp:75
PointType size() const
Definition BoundingBox.cpp:178
bool defined
Definition BoundingBox.hpp:22
Definition BoundingBox.hpp:212
Definition ClipperUtils.hpp:340
BoundingBox get_extents(const ExPolygonsWithIds &e)
Definition Emboss.cpp:1374

References Slic3r::ClipperUtils::ExPolygonsTile::bbox, Slic3r::BoundingBoxBase< PointType, APointsType >::defined, Slic3r::get_extents(), Slic3r::ClipperUtils::ExPolygonsTile::members, Slic3r::BoundingBoxBase< PointType, APointsType >::merge(), Slic3r::BoundingBoxBase< PointType, APointsType >::min, and Slic3r::BoundingBoxBase< PointType, APointsType >::size().

Referenced by Slic3r::clipper_ex_by_piece(), and Slic3r::segmentation_top_and_bottom_layers().

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