File: searching_sphere_orthogonally.cpp

package info (click to toggle)
cgal 6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 141,840 kB
  • sloc: cpp: 797,081; ansic: 203,398; sh: 490; python: 411; makefile: 286; javascript: 174
file content (42 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
#include <CGAL/Simple_cartesian.h>

#include <CGAL/point_generators_2.h>
#include <CGAL/Euclidean_distance.h>
#include <CGAL/Orthogonal_k_neighbor_search.h>
#include <CGAL/Search_traits_2.h>

typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Random_points_in_square_2<Point_2> Random_points_iterator;
typedef Kernel::Circle_2 Sphere_2;
typedef CGAL::Search_traits_2<Kernel> TreeTraits;
typedef CGAL::Euclidean_distance<TreeTraits> Distance;
typedef CGAL::Orthogonal_k_neighbor_search<TreeTraits, Distance> Neighbor_search;
typedef TreeTraits::Construct_center_d Construct_center_d;
typedef TreeTraits::Compute_squared_radius_d Compute_squared_radius_d;
typedef Neighbor_search::Tree Tree;

int main()
{
  const int N = 1000;
  const unsigned int K = 10;

  Tree tree;
  Random_points_iterator rpg;
  for(int i = 0; i < N; ++i)
    tree.insert(*rpg++);

  Sphere_2 query(*rpg,0.5);
  Distance tr_dist;

  Point_2 center = Construct_center_d()(query);
  Neighbor_search N1(tree, center, K, 0.0, false); // eps=0.0, nearest=false

  std::cout << "For the query circle  " << std::endl
            << "The " << K << " approximate furthest neighbors are: " << std::endl;
  double radius = Compute_squared_radius_d()(query);
  for (Neighbor_search::iterator it = N1.begin();it != N1.end();it++)
    std::cout << " Point " << it->first << " at distance = " << tr_dist.inverse_of_transformed_distance(it->second - radius) << std::endl;

  return 0;
}