SpiecsEngine
 
Loading...
Searching...
No Matches

◆ range_search_recursive()

template<uint32_t K>
void scl::kd_tree< K >::range_search_recursive ( Node * node,
const item & point,
const item & condition,
std::vector< item > & rangePoints,
int depth ) const
inlineprivate

Recursive function to search for all nearest points in the kd_tree.

Parameters
[in]noderecursive node.
[in]pointSearched point in k d.
[in]conditionnearest condition.
[in]rangePointsin range points.
[in]depthrecursive depth.

Base case: If node is null, the point is not found.

If the current node within range, than sote it.

Calculate current dimension (cd).

Recursive both in left anf right.

Definition at line 463 of file KDTree.h.

470 {
474 if (node == nullptr) return;
475
479 bool satisfied = true;
480 for (int i = 0; i < K; i++)
481 {
482 if (std::abs(node->m_Point[i] - point[i]) > condition[i])
483 {
484 satisfied = false;
485 break;
486 }
487 }
488 if (satisfied)
489 {
490 rangePoints.push_back(node->m_Point);
491 }
492
496 int cd = depth % K;
497
501 if (std::abs(node->m_Point[cd] - point[cd]) <= condition[cd])
502 {
503 if (node->m_Left)
504 {
505 range_search_recursive(node->m_Left, point, condition, rangePoints, depth + 1);
506 }
507 if (node->m_Right)
508 {
509 range_search_recursive(node->m_Right, point, condition, rangePoints, depth + 1);
510 }
511 }
512 else if (node->m_Point[cd] - point[cd] > 0.0f)
513 {
514 if (node->m_Left)
515 {
516 range_search_recursive(node->m_Left, point, condition, rangePoints, depth + 1);
517 }
518 }
519 else
520 {
521 if (node->m_Right)
522 {
523 range_search_recursive(node->m_Right, point, condition, rangePoints, depth + 1);
524 }
525 }
526 }
void range_search_recursive(Node *node, const item &point, const item &condition, std::vector< item > &rangePoints, int depth) const
Recursive function to search for all nearest points in the kd_tree.
Definition KDTree.h:463