tesseract  5.0.0-alpha-619-ge9db
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 119 of file kdtree.cpp.

Constructor & Destructor Documentation

◆ KDTreeSearch()

KDTreeSearch::KDTreeSearch ( KDTREE tree,
float *  query_point,
int  k_closest 
)

Definition at line 138 of file kdtree.cpp.

140  : tree_(tree), query_point_(query_point), results_(MAXSEARCH, k_closest) {
141  sb_min_ = new float[tree->KeySize];
142  sb_max_ = new float[tree->KeySize];

◆ ~KDTreeSearch()

KDTreeSearch::~KDTreeSearch ( )

Definition at line 144 of file kdtree.cpp.

145  {
146  delete[] sb_min_;
147  delete[] sb_max_;

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 151 of file kdtree.cpp.

154  {
155  if (tree_->Root.Left == nullptr) {
156  *result_count = 0;
157  } else {
158  for (int i = 0; i < tree_->KeySize; i++) {
159  sb_min_[i] = tree_->KeyDesc[i].Min;
160  sb_max_[i] = tree_->KeyDesc[i].Max;
161  }
162  SearchRec(0, tree_->Root.Left);
163  int count = results_.elements_count();
164  *result_count = count;
165  for (int j = 0; j < count; j++) {
166  // Pre-cast to float64 as key is a template type and we have no control
167  // over its actual type.
168  distances[j] = static_cast<float>(sqrt(static_cast<double>(results_.elements()[j].key)));
169  results[j] = results_.elements()[j].value;
170  }
171  }

The documentation for this class was generated from the following file:
KDTREE::KeyDesc
PARAM_DESC KeyDesc[1]
Definition: kdtree.h:50
PARAM_DESC::Min
float Min
Definition: ocrfeatures.h:44
MinK::elements_count
int elements_count()
Definition: kdtree.cpp:66
KDTREE::Root
KDNODE Root
Definition: kdtree.h:49
KDNODE::Left
struct KDNODE * Left
Definition: kdtree.h:43
PARAM_DESC::Max
float Max
Definition: ocrfeatures.h:45
KDTREE::KeySize
int16_t KeySize
Definition: kdtree.h:48
MAXSEARCH
#define MAXSEARCH
Definition: kdtree.cpp:35
count
int count(LIST var_list)
Definition: oldlist.cpp:79
MinK::elements
const Element * elements()
Definition: kdtree.cpp:67