PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.64k stars 4.59k forks source link

This piece of code seems to be ineffective. #6072

Closed mawenwuda closed 22 hours ago

mawenwuda commented 4 days ago
`// Build a list of (unique) indices for which we will need to compute SPFH signatures
// (We need an SPFH signature for every point that is a neighbor of any point in input_[indices_])
if (surface_ != input_ ||
    indices_->size () != surface_->size ())
{
  for (const auto& p_idx: *indices_)
  {
    if (this->searchForNeighbors (p_idx, search_parameter_, nn_indices, nn_dists) == 0)
      continue;

    spfh_indices.insert (nn_indices.begin (), nn_indices.end ());
  }
}
else
{
  // Special case: When a feature must be computed at every point, there is no need for a neighborhood search
  for (std::size_t idx = 0; idx < indices_->size (); ++idx)
    spfh_indices.insert (static_cast<int> (idx));
}`

This piece of code is from the computeSPFHSignatures function in the fpfh.hpp file, and the comment indicates that it computes SPFH for all points in the input point cloud.The comments are from the file fpfh.h. For example, after downsampling the point cloud where surface_ != input_ holds true, this->searchForNeighbors(p_idx, search_parameter_, nn_indices, nn_dists) performs nearest neighbor search on the downsampled point cloud. Despite this, after the loop, spfh_indices still stores indices from input_. What is its significance then?We can simply assign the indices stored in indices_ to spfh_indices.

Link to the repo: https://github.com/PointCloudLibrary/pcl/blob/master/features/include/pcl/features/impl/fpfh.hpp https://github.com/PointCloudLibrary/pcl/blob/master/features/include/pcl/features/fpfh.h

I am puzzled about the purpose of this code snippet.

mvieth commented 22 hours ago

The indices in nn_indices and spfh_indices refer to surface_, not to input_. The indices in indices_ refer to input_. I hope that helps.

Please use Stackoverflow or the Discord community chat for such questions in the future. The GitHub issues are intended for bug reports and compile errors.