tesseract v5.3.3.20231005
tesseract::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 128 of file kdtree.cpp.

Constructor & Destructor Documentation

◆ KDTreeSearch()

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

Definition at line 147 of file kdtree.cpp.

148 : tree_(tree), query_point_(query_point), results_(MAXSEARCH, k_closest) {
149 sb_min_ = new float[tree->KeySize];
150 sb_max_ = new float[tree->KeySize];
151}
#define MAXSEARCH
Definition: kdtree.cpp:37

◆ ~KDTreeSearch()

tesseract::KDTreeSearch::~KDTreeSearch ( )

Definition at line 153 of file kdtree.cpp.

153 {
154 delete[] sb_min_;
155 delete[] sb_max_;
156}

Member Function Documentation

◆ Search()

void tesseract::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 160 of file kdtree.cpp.

160 {
161 if (tree_->Root.Left == nullptr) {
162 *result_count = 0;
163 } else {
164 for (int i = 0; i < tree_->KeySize; i++) {
165 sb_min_[i] = tree_->KeyDesc[i].Min;
166 sb_max_[i] = tree_->KeyDesc[i].Max;
167 }
168 SearchRec(0, tree_->Root.Left);
169 int count = results_.elements_count();
170 *result_count = count;
171 for (int j = 0; j < count; j++) {
172 // Pre-cast to float64 as key is a template type and we have no control
173 // over its actual type.
174 distances[j] = static_cast<float>(sqrt(static_cast<double>(results_.elements()[j].key)));
175 results[j] = results_.elements()[j].value;
176 }
177 }
178}
int * count
int elements_count()
Definition: kdtree.cpp:69
const Element * elements()
Definition: kdtree.cpp:72
KDNODE * Left
Definition: kdtree.h:62
std::vector< PARAM_DESC > KeyDesc
Definition: kdtree.h:82
int16_t KeySize
Definition: kdtree.h:80
KDNODE Root
Definition: kdtree.h:81

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