Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: filter.h 3028 2011-11-01 04:12:17Z rusu $ 00037 * 00038 */ 00039 00040 #ifndef PCL_FILTER_H_ 00041 #define PCL_FILTER_H_ 00042 00043 #include "pcl/pcl_base.h" 00044 #include "pcl/ros/conversions.h" 00045 #include <boost/make_shared.hpp> 00046 #include <cfloat> 00047 00048 namespace pcl 00049 { 00058 template<typename PointT> void 00059 removeNaNFromPointCloud (const pcl::PointCloud<PointT> &cloud_in, pcl::PointCloud<PointT> &cloud_out, std::vector<int> &index); 00060 00062 00067 template<typename PointT> 00068 class Filter : public PCLBase<PointT> 00069 { 00070 public: 00071 using PCLBase<PointT>::indices_; 00072 using PCLBase<PointT>::input_; 00073 00074 typedef boost::shared_ptr< Filter<PointT> > Ptr; 00075 typedef boost::shared_ptr< const Filter<PointT> > ConstPtr; 00076 00077 typedef pcl::PointCloud<PointT> PointCloud; 00078 typedef typename PointCloud::Ptr PointCloudPtr; 00079 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00080 00082 Filter (bool extract_removed_indices = false) : 00083 filter_field_name_ (""), 00084 filter_limit_min_ (-FLT_MAX), filter_limit_max_ (FLT_MAX), 00085 filter_limit_negative_ (false), extract_removed_indices_ (extract_removed_indices) 00086 00087 { 00088 removed_indices_ = boost::make_shared<std::vector<int> > (); 00089 } 00090 00092 inline IndicesConstPtr const 00093 getRemovedIndices () 00094 { 00095 return (removed_indices_); 00096 } 00097 00102 inline void 00103 setFilterFieldName (const std::string &field_name) 00104 { 00105 filter_field_name_ = field_name; 00106 } 00107 00109 inline std::string const 00110 getFilterFieldName () 00111 { 00112 return (filter_field_name_); 00113 } 00114 00119 inline void 00120 setFilterLimits (const double &limit_min, const double &limit_max) 00121 { 00122 filter_limit_min_ = limit_min; 00123 filter_limit_max_ = limit_max; 00124 } 00125 00127 inline void 00128 getFilterLimits (double &limit_min, double &limit_max) 00129 { 00130 limit_min = filter_limit_min_; 00131 limit_max = filter_limit_max_; 00132 } 00133 00138 inline void 00139 setFilterLimitsNegative (const bool limit_negative) 00140 { 00141 filter_limit_negative_ = limit_negative; 00142 } 00143 00145 inline void 00146 getFilterLimitsNegative (bool &limit_negative) 00147 { 00148 limit_negative = filter_limit_negative_; 00149 } 00150 inline bool 00151 getFilterLimitsNegative () 00152 { 00153 return (filter_limit_negative_); 00154 } 00155 00159 inline void 00160 filter (PointCloud &output) 00161 { 00162 if (!initCompute ()) 00163 return; 00164 00165 // Resize the output dataset 00166 //if (output.points.size () != indices_->size ()) 00167 // output.points.resize (indices_->size ()); 00168 00169 // Copy header at a minimum 00170 output.header = input_->header; 00171 output.sensor_origin_ = input_->sensor_origin_; 00172 output.sensor_orientation_ = input_->sensor_orientation_; 00173 00174 // Apply the actual filter 00175 applyFilter (output); 00176 00177 deinitCompute (); 00178 } 00179 00180 protected: 00181 00182 using PCLBase<PointT>::initCompute; 00183 using PCLBase<PointT>::deinitCompute; 00184 00186 IndicesPtr removed_indices_; 00187 00189 std::string filter_name_; 00190 00192 std::string filter_field_name_; 00193 00195 double filter_limit_min_; 00196 00198 double filter_limit_max_; 00199 00201 bool filter_limit_negative_; 00202 00204 bool extract_removed_indices_; 00205 00210 virtual void 00211 applyFilter (PointCloud &output) = 0; 00212 00214 inline const std::string& 00215 getClassName () const 00216 { 00217 return (filter_name_); 00218 } 00219 }; 00220 00222 00227 template<> 00228 class PCL_EXPORTS Filter<sensor_msgs::PointCloud2> : public PCLBase<sensor_msgs::PointCloud2> 00229 { 00230 public: 00231 typedef sensor_msgs::PointCloud2 PointCloud2; 00232 typedef PointCloud2::Ptr PointCloud2Ptr; 00233 typedef PointCloud2::ConstPtr PointCloud2ConstPtr; 00234 00236 Filter (bool extract_removed_indices = false) : 00237 filter_field_name_ (""), filter_limit_min_ (-FLT_MAX), filter_limit_max_ (FLT_MAX), 00238 filter_limit_negative_ (false), extract_removed_indices_ (extract_removed_indices) 00239 { 00240 removed_indices_ = boost::make_shared<std::vector<int> > (); 00241 } 00242 00244 inline IndicesConstPtr const 00245 getRemovedIndices () 00246 { 00247 return (removed_indices_); 00248 } 00249 00254 inline void 00255 setFilterFieldName (const std::string &field_name) 00256 { 00257 filter_field_name_ = field_name; 00258 } 00259 00261 inline std::string const 00262 getFilterFieldName () 00263 { 00264 return (filter_field_name_); 00265 } 00266 00271 inline void 00272 setFilterLimits (const double &limit_min, const double &limit_max) 00273 { 00274 filter_limit_min_ = limit_min; 00275 filter_limit_max_ = limit_max; 00276 } 00277 00279 inline void 00280 getFilterLimits (double &limit_min, double &limit_max) 00281 { 00282 limit_min = filter_limit_min_; 00283 limit_max = filter_limit_max_; 00284 } 00285 00290 inline void 00291 setFilterLimitsNegative (const bool limit_negative) 00292 { 00293 filter_limit_negative_ = limit_negative; 00294 } 00295 00297 inline void 00298 getFilterLimitsNegative (bool &limit_negative) 00299 { 00300 limit_negative = filter_limit_negative_; 00301 } 00302 inline bool 00303 getFilterLimitsNegative () 00304 { 00305 return (filter_limit_negative_); 00306 } 00307 00311 void 00312 filter (PointCloud2 &output); 00313 00314 protected: 00315 00317 IndicesPtr removed_indices_; 00318 00320 std::string filter_name_; 00321 00323 std::string filter_field_name_; 00324 00326 double filter_limit_min_; 00327 00329 double filter_limit_max_; 00330 00332 bool filter_limit_negative_; 00333 00335 bool extract_removed_indices_; 00336 00341 virtual void 00342 applyFilter (PointCloud2 &output) = 0; 00343 00345 inline const std::string& 00346 getClassName () const 00347 { 00348 return (filter_name_); 00349 } 00350 }; 00351 } 00352 00353 #endif //#ifndef PCL_FILTER_H_