GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-3a95b7a4e6
|
binary search tree More...
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include "kdtree.h"
Go to the source code of this file.
Macros | |
#define | KD_BTOL 7 |
Functions | |
struct kdtree * | kdtree_create (char ndims, int *btol) |
void | kdtree_clear (struct kdtree *t) |
void | kdtree_destroy (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) |
void | kdtree_optimize (struct kdtree *t, int level) |
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) |
int | kdtree_init_trav (struct kdtrav *trav, struct kdtree *tree) |
int | kdtree_traverse (struct kdtrav *trav, double *c, int *uid) |
binary search tree
Dynamic balanced k-d tree implementation
(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.
Definition in file kdtree.c.
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 |