@@ -59,8 +59,9 @@ pcl::StatisticalOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
59
59
searcher_->setInputCloud (input_);
60
60
61
61
// The arrays to be used
62
- Indices nn_indices (mean_k_);
63
- std::vector<float > nn_dists (mean_k_);
62
+ const int searcher_k = mean_k_ + 1 ; // Find one more, since results include the query point.
63
+ Indices nn_indices (searcher_k);
64
+ std::vector<float > nn_dists (searcher_k);
64
65
std::vector<float > distances (indices_->size ());
65
66
indices.resize (indices_->size ());
66
67
removed_indices_->resize (indices_->size ());
@@ -79,7 +80,7 @@ pcl::StatisticalOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
79
80
}
80
81
81
82
// Perform the nearest k search
82
- if (searcher_->nearestKSearch ((*indices_)[iii], mean_k_ + 1 , nn_indices, nn_dists) == 0 )
83
+ if (searcher_->nearestKSearch ((*indices_)[iii], searcher_k , nn_indices, nn_dists) == 0 )
83
84
{
84
85
distances[iii] = 0.0 ;
85
86
PCL_WARN (" [pcl::%s::applyFilter] Searching for the closest %d neighbors failed.\n " , getClassName ().c_str (), mean_k_);
@@ -88,7 +89,7 @@ pcl::StatisticalOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
88
89
89
90
// Calculate the mean distance to its neighbors
90
91
double dist_sum = 0.0 ;
91
- for (int k = 1 ; k < mean_k_ + 1 ; ++k) // k = 0 is the query point
92
+ for (int k = 1 ; k < searcher_k ; ++k) // k = 0 is the query point
92
93
dist_sum += sqrt (nn_dists[k]);
93
94
distances[iii] = static_cast <float > (dist_sum / mean_k_);
94
95
valid_distances++;
0 commit comments