tesseract  3.05.02
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 122 of file kdtree.cpp.

Constructor & Destructor Documentation

◆ KDTreeSearch()

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

Definition at line 141 of file kdtree.cpp.

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

◆ ~KDTreeSearch()

KDTreeSearch::~KDTreeSearch ( )

Definition at line 149 of file kdtree.cpp.

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

Member Function Documentation

◆ Search()

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  // TODO: why FLOAT64 here?
171  distances[j] = (FLOAT32) sqrt((FLOAT64)results_.elements()[j].key);
172  results[j] = results_.elements()[j].value;
173  }
174  }
175 }
int count(LIST var_list)
Definition: oldlist.cpp:103
inT16 KeySize
Definition: kdtree.h:50
int elements_count()
Definition: kdtree.cpp:69
float FLOAT32
Definition: host.h:44
double FLOAT64
Definition: host.h:45
PARAM_DESC KeyDesc[1]
Definition: kdtree.h:52
FLOAT32 Min
Definition: ocrfeatures.h:49
struct KDNODE * Left
Definition: kdtree.h:45
FLOAT32 Max
Definition: ocrfeatures.h:50
KDNODE Root
Definition: kdtree.h:51
const Element * elements()
Definition: kdtree.cpp:70

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