From 13d126151c925ba76318558b844511e35fc2326f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Magnenat?= Date: Mon, 25 Jun 2012 10:55:50 +0200 Subject: [PATCH] Fixed the semantic of epsilon to match the documentation's and ANN's ones. --- nabo/kdtree_cpu.cpp | 38 ++++++++++++++++++++------------------ nabo/kdtree_opencl.cpp | 2 +- nabo/opencl/knn_bf.cl | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/nabo/kdtree_cpu.cpp b/nabo/kdtree_cpu.cpp index 7bbffea..85863b3 100644 --- a/nabo/kdtree_cpu.cpp +++ b/nabo/kdtree_cpu.cpp @@ -279,6 +279,7 @@ namespace Nabo const bool sortResults(optionFlags & NearestNeighbourSearch::SORT_RESULTS); const bool collectStatistics(creationOptionFlags & NearestNeighbourSearch::TOUCH_STATISTICS); const T maxRadius2(maxRadius * maxRadius); + const T maxError2((1+epsilon)*(1+epsilon)); assert(nodes.size() > 0); Heap heap(k); @@ -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; } @@ -302,6 +303,7 @@ namespace Nabo const bool allowSelfMatch(optionFlags & NearestNeighbourSearch::ALLOW_SELF_MATCH); const bool sortResults(optionFlags & NearestNeighbourSearch::SORT_RESULTS); const bool collectStatistics(creationOptionFlags & NearestNeighbourSearch::TOUCH_STATISTICS); + const T maxError2((1+epsilon)*(1+epsilon)); assert(nodes.size() > 0); Heap heap(k); @@ -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 - unsigned long KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt::onePointKnn(const Matrix& query, IndexMatrix& indices, Matrix& dists2, int i, Heap& heap, std::vector& off, const T maxError, const T maxRadius2, const bool allowSelfMatch, const bool collectStatistics, const bool sortResults) const + unsigned long KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt::onePointKnn(const Matrix& query, IndexMatrix& indices, Matrix& dists2, int i, Heap& heap, std::vector& 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(); @@ -329,16 +331,16 @@ namespace Nabo if (allowSelfMatch) { if (collectStatistics) - leafTouchedCount += recurseKnn(&query.coeff(0, i), 0, 0, heap, off, maxError, maxRadius2); + leafTouchedCount += recurseKnn(&query.coeff(0, i), 0, 0, heap, off, maxError2, maxRadius2); else - recurseKnn(&query.coeff(0, i), 0, 0, heap, off, maxError, maxRadius2); + recurseKnn(&query.coeff(0, i), 0, 0, heap, off, maxError2, maxRadius2); } else { if (collectStatistics) - leafTouchedCount += recurseKnn(&query.coeff(0, i), 0, 0, heap, off, maxError, maxRadius2); + leafTouchedCount += recurseKnn(&query.coeff(0, i), 0, 0, heap, off, maxError2, maxRadius2); else - recurseKnn(&query.coeff(0, i), 0, 0, heap, off, maxError, maxRadius2); + recurseKnn(&query.coeff(0, i), 0, 0, heap, off, maxError2, maxRadius2); } if (sortResults) @@ -349,7 +351,7 @@ namespace Nabo } template template - unsigned long KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt::recurseKnn(const T* query, const unsigned n, T rd, Heap& heap, std::vector& off, const T maxError, const T maxRadius2) const + unsigned long KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt::recurseKnn(const T* query, const unsigned n, T rd, Heap& heap, std::vector& off, const T maxError2, const T maxRadius2) const { const Node& node(nodes[n]); const uint32_t cd(getDim(node.dimChildBucketSize)); @@ -393,36 +395,36 @@ namespace Nabo if (new_off > 0) { if (collectStatistics) - leafVisitedCount += recurseKnn(query, rightChild, rd, heap, off, maxError, maxRadius2); + leafVisitedCount += recurseKnn(query, rightChild, rd, heap, off, maxError2, maxRadius2); else - recurseKnn(query, rightChild, rd, heap, off, maxError, maxRadius2); + recurseKnn(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(query, n + 1, rd, heap, off, maxError, maxRadius2); + leafVisitedCount += recurseKnn(query, n + 1, rd, heap, off, maxError2, maxRadius2); else - recurseKnn(query, n + 1, rd, heap, off, maxError, maxRadius2); + recurseKnn(query, n + 1, rd, heap, off, maxError2, maxRadius2); offcd = old_off; } } else { if (collectStatistics) - leafVisitedCount += recurseKnn(query, n+1, rd, heap, off, maxError, maxRadius2); + leafVisitedCount += recurseKnn(query, n+1, rd, heap, off, maxError2, maxRadius2); else - recurseKnn(query, n+1, rd, heap, off, maxError, maxRadius2); + recurseKnn(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(query, rightChild, rd, heap, off, maxError, maxRadius2); + leafVisitedCount += recurseKnn(query, rightChild, rd, heap, off, maxError2, maxRadius2); else - recurseKnn(query, rightChild, rd, heap, off, maxError, maxRadius2); + recurseKnn(query, rightChild, rd, heap, off, maxError2, maxRadius2); offcd = old_off; } } diff --git a/nabo/kdtree_opencl.cpp b/nabo/kdtree_opencl.cpp index fb97f0d..1912bbe 100644 --- a/nabo/kdtree_opencl.cpp +++ b/nabo/kdtree_opencl.cpp @@ -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); diff --git a/nabo/opencl/knn_bf.cl b/nabo/opencl/knn_bf.cl index 36ae99e..f150aed 100644 --- a/nabo/opencl/knn_bf.cl +++ b/nabo/opencl/knn_bf.cl @@ -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); }