GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-d6dec75dd4
|
Dynamic balanced k-d tree implementation. More...
Go to the source code of this file.
Data Structures | |
struct | kdnode |
Node for k-d tree. More... | |
struct | kdtree |
k-d tree More... | |
struct | kdtrav |
k-d tree traversal More... | |
Functions | |
struct kdtree * | kdtree_create (char ndims, int *btol) |
void | kdtree_destroy (struct kdtree *t) |
void | kdtree_clear (struct kdtree *t) |
int | kdtree_insert (struct kdtree *t, double *c, int uid, int dc) |
int | kdtree_remove (struct kdtree *t, double *c, int uid) |
int | kdtree_knn (struct kdtree *t, double *c, int *uid, double *d, int k, int *skip) |
int | kdtree_dnn (struct kdtree *t, double *c, int **puid, double **pd, double maxdist, int *skip) |
int | kdtree_rnn (struct kdtree *t, double *c, int **puid, int *skip) |
void | kdtree_optimize (struct kdtree *t, int level) |
int | kdtree_init_trav (struct kdtrav *trav, struct kdtree *tree) |
int | kdtree_traverse (struct kdtrav *trav, double *c, int *uid) |
Dynamic balanced k-d tree implementation.
k-d tree is a multidimensional (k-dimensional) binary search tree for nearest neighbor search and is part of GRASS Btree2 and k-d tree libraries.
Copyright and license:
(C) 2014 by the GRASS Development Team
This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
Here is a structure of basic usage:
Create a new k-d tree:
kdtree_create(...);
Insert points into the tree:
kdtree_insert(...);
Optionally optimize the tree:
kdtree_optimize(...);
Search k nearest neighbors:
kdtree_knn(...);
Search all neighbors in radius:
kdtree_dnn(...);
Destroy the tree:
kdtree_destroy(...);
);
. The parameter description now goes to the end of function description.Definition in file kdtree.h.
void kdtree_clear | ( | struct kdtree * | t | ) |
clear a tree, removing all entries
Definition at line 139 of file kdtree.c.
References kdnode::child, NULL, and t.
Referenced by kdtree_destroy().
struct kdtree* kdtree_create | ( | char | ndims, |
int * | btol | ||
) |
creae a new k-d tree
ndims | number of dimensions |
btol | optional balancing tolerance |
Definition at line 111 of file kdtree.c.
References kdtree::btol, G_malloc, KD_BTOL, kdtree::ndims, NULL, and t.
void kdtree_destroy | ( | struct kdtree * | t | ) |
int kdtree_dnn | ( | struct kdtree * | t, |
double * | c, | ||
int ** | puid, | ||
double ** | pd, | ||
double | maxdist, | ||
int * | skip | ||
) |
find all nearest neighbors within distance aka radius search results are stored in puid (uids) and pd (squared distances) memory is allocated as needed, the calling fn must free the memory optionally an uid to be skipped can be given
t | k-d tree |
c | coordinates |
puid | unique ids of the neighbors |
pd | squared distances to the neighbors |
maxdist | radius to search around the given coordinates |
skip | unique id to skip |
initialize tree traversal (re-)sets trav structure returns 0
Definition at line 847 of file kdtree.c.
References kdtrav::curr_node, kdtrav::first, kdtree::root, kdtrav::top, and kdtrav::tree.
int kdtree_insert | ( | struct kdtree * | t, |
double * | c, | ||
int | uid, | ||
int | dc | ||
) |
int kdtree_knn | ( | struct kdtree * | t, |
double * | c, | ||
int * | uid, | ||
double * | d, | ||
int | k, | ||
int * | skip | ||
) |
find k nearest neighbors results are stored in uid (uids) and d (squared distances) optionally an uid to be skipped can be given useful when searching for the nearest neighbors of an item that is also in the tree
t | k-d tree |
c | coordinates |
uid | unique ids of the neighbors |
d | squared distances to the neighbors |
k | number of neighbors to find |
skip | unique id to skip |
void kdtree_optimize | ( | struct kdtree * | t, |
int | level | ||
) |
int kdtree_remove | ( | struct kdtree * | t, |
double * | c, | ||
int | uid | ||
) |
int kdtree_rnn | ( | struct kdtree * | t, |
double * | c, | ||
int ** | puid, | ||
int * | skip | ||
) |
find all nearest neighbors within range aka box search the range is specified with min and max for each dimension as (min1, min2, ..., minn, max1, max2, ..., maxn) results are stored in puid (uids) and pd (squared distances) memory is allocated as needed, the calling fn must free the memory optionally an uid to be skipped can be given
t | k-d tree |
c | coordinates for range |
puid | unique ids of the neighbors |
skip | unique id to skip |