tesseract  4.0.0-1-g2a2b
KDTreeSearch Class Reference

Public Member Functions

 KDTreeSearch (KDTREE *tree, float *query_point, int k_closest)
 
 ~KDTreeSearch ()
 
void Search (int *result_count, float *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::KDTreeSearch ( KDTREE tree,
float *  query_point,
int  k_closest 
)

Definition at line 140 of file kdtree.cpp.

141  : tree_(tree), query_point_(query_point), results_(MAXSEARCH, k_closest) {
142  sb_min_ = new float[tree->KeySize];
143  sb_max_ = new float[tree->KeySize];
144 }
#define MAXSEARCH
Definition: kdtree.cpp:37
int16_t KeySize
Definition: kdtree.h:48

◆ ~KDTreeSearch()

KDTreeSearch::~KDTreeSearch ( )

Definition at line 146 of file kdtree.cpp.

146  {
147  delete[] sb_min_;
148  delete[] sb_max_;
149 }

Member Function Documentation

◆ Search()

void KDTreeSearch::Search ( int *  result_count,
float *  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 153 of file kdtree.cpp.

155  {
156  if (tree_->Root.Left == nullptr) {
157  *result_count = 0;
158  } else {
159  for (int i = 0; i < tree_->KeySize; i++) {
160  sb_min_[i] = tree_->KeyDesc[i].Min;
161  sb_max_[i] = tree_->KeyDesc[i].Max;
162  }
163  SearchRec(0, tree_->Root.Left);
164  int count = results_.elements_count();
165  *result_count = count;
166  for (int j = 0; j < count; j++) {
167  // Pre-cast to float64 as key is a template type and we have no control
168  // over its actual type.
169  distances[j] = (float)sqrt((double)results_.elements()[j].key);
170  results[j] = results_.elements()[j].value;
171  }
172  }
173 }
int elements_count()
Definition: kdtree.cpp:68
struct KDNODE * Left
Definition: kdtree.h:43
PARAM_DESC KeyDesc[1]
Definition: kdtree.h:50
float Min
Definition: ocrfeatures.h:46
int count(LIST var_list)
Definition: oldlist.cpp:98
int16_t KeySize
Definition: kdtree.h:48
KDNODE Root
Definition: kdtree.h:49
float Max
Definition: ocrfeatures.h:47
const Element * elements()
Definition: kdtree.cpp:69

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