Menu

#59 KdTree<Scalar>::doQueryK() inserts entry with illegal index

v1.0_(example)
open
nobody
None
1
2016-04-28
2016-04-28
Anonymous
No

KdTree<scalar>::doQueryK() inserts an initial entry onto the priority queue with an index of 0xffffffff:</scalar>

    template<typename Scalar>
    void KdTree<Scalar>::doQueryK(const VectorType& queryPoint, int k, PriorityQueue& mNeighborQueue)
    {
        mNeighborQueue.setMaxSize(k);
        mNeighborQueue.init();
        mNeighborQueue.insert(0xffffffff, std::numeric_limits<Scalar>::max());

If at least K nearest neighbours are found, this entry gets overwritten. But if not, the entry remains in the results. Other code in VCG which uses doQueryK(), eg. NDFeatureSet::getMatchingFixFeatureVec(), does not check for the presence of this entry, and creates a list of indices containing an illegal (-1) index:

void getMatchingFixFeatureVec(FeatureType &q, vector<int> &ffiVec, int maxNum)
{
  ffiVec.clear();
  typename KdTree<ScalarType>::PriorityQueue pq;
  this->fixFeatureTree->doQueryK(q.nd,maxNum,pq);
  for(int i=0;i<pq.getNofElements();++i)
  {
      if (pq.getIndex(i) < 0) DebugBreak(); <== this line, added by me, triggers a break to debugger
      ffiVec.push_back(pq.getIndex(i));
  }
} 

this illegal index causes a crash later in RansacFramework::Process_SearchEvaluateTriple().

The purpose of doQueryK() putting the initial entry onto the priority queue is not clear to me. After removing it, the code at least executes without crashing, though I'm not sure if the resulting behaviour is correct. I can't see any other code in VCG which checks for 0xffffffff in results from doQueryK().

Discussion

Anonymous
Anonymous

Add attachments
Cancel