[feat] Create a filter to compute pointcloud volume
Goal
This MR creates a filter to compute the volume of a space formed by an input pointcloud and a plane.
The volume is estimated by doing integral of areas formed by scanlines and the plane.
Input
- a pointcloud
- a plane represented by four corner points and the plane normal)
Output
- Rasterized pointcloud w.r.t input plane
- The estimated volume
Method
Step 1: Get the input pointcloud and the plane.
The plane is used to defined which part of volume would be calculated:
Step 2: Rasterize pointcloud into a 2D grid.
Rasterization
The resolution is defined by Raster resolution
. To simplify the computation, we rotate the input points to ensure that they are parallel to XY-plan and oriented along the Z-axis. So, the x, y coordinates of a point is used to place the point into the grid. Then we keep the point which has the maximum Z value in each bin of grid (similar to point pillar). Here is a raster of a point cloud.
Interpolation
An interpolation of raster can be enabled to improve the volume estimation in case of a sparse input pointcloud. The interpolation is done for each column and then for each row. The parameter Interpolation threshold
should be set appropriately. It controls the interpolation density.
By default, we use the weighted average value of the neighbor bins to interpolate an empty bin. To define which empty bins should be interpolated, we browse each non-empty bin and do a dilatation. The size of the dilatation window is defined by Interpolation threshold
. As show in the following figure, the blue points are the original input points. The empty bin to interpolate is marked by grey points.
Then for each bin marked by grey point, the value of the bin is computed by the weighted average value of its neighbor bins which are not empty before dilatation (blue points in the figure). Here the size of the window to take neighbor bins is the same as dilatation window.
Another way to interpolate empty bin is also implemented in the filter but not used actually. In this method, Interpolation threshold
indicates maximum consecutive empty bins allowed for the interpolation. If the number of consecutive empty bins is larger than the threshold, the area is considered as an empty area. The red points is the interpolated points for the col_i and the row_j. The interpolation threshold
is set to 2 in this example.
Step 3: Compute integral volume.
The volume is calculated by an addition of volume of each non-empty bins in the raster.
Parameters
- [double]
Grid resolution
: the size of a raster bin. The raster size depends on the pointcloud size and the raster resolution. - [bool]
Enable interpolation
: to enable the interpolation in case of a sparse pointcloud - [int]
Interpolation threshold
: to control the resolution of interpolation
Result
A demo can be found here.