OrcaSlicer latest
OrcaSlicer
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 </home/runner/work/OrcaSlicer/OrcaSlicer/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 Polygons & polygons () 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
44 : ConcaveHull{to_polygons(polys), merge_dist, thr} {}
ConcaveHull(const ExPolygons &polys, double merge_dist, ThrowOnCancel thr)
Definition ConcaveHull.hpp:43
Polygons to_polygons(const ExPolygon &src)
Definition ExPolygon.hpp:307

References ConcaveHull(), and Slic3r::to_polygons().

Referenced by ConcaveHull().

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

◆ ConcaveHull() [2/2]

Slic3r::sla::ConcaveHull::ConcaveHull ( const Polygons & polys,
double mergedist,
ThrowOnCancel thr )
117{
118 if(polys.empty()) return;
119
120 m_polys = polys;
122
123 if(m_polys.size() == 1) return;
124
125 Points centroids = calculate_centroids();
126
127 add_connector_rectangles(centroids, scaled(mergedist), thr);
128
130}
Points calculate_centroids() const
Definition ConcaveHull.cpp:52
void add_connector_rectangles(const Points &centroids, coord_t max_dist, ThrowOnCancel thr)
Definition ConcaveHull.cpp:66
Polygons m_polys
Definition ConcaveHull.hpp:28
void merge_polygons()
Definition ConcaveHull.cpp:64
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:284
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:73

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
69{
70 // Centroid of the centroids of islands. This is where the additional
71 // connector sticks are routed.
72 Point cc = centroid(centroids);
73
74 PointIndex ctrindex;
75 unsigned idx = 0;
76 for(const Point &ct : centroids) ctrindex.insert(to_vec3(ct), idx++);
77
78 m_polys.reserve(m_polys.size() + centroids.size());
79
80 idx = 0;
81 for (const Point &c : centroids) {
82 thr();
83
84 double dx = c.x() - cc.x(), dy = c.y() - cc.y();
85 double l = std::sqrt(dx * dx + dy * dy);
86 double nx = dx / l, ny = dy / l;
87
88 const Point &ct = centroids[idx];
89
90 std::vector<PointIndexEl> result = ctrindex.nearest(to_vec3(ct), 2);
91
92 double dist = max_dist;
93 for (const PointIndexEl &el : result)
94 if (el.second != idx) {
95 dist = Line(to_vec2(el.first), ct).length();
96 break;
97 }
98
99 idx++;
100
101 if (dist >= max_dist) return;
102
103 Polygon r;
104 r.points.reserve(3);
105 r.points.emplace_back(cc);
106
107 Point n(scaled(nx), scaled(ny));
108 r.points.emplace_back(c + Point(n.y(), -n.x()));
109 r.points.emplace_back(c + Point(-n.y(), n.x()));
110 offset(r, scaled<float>(1.));
111
112 m_polys.emplace_back(r);
113 }
114}
Points points
Definition MultiPoint.hpp:22
static Point centroid(const Points &pp)
Definition ConcaveHull.cpp:25
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:298
Kernel::Point_3 Point
Definition MeshRepair.cpp:81
Vec3d to_vec3(const Vec2crd &v2)
Definition ConcaveHull.cpp:21
Vec2crd to_vec2(const Vec3d &v3)
Definition ConcaveHull.cpp:23
std::pair< Vec3d, unsigned > PointIndexEl
Definition SpatIndex.hpp:19
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:582
Slic3r::Polygon Polygon
Definition Emboss.cpp:101

References centroid(), Slic3r::Geometry::dist(), 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
53{
54 // We get the centroids of all the islands in the 2D slice
55 Points centroids;
56 centroids.reserve(m_polys.size());
57 std::transform(m_polys.begin(), m_polys.end(),
58 std::back_inserter(centroids),
59 [](const Polygon &poly) { return centroid(poly); });
60
61 return centroids;
62}

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
26{
27 Point c;
28 switch(pp.size()) {
29 case 0: break;
30 case 1: c = pp.front(); break;
31 case 2: c = (pp[0] + pp[1]) / 2; break;
32 default: {
33 auto MAX = std::numeric_limits<Point::coord_type>::max();
34 auto MIN = std::numeric_limits<Point::coord_type>::min();
35 Point min = {MAX, MAX}, max = {MIN, MIN};
36
37 for(auto& p : pp) {
38 if(p(0) < min(0)) min(0) = p(0);
39 if(p(1) < min(1)) min(1) = p(1);
40 if(p(0) > max(0)) max(0) = p(0);
41 if(p(1) > max(1)) max(1) = p(1);
42 }
43 c(0) = min(0) + (max(0) - min(0)) / 2;
44 c(1) = min(1) + (max(1) - min(1)) / 2;
45 break;
46 }
47 }
48
49 return c;
50}
#define MAX(a, b)
Definition Scrollbar.hpp:18
@ MIN
Definition NLoptOptimizer.hpp:53

References MAX.

Referenced by add_connector_rectangles().

Here is the caller graph for this function:

◆ centroid() [2/2]

Point Slic3r::sla::ConcaveHull::centroid ( const Polygon & poly)
inlinestaticprivate
32{ return poly.centroid(); }
void poly(std::vector< std::pair< Vec2d, Vec2d > > &out, std::initializer_list< Vec2d > p)
Definition DesignSketchTool.cpp:7751

◆ merge_polygons()

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

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
48{ 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
133{
134 auto ret = reserve_vector<ExPolygon>(m_polys.size());
135 for (const Polygon &p : m_polys) ret.emplace_back(ExPolygon(p));
136 return ret;
137}
IntegerOnly< I, std::vector< T, Args... > > reserve_vector(I capacity)
Definition libslic3r.h:370

References m_polys, and Slic3r::reserve_vector().

Here is the call graph for this function:

Member Data Documentation

◆ m_polys

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

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