diff --git a/classify/kdtree.cpp b/classify/kdtree.cpp index 6ba7086d..14e823d3 100644 --- a/classify/kdtree.cpp +++ b/classify/kdtree.cpp @@ -133,21 +133,20 @@ class KDTreeSearch { KDTREE *tree_; FLOAT32 *query_point_; - MinK* results_; FLOAT32 *sb_min_; //< search box minimum FLOAT32 *sb_max_; //< search box maximum + MinK results_; }; KDTreeSearch::KDTreeSearch(KDTREE* tree, FLOAT32 *query_point, int k_closest) : tree_(tree), - query_point_(query_point) { - results_ = new MinK(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++) {