11 #ifndef UTILS_LLOYD_BUILDER_H_
12 #define UTILS_LLOYD_BUILDER_H_
22 SkBlComplex& complex_;
26 typedef typename SkBlComplex::Vertex_handle Vertex_handle;
32 Lloyd_builder(SkBlComplex& complex,
unsigned num_iterations) : complex_(complex), dim(-1) {
33 if (!complex_.empty()) {
34 dim = get_dimension();
35 while (num_iterations--) {
36 std::list<Point> new_points;
37 for (
auto v : complex.vertex_range())
38 new_points.push_back(barycenter_neighbors(v));
40 auto new_points_it = new_points.begin();
41 for (
auto v : complex.vertex_range())
42 complex_.point(v) = *(new_points_it++);
49 assert(!complex_.empty());
50 for (
auto v : complex_.vertex_range())
51 return complex_.point(v).dimension();
56 if (complex_.degree(v) == 0)
57 return complex_.point(v);
59 std::vector<double> res(dim, 0);
60 unsigned num_points = 0;
61 for (
auto nv : complex_.vertex_range(v)) {
63 const Point& point = complex_.point(nv);
64 assert(point.dimension() == dim);
65 for (
int i = 0; i < point.dimension(); ++i)
70 return Point(dim, res.begin(), res.end());
73 double squared_eucl_distance(
const Point& p1,
const Point& p2)
const {
74 return Geometry_trait::Squared_distance_d()(p1, p2);
Definition: Lloyd_builder.h:20
Lloyd_builder(SkBlComplex &complex, unsigned num_iterations)
Modify complex to be the expansion of the k-nearest neighbor symetric graph.
Definition: Lloyd_builder.h:32
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15