File: weighted_Minkowski_distance.cpp

package info (click to toggle)
cgal 4.0-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 65,068 kB
  • sloc: cpp: 500,870; ansic: 102,544; sh: 321; python: 92; makefile: 75; xml: 2
file content (39 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download | duplicates (5)
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
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Orthogonal_k_neighbor_search.h>
#include <CGAL/Weighted_Minkowski_distance.h>
#include <CGAL/Search_traits_2.h>
#include <CGAL/point_generators_2.h>

typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point_d;
typedef CGAL::Random_points_in_square_2<Point_d> Random_points_iterator;
typedef CGAL::Counting_iterator<Random_points_iterator> N_Random_points_iterator;
typedef CGAL::Search_traits_2<K> TreeTraits;
typedef CGAL::Weighted_Minkowski_distance<TreeTraits> Distance;
typedef CGAL::Orthogonal_k_neighbor_search<TreeTraits, Distance> K_neighbor_search;
typedef K_neighbor_search::Tree Tree;


int main() {
  const int D = 2;
  const int N = 1000;
  const unsigned int K = 5;


  Random_points_iterator rpit( 1.0);

  Tree tree(N_Random_points_iterator(rpit,0),
	    N_Random_points_iterator(N));

  Point_d query(0,0);

  double w[2] = { 1.0, 2.0};
  Distance tr_dist(3.14,D,w, w+D);

  K_neighbor_search search(tree, query, K, 0.0, true, tr_dist);

  for (K_neighbor_search::iterator it = search.begin(); it!=search.end(); ++it){
    std::cout << "Point " << (*it).first << " at distance = " << (*it).second << std::endl;
  }
  return 0;
}