Created
July 12, 2012 12:07
-
-
Save shawnchin/3097756 to your computer and use it in GitHub Desktop.
Usage example of kd3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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