Skip to content

Instantly share code, notes, and snippets.

@shawnchin
Created July 12, 2012 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnchin/3097756 to your computer and use it in GitHub Desktop.
Save shawnchin/3097756 to your computer and use it in GitHub Desktop.
Usage example of kd3
#include "kd3/kdtree.h"
void some_function(void) {
double *x, *y, *z; /* array of points */
size_t i, j; /* loop indices */
x = malloc(sizeof(double) * SIZE);
y = malloc(sizeof(double) * SIZE);
z = malloc(sizeof(double) * SIZE);
/* initialise values ..... */
/* for each iteration */
while(continue) {
/* build tree based on current positions */
kdtree_build(x, y, z, SIZE, &tree); /* tree obj recycled */
/* for each point */
for (i = 0; i < SIZE; i++) {
/* search for neighbours */
kdtree_search(tree, &results, SEARCH_RADIUS); /* result obj recycled */
/* kdtree_iterator_sort(result); // if you need results in order */
/* loop through each neighbour */
j = kdtee_iterator_get_next(result);
while (j != KDTREE_END) {
/* go stuff with point i and neighbour j ... */
j = kdtee_iterator_get_next(result); /* get next */
}
/* move points around ... */
}
/* clean at the end */
kdtree_delete(&tree);
kdtree_iterator_delete(&result);
free(x); free(y); free(z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment