OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::sla::anonymous_namespace{Clustering.cpp} Namespace Reference

Functions

bool cmp_ptidx_elements (const PointIndexEl &e1, const PointIndexEl &e2)
ClusteredPoints cluster (Index3D &sindex, unsigned max_points, std::function< std::vector< PointIndexEl >(const Index3D &, const PointIndexEl &)> qfn)
std::vector< PointIndexEl > distance_queryfn (const Index3D &sindex, const PointIndexEl &p, double dist, unsigned max_points)

Function Documentation

◆ cluster()

ClusteredPoints Slic3r::sla::anonymous_namespace{Clustering.cpp}::cluster ( Index3D & sindex,
unsigned max_points,
std::function< std::vector< PointIndexEl >(const Index3D &, const PointIndexEl &)> qfn )
31{
32 using Elems = std::vector<PointIndexEl>;
33
34 // Recursive function for visiting all the points in a given distance to
35 // each other
36 std::function<void(Elems&, Elems&)> group =
37 [&sindex, &group, max_points, qfn](Elems& pts, Elems& cluster)
38 {
39 for(auto& p : pts) {
40 std::vector<PointIndexEl> tmp = qfn(sindex, p);
41
42 std::sort(tmp.begin(), tmp.end(), cmp_ptidx_elements);
43
44 Elems newpts;
45 std::set_difference(tmp.begin(), tmp.end(),
46 cluster.begin(), cluster.end(),
47 std::back_inserter(newpts), cmp_ptidx_elements);
48
49 int c = max_points && newpts.size() + cluster.size() > max_points?
50 int(max_points - cluster.size()) : int(newpts.size());
51
52 cluster.insert(cluster.end(), newpts.begin(), newpts.begin() + c);
53 std::sort(cluster.begin(), cluster.end(), cmp_ptidx_elements);
54
55 if(!newpts.empty() && (!max_points || cluster.size() < max_points))
56 group(newpts, cluster);
57 }
58 };
59
60 std::vector<Elems> clusters;
61 for(auto it = sindex.begin(); it != sindex.end();) {
62 Elems cluster = {};
63 Elems pts = {*it};
64 group(pts, cluster);
65
66 for(auto& c : cluster) sindex.remove(c);
67 it = sindex.begin();
68
69 clusters.emplace_back(cluster);
70 }
71
72 ClusteredPoints result;
73 for(auto& cluster : clusters) {
74 result.emplace_back();
75 for(auto c : cluster) result.back().emplace_back(c.second);
76 }
77
78 return result;
79}
ClusteredPoints cluster(Index3D &sindex, unsigned max_points, std::function< std::vector< PointIndexEl >(const Index3D &, const PointIndexEl &)> qfn)
Definition Clustering.cpp:27
bool cmp_ptidx_elements(const PointIndexEl &e1, const PointIndexEl &e2)
Definition Clustering.cpp:22
std::vector< ClusterEl > ClusteredPoints
Definition Clustering.hpp:16

References cluster(), and cmp_ptidx_elements().

Referenced by cluster().

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

◆ cmp_ptidx_elements()

bool Slic3r::sla::anonymous_namespace{Clustering.cpp}::cmp_ptidx_elements ( const PointIndexEl & e1,
const PointIndexEl & e2 )
23{
24 return e1.second < e2.second;
25};

References cmp_ptidx_elements().

Referenced by cluster(), and cmp_ptidx_elements().

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

◆ distance_queryfn()

std::vector< PointIndexEl > Slic3r::sla::anonymous_namespace{Clustering.cpp}::distance_queryfn ( const Index3D & sindex,
const PointIndexEl & p,
double dist,
unsigned max_points )
85{
86 std::vector<PointIndexEl> tmp; tmp.reserve(max_points);
87 sindex.query(
88 bgi::nearest(p.first, max_points),
89 std::back_inserter(tmp)
90 );
91
92 for(auto it = tmp.begin(); it < tmp.end(); ++it)
93 if((p.first - it->first).norm() > dist) it = tmp.erase(it);
94
95 return tmp;
96}
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:298

References Slic3r::Geometry::dist(), and distance_queryfn().

Referenced by distance_queryfn().

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