Point Cloud Library (PCL)  1.11.1-dev
filter.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, 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$
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/pcl_base.h>
43 #include <pcl/common/io.h> // for copyPointCloud
44 #include <pcl/PointIndices.h>
45 
46 namespace pcl
47 {
48  /** \brief Removes points with x, y, or z equal to NaN
49  * \param[in] cloud_in the input point cloud
50  * \param[out] cloud_out the output point cloud
51  * \param[out] index the mapping (ordered): cloud_out[i] = cloud_in[index[i]]
52  * \note The density of the point cloud is lost.
53  * \note Can be called with cloud_in == cloud_out
54  * \ingroup filters
55  */
56  template<typename PointT> void
58  pcl::PointCloud<PointT> &cloud_out,
59  Indices &index);
60 
61  /** \brief Removes points that have their normals invalid (i.e., equal to NaN)
62  * \param[in] cloud_in the input point cloud
63  * \param[out] cloud_out the output point cloud
64  * \param[out] index the mapping (ordered): cloud_out[i] = cloud_in[index[i]]
65  * \note The density of the point cloud is lost.
66  * \note Can be called with cloud_in == cloud_out
67  * \ingroup filters
68  */
69  template<typename PointT> void
71  pcl::PointCloud<PointT> &cloud_out,
72  Indices &index);
73 
74  ////////////////////////////////////////////////////////////////////////////////////////////
75  /** \brief Filter represents the base filter class. All filters must inherit from this interface.
76  * \author Radu B. Rusu
77  * \ingroup filters
78  */
79  template<typename PointT>
80  class Filter : public PCLBase<PointT>
81  {
82  public:
83  using Ptr = shared_ptr<Filter<PointT> >;
84  using ConstPtr = shared_ptr<const Filter<PointT> >;
85 
86 
88  using PointCloudPtr = typename PointCloud::Ptr;
90 
91  /** \brief Empty constructor.
92  * \param[in] extract_removed_indices set to true if the filtered data indices should be saved in a
93  * separate list. Default: false.
94  */
95  Filter (bool extract_removed_indices = false) :
97  extract_removed_indices_ (extract_removed_indices)
98  {
99  }
100 
101  /** \brief Get the point indices being removed */
102  inline IndicesConstPtr const
104  {
105  return (removed_indices_);
106  }
107 
108  /** \brief Get the point indices being removed
109  * \param[out] pi the resultant point indices that have been removed
110  */
111  inline void
113  {
115  }
116 
117  /** \brief Calls the filtering method and returns the filtered dataset in output.
118  * \param[out] output the resultant filtered point cloud dataset
119  */
120  inline void
121  filter (PointCloud &output)
122  {
123  if (!initCompute ())
124  return;
125 
126  if (input_.get () == &output) // cloud_in = cloud_out
127  {
128  PointCloud output_temp;
129  applyFilter (output_temp);
130  output_temp.header = input_->header;
131  output_temp.sensor_origin_ = input_->sensor_origin_;
132  output_temp.sensor_orientation_ = input_->sensor_orientation_;
133  pcl::copyPointCloud (output_temp, output);
134  }
135  else
136  {
137  output.header = input_->header;
138  output.sensor_origin_ = input_->sensor_origin_;
139  output.sensor_orientation_ = input_->sensor_orientation_;
140  applyFilter (output);
141  }
142 
143  deinitCompute ();
144  }
145 
146  protected:
147 
150 
153 
154  /** \brief Indices of the points that are removed */
156 
157  /** \brief The filter name. */
158  std::string filter_name_;
159 
160  /** \brief Set to true if we want to return the indices of the removed points. */
162 
163  /** \brief Abstract filter method.
164  *
165  * The implementation needs to set output.{points, width, height, is_dense}.
166  *
167  * \param[out] output the resultant filtered point cloud
168  */
169  virtual void
170  applyFilter (PointCloud &output) = 0;
171 
172  /** \brief Get a string representation of the name of this class. */
173  inline const std::string&
174  getClassName () const
175  {
176  return (filter_name_);
177  }
178  };
179 
180  ////////////////////////////////////////////////////////////////////////////////////////////
181  /** \brief Filter represents the base filter class. All filters must inherit from this interface.
182  * \author Radu B. Rusu
183  * \ingroup filters
184  */
185  template<>
186  class PCL_EXPORTS Filter<pcl::PCLPointCloud2> : public PCLBase<pcl::PCLPointCloud2>
187  {
188  public:
189  using Ptr = shared_ptr<Filter<pcl::PCLPointCloud2> >;
190  using ConstPtr = shared_ptr<const Filter<pcl::PCLPointCloud2> >;
191 
195 
196  /** \brief Empty constructor.
197  * \param[in] extract_removed_indices set to true if the filtered data indices should be saved in a
198  * separate list. Default: false.
199  */
200  Filter (bool extract_removed_indices = false) :
201  removed_indices_ (new Indices),
202  extract_removed_indices_ (extract_removed_indices)
203  {
204  }
205 
206  /** \brief Get the point indices being removed */
207  inline IndicesConstPtr const
209  {
210  return (removed_indices_);
211  }
212 
213  /** \brief Get the point indices being removed
214  * \param[out] pi the resultant point indices that have been removed
215  */
216  inline void
218  {
219  pi.indices = *removed_indices_;
220  }
221 
222  /** \brief Calls the filtering method and returns the filtered dataset in output.
223  * \param[out] output the resultant filtered point cloud dataset
224  */
225  void
226  filter (PCLPointCloud2 &output);
227 
228  protected:
229 
230  /** \brief Indices of the points that are removed */
232 
233  /** \brief Set to true if we want to return the indices of the removed points. */
235 
236  /** \brief The filter name. */
237  std::string filter_name_;
238 
239  /** \brief Abstract filter method.
240  *
241  * The implementation needs to set output.{data, row_step, point_step, width, height, is_dense}.
242  *
243  * \param[out] output the resultant filtered point cloud
244  */
245  virtual void
246  applyFilter (PCLPointCloud2 &output) = 0;
247 
248  /** \brief Get a string representation of the name of this class. */
249  inline const std::string&
250  getClassName () const
251  {
252  return (filter_name_);
253  }
254  };
255 }
256 
257 #ifdef PCL_NO_PRECOMPILE
258 #include <pcl/filters/impl/filter.hpp>
259 #endif
pcl
Definition: convolution.h:46
pcl::Filter< pcl::PCLPointCloud2 >::removed_indices_
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition: filter.h:231
pcl::IndicesPtr
shared_ptr< Indices > IndicesPtr
Definition: pcl_base.h:58
pcl::Filter< pcl::PointXYZRGBL >::Ptr
shared_ptr< Filter< pcl::PointXYZRGBL > > Ptr
Definition: filter.h:83
pcl::PCLBase< pcl::PointXYZRGBL >::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:147
pcl::PCLBase< pcl::PointXYZRGBL >::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
pcl::removeNaNNormalsFromPointCloud
void removeNaNNormalsFromPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, Indices &index)
Removes points that have their normals invalid (i.e., equal to NaN)
Definition: filter.hpp:99
pcl::PCLPointCloud2::Ptr
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Definition: PCLPointCloud2.h:35
pcl::Filter::applyFilter
virtual void applyFilter(PointCloud &output)=0
Abstract filter method.
pcl::PointIndices::indices
Indices indices
Definition: PointIndices.h:21
pcl::Filter< pcl::PCLPointCloud2 >::ConstPtr
shared_ptr< const Filter< pcl::PCLPointCloud2 > > ConstPtr
Definition: filter.h:190
pcl::IndicesConstPtr
shared_ptr< const Indices > IndicesConstPtr
Definition: pcl_base.h:59
pcl::Filter::getRemovedIndices
const IndicesConstPtr getRemovedIndices() const
Get the point indices being removed.
Definition: filter.h:103
pcl::Filter< pcl::PCLPointCloud2 >::Filter
Filter(bool extract_removed_indices=false)
Empty constructor.
Definition: filter.h:200
pcl::Filter< pcl::PCLPointCloud2 >::getRemovedIndices
void getRemovedIndices(PointIndices &pi)
Get the point indices being removed.
Definition: filter.h:217
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:69
pcl::Filter::filter
void filter(PointCloud &output)
Calls the filtering method and returns the filtered dataset in output.
Definition: filter.h:121
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2ConstPtr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:186
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::copyPointCloud
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
Definition: io.hpp:122
pcl::Filter::getRemovedIndices
void getRemovedIndices(PointIndices &pi)
Get the point indices being removed.
Definition: filter.h:112
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:185
pcl::Filter::Filter
Filter(bool extract_removed_indices=false)
Empty constructor.
Definition: filter.h:95
pcl::Filter< pcl::PCLPointCloud2 >::Ptr
shared_ptr< Filter< pcl::PCLPointCloud2 > > Ptr
Definition: filter.h:189
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:36
pcl::Filter< pcl::PointXYZRGBL >::ConstPtr
shared_ptr< const Filter< pcl::PointXYZRGBL > > ConstPtr
Definition: filter.h:84
pcl::Filter< pcl::PCLPointCloud2 >::getRemovedIndices
const IndicesConstPtr getRemovedIndices() const
Get the point indices being removed.
Definition: filter.h:208
pcl::Filter::removed_indices_
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition: filter.h:155
pcl::PointCloud::sensor_origin_
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
Definition: point_cloud.h:399
pcl::Filter< pcl::PCLPointCloud2 >::filter_name_
std::string filter_name_
The filter name.
Definition: filter.h:237
pcl::PointCloud::sensor_orientation_
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
Definition: point_cloud.h:401
pcl::Filter
Filter represents the base filter class.
Definition: filter.h:80
pcl::removeNaNFromPointCloud
void removeNaNFromPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, Indices &index)
Removes points with x, y, or z equal to NaN.
Definition: filter.hpp:46
pcl::PointIndices
Definition: PointIndices.h:11
pcl::PointCloud::header
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:385
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:131
pcl::Filter< pcl::PCLPointCloud2 >::extract_removed_indices_
bool extract_removed_indices_
Set to true if we want to return the indices of the removed points.
Definition: filter.h:234
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:16
pcl::Filter::filter_name_
std::string filter_name_
The filter name.
Definition: filter.h:158
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:406
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:171
pcl::Filter::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: filter.h:174
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:407
pcl::Filter< pcl::PCLPointCloud2 >::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: filter.h:250
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:138
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:161
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:323