Skip to content

Commit

Permalink
Fixed the semantic of epsilon to match the documentation's and ANN's …
Browse files Browse the repository at this point in the history
…ones.
  • Loading branch information
stephanemagnenat committed Jun 25, 2012
1 parent 3dd9b9b commit 13d1261
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
38 changes: 20 additions & 18 deletions nabo/kdtree_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ namespace Nabo
const bool sortResults(optionFlags & NearestNeighbourSearch<T>::SORT_RESULTS);
const bool collectStatistics(creationOptionFlags & NearestNeighbourSearch<T>::TOUCH_STATISTICS);
const T maxRadius2(maxRadius * maxRadius);
const T maxError2((1+epsilon)*(1+epsilon));

assert(nodes.size() > 0);
Heap heap(k);
Expand All @@ -289,7 +290,7 @@ namespace Nabo
unsigned long leafTouchedCount(0);
for (int i = 0; i < colCount; ++i)
{
leafTouchedCount += onePointKnn(query, indices, dists2, i, heap, off, 1+epsilon, maxRadius2, allowSelfMatch, collectStatistics, sortResults);
leafTouchedCount += onePointKnn(query, indices, dists2, i, heap, off, maxError2, maxRadius2, allowSelfMatch, collectStatistics, sortResults);
}
return leafTouchedCount;
}
Expand All @@ -302,6 +303,7 @@ namespace Nabo
const bool allowSelfMatch(optionFlags & NearestNeighbourSearch<T>::ALLOW_SELF_MATCH);
const bool sortResults(optionFlags & NearestNeighbourSearch<T>::SORT_RESULTS);
const bool collectStatistics(creationOptionFlags & NearestNeighbourSearch<T>::TOUCH_STATISTICS);
const T maxError2((1+epsilon)*(1+epsilon));

assert(nodes.size() > 0);
Heap heap(k);
Expand All @@ -314,13 +316,13 @@ namespace Nabo
{
const T maxRadius(maxRadii[i]);
const T maxRadius2(maxRadius * maxRadius);
leafTouchedCount += onePointKnn(query, indices, dists2, i, heap, off, 1+epsilon, maxRadius2, allowSelfMatch, collectStatistics, sortResults);
leafTouchedCount += onePointKnn(query, indices, dists2, i, heap, off, maxError2, maxRadius2, allowSelfMatch, collectStatistics, sortResults);
}
return leafTouchedCount;
}

template<typename T, typename Heap>
unsigned long KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt<T, Heap>::onePointKnn(const Matrix& query, IndexMatrix& indices, Matrix& dists2, int i, Heap& heap, std::vector<T>& off, const T maxError, const T maxRadius2, const bool allowSelfMatch, const bool collectStatistics, const bool sortResults) const
unsigned long KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt<T, Heap>::onePointKnn(const Matrix& query, IndexMatrix& indices, Matrix& dists2, int i, Heap& heap, std::vector<T>& off, const T maxError2, const T maxRadius2, const bool allowSelfMatch, const bool collectStatistics, const bool sortResults) const
{
fill(off.begin(), off.end(), 0);
heap.reset();
Expand All @@ -329,16 +331,16 @@ namespace Nabo
if (allowSelfMatch)
{
if (collectStatistics)
leafTouchedCount += recurseKnn<true, true>(&query.coeff(0, i), 0, 0, heap, off, maxError, maxRadius2);
leafTouchedCount += recurseKnn<true, true>(&query.coeff(0, i), 0, 0, heap, off, maxError2, maxRadius2);
else
recurseKnn<true, false>(&query.coeff(0, i), 0, 0, heap, off, maxError, maxRadius2);
recurseKnn<true, false>(&query.coeff(0, i), 0, 0, heap, off, maxError2, maxRadius2);
}
else
{
if (collectStatistics)
leafTouchedCount += recurseKnn<false, true>(&query.coeff(0, i), 0, 0, heap, off, maxError, maxRadius2);
leafTouchedCount += recurseKnn<false, true>(&query.coeff(0, i), 0, 0, heap, off, maxError2, maxRadius2);
else
recurseKnn<false, false>(&query.coeff(0, i), 0, 0, heap, off, maxError, maxRadius2);
recurseKnn<false, false>(&query.coeff(0, i), 0, 0, heap, off, maxError2, maxRadius2);
}

if (sortResults)
Expand All @@ -349,7 +351,7 @@ namespace Nabo
}

template<typename T, typename Heap> template<bool allowSelfMatch, bool collectStatistics>
unsigned long KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt<T, Heap>::recurseKnn(const T* query, const unsigned n, T rd, Heap& heap, std::vector<T>& off, const T maxError, const T maxRadius2) const
unsigned long KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt<T, Heap>::recurseKnn(const T* query, const unsigned n, T rd, Heap& heap, std::vector<T>& off, const T maxError2, const T maxRadius2) const
{
const Node& node(nodes[n]);
const uint32_t cd(getDim(node.dimChildBucketSize));
Expand Down Expand Up @@ -393,36 +395,36 @@ namespace Nabo
if (new_off > 0)
{
if (collectStatistics)
leafVisitedCount += recurseKnn<allowSelfMatch, true>(query, rightChild, rd, heap, off, maxError, maxRadius2);
leafVisitedCount += recurseKnn<allowSelfMatch, true>(query, rightChild, rd, heap, off, maxError2, maxRadius2);
else
recurseKnn<allowSelfMatch, false>(query, rightChild, rd, heap, off, maxError, maxRadius2);
recurseKnn<allowSelfMatch, false>(query, rightChild, rd, heap, off, maxError2, maxRadius2);
rd += - old_off*old_off + new_off*new_off;
if ((rd <= maxRadius2) &&
(rd * maxError < heap.headValue()))
(rd * maxError2 < heap.headValue()))
{
offcd = new_off;
if (collectStatistics)
leafVisitedCount += recurseKnn<allowSelfMatch, true>(query, n + 1, rd, heap, off, maxError, maxRadius2);
leafVisitedCount += recurseKnn<allowSelfMatch, true>(query, n + 1, rd, heap, off, maxError2, maxRadius2);
else
recurseKnn<allowSelfMatch, false>(query, n + 1, rd, heap, off, maxError, maxRadius2);
recurseKnn<allowSelfMatch, false>(query, n + 1, rd, heap, off, maxError2, maxRadius2);
offcd = old_off;
}
}
else
{
if (collectStatistics)
leafVisitedCount += recurseKnn<allowSelfMatch, true>(query, n+1, rd, heap, off, maxError, maxRadius2);
leafVisitedCount += recurseKnn<allowSelfMatch, true>(query, n+1, rd, heap, off, maxError2, maxRadius2);
else
recurseKnn<allowSelfMatch, false>(query, n+1, rd, heap, off, maxError, maxRadius2);
recurseKnn<allowSelfMatch, false>(query, n+1, rd, heap, off, maxError2, maxRadius2);
rd += - old_off*old_off + new_off*new_off;
if ((rd <= maxRadius2) &&
(rd * maxError < heap.headValue()))
(rd * maxError2 < heap.headValue()))
{
offcd = new_off;
if (collectStatistics)
leafVisitedCount += recurseKnn<allowSelfMatch, true>(query, rightChild, rd, heap, off, maxError, maxRadius2);
leafVisitedCount += recurseKnn<allowSelfMatch, true>(query, rightChild, rd, heap, off, maxError2, maxRadius2);
else
recurseKnn<allowSelfMatch, false>(query, rightChild, rd, heap, off, maxError, maxRadius2);
recurseKnn<allowSelfMatch, false>(query, rightChild, rd, heap, off, maxError2, maxRadius2);
offcd = old_off;
}
}
Expand Down
2 changes: 1 addition & 1 deletion nabo/kdtree_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ namespace Nabo

// set resulting parameters
knnKernel.setArg(4, k);
knnKernel.setArg(5, 1 + epsilon);
knnKernel.setArg(5, (1 + epsilon)*(1 + epsilon));
knnKernel.setArg(6, maxRadius*maxRadius);
knnKernel.setArg(7, optionFlags);
knnKernel.setArg(8, indexStride);
Expand Down
2 changes: 1 addition & 1 deletion nabo/opencl/knn_bf.cl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ kernel void knnBruteForce(const global T* cloud,
}
if ((dist <= maxRadius2) &&
(dist < heapHeadValue(heap) &&
(allowSelfMatch || (dist > (T)EPSILON))))
(allowSelfMatch || (dist > 0)))
heapHeadReplace(heap, index, dist, K);
}

Expand Down

0 comments on commit 13d1261

Please sign in to comment.