Skip to content

Commit

Permalink
Merge pull request #3461 from taketwo/improve-uniform-sampling-tool
Browse files Browse the repository at this point in the history
Do not discard data fields in uniform sampling tool
  • Loading branch information
SergioRAgostinho authored Nov 14, 2019
2 parents 6c049a8 + 7680ea8 commit e0e7cb9
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 e0e7cb9

Please sign in to comment.