Point Cloud Library (PCL)  1.7.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
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:
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 
189  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
190  /** \brief @b FilterIndices represents the base class for filters that are about binary point removal.
191  * <br>
192  * All derived classes have to implement the \a filter (PointCloud &output) and the \a filter (std::vector<int> &indices) methods.
193  * Ideally they also make use of the \a negative_, \a keep_organized_ and \a extract_removed_indices_ systems.
194  * The distinguishment between the \a negative_ and \a extract_removed_indices_ systems only makes sense if the class automatically
195  * filters non-finite entries in the filtering methods (recommended).
196  * \author Justin Rosen
197  * \ingroup filters
198  */
199  template<>
200  class PCL_EXPORTS FilterIndices<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
201  {
202  public:
204 
205  /** \brief Constructor.
206  * \param[in] extract_removed_indices Set to true if you want to extract the indices of points being removed (default = false).
207  */
208  FilterIndices (bool extract_removed_indices = false) :
209  negative_ (false),
210  keep_organized_ (false),
211  user_filter_value_ (std::numeric_limits<float>::quiet_NaN ())
212  {
213  extract_removed_indices_ = extract_removed_indices;
214  }
215 
216  /** \brief Empty virtual destructor. */
217  virtual
219  {
220  }
221 
222  virtual void
224  {
226  }
227 
228  /** \brief Calls the filtering method and returns the filtered point cloud indices.
229  * \param[out] indices the resultant filtered point cloud indices
230  */
231  void
232  filter (std::vector<int> &indices);
233 
234  /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions.
235  * \param[in] negative false = normal filter behavior (default), true = inverted behavior.
236  */
237  inline void
238  setNegative (bool negative)
239  {
240  negative_ = negative;
241  }
242 
243  /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions.
244  * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior.
245  */
246  inline bool
248  {
249  return (negative_);
250  }
251 
252  /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN),
253  * or removed from the PointCloud, thus potentially breaking its organized structure.
254  * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure.
255  */
256  inline void
257  setKeepOrganized (bool keep_organized)
258  {
259  keep_organized_ = keep_organized;
260  }
261 
262  /** \brief Get whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default = NaN),
263  * or removed from the PointCloud, thus potentially breaking its organized structure.
264  * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure.
265  */
266  inline bool
268  {
269  return (keep_organized_);
270  }
271 
272  /** \brief Provide a value that the filtered points should be set to instead of removing them.
273  * Used in conjunction with \a setKeepOrganized ().
274  * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN).
275  */
276  inline void
277  setUserFilterValue (float value)
278  {
279  user_filter_value_ = value;
280  }
281 
282  protected:
283  /** \brief False = normal filter behavior (default), true = inverted behavior. */
284  bool negative_;
285 
286  /** \brief False = remove points (default), true = redefine points, keep structure. */
288 
289  /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */
291 
292  /** \brief Abstract filter method for point cloud indices. */
293  virtual void
294  applyFilter (std::vector<int> &indices) = 0;
295  };
296 }
297 
298 #ifdef PCL_NO_PRECOMPILE
299 #include <pcl/filters/impl/filter_indices.hpp>
300 #endif
301 
302 #endif //#ifndef PCL_FILTERS_FILTER_INDICES_H_
303 
bool getNegative()
Get whether the regular conditions for points filtering should apply, or the inverted conditions...
void setNegative(bool negative)
Set whether the regular conditions for points filtering should apply, or the inverted conditions...
void filter(PointCloud &output)
pcl::PointCloud< PointT > PointCloud
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
bool getKeepOrganized()
Get whether the filtered points should be kept and set to the value given through setUserFilterValue ...
float user_filter_value_
The user given value that the filtered point dimensions should be set to (default = NaN)...
FilterIndices represents the base class for filters that are about binary point removal.
void setKeepOrganized(bool keep_organized)
Set whether the filtered points should be kept and set to the value given through setUserFilterValue ...
bool getKeepOrganized()
Get whether the filtered points should be kept and set to the value given through setUserFilterValue ...
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:139
bool negative_
False = normal filter behavior (default), true = inverted behavior.
bool extract_removed_indices_
Set to true if we want to return the indices of the removed points.
Definition: filter.h:163
void setNegative(bool negative)
Set whether the regular conditions for points filtering should apply, or the inverted conditions...
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:174
void filter(PointCloud &output)
Calls the filtering method and returns the filtered dataset in output.
Definition: filter.h:131
float user_filter_value_
The user given value that the filtered point dimensions should be set to (default = NaN)...
void filter(std::vector< int > &indices)
Calls the filtering method and returns the filtered point cloud indices.
virtual void filter(PCLPointCloud2 &output)
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
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
boost::shared_ptr< FilterIndices< PointT > > Ptr
virtual ~FilterIndices()
Empty virtual destructor.
FilterIndices(bool extract_removed_indices=false)
Constructor.
void setKeepOrganized(bool keep_organized)
Set whether the filtered points should be kept and set to the value given through setUserFilterValue ...
virtual void applyFilter(std::vector< int > &indices)=0
Abstract filter method for point cloud indices.
void setUserFilterValue(float value)
Provide a value that the filtered points should be set to instead of removing them.
bool negative_
False = normal filter behavior (default), true = inverted behavior.
boost::shared_ptr< const FilterIndices< PointT > > ConstPtr
Filter represents the base filter class.
Definition: filter.h:83
FilterIndices(bool extract_removed_indices=false)
Constructor.
virtual ~FilterIndices()
Empty virtual destructor.
bool getNegative()
Get whether the regular conditions for points filtering should apply, or the inverted conditions...
void setUserFilterValue(float value)
Provide a value that the filtered points should be set to instead of removing them.