Point Cloud Library (PCL)  1.9.1-dev
filter_indices.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: filter_indices.h 4707 2012-02-23 10:34:17Z florentinus $
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/filters/filter.h>
43 
44 namespace pcl
45 {
46  /** \brief Removes points with x, y, or z equal to NaN (dry run).
47  *
48  * This function only computes the mapping between the points in the input
49  * cloud and the cloud that would result from filtering. It does not
50  * actually construct and output the filtered cloud.
51  *
52  * \note This function does not modify the input point cloud!
53  *
54  * \param cloud_in the input point cloud
55  * \param index the mapping (ordered): filtered_cloud.points[i] = cloud_in.points[index[i]]
56  *
57  * \see removeNaNFromPointCloud
58  * \ingroup filters
59  */
60  template<typename PointT> void
61  removeNaNFromPointCloud (const pcl::PointCloud<PointT> &cloud_in, std::vector<int> &index);
62 
63  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64  /** \brief @b FilterIndices represents the base class for filters that are about binary point removal.
65  * <br>
66  * All derived classes have to implement the \a filter (PointCloud &output) and the \a filter (std::vector<int> &indices) methods.
67  * Ideally they also make use of the \a negative_, \a keep_organized_ and \a extract_removed_indices_ systems.
68  * The distinguishment between the \a negative_ and \a extract_removed_indices_ systems only makes sense if the class automatically
69  * filters non-finite entries in the filtering methods (recommended).
70  * \author Justin Rosen
71  * \ingroup filters
72  */
73  template<typename PointT>
74  class FilterIndices : public Filter<PointT>
75  {
76  public:
79 
80  using Ptr = boost::shared_ptr<FilterIndices<PointT> >;
81  using ConstPtr = boost::shared_ptr<const FilterIndices<PointT> >;
82 
83 
84  /** \brief Constructor.
85  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
86  */
87  FilterIndices (bool extract_removed_indices = false) :
88  negative_ (false),
89  keep_organized_ (false),
90  user_filter_value_ (std::numeric_limits<float>::quiet_NaN ())
91  {
92  extract_removed_indices_ = extract_removed_indices;
93  }
94 
95  /** \brief Empty virtual destructor. */
96 
98  {
99  }
100 
101  inline void
102  filter (PointCloud &output)
103  {
105  }
106 
107  /** \brief Calls the filtering method and returns the filtered point cloud indices.
108  * \param[out] indices the resultant filtered point cloud indices
109  */
110  inline void
111  filter (std::vector<int> &indices)
112  {
113  if (!initCompute ())
114  return;
115 
116  // Apply the actual filter
117  applyFilter (indices);
118 
119  deinitCompute ();
120  }
121 
122  /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions.
123  * \param[in] negative false = normal filter behavior (default), true = inverted behavior.
124  */
125  inline void
126  setNegative (bool negative)
127  {
128  negative_ = negative;
129  }
130 
131  /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions.
132  * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior.
133  */
134  inline bool
135  getNegative () const
136  {
137  return (negative_);
138  }
139 
140  /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN),
141  * or removed from the PointCloud, thus potentially breaking its organized structure.
142  * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure.
143  */
144  inline void
145  setKeepOrganized (bool keep_organized)
146  {
147  keep_organized_ = keep_organized;
148  }
149 
150  /** \brief Get whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default = NaN),
151  * or removed from the PointCloud, thus potentially breaking its organized structure.
152  * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure.
153  */
154  inline bool
156  {
157  return (keep_organized_);
158  }
159 
160  /** \brief Provide a value that the filtered points should be set to instead of removing them.
161  * Used in conjunction with \a setKeepOrganized ().
162  * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN).
163  */
164  inline void
165  setUserFilterValue (float value)
166  {
167  user_filter_value_ = value;
168  }
169 
170  protected:
171 
174 
175  /** \brief False = normal filter behavior (default), true = inverted behavior. */
176  bool negative_;
177 
178  /** \brief False = remove points (default), true = redefine points, keep structure. */
180 
181  /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */
183 
184  /** \brief Abstract filter method for point cloud indices. */
185  virtual void
186  applyFilter (std::vector<int> &indices) = 0;
187 
188  /** \brief Abstract filter method for point cloud. */
189  void
190  applyFilter (PointCloud &output) override = 0;
191  };
192 
193  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
194  /** \brief @b FilterIndices represents the base class for filters that are about binary point removal.
195  * <br>
196  * All derived classes have to implement the \a filter (PointCloud &output) and the \a filter (std::vector<int> &indices) methods.
197  * Ideally they also make use of the \a negative_, \a keep_organized_ and \a extract_removed_indices_ systems.
198  * The distinguishment between the \a negative_ and \a extract_removed_indices_ systems only makes sense if the class automatically
199  * filters non-finite entries in the filtering methods (recommended).
200  * \author Justin Rosen
201  * \ingroup filters
202  */
203  template<>
204  class PCL_EXPORTS FilterIndices<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
205  {
206  public:
208 
209  /** \brief Constructor.
210  * \param[in] extract_removed_indices Set to true if you want to extract the indices of points being removed (default = false).
211  */
212  FilterIndices (bool extract_removed_indices = false) :
213  negative_ (false),
214  keep_organized_ (false),
215  user_filter_value_ (std::numeric_limits<float>::quiet_NaN ())
216  {
217  extract_removed_indices_ = extract_removed_indices;
218  }
219 
220  /** \brief Empty virtual destructor. */
221 
223  {
224  }
225 
226  virtual void
228  {
230  }
231 
232  /** \brief Calls the filtering method and returns the filtered point cloud indices.
233  * \param[out] indices the resultant filtered point cloud indices
234  */
235  void
236  filter (std::vector<int> &indices);
237 
238  /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions.
239  * \param[in] negative false = normal filter behavior (default), true = inverted behavior.
240  */
241  inline void
242  setNegative (bool negative)
243  {
244  negative_ = negative;
245  }
246 
247  /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions.
248  * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior.
249  */
250  inline bool
251  getNegative () const
252  {
253  return (negative_);
254  }
255 
256  /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN),
257  * or removed from the PointCloud, thus potentially breaking its organized structure.
258  * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure.
259  */
260  inline void
261  setKeepOrganized (bool keep_organized)
262  {
263  keep_organized_ = keep_organized;
264  }
265 
266  /** \brief Get whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default = NaN),
267  * or removed from the PointCloud, thus potentially breaking its organized structure.
268  * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure.
269  */
270  inline bool
272  {
273  return (keep_organized_);
274  }
275 
276  /** \brief Provide a value that the filtered points should be set to instead of removing them.
277  * Used in conjunction with \a setKeepOrganized ().
278  * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN).
279  */
280  inline void
281  setUserFilterValue (float value)
282  {
283  user_filter_value_ = value;
284  }
285 
286  protected:
287 
288  /** \brief False = normal filter behavior (default), true = inverted behavior. */
289  bool negative_;
290 
291  /** \brief False = remove points (default), true = redefine points, keep structure. */
293 
294  /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */
296 
297  /** \brief Abstract filter method for point cloud indices. */
298  virtual void
299  applyFilter (std::vector<int> &indices) = 0;
300 
301  /** \brief Abstract filter method for point cloud. */
302  void
303  applyFilter (PCLPointCloud2 &output) override = 0;
304  };
305 }
306 
307 #ifdef PCL_NO_PRECOMPILE
308 #include <pcl/filters/impl/filter_indices.hpp>
309 #endif
boost::shared_ptr< const Filter< pcl::pcl::PCLPointCloud2 > > ConstPtr
Definition: filter.h:90
float user_filter_value_
The user given value that the filtered point dimensions should be set to (default = NaN)...
void setKeepOrganized(bool keep_organized)
Set whether the filtered points should be kept and set to the value given through setUserFilterValue ...
void setNegative(bool negative)
Set whether the regular conditions for points filtering should apply, or the inverted conditions...
void filter(std::vector< int > &indices)
Calls the filtering method and returns the filtered point cloud indices.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void removeNaNFromPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, std::vector< int > &index)
Removes points with x, y, or z equal to NaN.
Definition: filter.hpp:46
virtual void filter(PCLPointCloud2 &output)
float user_filter_value_
The user given value that the filtered point dimensions should be set to (default = NaN)...
void setNegative(bool negative)
Set whether the regular conditions for points filtering should apply, or the inverted conditions...
bool negative_
False = normal filter behavior (default), true = inverted behavior.
bool getKeepOrganized() const
Get whether the filtered points should be kept and set to the value given through setUserFilterValue ...
void filter(PointCloud &output)
Calls the filtering method and returns the filtered dataset in output.
Definition: filter.h:130
void setUserFilterValue(float value)
Provide a value that the filtered points should be set to instead of removing them.
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:138
~FilterIndices()
Empty virtual destructor.
FilterIndices represents the base class for filters that are about binary point removal.
~FilterIndices()
Empty virtual destructor.
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
virtual void applyFilter(std::vector< int > &indices)=0
Abstract filter method for point cloud indices.
Filter represents the base filter class.
Definition: filter.h:83
bool getNegative() const
Get whether the regular conditions for points filtering should apply, or the inverted conditions...
FilterIndices(bool extract_removed_indices=false)
Constructor.
void setUserFilterValue(float value)
Provide a value that the filtered points should be set to instead of removing them.
bool getKeepOrganized() const
Get whether the filtered points should be kept and set to the value given through setUserFilterValue ...
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:173
void setKeepOrganized(bool keep_organized)
Set whether the filtered points should be kept and set to the value given through setUserFilterValue ...
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void filter(PointCloud &output)
boost::shared_ptr< Filter< pcl::pcl::PCLPointCloud2 > > Ptr
Definition: filter.h:89
bool getNegative() const
Get whether the regular conditions for points filtering should apply, or the inverted conditions...
bool extract_removed_indices_
Set to true if we want to return the indices of the removed points.
Definition: filter.h:167
bool negative_
False = normal filter behavior (default), true = inverted behavior.
FilterIndices(bool extract_removed_indices=false)
Constructor.