Point Cloud Library (PCL)  1.11.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
passthrough.h
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 the copyright holder(s) 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$
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/pcl_macros.h>
43 #include <pcl/filters/filter_indices.h>
44 
45 namespace pcl
46 {
47  /** \brief @b PassThrough passes points in a cloud based on constraints for one particular field of the point type.
48  * \details Iterates through the entire input once, automatically filtering non-finite points and the points outside
49  * the interval specified by setFilterLimits(), which applies only to the field specified by setFilterFieldName().
50  * <br><br>
51  * Usage example:
52  * \code
53  * pcl::PassThrough<PointType> ptfilter (true); // Initializing with true will allow us to extract the removed indices
54  * ptfilter.setInputCloud (cloud_in);
55  * ptfilter.setFilterFieldName ("x");
56  * ptfilter.setFilterLimits (0.0, 1000.0);
57  * ptfilter.filter (*indices_x);
58  * // The indices_x array indexes all points of cloud_in that have x between 0.0 and 1000.0
59  * indices_rem = ptfilter.getRemovedIndices ();
60  * // The indices_rem array indexes all points of cloud_in that have x smaller than 0.0 or larger than 1000.0
61  * // and also indexes all non-finite points of cloud_in
62  * ptfilter.setIndices (indices_x);
63  * ptfilter.setFilterFieldName ("z");
64  * ptfilter.setFilterLimits (-10.0, 10.0);
65  * ptfilter.setNegative (true);
66  * ptfilter.filter (*indices_xz);
67  * // The indices_xz array indexes all points of cloud_in that have x between 0.0 and 1000.0 and z larger than 10.0 or smaller than -10.0
68  * ptfilter.setIndices (indices_xz);
69  * ptfilter.setFilterFieldName ("intensity");
70  * ptfilter.setFilterLimits (FLT_MIN, 0.5);
71  * ptfilter.setNegative (false);
72  * ptfilter.filter (*cloud_out);
73  * // The resulting cloud_out contains all points of cloud_in that are finite and have:
74  * // x between 0.0 and 1000.0, z larger than 10.0 or smaller than -10.0 and intensity smaller than 0.5.
75  * \endcode
76  * \author Radu Bogdan Rusu
77  * \ingroup filters
78  */
79  template <typename PointT>
80  class PassThrough : public FilterIndices<PointT>
81  {
82  protected:
84  using PointCloudPtr = typename PointCloud::Ptr;
87 
88  public:
89 
90  using Ptr = shared_ptr<PassThrough<PointT> >;
91  using ConstPtr = shared_ptr<const PassThrough<PointT> >;
92 
93 
94  /** \brief Constructor.
95  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
96  */
97  PassThrough (bool extract_removed_indices = false) :
98  FilterIndices<PointT> (extract_removed_indices),
99  filter_field_name_ (""),
100  filter_limit_min_ (FLT_MIN),
101  filter_limit_max_ (FLT_MAX)
102  {
103  filter_name_ = "PassThrough";
104  }
105 
106  /** \brief Provide the name of the field to be used for filtering data.
107  * \details In conjunction with setFilterLimits(), points having values outside this interval for this field will be discarded.
108  * \param[in] field_name The name of the field that will be used for filtering.
109  */
110  inline void
111  setFilterFieldName (const std::string &field_name)
112  {
113  filter_field_name_ = field_name;
114  }
115 
116  /** \brief Retrieve the name of the field to be used for filtering data.
117  * \return The name of the field that will be used for filtering.
118  */
119  inline std::string const
121  {
122  return (filter_field_name_);
123  }
124 
125  /** \brief Set the numerical limits for the field for filtering data.
126  * \details In conjunction with setFilterFieldName(), points having values outside this interval for this field will be discarded.
127  * \param[in] limit_min The minimum allowed field value (default = FLT_MIN).
128  * \param[in] limit_max The maximum allowed field value (default = FLT_MAX).
129  */
130  inline void
131  setFilterLimits (const float &limit_min, const float &limit_max)
132  {
133  filter_limit_min_ = limit_min;
134  filter_limit_max_ = limit_max;
135  }
136 
137  /** \brief Get the numerical limits for the field for filtering data.
138  * \param[out] limit_min The minimum allowed field value (default = FLT_MIN).
139  * \param[out] limit_max The maximum allowed field value (default = FLT_MAX).
140  */
141  inline void
142  getFilterLimits (float &limit_min, float &limit_max) const
143  {
144  limit_min = filter_limit_min_;
145  limit_max = filter_limit_max_;
146  }
147 
148  /** \brief Set to true if we want to return the data outside the interval specified by setFilterLimits (min, max)
149  * Default: false.
150  * \warning This method will be removed in the future. Use setNegative() instead.
151  * \param[in] limit_negative return data inside the interval (false) or outside (true)
152  */
153  PCL_DEPRECATED(1, 13, "use inherited FilterIndices::setNegative() instead")
154  inline void
155  setFilterLimitsNegative (const bool limit_negative)
156  {
157  negative_ = limit_negative;
158  }
159 
160  /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
161  * \warning This method will be removed in the future. Use getNegative() instead.
162  * \param[out] limit_negative true if data \b outside the interval [min; max] is to be returned, false otherwise
163  */
164  PCL_DEPRECATED(1, 13, "use inherited FilterIndices::getNegative() instead")
165  inline void
166  getFilterLimitsNegative (bool &limit_negative) const
167  {
168  limit_negative = negative_;
169  }
170 
171  /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
172  * \warning This method will be removed in the future. Use getNegative() instead.
173  * \return true if data \b outside the interval [min; max] is to be returned, false otherwise
174  */
175  inline bool
177  {
178  return (negative_);
179  }
180 
181  protected:
191 
192  /** \brief Filtered results are indexed by an indices array.
193  * \param[out] indices The resultant indices.
194  */
195  void
196  applyFilter (std::vector<int> &indices) override
197  {
198  applyFilterIndices (indices);
199  }
200 
201  /** \brief Filtered results are indexed by an indices array.
202  * \param[out] indices The resultant indices.
203  */
204  void
205  applyFilterIndices (std::vector<int> &indices);
206 
207  private:
208  /** \brief The name of the field that will be used for filtering. */
209  std::string filter_field_name_;
210 
211  /** \brief The minimum allowed field value (default = FLT_MIN). */
212  float filter_limit_min_;
213 
214  /** \brief The maximum allowed field value (default = FLT_MIN). */
215  float filter_limit_max_;
216  };
217 
218  ////////////////////////////////////////////////////////////////////////////////////////////
219  /** \brief PassThrough uses the base Filter class methods to pass through all data that satisfies the user given
220  * constraints.
221  * \author Radu B. Rusu
222  * \ingroup filters
223  */
224  template<>
225  class PCL_EXPORTS PassThrough<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
226  {
228  using PCLPointCloud2Ptr = PCLPointCloud2::Ptr;
229  using PCLPointCloud2ConstPtr = PCLPointCloud2::ConstPtr;
230 
233 
234  public:
235  /** \brief Constructor. */
236  PassThrough (bool extract_removed_indices = false) :
237  FilterIndices<pcl::PCLPointCloud2>::FilterIndices (extract_removed_indices),
238  filter_field_name_ (""), filter_limit_min_ (-FLT_MAX), filter_limit_max_ (FLT_MAX)
239  {
240  filter_name_ = "PassThrough";
241  }
242 
243  /** \brief Provide the name of the field to be used for filtering data. In conjunction with \a setFilterLimits,
244  * points having values outside this interval will be discarded.
245  * \param[in] field_name the name of the field that contains values used for filtering
246  */
247  inline void
248  setFilterFieldName (const std::string &field_name)
249  {
250  filter_field_name_ = field_name;
251  }
252 
253  /** \brief Get the name of the field used for filtering. */
254  inline std::string const
256  {
257  return (filter_field_name_);
258  }
259 
260  /** \brief Set the field filter limits. All points having field values outside this interval will be discarded.
261  * \param[in] limit_min the minimum allowed field value
262  * \param[in] limit_max the maximum allowed field value
263  */
264  inline void
265  setFilterLimits (const double &limit_min, const double &limit_max)
266  {
267  filter_limit_min_ = limit_min;
268  filter_limit_max_ = limit_max;
269  }
270 
271  /** \brief Get the field filter limits (min/max) set by the user. The default values are -FLT_MAX, FLT_MAX.
272  * \param[out] limit_min the minimum allowed field value
273  * \param[out] limit_max the maximum allowed field value
274  */
275  inline void
276  getFilterLimits (double &limit_min, double &limit_max) const
277  {
278  limit_min = filter_limit_min_;
279  limit_max = filter_limit_max_;
280  }
281 
282  /** \brief Set to true if we want to return the data outside the interval specified by setFilterLimits (min, max).
283  * Default: false.
284  * \param[in] limit_negative return data inside the interval (false) or outside (true)
285  */
286  PCL_DEPRECATED(1, 12, "use inherited FilterIndices::setNegative() instead")
287  inline void
288  setFilterLimitsNegative (const bool limit_negative)
289  {
290  negative_ = limit_negative;
291  }
292 
293  /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
294  * \param[out] limit_negative true if data \b outside the interval [min; max] is to be returned, false otherwise
295  */
296  PCL_DEPRECATED(1, 12, "use inherited FilterIndices::getNegative() instead")
297  inline void
298  getFilterLimitsNegative (bool &limit_negative) const
299  {
300  limit_negative = negative_;
301  }
302 
303  /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
304  * \return true if data \b outside the interval [min; max] is to be returned, false otherwise
305  */
306  PCL_DEPRECATED(1, 12, "use inherited FilterIndices::getNegative() instead")
307  inline bool
308  getFilterLimitsNegative () const
309  {
310  return (negative_);
311  }
312 
313  protected:
314  void
315  applyFilter (PCLPointCloud2 &output) override;
316 
317  void
318  applyFilter (std::vector<int> &indices) override;
319 
320  private:
321  /** \brief The desired user filter field name. */
322  std::string filter_field_name_;
323 
324  /** \brief The minimum allowed filter value a point will be considered from. */
325  double filter_limit_min_;
326 
327  /** \brief The maximum allowed filter value a point will be considered from. */
328  double filter_limit_max_;
329 
330  };
331 }
332 
333 #ifdef PCL_NO_PRECOMPILE
334 #include <pcl/filters/impl/passthrough.hpp>
335 #endif
PassThrough(bool extract_removed_indices=false)
Constructor.
Definition: passthrough.h:97
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
Definition: passthrough.h:265
std::string const getFilterFieldName() const
Retrieve the name of the field to be used for filtering data.
Definition: passthrough.h:120
typename pcl::traits::fieldList< PointInT >::type FieldList
Definition: passthrough.h:86
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
Definition: passthrough.h:248
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min...
Definition: passthrough.h:155
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
Definition: passthrough.h:111
bool negative_
False = normal filter behavior (default), true = inverted behavior.
PassThrough(bool extract_removed_indices=false)
Constructor.
Definition: passthrough.h:236
void applyFilter(std::vector< int > &indices) override
Filtered results are indexed by an indices array.
Definition: passthrough.h:196
FilterIndices represents the base class for filters that are about binary point removal.
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
Filter represents the base filter class.
Definition: filter.h:83
void setFilterLimits(const float &limit_min, const float &limit_max)
Set the numerical limits for the field for filtering data.
Definition: passthrough.h:131
shared_ptr< Filter< PointInT > > Ptr
Definition: filter.h:86
PCL base class.
Definition: pcl_base.h:69
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false)...
Definition: passthrough.h:176
PassThrough passes points in a cloud based on constraints for one particular field of the point type...
Definition: passthrough.h:80
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
Definition: passthrough.h:276
std::string const getFilterFieldName() const
Get the name of the field used for filtering.
Definition: passthrough.h:255
void getFilterLimits(float &limit_min, float &limit_max) const
Get the numerical limits for the field for filtering data.
Definition: passthrough.h:142
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:186
void applyFilterIndices(std::vector< int > &indices)
Filtered results are indexed by an indices array.
Definition: passthrough.hpp:48
std::string filter_name_
The filter name.
Definition: filter.h:161
shared_ptr< const Filter< PointInT > > ConstPtr
Definition: filter.h:87
A point structure representing Euclidean xyz coordinates, and the RGB color.
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:185
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74