Skip to content

Commit

Permalink
Improve per review.
Browse files Browse the repository at this point in the history
  • Loading branch information
larshg committed Dec 5, 2024
1 parent 23f7300 commit e1011b6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
1 change: 0 additions & 1 deletion filters/include/pcl/filters/impl/filter_indices.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ pcl::FilterIndices<PointT>::applyFilter (PointCloud &output)
{
applyFilter (indices);
pcl::copyPointCloud (*input_, indices, output);
output.is_dense = true;
}
}

Expand Down
27 changes: 8 additions & 19 deletions filters/include/pcl/filters/impl/radius_outlier_removal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pcl::RadiusOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
std::vector<float> nn_dists(mean_k);
// Set to keep all points and in the filtering set those we don't want to keep, assuming
// we want to keep the majority of the points.
// 0 = remove, 1 = keep, 2 = remove due to inf/nan
// 0 = remove, 1 = keep
std::vector<std::uint8_t> to_keep(indices_->size(), 1);
indices.resize (indices_->size ());
removed_indices_->resize (indices_->size ());
Expand All @@ -106,17 +106,10 @@ pcl::RadiusOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
// Note: nn_dists is sorted, so check the last item
if (k == mean_k)
{
// if a neighbor is furhter away than max distance, remove the point
// if negative is true we keep the point
if (!negative_ && nn_dists_max < nn_dists[k-1])
{
to_keep[i] = 0;
continue;
}

// if a neighbor is closer than max distance and negative is true, remove the point
// if negative is false, we keep the point
if (negative_ && nn_dists_max >= nn_dists[k - 1])
// if negative_ is false and a neighbor is further away than max distance, remove the point
// or
// if negative is true and a neighbor is closer than max distance, remove the point
if ((!negative_ && nn_dists_max < nn_dists[k-1]) || (negative_ && nn_dists_max >= nn_dists[k - 1]))
{
to_keep[i] = 0;
continue;
Expand Down Expand Up @@ -156,17 +149,13 @@ pcl::RadiusOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
// last parameter (max_nn) is the maximum number of neighbors returned. If enough neighbors are found so that point can not be an outlier, we stop searching.
const int k = searcher_->radiusSearch (index, search_radius_, nn_indices, nn_dists, min_pts_radius_ + 1);

// Points having too few neighbors are outliers
if (!negative_ && k <= min_pts_radius_)
// Points having too few neighbors are removed
// or if negative_ is true, then if it has too many neighbors
if ((!negative_ && k <= min_pts_radius_) || (negative_ && k > min_pts_radius_))
{
to_keep[i] = 0;
continue;
}

if (negative_ && k > min_pts_radius_) {
to_keep[i] = 0;
continue;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/filters/test_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,12 +1525,12 @@ TEST (RadiusOutlierRemoval, Filters)

EXPECT_EQ(cloud_out_rgb.size(), 240801);
EXPECT_EQ(cloud_out_rgb.width, 240801);
EXPECT_TRUE(cloud_out_rgb.is_dense);
//EXPECT_TRUE(cloud_out_rgb.is_dense);

outremNonDense.setNegative(true);
outremNonDense.filter(cloud_out_rgb_neg);
EXPECT_EQ(cloud_out_rgb_neg.size(), 606);
EXPECT_TRUE(cloud_out_rgb_neg.is_dense);
//EXPECT_TRUE(cloud_out_rgb_neg.is_dense);

// Test the pcl::PCLPointCloud2 method
PCLPointCloud2 cloud_out2;
Expand Down

0 comments on commit e1011b6

Please sign in to comment.