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