All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
KDTreeSearch Class Reference

Public Member Functions

 KDTreeSearch (KDTREE *tree, FLOAT32 *query_point, int k_closest)
 
 ~KDTreeSearch ()
 
void Search (int *result_count, FLOAT32 *distances, void **results)
 

Detailed Description

Helper class for searching for the k closest points to query_point in tree.

Definition at line 121 of file kdtree.cpp.

Constructor & Destructor Documentation

KDTreeSearch::KDTreeSearch ( KDTREE tree,
FLOAT32 query_point,
int  k_closest 
)

Definition at line 140 of file kdtree.cpp.

140  :
141  tree_(tree),
142  query_point_(query_point) {
143  results_ = new MinK<FLOAT32, void *>(MAXSEARCH, k_closest);
144  sb_min_ = new FLOAT32[tree->KeySize];
145  sb_max_ = new FLOAT32[tree->KeySize];
146 }
float FLOAT32
Definition: host.h:111
inT16 KeySize
Definition: kdtree.h:50
#define MAXSEARCH
Definition: kdtree.cpp:38
KDTreeSearch::~KDTreeSearch ( )

Definition at line 148 of file kdtree.cpp.

148  {
149  delete results_;
150  delete[] sb_min_;
151  delete[] sb_max_;
152 }

Member Function Documentation

void KDTreeSearch::Search ( int *  result_count,
FLOAT32 distances,
void **  results 
)

Return the k nearest points' data.

Locate the k_closest points to query_point_, and return their distances and data into the given buffers.

Definition at line 156 of file kdtree.cpp.

158  {
159  if (tree_->Root.Left == NULL) {
160  *result_count = 0;
161  } else {
162  for (int i = 0; i < tree_->KeySize; i++) {
163  sb_min_[i] = tree_->KeyDesc[i].Min;
164  sb_max_[i] = tree_->KeyDesc[i].Max;
165  }
166  SearchRec(0, tree_->Root.Left);
167  int count = results_->elements_count();
168  *result_count = count;
169  for (int j = 0; j < count; j++) {
170  distances[j] = (FLOAT32) sqrt((FLOAT64)results_->elements()[j].key);
171  results[j] = results_->elements()[j].value;
172  }
173  }
174 }
FLOAT32 Min
Definition: ocrfeatures.h:49
float FLOAT32
Definition: host.h:111
inT16 KeySize
Definition: kdtree.h:50
KDNODE Root
Definition: kdtree.h:51
PARAM_DESC KeyDesc[1]
Definition: kdtree.h:52
struct KDNODE * Left
Definition: kdtree.h:45
const Element * elements()
Definition: kdtree.cpp:70
int count(LIST var_list)
Definition: oldlist.cpp:108
int elements_count()
Definition: kdtree.cpp:69
#define NULL
Definition: host.h:144
FLOAT32 Max
Definition: ocrfeatures.h:50
double FLOAT64
Definition: host.h:112

The documentation for this class was generated from the following file: