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