summaryrefslogtreecommitdiff
path: root/src/Spatial_searching/example/example_spatial_searching.cpp
blob: ba387b71e1947c315b8723426b41625ae2cbbb65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <gudhi/Spatial_tree_data_structure.h>

#include <CGAL/Epick_d.h>
#include <CGAL/Random.h>

#include <array>
#include <vector>

namespace gss = Gudhi::spatial_searching;

int main (void)
{
  typedef CGAL::Epick_d<CGAL::Dimension_tag<4> >      K;
  typedef typename K::FT                              FT;
  typedef typename K::Point_d                         Point;
  typedef std::vector<Point>                          Points;

  typedef gss::Spatial_tree_data_structure<K, Points> Points_ds;
  typedef typename Points_ds::KNS_range               KNS_range;
  typedef typename Points_ds::KNS_iterator            KNS_iterator;
  typedef typename Points_ds::INS_range               INS_range;
  typedef typename Points_ds::INS_iterator            INS_iterator;

  CGAL::Random rd;

  Points points;
  for (int i = 0; i < 500; ++i)
    points.push_back(Point(std::array<FT, 4>({ rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1) })));

  Points_ds points_ds(points);

  auto kns_range = points_ds.query_ANN(points[20], 10, true);
  for (auto const& nghb : kns_range)
    std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n";

  return 0;
}