kdtree.h 1.0 KB

1234567891011121314151617181920212223242526272829
  1. struct kdnode
  2. {
  3. unsigned char dim; /* split dimension of this node */
  4. unsigned char depth; /* depth at this node */
  5. double *c; /* coordinates */
  6. int uid; /* unique id of this node */
  7. struct kdnode *child[2]; /* link to children: link[0] for smaller, link[1] for larger */
  8. };
  9. struct kdtree
  10. {
  11. unsigned char ndims; /* number of dimensions */
  12. unsigned char *nextdim; /* split dimension of child nodes */
  13. int csize; /* size of coordinates in bytes */
  14. int btol; /* balancing tolerance */
  15. size_t count; /* number of items in the tree */
  16. struct kdnode *root; /* tree root */
  17. };
  18. struct kdtree *kdtree_create(char, int *);
  19. void kdtree_destroy(struct kdtree *);
  20. void kdtree_clear(struct kdtree *);
  21. int kdtree_insert(struct kdtree *, double *, int, int);
  22. int kdtree_remove(struct kdtree *, double *, int);
  23. int kdtree_knn(struct kdtree *, double *, int *, double *, int, int *);
  24. int kdtree_dnn(struct kdtree *, double *, int **, double **, double, int *);
  25. void kdtree_optimize(struct kdtree *, int);