Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::sla::ConcaveHull Class Reference

A fake concave hull that is constructed by connecting separate shapes with explicit bridges. Bridges are generated from each shape's centroid to the center of the "scene" which is the centroid calculated from the shape centroids (a star is created...) More...

#include <src/libslic3r/SLA/ConcaveHull.hpp>

+ Collaboration diagram for Slic3r::sla::ConcaveHull:

Public Member Functions

 ConcaveHull (const ExPolygons &polys, double merge_dist, ThrowOnCancel thr)
 
 ConcaveHull (const Polygons &polys, double mergedist, ThrowOnCancel thr)
 
const Polygonspolygons () const
 
ExPolygons to_expolygons () const
 

Private Member Functions

Points calculate_centroids () const
 
void merge_polygons ()
 
void add_connector_rectangles (const Points &centroids, coord_t max_dist, ThrowOnCancel thr)
 

Static Private Member Functions

static Point centroid (const Points &pp)
 
static Point centroid (const Polygon &poly)
 

Private Attributes

Polygons m_polys
 

Detailed Description

A fake concave hull that is constructed by connecting separate shapes with explicit bridges. Bridges are generated from each shape's centroid to the center of the "scene" which is the centroid calculated from the shape centroids (a star is created...)

Constructor & Destructor Documentation

◆ ConcaveHull() [1/2]

Slic3r::sla::ConcaveHull::ConcaveHull ( const ExPolygons polys,
double  merge_dist,
ThrowOnCancel  thr 
)
inline
40 : ConcaveHull{to_polygons(polys), merge_dist, thr} {}
ConcaveHull(const ExPolygons &polys, double merge_dist, ThrowOnCancel thr)
Definition ConcaveHull.hpp:39
Polygons to_polygons(const ExPolygon &src)
Definition ExPolygon.hpp:281

◆ ConcaveHull() [2/2]

Slic3r::sla::ConcaveHull::ConcaveHull ( const Polygons polys,
double  mergedist,
ThrowOnCancel  thr 
)
108{
109 if(polys.empty()) return;
110
111 m_polys = polys;
113
114 if(m_polys.size() == 1) return;
115
116 Points centroids = calculate_centroids();
117
118 add_connector_rectangles(centroids, scaled(mergedist), thr);
119
121}
Points calculate_centroids() const
Definition ConcaveHull.cpp:43
void add_connector_rectangles(const Points &centroids, coord_t max_dist, ThrowOnCancel thr)
Definition ConcaveHull.cpp:57
Polygons m_polys
Definition ConcaveHull.hpp:24
void merge_polygons()
Definition ConcaveHull.cpp:55
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:240
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:58

References add_connector_rectangles(), calculate_centroids(), m_polys, merge_polygons(), and Slic3r::scaled().

+ Here is the call graph for this function:

Member Function Documentation

◆ add_connector_rectangles()

void Slic3r::sla::ConcaveHull::add_connector_rectangles ( const Points centroids,
coord_t  max_dist,
ThrowOnCancel  thr 
)
private
60{
61 // Centroid of the centroids of islands. This is where the additional
62 // connector sticks are routed.
63 Point cc = centroid(centroids);
64
65 PointIndex ctrindex;
66 unsigned idx = 0;
67 for(const Point &ct : centroids) ctrindex.insert(to_vec3(ct), idx++);
68
69 m_polys.reserve(m_polys.size() + centroids.size());
70
71 idx = 0;
72 for (const Point &c : centroids) {
73 thr();
74
75 double dx = c.x() - cc.x(), dy = c.y() - cc.y();
76 double l = std::sqrt(dx * dx + dy * dy);
77 double nx = dx / l, ny = dy / l;
78
79 const Point &ct = centroids[idx];
80
81 std::vector<PointIndexEl> result = ctrindex.nearest(to_vec3(ct), 2);
82
83 double dist = max_dist;
84 for (const PointIndexEl &el : result)
85 if (el.second != idx) {
86 dist = Line(to_vec2(el.first), ct).length();
87 break;
88 }
89
90 idx++;
91
92 if (dist >= max_dist) return;
93
94 Polygon r;
95 r.points.reserve(3);
96 r.points.emplace_back(cc);
97
98 Point n(scaled(nx), scaled(ny));
99 r.points.emplace_back(c + Point(n.y(), -n.x()));
100 r.points.emplace_back(c + Point(-n.y(), n.x()));
101 offset(r, scaled<float>(1.));
102
103 m_polys.emplace_back(r);
104 }
105}
Points points
Definition MultiPoint.hpp:18
static Point centroid(const Points &pp)
Definition ConcaveHull.cpp:16
if(!(yy_init))
Definition lexer.c:1190
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:280
std::pair< Vec3d, unsigned > PointIndexEl
Definition SpatIndex.hpp:16
Vec3d to_vec3(const Vec2crd &v2)
Definition ConcaveHull.cpp:12
Vec2crd to_vec2(const Vec3d &v3)
Definition ConcaveHull.cpp:14
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:416
Slic3r::Polygon Polygon
Definition Emboss.cpp:34
Kernel::Point_2 Point
Definition point_areas.cpp:20

References centroid(), Slic3r::sla::PointIndex::insert(), Slic3r::Line::length(), m_polys, Slic3r::sla::PointIndex::nearest(), Slic3r::offset(), Slic3r::MultiPoint::points, Slic3r::scaled(), Slic3r::sla::to_vec2(), and Slic3r::sla::to_vec3().

Referenced by ConcaveHull().

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

◆ calculate_centroids()

Points Slic3r::sla::ConcaveHull::calculate_centroids ( ) const
private
44{
45 // We get the centroids of all the islands in the 2D slice
46 Points centroids;
47 centroids.reserve(m_polys.size());
48 std::transform(m_polys.begin(), m_polys.end(),
49 std::back_inserter(centroids),
50 [](const Polygon &poly) { return centroid(poly); });
51
52 return centroids;
53}

References m_polys.

Referenced by ConcaveHull().

+ Here is the caller graph for this function:

◆ centroid() [1/2]

Point Slic3r::sla::ConcaveHull::centroid ( const Points pp)
staticprivate
17{
18 Point c;
19 switch(pp.size()) {
20 case 0: break;
21 case 1: c = pp.front(); break;
22 case 2: c = (pp[0] + pp[1]) / 2; break;
23 default: {
24 auto MAX = std::numeric_limits<Point::coord_type>::max();
25 auto MIN = std::numeric_limits<Point::coord_type>::min();
26 Point min = {MAX, MAX}, max = {MIN, MIN};
27
28 for(auto& p : pp) {
29 if(p(0) < min(0)) min(0) = p(0);
30 if(p(1) < min(1)) min(1) = p(1);
31 if(p(0) > max(0)) max(0) = p(0);
32 if(p(1) > max(1)) max(1) = p(1);
33 }
34 c(0) = min(0) + (max(0) - min(0)) / 2;
35 c(1) = min(1) + (max(1) - min(1)) / 2;
36 break;
37 }
38 }
39
40 return c;
41}
#define MIN(a, b)
Definition avrftdi.c:48
#define MAX(a, b)
Definition avrftdi.c:45
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() min(const half &a, const half &b)
Definition Half.h:507
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
Definition Half.h:516

References MAX, and MIN.

Referenced by add_connector_rectangles().

+ Here is the caller graph for this function:

◆ centroid() [2/2]

static Point Slic3r::sla::ConcaveHull::centroid ( const Polygon poly)
inlinestaticprivate
28{ return poly.centroid(); }

References Slic3r::Polygon::centroid().

+ Here is the call graph for this function:

◆ merge_polygons()

void Slic3r::sla::ConcaveHull::merge_polygons ( )
private
Polygons get_contours(const ExPolygons &poly)
Definition ConcaveHull.hpp:9
Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, ClipperLib::PolyFillType fill_type)
Definition ClipperUtils.cpp:774

References Slic3r::sla::get_contours(), m_polys, and Slic3r::union_ex().

Referenced by ConcaveHull().

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

◆ polygons()

const Polygons & Slic3r::sla::ConcaveHull::polygons ( ) const
inline
44{ return m_polys; }

References m_polys.

Referenced by Slic3r::sla::offset_waffle_style().

+ Here is the caller graph for this function:

◆ to_expolygons()

ExPolygons Slic3r::sla::ConcaveHull::to_expolygons ( ) const
124{
125 auto ret = reserve_vector<ExPolygon>(m_polys.size());
126 for (const Polygon &p : m_polys) ret.emplace_back(ExPolygon(p));
127 return ret;
128}

References m_polys.

Member Data Documentation

◆ m_polys

Polygons Slic3r::sla::ConcaveHull::m_polys
private

The documentation for this class was generated from the following files: