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: statistical_outlier_removal.h 35433 2011-01-25 01:51:41Z rusu $ 00035 * 00036 */ 00037 00038 #ifndef PCL_FILTERS_STATISTICALOUTLIERREMOVAL_H_ 00039 #define PCL_FILTERS_STATISTICALOUTLIERREMOVAL_H_ 00040 00041 #include "pcl/point_types.h" 00042 #include "pcl/filters/filter.h" 00043 #include "pcl/kdtree/kdtree_flann.h" 00044 #include "pcl/common/common.h" 00045 00046 namespace pcl 00047 { 00048 00060 template <typename PointT> 00061 class StatisticalOutlierRemoval: public Filter<PointT> 00062 { 00063 using Filter<PointT>::input_; 00064 using Filter<PointT>::indices_; 00065 using Filter<PointT>::filter_name_; 00066 using Filter<PointT>::getClassName; 00067 00068 typedef typename pcl::KdTree<PointT> KdTree; 00069 typedef typename pcl::KdTree<PointT>::Ptr KdTreePtr; 00070 00071 typedef typename Filter<PointT>::PointCloud PointCloud; 00072 typedef typename PointCloud::Ptr PointCloudPtr; 00073 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00074 00075 public: 00077 StatisticalOutlierRemoval () : mean_k_ (2), std_mul_ (0.0), tree_ (), negative_ (false) 00078 { 00079 filter_name_ = "StatisticalOutlierRemoval"; 00080 }; 00081 00085 inline void setMeanK (int nr_k) { mean_k_ = nr_k; } 00086 00088 inline int getMeanK () { return (mean_k_); } 00089 00096 inline void setStddevMulThresh (double std_mul) { std_mul_ = std_mul; } 00097 00099 inline double getStddevMulThresh () { return (std_mul_); } 00100 00104 inline void setNegative (bool negative) { negative_ = negative; } 00105 00109 inline bool getNegative () { return (negative_); } 00110 00111 protected: 00113 int mean_k_; 00114 00117 double std_mul_; 00118 00120 KdTreePtr tree_; 00121 00123 bool negative_; 00124 00128 void applyFilter (PointCloud &output); 00129 }; 00130 00142 template <> 00143 class StatisticalOutlierRemoval<sensor_msgs::PointCloud2> : public Filter<sensor_msgs::PointCloud2> 00144 { 00145 using Filter<sensor_msgs::PointCloud2>::filter_name_; 00146 using Filter<sensor_msgs::PointCloud2>::getClassName; 00147 00148 typedef pcl::KdTree<pcl::PointXYZ> KdTree; 00149 typedef pcl::KdTree<pcl::PointXYZ>::Ptr KdTreePtr; 00150 00151 typedef sensor_msgs::PointCloud2 PointCloud2; 00152 typedef PointCloud2::Ptr PointCloud2Ptr; 00153 typedef PointCloud2::ConstPtr PointCloud2ConstPtr; 00154 00155 public: 00157 StatisticalOutlierRemoval () : mean_k_ (2), std_mul_ (0.0), tree_ (), negative_ (false) 00158 { 00159 filter_name_ = "StatisticalOutlierRemoval"; 00160 }; 00161 00165 inline void setMeanK (int nr_k) { mean_k_ = nr_k; } 00166 00168 inline int getMeanK () { return (mean_k_); } 00169 00176 inline void setStddevMulThresh (double std_mul) { std_mul_ = std_mul; } 00177 00179 inline double getStddevMulThresh () { return (std_mul_); } 00180 00184 inline void setNegative (bool negative) { negative_ = negative; } 00185 00189 inline bool getNegative () { return (negative_); } 00190 00191 protected: 00193 int mean_k_; 00194 00197 double std_mul_; 00198 00200 KdTreePtr tree_; 00201 00203 bool negative_; 00204 00205 void applyFilter (PointCloud2 &output); 00206 }; 00207 } 00208 00209 #endif //#ifndef PCL_FILTERS_STATISTICALOUTLIERREMOVAL_H_