00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id: radius_outlier_removal.h 34663 2010-12-11 21:54:46Z rusu $ 00035 * 00036 */ 00037 00038 #ifndef PCL_FILTERS_RADIUSOUTLIERREMOVAL_H_ 00039 #define PCL_FILTERS_RADIUSOUTLIERREMOVAL_H_ 00040 00041 #include "pcl/filters/filter.h" 00042 #include "pcl/point_types.h" 00043 #include "pcl/kdtree/kdtree_flann.h" 00044 00045 namespace pcl 00046 { 00050 00055 template <typename PointT> 00056 class RadiusOutlierRemoval: public Filter<PointT> 00057 { 00058 using Filter<PointT>::input_; 00059 using Filter<PointT>::indices_; 00060 using Filter<PointT>::filter_name_; 00061 using Filter<PointT>::getClassName; 00062 00063 typedef typename pcl::KdTree<PointT> KdTree; 00064 typedef typename pcl::KdTree<PointT>::Ptr KdTreePtr; 00065 00066 typedef typename Filter<PointT>::PointCloud PointCloud; 00067 typedef typename PointCloud::Ptr PointCloudPtr; 00068 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00069 00070 public: 00072 00073 RadiusOutlierRemoval () : search_radius_ (0.0), min_pts_radius_ (1), tree_ () 00074 { 00075 filter_name_ = "RadiusOutlierRemoval"; 00076 }; 00077 00079 00082 inline void setRadiusSearch (double radius) { search_radius_ = radius; } 00083 00085 00086 inline double getRadiusSearch () { return (search_radius_); } 00087 00089 00093 inline void setMinNeighborsInRadius (int min_pts) { min_pts_radius_ = min_pts; } 00094 00096 00098 inline double getMinNeighborsInRadius () { return (min_pts_radius_); } 00099 00100 protected: 00102 double search_radius_; 00103 00106 int min_pts_radius_; 00107 00109 KdTreePtr tree_; 00110 00112 00115 void applyFilter (PointCloud &output); 00116 }; 00117 00121 00126 template <> 00127 class RadiusOutlierRemoval<sensor_msgs::PointCloud2> : public Filter<sensor_msgs::PointCloud2> 00128 { 00129 using Filter<sensor_msgs::PointCloud2>::filter_name_; 00130 using Filter<sensor_msgs::PointCloud2>::getClassName; 00131 00132 typedef pcl::KdTree<pcl::PointXYZ> KdTree; 00133 typedef pcl::KdTree<pcl::PointXYZ>::Ptr KdTreePtr; 00134 00135 typedef sensor_msgs::PointCloud2 PointCloud2; 00136 typedef PointCloud2::Ptr PointCloud2Ptr; 00137 typedef PointCloud2::ConstPtr PointCloud2ConstPtr; 00138 00139 public: 00141 00142 RadiusOutlierRemoval () : search_radius_ (0.0), min_pts_radius_ (1), tree_ () 00143 { 00144 filter_name_ = "RadiusOutlierRemoval"; 00145 }; 00146 00148 00151 inline void setRadiusSearch (double radius) { search_radius_ = radius; } 00152 00154 00155 inline double getRadiusSearch () { return (search_radius_); } 00156 00158 00162 inline void setMinNeighborsInRadius (int min_pts) { min_pts_radius_ = min_pts; } 00163 00165 00167 inline double getMinNeighborsInRadius () { return (min_pts_radius_); } 00168 00169 protected: 00171 double search_radius_; 00172 00175 int min_pts_radius_; 00176 00178 KdTreePtr tree_; 00179 00180 void applyFilter (PointCloud2 &output); 00181 }; 00182 } 00183 00184 #endif //#ifndef PCL_FILTERS_RADIUSOUTLIERREMOVAL_H_