Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
filter.h
Go to the documentation of this file.
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 3746 2011-12-31 22:19:47Z 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, 
00060                            pcl::PointCloud<PointT> &cloud_out, 
00061                            std::vector<int> &index);
00062 
00064 
00068   template<typename PointT>
00069   class Filter : public PCLBase<PointT>
00070   {
00071     public:
00072       using PCLBase<PointT>::indices_;
00073       using PCLBase<PointT>::input_;
00074 
00075       typedef boost::shared_ptr< Filter<PointT> > Ptr;
00076       typedef boost::shared_ptr< const Filter<PointT> > ConstPtr;
00077 
00078       typedef pcl::PointCloud<PointT> PointCloud;
00079       typedef typename PointCloud::Ptr PointCloudPtr;
00080       typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00081 
00086       Filter (bool extract_removed_indices = false) : extract_removed_indices_ (extract_removed_indices)
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 
00101       inline void
00102       filter (PointCloud &output)
00103       {
00104         if (!initCompute ())
00105           return;
00106 
00107         // Resize the output dataset
00108         //if (output.points.size () != indices_->size ())
00109         //  output.points.resize (indices_->size ());
00110 
00111         // Copy header at a minimum
00112         output.header = input_->header;
00113         output.sensor_origin_ = input_->sensor_origin_;
00114         output.sensor_orientation_ = input_->sensor_orientation_;
00115 
00116         // Apply the actual filter
00117         applyFilter (output);
00118 
00119         deinitCompute ();
00120       }
00121 
00122     protected:
00123 
00124       using PCLBase<PointT>::initCompute;
00125       using PCLBase<PointT>::deinitCompute;
00126 
00128       IndicesPtr removed_indices_;
00129 
00131       std::string filter_name_;
00132 
00134       bool extract_removed_indices_;
00135 
00142       virtual void
00143       applyFilter (PointCloud &output) = 0;
00144 
00146       inline const std::string&
00147       getClassName () const
00148       {
00149         return (filter_name_);
00150       }
00151   };
00152 
00154 
00158   template<>
00159   class PCL_EXPORTS Filter<sensor_msgs::PointCloud2> : public PCLBase<sensor_msgs::PointCloud2>
00160   {
00161     public:
00162       typedef sensor_msgs::PointCloud2 PointCloud2;
00163       typedef PointCloud2::Ptr PointCloud2Ptr;
00164       typedef PointCloud2::ConstPtr PointCloud2ConstPtr;
00165 
00170       Filter (bool extract_removed_indices = false) : extract_removed_indices_ (extract_removed_indices)
00171       {
00172         removed_indices_ = boost::make_shared<std::vector<int> > ();
00173       }
00174 
00176       inline IndicesConstPtr const
00177       getRemovedIndices ()
00178       {
00179         return (removed_indices_);
00180       }
00181 
00185       void
00186       filter (PointCloud2 &output);
00187 
00188     protected:
00189 
00191       IndicesPtr removed_indices_;
00192 
00194       bool extract_removed_indices_;
00195 
00197       std::string filter_name_;
00198 
00205       virtual void
00206       applyFilter (PointCloud2 &output) = 0;
00207 
00209       inline const std::string&
00210       getClassName () const
00211       {
00212         return (filter_name_);
00213       }
00214   };
00215 }
00216 
00217 #endif  //#ifndef PCL_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines