Skip to content

Commit

Permalink
Remove the need for #pragma critical, by saving if a point should be …
Browse files Browse the repository at this point in the history
…removed in an array.

Do a second loop, to assign indexes to indices and removed_indices_.
  • Loading branch information
larshg committed Nov 26, 2024
1 parent c93bae9 commit c3caed5
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions filters/include/pcl/filters/impl/radius_outlier_removal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pcl::RadiusOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
// The arrays to be used
Indices nn_indices (mean_k);
std::vector<float> nn_dists(mean_k);
std::vector<std::uint8_t> to_keep(indices_->size());
indices.resize (indices_->size ());
removed_indices_->resize (indices_->size ());
int oii = 0, rii = 0; // oii = output indices iterator, rii = removed indices iterator
Expand All @@ -94,7 +95,7 @@ pcl::RadiusOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
num_threads(num_threads_)
for (ptrdiff_t i = 0; i < static_cast<ptrdiff_t>(indices_->size()); i++)
{
const index_t index = indices_->at(i);
const index_t& index = (*indices_)[i];
// Perform the nearest-k search
const int k = searcher_->nearestKSearch (index, mean_k, nn_indices, nn_dists);

Expand Down Expand Up @@ -129,22 +130,12 @@ pcl::RadiusOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
// Unless negative was set, then it's the opposite condition
if (!chk_neighbors)
{
if (extract_removed_indices_)
{
#pragma omp critical
{
(*removed_indices_)[rii++] = index;
}
}

to_keep[index] = 0;
continue;
}

// Otherwise it was a normal point for output (inlier)
#pragma omp critical
{
indices[oii++] = index;
}
to_keep[index] = 1;
}
}
// NaN or Inf values could exist => use radius search
Expand All @@ -158,7 +149,7 @@ pcl::RadiusOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
num_threads(num_threads_)
for (ptrdiff_t i = 0; i < static_cast<ptrdiff_t>(indices_->size()); i++)
{
const index_t index = indices_->at(i);
const index_t& index = (*indices_)[i];
if (!pcl::isXYFinite((*input_)[index]))
continue;
// Perform the radius search
Expand All @@ -170,21 +161,24 @@ pcl::RadiusOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
// Unless negative was set, then it's the opposite condition
if ((!negative_ && k <= min_pts_radius_) || (negative_ && k > min_pts_radius_))
{
if (extract_removed_indices_)
{
#pragma omp critical
{
(*removed_indices_)[rii++] = index;
}
}
to_keep[index] = 0;
continue;
}

// Otherwise it was a normal point for output (inlier)
#pragma omp critical
{
indices[oii++] = index;
}
to_keep[index] = 1;
}
}

for (index_t i=0; i < to_keep.size(); i++)
{
if (to_keep[i] == 1)
{
indices[oii++] = i;
}
else
{
(*removed_indices_)[rii++] = i;
}
}

Expand Down

0 comments on commit c3caed5

Please sign in to comment.