Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
statistical_outlier_removal.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: statistical_outlier_removal.h 6144 2012-07-04 22:06:28Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FILTERS_STATISTICAL_OUTLIER_REMOVAL_H_
41 #define PCL_FILTERS_STATISTICAL_OUTLIER_REMOVAL_H_
42 
44 #include <pcl/search/pcl_search.h>
45 
46 namespace pcl
47 {
80  template<typename PointT>
82  {
83  protected:
85  typedef typename PointCloud::Ptr PointCloudPtr;
87  typedef typename pcl::search::Search<PointT>::Ptr SearcherPtr;
88 
89  public:
93  StatisticalOutlierRemoval (bool extract_removed_indices = false) :
94  FilterIndices<PointT>::FilterIndices (extract_removed_indices),
95  searcher_ (),
96  mean_k_ (1),
97  std_mul_ (0.0)
98  {
99  filter_name_ = "StatisticalOutlierRemoval";
100  }
101 
105  inline void
106  setMeanK (int nr_k)
107  {
108  mean_k_ = nr_k;
109  }
110 
114  inline int
116  {
117  return (mean_k_);
118  }
119 
125  inline void
126  setStddevMulThresh (double stddev_mult)
127  {
128  std_mul_ = stddev_mult;
129  }
130 
136  inline double
138  {
139  return (std_mul_);
140  }
141 
142  protected:
152 
156  void
157  applyFilter (PointCloud &output);
158 
162  void
163  applyFilter (std::vector<int> &indices)
164  {
165  applyFilterIndices (indices);
166  }
167 
171  void
172  applyFilterIndices (std::vector<int> &indices);
173 
174  private:
176  SearcherPtr searcher_;
177 
179  int mean_k_;
180 
183  double std_mul_;
184  };
185 
196  template<>
197  class PCL_EXPORTS StatisticalOutlierRemoval<sensor_msgs::PointCloud2> : public Filter<sensor_msgs::PointCloud2>
198  {
201 
204 
206  typedef pcl::search::Search<pcl::PointXYZ>::Ptr KdTreePtr;
207 
211 
212  public:
214  StatisticalOutlierRemoval (bool extract_removed_indices = false) :
215  Filter<sensor_msgs::PointCloud2>::Filter (extract_removed_indices), mean_k_ (2),
216  std_mul_ (0.0), tree_ (), negative_ (false)
217  {
218  filter_name_ = "StatisticalOutlierRemoval";
219  }
220 
224  inline void
225  setMeanK (int nr_k)
226  {
227  mean_k_ = nr_k;
228  }
229 
231  inline int
232  getMeanK ()
233  {
234  return (mean_k_);
235  }
236 
243  inline void
244  setStddevMulThresh (double std_mul)
245  {
246  std_mul_ = std_mul;
247  }
248 
250  inline double
251  getStddevMulThresh ()
252  {
253  return (std_mul_);
254  }
255 
259  inline void
260  setNegative (bool negative)
261  {
262  negative_ = negative;
263  }
264 
269  inline bool
270  getNegative ()
271  {
272  return (negative_);
273  }
274 
275  protected:
277  int mean_k_;
278 
282  double std_mul_;
283 
285  KdTreePtr tree_;
286 
288  bool negative_;
289 
290  void
291  applyFilter (PointCloud2 &output);
292  };
293 }
294 
295 #endif // PCL_FILTERS_STATISTICAL_OUTLIER_REMOVAL_H_
296