Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filter.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-2011, 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: filter.h 5026 2012-03-12 02:51:44Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FILTER_H_
41 #define PCL_FILTER_H_
42 
43 #include <pcl/pcl_base.h>
44 #include <pcl/ros/conversions.h>
45 #include <boost/make_shared.hpp>
46 #include <cfloat>
47 
48 namespace pcl
49 {
58  template<typename PointT> void
60  pcl::PointCloud<PointT> &cloud_out,
61  std::vector<int> &index);
62 
64 
68  template<typename PointT>
69  class Filter : public PCLBase<PointT>
70  {
71  public:
74 
75  typedef boost::shared_ptr< Filter<PointT> > Ptr;
76  typedef boost::shared_ptr< const Filter<PointT> > ConstPtr;
77 
79  typedef typename PointCloud::Ptr PointCloudPtr;
81 
86  Filter (bool extract_removed_indices = false) :
87  removed_indices_ (new std::vector<int>),
88  filter_name_ (),
89  extract_removed_indices_ (extract_removed_indices)
90  {
91  }
92 
94  inline IndicesConstPtr const
96  {
97  return (removed_indices_);
98  }
99 
103  inline void
104  filter (PointCloud &output)
105  {
106  if (!initCompute ())
107  return;
108 
109  // Resize the output dataset
110  //if (output.points.size () != indices_->size ())
111  // output.points.resize (indices_->size ());
112 
113  // Copy header at a minimum
114  output.header = input_->header;
115  output.sensor_origin_ = input_->sensor_origin_;
116  output.sensor_orientation_ = input_->sensor_orientation_;
117 
118  // Apply the actual filter
119  applyFilter (output);
120 
121  deinitCompute ();
122  }
123 
124  protected:
125 
128 
130  IndicesPtr removed_indices_;
131 
133  std::string filter_name_;
134 
136  bool extract_removed_indices_;
137 
144  virtual void
145  applyFilter (PointCloud &output) = 0;
146 
148  inline const std::string&
149  getClassName () const
150  {
151  return (filter_name_);
152  }
153  };
154 
156 
160  template<>
161  class PCL_EXPORTS Filter<sensor_msgs::PointCloud2> : public PCLBase<sensor_msgs::PointCloud2>
162  {
163  public:
167 
172  Filter (bool extract_removed_indices = false) :
173  removed_indices_ (new std::vector<int>),
174  extract_removed_indices_ (extract_removed_indices),
175  filter_name_ ()
176  {
177  }
178 
180  inline IndicesConstPtr const
181  getRemovedIndices ()
182  {
183  return (removed_indices_);
184  }
185 
189  void
190  filter (PointCloud2 &output);
191 
192  protected:
193 
195  IndicesPtr removed_indices_;
196 
198  bool extract_removed_indices_;
199 
201  std::string filter_name_;
202 
209  virtual void
210  applyFilter (PointCloud2 &output) = 0;
211 
213  inline const std::string&
214  getClassName () const
215  {
216  return (filter_name_);
217  }
218  };
219 }
220 
221 #endif //#ifndef PCL_FILTER_H_