1 #ifndef SLA_CONCAVEHULL_HPP
2 #define SLA_CONCAVEHULL_HPP
3 
4 #include <libslic3r/ExPolygon.hpp>
5 
6 namespace Slic3r {
7 namespace sla {
8 
get_contours(const ExPolygons & poly)9 inline Polygons get_contours(const ExPolygons &poly)
10 {
11     Polygons ret; ret.reserve(poly.size());
12     for (const ExPolygon &p : poly) ret.emplace_back(p.contour);
13 
14     return ret;
15 }
16 
17 using ThrowOnCancel = std::function<void()>;
18 
19 /// A fake concave hull that is constructed by connecting separate shapes
20 /// with explicit bridges. Bridges are generated from each shape's centroid
21 /// to the center of the "scene" which is the centroid calculated from the shape
22 /// centroids (a star is created...)
23 class ConcaveHull {
24     Polygons m_polys;
25 
26     static Point centroid(const Points& pp);
27 
centroid(const Polygon & poly)28     static inline Point centroid(const Polygon &poly) { return poly.centroid(); }
29 
30     Points calculate_centroids() const;
31 
32     void merge_polygons();
33 
34     void add_connector_rectangles(const Points &centroids,
35                                   coord_t       max_dist,
36                                   ThrowOnCancel thr);
37 public:
38 
ConcaveHull(const ExPolygons & polys,double merge_dist,ThrowOnCancel thr)39     ConcaveHull(const ExPolygons& polys, double merge_dist, ThrowOnCancel thr)
40         : ConcaveHull{to_polygons(polys), merge_dist, thr} {}
41 
42     ConcaveHull(const Polygons& polys, double mergedist, ThrowOnCancel thr);
43 
polygons() const44     const Polygons & polygons() const { return m_polys; }
45 
46     ExPolygons to_expolygons() const;
47 };
48 
49 ExPolygons offset_waffle_style_ex(const ConcaveHull &ccvhull, coord_t delta);
50 Polygons   offset_waffle_style(const ConcaveHull &polys, coord_t delta);
51 
52 }}     // namespace Slic3r::sla
53 #endif // CONCAVEHULL_HPP
54