tesseract 4.1.1
Loading...
Searching...
No Matches
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 120 of file kdtree.cpp.

Constructor & Destructor Documentation

◆ KDTreeSearch()

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

Definition at line 139 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];
143}
#define MAXSEARCH
Definition: kdtree.cpp:36
int16_t KeySize
Definition: kdtree.h:49

◆ ~KDTreeSearch()

KDTreeSearch::~KDTreeSearch ( )

Definition at line 145 of file kdtree.cpp.

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

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 152 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 }
172}
int count(LIST var_list)
Definition: oldlist.cpp:95
int elements_count()
Definition: kdtree.cpp:67
const Element * elements()
Definition: kdtree.cpp:68
struct KDNODE * Left
Definition: kdtree.h:44
PARAM_DESC KeyDesc[1]
Definition: kdtree.h:51
KDNODE Root
Definition: kdtree.h:50
float Max
Definition: ocrfeatures.h:46
float Min
Definition: ocrfeatures.h:45

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