iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FilterBase.H
Go to the documentation of this file.
1 /*! @file
2  @author Shane Grant
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 #ifdef NRT_HAVE_CLOUD
36 #ifndef INCLUDE_NRT_POINTCLOUD2_FILTER_FILTERBASE_H
37 #define INCLUDE_NRT_POINTCLOUD2_FILTER_FILTERBASE_H
38 
40 
41 namespace nrt
42 {
43  /*! @defgroup pointcloud2filters Pointcloud Filtering Operations
44 
45  Contains classes and functionality related to filtering point
46  clouds in a variety of ways, such as removing outliers, creating
47  voxel grids, or passing through points.
48 
49  @ingroup pointcloud2 */
50 
51  //! Filter interface that all filters must inherit from
52  /*! @ingroup pointcloud2filters */
53  class FilterBase
54  {
55  public:
56  //! Virtual destruction
57  virtual ~FilterBase() {}
58 
59  //! Filters the input point cloud
60  /*! @param input The input point cloud
61  @return The filtered output */
62  virtual PointCloud2 filter( PointCloud2 const input ) = 0;
63 
64  //! Filter a subset of an input point cloud
65  /*! @param input The input point cloud
66  @param indices The indices describing a subset of the cloud
67  @return The filtered output */
68  virtual PointCloud2 filter( PointCloud2 const input, Indices const indices ) = 0;
69 
70  //! Force the filter to operate on a specific field, if supported
71  /*! If your filter is capable of operating on specific dense or sparse
72  fields of a point cloud other than geometry, it should override
73  this function and provide a working implementation.
74 
75  @tparam The field to filter
76  @param input The input point cloud
77  @return The filtered point cloud
78  @throws PointCloud2FilterException If this operation is not supported */
79  template <class Field>
80  PointCloud2 filter( PointCloud2 const input );
81 
82  //! Force the filter to operate on a specific field of a subset, if supported
83  /*! If your filter is capable of operating on specific dense or sparse
84  fields of a point cloud other than geometry, it should override
85  this function and provide a working implementation.
86 
87  @tparam The field to filter
88  @param input The input point cloud
89  @param indices The indices describing some subset
90  @return The filtered point cloud
91  @throws PointCloud2FilterException If this operation is not supported */
92  template <class Field>
93  PointCloud2 filter( PointCloud2 const input, Indices const indices );
94  };
95 
96  //! Filter a point cloud using some filter
97  /*! @tparam Filter The filter class
98  @param input The point cloud to filter
99  @param filter The parameterized filter to apply to the input
100  @return The filtered point cloud
101  @ingroup pointcloud2filters */
102  template <class Filter>
103  PointCloud2 filterPointCloud( PointCloud2 const input, Filter && filter );
104 
105  //! Filter a point cloud subset using some filter
106  /*! @tparam Filter The filter class
107  @param input The point cloud to filter
108  @param indices The subset of the cloud to filter
109  @param filter The parameterized filter to apply to the input
110  @return The filtered point cloud
111  @ingroup pointcloud2filters */
112  template <class Filter>
113  PointCloud2 filterPointCloud( PointCloud2 const input, Indices const indices, Filter && filter );
114 
115  //! Filter a point cloud using some filter that has special arguments
116  //! to its filter function
117  /*! @tparam Filter The filter class
118  @tparam FilterArgs optional arguments to the filter
119  @param input The point cloud to filter
120  @param filter The parameterized filter to apply to the input
121  @param args The arguments required by the Filter class' filter function
122  @return The filtered point cloud
123  @ingroup pointcloud2filters */
124  template <class Filter, class ... FilterArgs>
125  PointCloud2 filterPointCloud( PointCloud2 const input, Filter && filter, FilterArgs && ... args );
126 
127  //! Filter a point cloud subset using some filter that has special arguments
128  //! to its filter function
129  /*! @tparam Filter The filter class
130  @tparam FilterArgs optional arguments to the filter
131  @param input The point cloud to filter
132  @param indices The subset of the cloud to filter
133  @param filter The parameterized filter to apply to the input
134  @param args The arguments required by the Filter class' filter function
135  @return The filtered point cloud
136  @ingroup pointcloud2filters */
137  template <class Filter, class ... FilterArgs>
138  PointCloud2 filterPointCloud( PointCloud2 const input, Indices const indices, Filter && filter, FilterArgs && ... args );
139 
140  //! Filter a specific dense or sparse field of a cloud using some filter
141  /*! @throws PointCloud2FilterException If this operation is not supported
142 
143  @tparam Field The specific field (omit SparseField<>) to filter
144  @tparam Filter The filter class
145  @param input The point cloud to filter
146  @param filter The parameterized filter to apply to the input
147  @return The filtered point cloud
148  @ingroup pointcloud2filters */
149  template <class Field, class Filter>
150  PointCloud2 filterPointCloud( PointCloud2 const input, Filter && filter );
151 
152  //! Filter a specific dense or sparse field of a cloud subset using some filter
153  /*! @throws PointCloud2FilterException If this operation is not supported
154 
155  @tparam Field The specific field (omit SparseField<>) to filter
156  @tparam Filter The filter class
157  @param input The point cloud to filter
158  @param indices The subset of the cloud to filter
159  @param filter The parameterized filter to apply to the input
160  @return The filtered point cloud
161  @ingroup pointcloud2filters */
162  template <class Field, class Filter>
163  PointCloud2 filterPointCloud( PointCloud2 const input, Indices const indices, Filter && filter );
164 
165  //! Filter a specific dense or sparse field of a cloud using some filter
166  //! that has arguments to its filter function
167  /*! @throws PointCloud2FilterException If this operation is not supported
168 
169  @tparam Field The specific field (omit SparseField<>) to filter
170  @tparam Filter The filter class
171  @tparam FilterArgs optional arguments to the filter
172  @param input The point cloud to filter
173  @param filter The parameterized filter to apply to the input
174  @param args The arguments required by the Filter class' filter function
175  @return The filtered point cloud
176  @ingroup pointcloud2filters */
177  template <class Field, class Filter, class ... FilterArgs>
178  PointCloud2 filterPointCloud( PointCloud2 const input, Filter && filter, FilterArgs && ... args );
179 
180  //! Filter a specific dense or sparse field of a cloud subset using some filter
181  //! that has arguments to its filter function
182  /*! @throws PointCloud2FilterException If this operation is not supported
183 
184  @tparam Field The specific field (omit SparseField<>) to filter
185  @tparam Filter The filter class
186  @tparam FilterArgs optional arguments to the filter
187  @param input The point cloud to filter
188  @param indices The subset of the cloud to filter
189  @param filter The parameterized filter to apply to the input
190  @param args The arguments required by the Filter class' filter function
191  @return The filtered point cloud
192  @ingroup pointcloud2filters */
193  template <class Field, class Filter, class ... FilterArgs>
194  PointCloud2 filterPointCloud( PointCloud2 const input, Indices const indices, Filter && filter, FilterArgs && ... args );
195 
196  namespace exception
197  {
198  //! An exception thrown during errors with filtering
200  {
201  public:
202  //! Construct a new exception for an incompatible field
203  PointCloud2FilterException( std::string const & field ) noexcept;
204 
205  virtual ~PointCloud2FilterException() noexcept;
206 
207  //! Get the field name that caused the error
208  std::string const & field() const;
209 
210  private:
211  std::string itsField;
212  std::string whatstring;
213  };
214  } // namespace exception
215 } //namespace nrt
216 
218 
219 #endif // INCLUDE_NRT_POINTCLOUD2_FILTER_FILTERBASE_H
220 #endif // NRT_HAVE_CLOUD