|
| 1 | +.. _grid_filters: |
| 2 | + |
| 3 | +Design of VoxelGrid code structure |
| 4 | +---------------------------------- |
| 5 | + |
| 6 | +This document is intended to explain our new ``VoxelGrid`` design and help you implementing your own grid based filters easily by reusing our implementations. |
| 7 | + |
| 8 | +Inheritance structure of VoxelGrid |
| 9 | +---------------------------------- |
| 10 | + |
| 11 | +.. image:: images/voxel_grid_code_structure.jpg |
| 12 | + :height: 150px |
| 13 | + :align: center |
| 14 | + |
| 15 | +Structure explanation |
| 16 | +--------------------- |
| 17 | + |
| 18 | +We will explain the pieces composing ``VoxelGrid``, then elaborate their purpose and demonstrate how they can be reused to implement your custom grid filters. |
| 19 | + |
| 20 | +In a high level view, ``VoxelGrid`` is comprised from several important classes: |
| 21 | + |
| 22 | +1. ``VoxelFilter`` |
| 23 | +2. ``VoxelStruct`` |
| 24 | +3. ``Voxel`` |
| 25 | +4. ``CartesianFilter`` |
| 26 | +5. ``TransformFilter`` |
| 27 | + |
| 28 | + |
| 29 | +``VoxelFilter<VoxelStruct<Voxel<PointT>,PointT>>`` is aliased as ``VoxelGrid<PointT>`` in our source code, it implements the API specified for ``VoxelGrid``. |
| 30 | +Apart from ``PointT``, it also accepts a class ``GridStruct`` as template argument. |
| 31 | + |
| 32 | +``GridStruct`` should implement the filtering logic of a grid based filter, e.g., how to group points and add them to the same grid cell (voxel in ``VoxelGrid``), |
| 33 | +which grid cells are exported and how to export them to the output point cloud. |
| 34 | +They are several requirements on the member functions of ``GridStruct``, below are their requirements and their intended usage: |
| 35 | + |
| 36 | +.. note:: |
| 37 | + |
| 38 | + 1. ``size_t size()`` |
| 39 | + - return the number of the non-empty grid cells |
| 40 | + 2. ``begin()`` and ``end()`` |
| 41 | + - used for iterating through the grid cells |
| 42 | + - can return any type which can be incremented and compared, e.g., iterator, index |
| 43 | + 3. ``bool setUp(CartesianFilter<FilterBase, GridStruct>&)`` |
| 44 | + - initialize the member variables needed for filtering |
| 45 | + - input point cloud and all settings of CartesianFilter can be accessed from the reference |
| 46 | + 4. ``void addPointToGrid(PointT&)`` |
| 47 | + - add a single point to a grid cell |
| 48 | + 5. ``pcl::experimental::optional<PointT> filterGrid(...)`` |
| 49 | + - accepts output from ``begin()`` and ``end()`` |
| 50 | + - decide whether the iterating grid cell is eligible to be output |
| 51 | + - export a point representing the iterating grid cell |
| 52 | + |
| 53 | +``VoxelStruct<VoxelT, PointT>`` is passed as ``GridStruct`` in our ``VoxelGrid``. It accepts a class ``VoxelT``, which is ``Voxel<PointT>`` in our ``VoxelGrid``. |
| 54 | +``VoxelT`` is intented to store the information of a single grid cell (voxel), e.g., number of points in the cell, mean or covariance of the points. |
| 55 | + |
| 56 | +In ``VoxelFilter``, ``GridStruct`` is passed down again as template argument to ``CartesianFilter`` then to ``TransformFilter``. |
| 57 | +``CartesianFilter`` simplily implements the common API for our grid based filters. |
| 58 | +Note that we can pass either ``pcl::FilterIndices`` (for binary removal) or ``pcl::Filter`` (for another purposes) to ``FilterBase``. |
| 59 | + |
| 60 | +``TransformFilter`` implements the three main phases of grid based filtering: |
| 61 | + |
| 62 | +1. Initialize the filter given the input point cloud and filtering settings |
| 63 | +2. Iterate through all points in the input cloud and add them to grid cells one by one |
| 64 | +3. Iterate through all the non-empty grid cells and output a point based of the information of the grid cells |
| 65 | + |
| 66 | +It can easily be reused for other filters, as long as a filter has the similar logic of collecting points into smaller groups and transforming each group to a point. |
| 67 | + |
| 68 | +Example usage |
| 69 | +------------- |
0 commit comments