Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VoxelGrid] Remove getLeafLayout #4897

Open
tin1254 opened this issue Aug 14, 2021 · 5 comments
Open

[VoxelGrid] Remove getLeafLayout #4897

tin1254 opened this issue Aug 14, 2021 · 5 comments
Labels
kind: proposal Type of issue module: filters priority: gsoc Reason for prioritization

Comments

@tin1254
Copy link
Contributor

tin1254 commented Aug 14, 2021

Is your feature request related to a problem? Please describe.
Raised while refactoring VoxelGrid #4829 (review)

As we are upgrading point hash datatype from int to size_t, the API std::vector<int> getLeafLayout() is not compatible anymore

Context

Reasons to upgrade to size_t: #4365 #585

Expected behavior

Users can query the voxel index using point coordinate or point hash

Current Behavior

We can query the voxel index using point coordinate with int getCentroidIndexAt(const Eigen::Vector3i&).
But if we wanted to query using point hash, we will need to first get a large vector with std::vector<int> getLeafLayout(), and query with the vector

Describe the solution you'd like

Use the following functions to replace getLeafLayout() to avoid return large vector when we upgrade to size_t.
leaf_layout_ will be a unordered_map

// int -> size_t
size_t getCentroidIndexAt(const Eigen::Vector3i& pt) { return leaf_layout_[hashPoint(pt)]; }
// new function
size_t getCentroidIndexAtLeafIdx(const size_t idx) { return leaf_layout_[idx]; }

Describe alternatives you've considered

Same as above, but leaf_layout_ is avector<size_t>

@tin1254 tin1254 added kind: request Type of issue status: triage Labels incomplete labels Aug 14, 2021
@kunaltyagi
Copy link
Member

For the index, we'd need to let the user find the size as well

@kunaltyagi kunaltyagi added kind: proposal Type of issue module: filters priority: gsoc Reason for prioritization and removed status: triage Labels incomplete kind: request Type of issue labels Aug 14, 2021
@tin1254
Copy link
Contributor Author

tin1254 commented Aug 14, 2021

you mean the number of voxels in the filtered cloud? but #voxels = #points in the filtered cloud

@kunaltyagi
Copy link
Member

#voxels = #points in the filtered cloud

That's not necessarily true. In the new voxelgrid, you're making the voxel 0, but still not removing it from the map

@tin1254
Copy link
Contributor Author

tin1254 commented Aug 18, 2021

I mean use can for example get the size from the number of points in the output cloud

PointCloud<PointXYZ> output;
VoxelGrid<PointXYZ> grid;

grid.setLeafSize (0.02f, 0.02f, 0.02f);
grid.setInputCloud (cloud);
grid.filter (output);

Because the leaf_layout_ size is only incremented if a point is pushed to the output

inline experimental::optional<PointT>
filterGrid(const iterator grid_it)
{
  const auto& voxel = grid_it->second;
  if (voxel.size() >= min_points_per_voxel_) {

    if (save_leaf_layout_)
      leaf_layout_[grid_it->first] = num_voxels_++;

    return voxel.get();
  }

  return boost::none;
}

But anyway we can do that easily by returning the following member in the new voxelgrid

/** \brief Total number of voxels in the output cloud */
std::size_t num_voxels_;

@kunaltyagi
Copy link
Member

https://github.com/tin1254/pcl/pull/2/files#diff-d07ab844703ea9f1f13139fe03f22f7399e31d1e603b128957659e7cce53bc4cR221-R226

This clearly leaves some leaves which are not added during the filter operation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: proposal Type of issue module: filters priority: gsoc Reason for prioritization
Projects
None yet
Development

No branches or pull requests

2 participants