\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)
CGAL 5.0.3 - dD Spatial Searching
Spatial_searching/weighted_Minkowski_distance.cpp
#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 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 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;
}