mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 12:49:35 +08:00
Reduce number of new / delete operations for class KDTreeSearch
Add also several TODO comments because it is not clear why expensive FLOAT64 calculations are used instead of cheaper FLOAT32 ones. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
acf318af77
commit
046684f4cb
@ -133,21 +133,20 @@ class KDTreeSearch {
|
||||
|
||||
KDTREE *tree_;
|
||||
FLOAT32 *query_point_;
|
||||
MinK<FLOAT32, void *>* results_;
|
||||
FLOAT32 *sb_min_; //< search box minimum
|
||||
FLOAT32 *sb_max_; //< search box maximum
|
||||
MinK<FLOAT32, void *> results_;
|
||||
};
|
||||
|
||||
KDTreeSearch::KDTreeSearch(KDTREE* tree, FLOAT32 *query_point, int k_closest) :
|
||||
tree_(tree),
|
||||
query_point_(query_point) {
|
||||
results_ = new MinK<FLOAT32, void *>(MAXSEARCH, k_closest);
|
||||
query_point_(query_point),
|
||||
results_(MAXSEARCH, k_closest) {
|
||||
sb_min_ = new FLOAT32[tree->KeySize];
|
||||
sb_max_ = new FLOAT32[tree->KeySize];
|
||||
}
|
||||
|
||||
KDTreeSearch::~KDTreeSearch() {
|
||||
delete results_;
|
||||
delete[] sb_min_;
|
||||
delete[] sb_max_;
|
||||
}
|
||||
@ -165,11 +164,12 @@ void KDTreeSearch::Search(int *result_count,
|
||||
sb_max_[i] = tree_->KeyDesc[i].Max;
|
||||
}
|
||||
SearchRec(0, tree_->Root.Left);
|
||||
int count = results_->elements_count();
|
||||
int count = results_.elements_count();
|
||||
*result_count = count;
|
||||
for (int j = 0; j < count; j++) {
|
||||
distances[j] = (FLOAT32) sqrt((FLOAT64)results_->elements()[j].key);
|
||||
results[j] = results_->elements()[j].value;
|
||||
// TODO: why FLOAT64 here?
|
||||
distances[j] = (FLOAT32) sqrt((FLOAT64)results_.elements()[j].key);
|
||||
results[j] = results_.elements()[j].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -406,9 +406,9 @@ void KDTreeSearch::SearchRec(int level, KDNODE *sub_tree) {
|
||||
if (!BoxIntersectsSearch(sb_min_, sb_max_))
|
||||
return;
|
||||
|
||||
results_->insert(DistanceSquared(tree_->KeySize, tree_->KeyDesc,
|
||||
results_.insert(DistanceSquared(tree_->KeySize, tree_->KeyDesc,
|
||||
query_point_, sub_tree->Key),
|
||||
sub_tree->Data);
|
||||
sub_tree->Data);
|
||||
|
||||
if (query_point_[level] < sub_tree->BranchPoint) {
|
||||
if (sub_tree->Left != NULL) {
|
||||
@ -480,9 +480,10 @@ FLOAT32 ComputeDistance(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) {
|
||||
/// one wrap distance away from the query.
|
||||
bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) {
|
||||
FLOAT32 *query = query_point_;
|
||||
// Why FLOAT64?
|
||||
FLOAT64 total_distance = 0.0;
|
||||
FLOAT64 radius_squared =
|
||||
results_->max_insertable_key() * results_->max_insertable_key();
|
||||
results_.max_insertable_key() * results_.max_insertable_key();
|
||||
PARAM_DESC *dim = tree_->KeyDesc;
|
||||
|
||||
for (int i = tree_->KeySize; i > 0; i--, dim++, query++, lower++, upper++) {
|
||||
|
Loading…
Reference in New Issue
Block a user