| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef VL_KDTREE_H |
| | #define VL_KDTREE_H |
| |
|
| | #include "generic.h" |
| |
|
| | #define VL_KDTREE_SPLIT_HEALP_SIZE 5 |
| |
|
| | typedef struct _VlKDTreeNode VlKDTreeNode ; |
| | typedef struct _VlKDTreeSplitDimension VlKDTreeSplitDimension ; |
| | typedef struct _VlKDTreeDataIndexEntry VlKDTreeDataIndexEntry ; |
| | typedef struct _VlKDForestSearchState VlKDForestSearchState ; |
| |
|
| | struct _VlKDTreeNode |
| | { |
| | int unsigned parent ; |
| | int lowerChild ; |
| | int upperChild ; |
| | int unsigned splitDimension ; |
| | float splitThreshold ; |
| | float lowerBound ; |
| | float upperBound ; |
| | } ; |
| |
|
| | struct _VlKDTreeSplitDimension |
| | { |
| | int unsigned dimension ; |
| | float mean ; |
| | float variance ; |
| | } ; |
| |
|
| | struct _VlKDTreeDataIndexEntry |
| | { |
| | int index ; |
| | float value ; |
| | } ; |
| |
|
| | |
| | typedef enum _VlKDTreeThresholdingMethod |
| | { |
| | VL_KDTREE_MEDIAN, |
| | VL_KDTREE_MEAN |
| | } VlKDTreeThresholdingMethod ; |
| |
|
| | |
| | typedef struct _VlKDForestNeighbor { |
| | float distance ; |
| | unsigned int index ; |
| | } VlKDForestNeighbor ; |
| |
|
| | typedef struct _VlKDTree |
| | { |
| | VlKDTreeNode * nodes ; |
| | int unsigned numUsedNodes ; |
| | int unsigned numAllocatedNodes ; |
| | VlKDTreeDataIndexEntry * dataIndex ; |
| | int depth ; |
| | } VlKDTree ; |
| |
|
| | struct _VlKDForestSearchState |
| | { |
| | VlKDTree * tree ; |
| | unsigned int nodeIndex ; |
| | float distanceLowerBound ; |
| | } ; |
| |
|
| | |
| | typedef struct _VlKDForest |
| | { |
| | int numDimensions ; |
| |
|
| | |
| | float const * data ; |
| | int numData ; |
| |
|
| | |
| | VlKDTree ** trees ; |
| | unsigned int numTrees ; |
| |
|
| | |
| | VlKDTreeThresholdingMethod thresholdingMethod ; |
| | VlKDTreeSplitDimension splitHeapArray [VL_KDTREE_SPLIT_HEALP_SIZE] ; |
| | int unsigned splitHeapNumNodes ; |
| | int unsigned splitHeapSize ; |
| |
|
| | |
| | VlKDForestSearchState * searchHeapArray ; |
| | int unsigned searchHeapNumNodes ; |
| | int unsigned searchId ; |
| | int unsigned * searchIdBook ; |
| |
|
| | int unsigned searchMaxNumComparisons ; |
| | int unsigned searchNumComparisons; |
| | int unsigned searchNumRecursions ; |
| | int unsigned searchNumSimplifications ; |
| | } VlKDForest ; |
| |
|
| | |
| | |
| | VL_EXPORT VlKDForest * vl_kdforest_new (int unsigned numDimensions, int unsigned numTrees) ; |
| | VL_EXPORT void vl_kdforest_delete (VlKDForest * self) ; |
| | |
| |
|
| |
|
| | |
| | |
| | VL_EXPORT void vl_kdforest_build (VlKDForest * self, int numData, float const * data) ; |
| | VL_EXPORT int vl_kdforest_query (VlKDForest * self, |
| | VlKDForestNeighbor * neighbors, |
| | int unsigned numNeighbors, |
| | float const * query) ; |
| | |
| |
|
| | |
| | |
| | VL_INLINE int unsigned vl_kdforest_get_depth_of_tree (VlKDForest const * self, int unsigned treeIndex) ; |
| | VL_INLINE int unsigned vl_kdforest_get_num_nodes_of_tree (VlKDForest const * self, int unsigned treeIndex) ; |
| | VL_INLINE int unsigned vl_kdforest_get_num_trees (VlKDForest const * self) ; |
| | VL_INLINE void vl_kdforest_set_max_num_comparisons (VlKDForest * self, int unsigned n) ; |
| | VL_INLINE int unsigned vl_kdforest_get_max_num_comparisons (VlKDForest * self) ; |
| | VL_INLINE void vl_kdforest_set_thresholding_method (VlKDForest * self, VlKDTreeThresholdingMethod method) ; |
| | VL_INLINE VlKDTreeThresholdingMethod vl_kdforest_get_thresholding_method (VlKDForest const * self) ; |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | int unsigned |
| | vl_kdforest_get_num_nodes_of_tree (VlKDForest const * self, int unsigned treeIndex) |
| | { |
| | assert (treeIndex < self->numTrees) ; |
| | return self->trees[treeIndex]->numUsedNodes ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | int unsigned |
| | vl_kdforest_get_depth_of_tree (VlKDForest const * self, int unsigned treeIndex) |
| | { |
| | assert (treeIndex < self->numTrees) ; |
| | return self->trees[treeIndex]->depth ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | int unsigned |
| | vl_kdforest_get_num_trees (VlKDForest const * self) |
| | { |
| | return self->numTrees ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | void |
| | vl_kdforest_set_max_num_comparisons (VlKDForest * self, int unsigned n) |
| | { |
| | self->searchMaxNumComparisons = n ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | int unsigned |
| | vl_kdforest_get_max_num_comparisons (VlKDForest * self) |
| | { |
| | return self->searchMaxNumComparisons ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE void |
| | vl_kdforest_set_thresholding_method (VlKDForest * self, VlKDTreeThresholdingMethod method) |
| | { |
| | assert(VL_KDTREE_MEDIAN <= method && method <= VL_KDTREE_MEAN) ; |
| | self->thresholdingMethod = method ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE VlKDTreeThresholdingMethod |
| | vl_kdforest_get_thresholding_method (VlKDForest const * self) |
| | { |
| | return self->thresholdingMethod ; |
| | } |
| |
|
| | |
| | #endif |
| |
|