File: searching_with_circular_query.cpp

package info (click to toggle)
cgal 4.9-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 85,584 kB
  • sloc: cpp: 640,841; ansic: 140,696; sh: 708; fortran: 131; makefile: 114; python: 92
file content (62 lines) | stat: -rw-r--r-- 1,928 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Kd_tree.h>
#include <CGAL/Search_traits_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/algorithm.h>
#include <CGAL/Fuzzy_sphere.h>

typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point;
typedef CGAL::Random_points_in_square_2<Point> Random_points_iterator;
typedef CGAL::Counting_iterator<Random_points_iterator> N_Random_points_iterator;
typedef CGAL::Search_traits_2<K> Traits;
typedef CGAL::Fuzzy_sphere<Traits> Fuzzy_circle;
typedef CGAL::Kd_tree<Traits> Tree;
typedef CGAL::Random Random;

int main() {

  const int N=1000;

  // generator for random data points in the square ( (-1,-1), (1,1) )
  Random rnd(0);
  Random_points_iterator rpit(1.0, rnd);

  // Insert also the N points in the tree
  Tree tree(N_Random_points_iterator(rpit,0),
			      N_Random_points_iterator(N));

  // define exact circular range query
  Point center(0.2, 0.2);
  Fuzzy_circle exact_range(center, 0.2);

  boost::optional<Point> any = tree.search_any_point(exact_range);
  if(any){
    std::cout << *any << " is in the query circle\n";
  }else{
    std::cout << "Empty query circle\n";
  }
  std::list<Point> result;
  tree.search(std::back_inserter( result ), exact_range);

  std::cout << "\nPoints in cirle with center " << center << " and radius 0.2" << std::endl;

  std::list<Point>::iterator it;
  for (it=result.begin(); (it != result.end()); ++it) {
    std::cout << *it << std::endl;
  }

  result.clear();
  // approximate range searching using value 0.1 for fuzziness parameter
  Fuzzy_circle approximate_range(center, 0.2, 0.1);

  tree.search(std::back_inserter( result ), approximate_range);

  std::cout << "\n\nPoints in cirle with center " << center << " and fuzzy radius [0.1,0.3]" << std::endl;

  for (it=result.begin(); (it != result.end()); ++it) {
    std::cout << *it << std::endl;
  }
  std::cout << "\ndone" << std::endl;
  return 0;
}