Create The tree and distribute it.
459 const int nIni = (int)round(
static_cast<float>(maxX - minX) / (maxY - minY));
461 const float hX =
static_cast<float>(maxX - minX) / nIni;
463 list<CVRaulMurExtNode> lNodes;
465 vector<CVRaulMurExtNode*> vpIniNodes;
466 vpIniNodes.resize((uint)nIni);
468 for (
int i = 0; i < nIni; i++)
479 ni.
vKeys.reserve(vToDistributeKeys.size());
481 lNodes.push_back(ni);
482 vpIniNodes[(uint)i] = &lNodes.back();
486 for (
size_t i = 0; i < vToDistributeKeys.size(); i++)
489 vpIniNodes[(uint)(kp.pt.x / hX)]->vKeys.push_back(kp);
492 list<CVRaulMurExtNode>::iterator lit = lNodes.begin();
494 while (lit != lNodes.end())
496 if (lit->vKeys.size() == 1)
501 else if (lit->vKeys.empty())
502 lit = lNodes.erase(lit);
507 bool bFinish =
false;
511 vector<pair<int, CVRaulMurExtNode*>> vSizeAndPointerToNode;
512 vSizeAndPointerToNode.reserve(lNodes.size() * 4);
516 int prevSize = (int)lNodes.size();
518 lit = lNodes.begin();
522 vSizeAndPointerToNode.clear();
524 while (lit != lNodes.end())
539 if (!n1.
vKeys.empty())
541 lNodes.push_front(n1);
542 if (!n1.
vKeys.empty())
545 vSizeAndPointerToNode.push_back(std::make_pair(n1.
vKeys.size(), &lNodes.front()));
546 lNodes.front().lit = lNodes.begin();
549 if (!n2.
vKeys.empty())
551 lNodes.push_front(n2);
552 if (n2.
vKeys.size() > 1)
555 vSizeAndPointerToNode.push_back(std::make_pair(n2.
vKeys.size(), &lNodes.front()));
556 lNodes.front().lit = lNodes.begin();
559 if (!n3.
vKeys.empty())
561 lNodes.push_front(n3);
562 if (n3.
vKeys.size() > 1)
565 vSizeAndPointerToNode.push_back(std::make_pair(n3.
vKeys.size(), &lNodes.front()));
566 lNodes.front().lit = lNodes.begin();
569 if (!n4.
vKeys.empty())
571 lNodes.push_front(n4);
572 if (n4.
vKeys.size() > 1)
575 vSizeAndPointerToNode.push_back(std::make_pair(n4.
vKeys.size(), &lNodes.front()));
576 lNodes.front().lit = lNodes.begin();
580 lit = lNodes.erase(lit);
588 if ((
int)lNodes.size() >= N || (int)lNodes.size() == prevSize)
592 else if (((
int)lNodes.size() + nToExpand * 3) > N)
596 prevSize = (int)lNodes.size();
598 vector<pair<int, CVRaulMurExtNode*>> vPrevSizeAndPointerToNode = vSizeAndPointerToNode;
599 vSizeAndPointerToNode.clear();
601 sort(vPrevSizeAndPointerToNode.begin(), vPrevSizeAndPointerToNode.end());
602 for (
int j = (
int)vPrevSizeAndPointerToNode.size() - 1; j >= 0; j--)
605 vPrevSizeAndPointerToNode[(uint)j].second->
DivideNode(n1, n2, n3, n4);
608 if (!n1.
vKeys.empty())
610 lNodes.push_front(n1);
611 if (n1.
vKeys.size() > 1)
613 vSizeAndPointerToNode.push_back(std::make_pair(n1.
vKeys.size(), &lNodes.front()));
614 lNodes.front().lit = lNodes.begin();
617 if (!n2.
vKeys.empty())
619 lNodes.push_front(n2);
620 if (n2.
vKeys.size() > 1)
622 vSizeAndPointerToNode.push_back(std::make_pair(n2.
vKeys.size(), &lNodes.front()));
623 lNodes.front().lit = lNodes.begin();
626 if (!n3.
vKeys.empty())
628 lNodes.push_front(n3);
629 if (n3.
vKeys.size() > 1)
631 vSizeAndPointerToNode.push_back(std::make_pair(n3.
vKeys.size(), &lNodes.front()));
632 lNodes.front().lit = lNodes.begin();
635 if (!n4.
vKeys.empty())
637 lNodes.push_front(n4);
638 if (n4.
vKeys.size() > 1)
640 vSizeAndPointerToNode.push_back(std::make_pair(n4.
vKeys.size(), &lNodes.front()));
641 lNodes.front().lit = lNodes.begin();
645 lNodes.erase(vPrevSizeAndPointerToNode[(uint)j].second->lit);
647 if ((
int)lNodes.size() >= N)
651 if ((
int)lNodes.size() >= N || (int)lNodes.size() == prevSize)
660 for (list<CVRaulMurExtNode>::iterator lit = lNodes.begin(); lit != lNodes.end(); lit++)
664 float maxResponse = pKP->response;
666 for (
size_t k = 1; k < vNodeKeys.size(); k++)
668 if (vNodeKeys[k].response > maxResponse)
671 maxResponse = vNodeKeys[k].response;
675 vResultKeys.push_back(*pKP);
Data structure used to subdivide the Image with key points into segments.
void DivideNode(CVRaulMurExtNode &n1, CVRaulMurExtNode &n2, CVRaulMurExtNode &n3, CVRaulMurExtNode &n4)