Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef VL_KDTREE_H
00015 #define VL_KDTREE_H
00016
00017 #include "generic.h"
00018 #include "mathop.h"
00019
00020 #define VL_KDTREE_SPLIT_HEAP_SIZE 5
00021 #define VL_KDTREE_VARIANCE_EST_NUM_SAMPLES 1024
00022
00023 typedef struct _VlKDTreeNode VlKDTreeNode ;
00024 typedef struct _VlKDTreeSplitDimension VlKDTreeSplitDimension ;
00025 typedef struct _VlKDTreeDataIndexEntry VlKDTreeDataIndexEntry ;
00026 typedef struct _VlKDForestSearchState VlKDForestSearchState ;
00027
00028 struct _VlKDTreeNode
00029 {
00030 vl_uindex parent ;
00031 vl_index lowerChild ;
00032 vl_index upperChild ;
00033 unsigned int splitDimension ;
00034 double splitThreshold ;
00035 double lowerBound ;
00036 double upperBound ;
00037 } ;
00038
00039 struct _VlKDTreeSplitDimension
00040 {
00041 unsigned int dimension ;
00042 double mean ;
00043 double variance ;
00044 } ;
00045
00046 struct _VlKDTreeDataIndexEntry
00047 {
00048 vl_index index ;
00049 double value ;
00050 } ;
00051
00053 typedef enum _VlKDTreeThresholdingMethod
00054 {
00055 VL_KDTREE_MEDIAN,
00056 VL_KDTREE_MEAN
00057 } VlKDTreeThresholdingMethod ;
00058
00060 typedef struct _VlKDForestNeighbor {
00061 double distance ;
00062 vl_uindex index ;
00063 } VlKDForestNeighbor ;
00064
00065 typedef struct _VlKDTree
00066 {
00067 VlKDTreeNode * nodes ;
00068 vl_size numUsedNodes ;
00069 vl_size numAllocatedNodes ;
00070 VlKDTreeDataIndexEntry * dataIndex ;
00071 unsigned int depth ;
00072 } VlKDTree ;
00073
00074 struct _VlKDForestSearchState
00075 {
00076 VlKDTree * tree ;
00077 vl_uindex nodeIndex ;
00078 double distanceLowerBound ;
00079 } ;
00080
00081 struct _VlKDForestSearcher;
00082
00084 typedef struct _VlKDForest
00085 {
00086 vl_size dimension ;
00087
00088
00089 VlRand * rand ;
00090
00091
00092 vl_type dataType ;
00093 void const * data ;
00094 vl_size numData ;
00095 VlVectorComparisonType distance;
00096 void (*distanceFunction)(void) ;
00097
00098
00099 VlKDTree ** trees ;
00100 vl_size numTrees ;
00101
00102
00103 VlKDTreeThresholdingMethod thresholdingMethod ;
00104 VlKDTreeSplitDimension splitHeapArray [VL_KDTREE_SPLIT_HEAP_SIZE] ;
00105 vl_size splitHeapNumNodes ;
00106 vl_size splitHeapSize ;
00107 vl_size maxNumNodes;
00108
00109
00110 vl_size searchMaxNumComparisons ;
00111 vl_size numSearchers;
00112 struct _VlKDForestSearcher * headSearcher ;
00113
00114 } VlKDForest ;
00115
00117 typedef struct _VlKDForestSearcher
00118 {
00119
00120 struct _VlKDForestSearcher * next;
00121 struct _VlKDForestSearcher * previous;
00122
00123 vl_uindex * searchIdBook ;
00124 VlKDForestSearchState * searchHeapArray ;
00125 VlKDForest * forest;
00126
00127 vl_size searchNumComparisons;
00128 vl_size searchNumRecursions ;
00129 vl_size searchNumSimplifications ;
00130
00131 vl_size searchHeapNumNodes ;
00132 vl_uindex searchId ;
00133 } VlKDForestSearcher ;
00134
00137 VL_EXPORT VlKDForest * vl_kdforest_new (vl_type dataType,
00138 vl_size dimension, vl_size numTrees, VlVectorComparisonType normType) ;
00139 VL_EXPORT VlKDForestSearcher * vl_kdforest_new_searcher (VlKDForest * kdforest);
00140 VL_EXPORT void vl_kdforest_delete (VlKDForest * self) ;
00141 VL_EXPORT void vl_kdforestsearcher_delete (VlKDForestSearcher * searcher) ;
00146 VL_EXPORT void vl_kdforest_build (VlKDForest * self,
00147 vl_size numData,
00148 void const * data) ;
00149
00150 VL_EXPORT vl_size vl_kdforest_query (VlKDForest * self,
00151 VlKDForestNeighbor * neighbors,
00152 vl_size numNeighbors,
00153 void const * query) ;
00154
00155 VL_EXPORT vl_size vl_kdforest_query_with_array (VlKDForest * self,
00156 vl_uint32 * index,
00157 vl_size numNeighbors,
00158 vl_size numQueries,
00159 void * distance,
00160 void const * queries) ;
00161
00162 VL_EXPORT vl_size vl_kdforestsearcher_query (VlKDForestSearcher * self,
00163 VlKDForestNeighbor * neighbors,
00164 vl_size numNeighbors,
00165 void const * query) ;
00170 VL_EXPORT vl_size vl_kdforest_get_depth_of_tree (VlKDForest const * self, vl_uindex treeIndex) ;
00171 VL_EXPORT vl_size vl_kdforest_get_num_nodes_of_tree (VlKDForest const * self, vl_uindex treeIndex) ;
00172 VL_EXPORT vl_size vl_kdforest_get_num_trees (VlKDForest const * self) ;
00173 VL_EXPORT vl_size vl_kdforest_get_data_dimension (VlKDForest const * self) ;
00174 VL_EXPORT vl_type vl_kdforest_get_data_type (VlKDForest const * self) ;
00175 VL_EXPORT void vl_kdforest_set_max_num_comparisons (VlKDForest * self, vl_size n) ;
00176 VL_EXPORT vl_size vl_kdforest_get_max_num_comparisons (VlKDForest * self) ;
00177 VL_EXPORT void vl_kdforest_set_thresholding_method (VlKDForest * self, VlKDTreeThresholdingMethod method) ;
00178 VL_EXPORT VlKDTreeThresholdingMethod vl_kdforest_get_thresholding_method (VlKDForest const * self) ;
00179 VL_EXPORT VlKDForest * vl_kdforest_searcher_get_forest (VlKDForestSearcher const * self) ;
00180 VL_EXPORT VlKDForestSearcher * vl_kdforest_get_searcher (VlKDForest const * self, vl_uindex pos) ;
00184
00185 #endif