Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filter_indices.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: filter_indices.h 6144 2012-07-04 22:06:28Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FILTERS_FILTER_INDICES_H_
41 #define PCL_FILTERS_FILTER_INDICES_H_
42 
43 #include <pcl/filters/filter.h>
44 
45 namespace pcl
46 {
54  template<typename PointT> void
55  removeNaNFromPointCloud (const pcl::PointCloud<PointT> &cloud_in, std::vector<int> &index);
56 
58 
67  template<typename PointT>
68  class FilterIndices : public Filter<PointT>
69  {
70  public:
72 
76  FilterIndices (bool extract_removed_indices = false) :
77  negative_ (false),
78  keep_organized_ (false),
79  extract_removed_indices_ (extract_removed_indices),
80  user_filter_value_ (std::numeric_limits<float>::quiet_NaN ()),
81  removed_indices_ (new std::vector<int> ())
82  {
83  }
84 
86  virtual
88  {
89  }
90 
91  inline void
92  filter (PointCloud &output)
93  {
95  }
96 
100  inline void
101  filter (std::vector<int> &indices)
102  {
103  if (!initCompute ())
104  return;
105 
106  // Apply the actual filter
107  applyFilter (indices);
108 
109  deinitCompute ();
110  }
111 
115  inline void
116  setNegative (bool negative)
117  {
118  negative_ = negative;
119  }
120 
124  inline bool
126  {
127  return (negative_);
128  }
129 
134  inline void
135  setKeepOrganized (bool keep_organized)
136  {
137  keep_organized_ = keep_organized;
138  }
139 
144  inline bool
146  {
147  return (keep_organized_);
148  }
149 
154  inline void
155  setUserFilterValue (float value)
156  {
157  user_filter_value_ = value;
158  }
159 
163  inline IndicesConstPtr const
165  {
166  return (removed_indices_);
167  }
168 
169  protected:
172 
174  bool negative_;
175 
177  bool keep_organized_;
178 
180  bool extract_removed_indices_;
181 
183  float user_filter_value_;
184 
186  IndicesPtr removed_indices_;
187 
189  virtual void
190  applyFilter (std::vector<int> &indices) = 0;
191  };
192 
194 
203  template<>
204  class PCL_EXPORTS FilterIndices<sensor_msgs::PointCloud2> : public Filter<sensor_msgs::PointCloud2>
205  {
206  public:
208 
212  FilterIndices (bool extract_removed_indices = false) :
213  negative_ (false),
214  keep_organized_ (false),
215  extract_removed_indices_ (extract_removed_indices),
216  user_filter_value_ (std::numeric_limits<float>::quiet_NaN ()),
217  removed_indices_ (new std::vector<int>)
218  {
219  }
220 
222  virtual
224  {
225  }
226 
227  virtual void
228  filter (PointCloud2 &output)
229  {
231  }
232 
236  void
237  filter (std::vector<int> &indices);
238 
242  inline void
243  setNegative (bool negative)
244  {
245  negative_ = negative;
246  }
247 
251  inline bool
253  {
254  return (negative_);
255  }
256 
261  inline void
262  setKeepOrganized (bool keep_organized)
263  {
264  keep_organized_ = keep_organized;
265  }
266 
271  inline bool
273  {
274  return (keep_organized_);
275  }
276 
281  inline void
282  setUserFilterValue (float value)
283  {
284  user_filter_value_ = value;
285  }
286 
290  inline IndicesConstPtr const
292  {
293  return (removed_indices_);
294  }
295 
296  protected:
298  bool negative_;
299 
301  bool keep_organized_;
302 
304  bool extract_removed_indices_;
305 
307  float user_filter_value_;
308 
310  IndicesPtr removed_indices_;
311 
313  virtual void
314  applyFilter (std::vector<int> &indices) = 0;
315  };
316 }
317 
318 #endif //#ifndef PCL_FILTERS_FILTER_INDICES_H_
319