PointCloudLibrary / pcl

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

OctreePointCloud*** functionality for complete voxelization #4798

Closed rwbot closed 3 years ago

rwbot commented 3 years ago

My goal is to take a point cloud of a space with volume 1m^3^ and discretize it in 1cm^3^ voxels and have a data structure containing each and every 1cm^3^ voxel, regardless if it's empty or occupied, so quite literally a grid of voxels, like the image below. Cube Grid

I've tried using the VoxelGrid class, but it returns only the occupied voxels. I've looked at the Spatial Partitioning and Search Operations with Octrees tutorial, and noticed there are other Octree types in the Additional Details section:

Several octree types are provided by the PCL octree component. They basically differ by their individual leaf node characteristics: -OctreePointCloudPointVector (equal to OctreePointCloud): This octree can hold a list of point indices at each leaf node. -OctreePointCloudSinglePoint: This octree class hold only a single point indices at each leaf node. Only the most recent point index that is assigned to the leaf node is stored. -OctreePointCloudOccupancy: This octree does not store any point information at its leaf nodes. It can be used for spatial occupancy checks. -OctreePointCloudDensity: This octree counts the amount of points within each leaf node voxel. It allows for spatial density queries.

However, I'm having trouble understanding the use cases for the different types and interpreting their documentation. Specifically, the OctreePointCloudOccupancy class seems most suitable for my application, however, there are only two functions setOccupiedVoxelAtPoint and setOccupiedVoxelsAtPointsFromCloud, and while I see it inherits getOccupiedVoxelCenters, I'm unable to find a function that returns the voxels that are empty.

If this is an implemented functionality, could you point me to the documentation? If not, what are some suggestions to creating this functionality?

mvieth commented 3 years ago

Can you describe your use case a bit more? What do you want to do with the voxels? Do you e.g. want to put something into the voxels? Usually, leaving the unused parts of the space empty makes the octree more efficient.

tin1254 commented 3 years ago

Can you describe your use case a bit more?

+1

But based on your description, does getLeafLayout, getCentroidIndexAt and getLeafLayout in VoxelGrid look right to you? getCentroidIndexAt returns point index if the voxel is occupied or -1 if empty

rwbot commented 3 years ago

@mvieth @tin1254 I'm working on the 3D tetris problem, and need an efficient way of representing the state of each voxel in order to know which voxels to place the next piece, and ultimately how much space was wasted after each attempt.

rwbot commented 3 years ago

Can you describe your use case a bit more?

+1

But based on your description, does getLeafLayout, getCentroidIndexAt and getLeafLayout in VoxelGrid look right to you? getCentroidIndexAt returns point index if the voxel is occupied or -1 if empty

@tin1254 so this is with VoxelGrid, not with an Octree type?

tin1254 commented 3 years ago

@tin1254 so this is with VoxelGrid, not with an Octree type?

Yes. I guess both VoxelGrid and Octree can achieve your goal.

For Octree you can look at isVoxelOccupiedAtPoint in OctreePointCloud (base of OctreePointCloudOccupancy), if all you want is to query a voxel is empty or not

mvieth commented 3 years ago

@rwbot Have you considered using a simple 3D array, maybe something like std::uint8_t voxels[100][100][100], or similar with std::array or std::vector, or even with std::vectory<bool> if you want a very space-efficient solution and only care about occupied/not-occupied? Since you work on a discretized grid, not with continuous points, and don't need/want the adaptive voxelization that an octree gives, VoxelGrid and Octree seem to be more than necessary and maybe not the optimal datatype for you.

rwbot commented 3 years ago

@tin1254 so this is with VoxelGrid, not with an Octree type?

Yes. I guess both VoxelGrid and Octree can achieve your goal.

For Octree you can look at isVoxelOccupiedAtPoint in OctreePointCloud (base of OctreePointCloudOccupancy), if all you want is to query a voxel is empty or not

@mvieth I do need the points for finding free space regions for different box sizes and orientations @tin1254 thanks i'll be using that