11#ifndef UTILS_K_NEAREST_BUILDER_H_
12#define UTILS_K_NEAREST_BUILDER_H_
14#include <CGAL/Euclidean_distance.h>
15#include <CGAL/Orthogonal_k_neighbor_search.h>
16#include <CGAL/Search_traits_d.h>
17#include <CGAL/Search_traits_adapter.h>
18#include <CGAL/property_map.h>
20#include <unordered_map>
24#include "utils/UI_utils.h"
25#include "model/Complex_typedefs.h"
27template<
typename SkBlComplex>
class K_nearest_builder {
29 typedef Geometry_trait Kernel;
30 typedef Point Point_d;
31 typedef std::pair<Point_d, unsigned> Point_d_with_id;
32 typedef CGAL::Search_traits_d<Kernel> Traits_base;
33 typedef CGAL::Search_traits_adapter<Point_d_with_id, CGAL::First_of_pair_property_map<Point_d_with_id>,
35 typedef CGAL::Orthogonal_k_neighbor_search<Traits> Neighbor_search;
36 typedef Neighbor_search::Tree Tree;
37 typedef Neighbor_search::Distance Distance;
39 SkBlComplex& complex_;
46 K_nearest_builder(SkBlComplex& complex,
unsigned k) : complex_(complex) {
47 complex.keep_only_vertices();
52 double squared_eucl_distance(
const Point& p1,
const Point& p2)
const {
53 return Geometry_trait::Squared_distance_d()(p1, p2);
56 void compute_edges(
unsigned k) {
57 std::list<Point_d_with_id> points_with_id;
58 for (
auto v : complex_.vertex_range()) {
59 Point_d_with_id point_v(complex_.point(v), v.vertex);
60 points_with_id.push_back(point_v);
63 Tree tree(points_with_id.begin(), points_with_id.end());
66 for (
auto p : complex_.vertex_range()) {
67 Neighbor_search search(tree, complex_.point(p), k + 1);
68 for (
auto it = ++search.begin(); it != search.end(); ++it) {
70 if (p != q && complex_.contains_vertex(p) && complex_.contains_vertex(q))
71 complex_.add_edge_without_blockers(p, q);
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15