Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
radius_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: radius_outlier_removal.h 6144 2012-07-04 22:06:28Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FILTERS_RADIUS_OUTLIER_REMOVAL_H_
41 #define PCL_FILTERS_RADIUS_OUTLIER_REMOVAL_H_
42 
44 #include <pcl/search/pcl_search.h>
45 
46 namespace pcl
47 {
71  template<typename PointT>
72  class RadiusOutlierRemoval : public FilterIndices<PointT>
73  {
74  protected:
76  typedef typename PointCloud::Ptr PointCloudPtr;
78  typedef typename pcl::search::Search<PointT>::Ptr SearcherPtr;
79 
80  public:
84  RadiusOutlierRemoval (bool extract_removed_indices = false) :
85  FilterIndices<PointT>::FilterIndices (extract_removed_indices),
86  searcher_ (),
87  search_radius_ (0.0),
88  min_pts_radius_ (1)
89  {
90  filter_name_ = "RadiusOutlierRemoval";
91  }
92 
98  inline void
99  setRadiusSearch (double radius)
100  {
101  search_radius_ = radius;
102  }
103 
109  inline double
111  {
112  return (search_radius_);
113  }
114 
120  inline void
122  {
123  min_pts_radius_ = min_pts;
124  }
125 
131  inline int
133  {
134  return (min_pts_radius_);
135  }
136 
137  protected:
147 
151  void
152  applyFilter (PointCloud &output);
153 
157  void
158  applyFilter (std::vector<int> &indices)
159  {
160  applyFilterIndices (indices);
161  }
162 
166  void
167  applyFilterIndices (std::vector<int> &indices);
168 
169  private:
171  SearcherPtr searcher_;
172 
174  double search_radius_;
175 
177  int min_pts_radius_;
178  };
179 
181 
187  template<>
188  class PCL_EXPORTS RadiusOutlierRemoval<sensor_msgs::PointCloud2> : public Filter<sensor_msgs::PointCloud2>
189  {
192 
195 
197  typedef pcl::search::Search<pcl::PointXYZ>::Ptr KdTreePtr;
198 
202 
203  public:
205  RadiusOutlierRemoval (bool extract_removed_indices = false) :
206  Filter<sensor_msgs::PointCloud2>::Filter (extract_removed_indices),
207  search_radius_ (0.0), min_pts_radius_ (1), tree_ ()
208  {
209  filter_name_ = "RadiusOutlierRemoval";
210  }
211 
215  inline void
216  setRadiusSearch (double radius)
217  {
218  search_radius_ = radius;
219  }
220 
222  inline double
223  getRadiusSearch ()
224  {
225  return (search_radius_);
226  }
227 
232  inline void
233  setMinNeighborsInRadius (int min_pts)
234  {
235  min_pts_radius_ = min_pts;
236  }
237 
241  inline double
242  getMinNeighborsInRadius ()
243  {
244  return (min_pts_radius_);
245  }
246 
247  protected:
249  double search_radius_;
250 
254  int min_pts_radius_;
255 
257  KdTreePtr tree_;
258 
259  void
260  applyFilter (PointCloud2 &output);
261  };
262 }
263 
264 #endif // PCL_FILTERS_RADIUS_OUTLIER_REMOVAL_H_
265