Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
passthrough.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-2012, 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: passthrough.h 6144 2012-07-04 22:06:28Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FILTERS_PASSTHROUGH_H_
41 #define PCL_FILTERS_PASSTHROUGH_H_
42 
44 
45 namespace pcl
46 {
79  template <typename PointT>
80  class PassThrough : public FilterIndices<PointT>
81  {
82  protected:
84  typedef typename PointCloud::Ptr PointCloudPtr;
86  typedef typename pcl::traits::fieldList<PointT>::type FieldList;
87 
88  public:
92  PassThrough (bool extract_removed_indices = false) :
93  FilterIndices<PointT>::FilterIndices (extract_removed_indices),
94  filter_field_name_ (""),
95  filter_limit_min_ (FLT_MIN),
96  filter_limit_max_ (FLT_MAX)
97  {
98  filter_name_ = "PassThrough";
99  }
100 
105  inline void
106  setFilterFieldName (const std::string &field_name)
107  {
108  filter_field_name_ = field_name;
109  }
110 
114  inline std::string const
116  {
117  return (filter_field_name_);
118  }
119 
125  inline void
126  setFilterLimits (const float &limit_min, const float &limit_max)
127  {
128  filter_limit_min_ = limit_min;
129  filter_limit_max_ = limit_max;
130  }
131 
136  inline void
137  getFilterLimits (float &limit_min, float &limit_max)
138  {
139  limit_min = filter_limit_min_;
140  limit_max = filter_limit_max_;
141  }
142 
148  inline void
149  setFilterLimitsNegative (const bool limit_negative)
150  {
151  negative_ = limit_negative;
152  }
153 
158  inline void
159  getFilterLimitsNegative (bool &limit_negative)
160  {
161  limit_negative = negative_;
162  }
163 
168  inline bool
170  {
171  return (negative_);
172  }
173 
174  protected:
184 
188  void
189  applyFilter (PointCloud &output);
190 
194  void
195  applyFilter (std::vector<int> &indices)
196  {
197  applyFilterIndices (indices);
198  }
199 
203  void
204  applyFilterIndices (std::vector<int> &indices);
205 
206  private:
208  std::string filter_field_name_;
209 
211  float filter_limit_min_;
212 
214  float filter_limit_max_;
215  };
216 
218 
223  template<>
224  class PCL_EXPORTS PassThrough<sensor_msgs::PointCloud2> : public Filter<sensor_msgs::PointCloud2>
225  {
229 
232 
233  public:
235  PassThrough (bool extract_removed_indices = false) :
236  Filter<sensor_msgs::PointCloud2>::Filter (extract_removed_indices), keep_organized_ (false),
237  user_filter_value_ (std::numeric_limits<float>::quiet_NaN ()),
238  filter_field_name_ (""), filter_limit_min_ (-FLT_MAX), filter_limit_max_ (FLT_MAX),
239  filter_limit_negative_ (false)
240  {
241  filter_name_ = "PassThrough";
242  }
243 
252  inline void
253  setKeepOrganized (bool val)
254  {
255  keep_organized_ = val;
256  }
257 
259  inline bool
261  {
262  return (keep_organized_);
263  }
264 
270  inline void
271  setUserFilterValue (float val)
272  {
273  user_filter_value_ = val;
274  }
275 
280  inline void
281  setFilterFieldName (const std::string &field_name)
282  {
283  filter_field_name_ = field_name;
284  }
285 
287  inline std::string const
289  {
290  return (filter_field_name_);
291  }
292 
297  inline void
298  setFilterLimits (const double &limit_min, const double &limit_max)
299  {
300  filter_limit_min_ = limit_min;
301  filter_limit_max_ = limit_max;
302  }
303 
308  inline void
309  getFilterLimits (double &limit_min, double &limit_max)
310  {
311  limit_min = filter_limit_min_;
312  limit_max = filter_limit_max_;
313  }
314 
319  inline void
320  setFilterLimitsNegative (const bool limit_negative)
321  {
322  filter_limit_negative_ = limit_negative;
323  }
324 
328  inline void
329  getFilterLimitsNegative (bool &limit_negative)
330  {
331  limit_negative = filter_limit_negative_;
332  }
333 
337  inline bool
339  {
340  return (filter_limit_negative_);
341  }
342 
343  protected:
344  void
345  applyFilter (PointCloud2 &output);
346 
347  private:
351  bool keep_organized_;
352 
356  float user_filter_value_;
357 
359  std::string filter_field_name_;
360 
362  double filter_limit_min_;
363 
365  double filter_limit_max_;
366 
368  bool filter_limit_negative_;
369 
370  };
371 }
372 
373 #endif // PCL_FILTERS_PASSTHROUGH_H_
374