Skip to content

Commit

Permalink
Improve uniform sampling tool
Browse files Browse the repository at this point in the history
  • Loading branch information
taketwo committed Nov 13, 2019
1 parent f2c1674 commit 7680ea8
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions tools/uniform_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,32 @@ compute (const pcl::PCLPointCloud2::ConstPtr &input, pcl::PCLPointCloud2 &output
// Estimate
TicToc tt;
tt.tic ();

print_highlight (stderr, "Computing ");

UniformSampling<PointXYZ> us;
us.setInputCloud (xyz);
us.setRadiusSearch (radius);
PointCloud<PointXYZ> output_;
us.filter (output_);
UniformSampling<PointXYZ> us(true); // extract removed indices
us.setInputCloud(xyz);
us.setRadiusSearch(radius);
PointCloud<PointXYZ> temp;
us.filter(temp);

pcl::PointIndices removed_indices;
// These are "fake" indices generated by initCompute(), already sorted
auto input_indices = us.getIndices();
// Removed indices, not guaranteed to be sorted
us.getRemovedIndices(removed_indices);
std::sort(removed_indices.indices.begin(), removed_indices.indices.end());
// Compute retained indices as a set difference between all and removed
std::vector<int> retained;
std::set_difference(input_indices->begin(),
input_indices->end(),
removed_indices.indices.begin(),
removed_indices.indices.end(),
std::inserter(retained, retained.begin()));
pcl::copyPointCloud(*input, retained, output);

print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : ");
print_value ("%d", output_.size()); print_info (" points]\n");

// Convert data back
toPCLPointCloud2 (output_, output);
print_value ("%d", retained.size()); print_info (" points]\n");
}

void
Expand Down

0 comments on commit 7680ea8

Please sign in to comment.