Point Cloud Library (PCL)  1.11.0-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[i] = cloud_in[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 = shared_ptr<FilterIndices<PointT> >;
81  using ConstPtr = 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  Filter<PointT> (extract_removed_indices),
89  negative_ (false),
90  keep_organized_ (false),
91  user_filter_value_ (std::numeric_limits<float>::quiet_NaN ())
92  {
93  }
94 
96 
97  /** \brief Calls the filtering method and returns the filtered point cloud indices.
98  * \param[out] indices the resultant filtered point cloud indices
99  */
100  void
101  filter (std::vector<int> &indices)
102  {
103  if (!initCompute ())
104  return;
105 
106  // Apply the actual filter
107  applyFilter (indices);
108 
109  deinitCompute ();
110  }
111 
112  /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions.
113  * \param[in] negative false = normal filter behavior (default), true = inverted behavior.
114  */
115  inline void
116  setNegative (bool negative)
117  {
118  negative_ = negative;
119  }
120 
121  /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions.
122  * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior.
123  */
124  inline bool
125  getNegative () const
126  {
127  return (negative_);
128  }
129 
130  /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN),
131  * or removed from the PointCloud, thus potentially breaking its organized structure.
132  * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure.
133  */
134  inline void
135  setKeepOrganized (bool keep_organized)
136  {
137  keep_organized_ = keep_organized;
138  }
139 
140  /** \brief Get 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  * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure.
143  */
144  inline bool
146  {
147  return (keep_organized_);
148  }
149 
150  /** \brief Provide a value that the filtered points should be set to instead of removing them.
151  * Used in conjunction with \a setKeepOrganized ().
152  * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN).
153  */
154  inline void
155  setUserFilterValue (float value)
156  {
157  user_filter_value_ = value;
158  }
159 
160  protected:
161 
166 
167  /** \brief False = normal filter behavior (default), true = inverted behavior. */
168  bool negative_;
169 
170  /** \brief False = remove points (default), true = redefine points, keep structure. */
172 
173  /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */
175 
176  /** \brief Abstract filter method for point cloud indices. */
177  virtual void
178  applyFilter (std::vector<int> &indices) = 0;
179 
180  /** \brief Abstract filter method for point cloud. */
181  void
182  applyFilter (PointCloud &output) override;
183  };
184 
185  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
186  /** \brief @b FilterIndices represents the base class for filters that are about binary point removal.
187  * <br>
188  * All derived classes have to implement the \a filter (PointCloud &output) and the \a filter (std::vector<int> &indices) methods.
189  * Ideally they also make use of the \a negative_, \a keep_organized_ and \a extract_removed_indices_ systems.
190  * The distinguishment between the \a negative_ and \a extract_removed_indices_ systems only makes sense if the class automatically
191  * filters non-finite entries in the filtering methods (recommended).
192  * \author Justin Rosen
193  * \ingroup filters
194  */
195  template<>
196  class PCL_EXPORTS FilterIndices<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
197  {
198  public:
200 
201  /** \brief Constructor.
202  * \param[in] extract_removed_indices Set to true if you want to extract the indices of points being removed (default = false).
203  */
204  FilterIndices (bool extract_removed_indices = false) :
205  Filter<PCLPointCloud2> (extract_removed_indices),
206  negative_ (false),
207  keep_organized_ (false),
208  user_filter_value_ (std::numeric_limits<float>::quiet_NaN ())
209  {
210  }
211 
213 
214  /** \brief Calls the filtering method and returns the filtered point cloud indices.
215  * \param[out] indices the resultant filtered point cloud indices
216  */
217  void
218  filter (std::vector<int> &indices);
219 
220  /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions.
221  * \param[in] negative false = normal filter behavior (default), true = inverted behavior.
222  */
223  inline void
224  setNegative (bool negative)
225  {
226  negative_ = negative;
227  }
228 
229  /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions.
230  * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior.
231  */
232  inline bool
233  getNegative () const
234  {
235  return (negative_);
236  }
237 
238  /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN),
239  * or removed from the PointCloud, thus potentially breaking its organized structure.
240  * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure.
241  */
242  inline void
243  setKeepOrganized (bool keep_organized)
244  {
245  keep_organized_ = keep_organized;
246  }
247 
248  /** \brief Get whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default = NaN),
249  * or removed from the PointCloud, thus potentially breaking its organized structure.
250  * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure.
251  */
252  inline bool
254  {
255  return (keep_organized_);
256  }
257 
258  /** \brief Provide a value that the filtered points should be set to instead of removing them.
259  * Used in conjunction with \a setKeepOrganized ().
260  * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN).
261  */
262  inline void
263  setUserFilterValue (float value)
264  {
265  user_filter_value_ = value;
266  }
267 
268  protected:
269 
270  /** \brief False = normal filter behavior (default), true = inverted behavior. */
271  bool negative_;
272 
273  /** \brief False = remove points (default), true = redefine points, keep structure. */
275 
276  /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */
278 
279  /** \brief Abstract filter method for point cloud indices. */
280  virtual void
281  applyFilter (std::vector<int> &indices) = 0;
282 
283  /** \brief Abstract filter method for point cloud. */
284  void
285  applyFilter (PCLPointCloud2 &output) override = 0;
286  };
287 }
288 
289 #ifdef PCL_NO_PRECOMPILE
290 #include <pcl/filters/impl/filter_indices.hpp>
291 #endif
pcl
Definition: convolution.h:46
pcl::Filter< PointInT >::Ptr
shared_ptr< Filter< PointInT > > Ptr
Definition: filter.h:86
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:224
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:243
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:233
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:145
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:253
pcl::FilterIndices::applyFilter
virtual void applyFilter(std::vector< int > &indices)=0
Abstract filter method for point cloud indices.
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:53
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:628
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:135
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:116
pcl::FilterIndices::keep_organized_
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
Definition: filter_indices.h:171
pcl::FilterIndices< pcl::PCLPointCloud2 >::keep_organized_
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
Definition: filter_indices.h:274
pcl::Filter< PointInT >::ConstPtr
shared_ptr< const Filter< PointInT > > ConstPtr
Definition: filter.h:87
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:174
pcl::FilterIndices
FilterIndices represents the base class for filters that are about binary point removal.
Definition: filter_indices.h:74
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:83
pcl::FilterIndices::FilterIndices
FilterIndices(bool extract_removed_indices=false)
Constructor.
Definition: filter_indices.h:87
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:15
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:263
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:171
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:277
pcl::FilterIndices< pcl::PCLPointCloud2 >::FilterIndices
FilterIndices(bool extract_removed_indices=false)
Constructor.
Definition: filter_indices.h:204
pcl::FilterIndices::getNegative
bool getNegative() const
Get whether the regular conditions for points filtering should apply, or the inverted conditions.
Definition: filter_indices.h:125
pcl::FilterIndices< pcl::PCLPointCloud2 >::negative_
bool negative_
False = normal filter behavior (default), true = inverted behavior.
Definition: filter_indices.h:271
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:155
pcl::FilterIndices::filter
void filter(std::vector< int > &indices)
Calls the filtering method and returns the filtered point cloud indices.
Definition: filter_indices.h:101
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:138
pcl::FilterIndices::negative_
bool negative_
False = normal filter behavior (default), true = inverted behavior.
Definition: filter_indices.h:168
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:331