Point Cloud Library (PCL)  1.8.1-dev
filter.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder(s) nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id$
35  *
36  */
37 
38 #ifndef PCL_FILTERS_IMPL_FILTER_H_
39 #define PCL_FILTERS_IMPL_FILTER_H_
40 
41 #include <pcl/pcl_macros.h>
42 #include <pcl/filters/filter.h>
43 
44 //////////////////////////////////////////////////////////////////////////
45 template <typename PointT> void
47  pcl::PointCloud<PointT> &cloud_out,
48  std::vector<int> &index)
49 {
50  // If the clouds are not the same, prepare the output
51  if (&cloud_in != &cloud_out)
52  {
53  cloud_out.header = cloud_in.header;
54  cloud_out.points.resize (cloud_in.points.size ());
55  }
56  // Reserve enough space for the indices
57  index.resize (cloud_in.points.size ());
58  size_t j = 0;
59 
60  // If the data is dense, we don't need to check for NaN
61  if (cloud_in.is_dense)
62  {
63  // Simply copy the data
64  cloud_out = cloud_in;
65  for (j = 0; j < cloud_out.points.size (); ++j)
66  index[j] = static_cast<int>(j);
67  }
68  else
69  {
70  for (size_t i = 0; i < cloud_in.points.size (); ++i)
71  {
72  if (!pcl_isfinite (cloud_in.points[i].x) ||
73  !pcl_isfinite (cloud_in.points[i].y) ||
74  !pcl_isfinite (cloud_in.points[i].z))
75  continue;
76  cloud_out.points[j] = cloud_in.points[i];
77  index[j] = static_cast<int>(i);
78  j++;
79  }
80  if (j != cloud_in.points.size ())
81  {
82  // Resize to the correct size
83  cloud_out.points.resize (j);
84  index.resize (j);
85  }
86 
87  cloud_out.height = 1;
88  cloud_out.width = static_cast<uint32_t>(j);
89 
90  // Removing bad points => dense (note: 'dense' doesn't mean 'organized')
91  cloud_out.is_dense = true;
92  }
93 }
94 
95 //////////////////////////////////////////////////////////////////////////
96 template <typename PointT> void
98  pcl::PointCloud<PointT> &cloud_out,
99  std::vector<int> &index)
100 {
101  // If the clouds are not the same, prepare the output
102  if (&cloud_in != &cloud_out)
103  {
104  cloud_out.header = cloud_in.header;
105  cloud_out.points.resize (cloud_in.points.size ());
106  }
107  // Reserve enough space for the indices
108  index.resize (cloud_in.points.size ());
109  size_t j = 0;
110 
111  for (size_t i = 0; i < cloud_in.points.size (); ++i)
112  {
113  if (!pcl_isfinite (cloud_in.points[i].normal_x) ||
114  !pcl_isfinite (cloud_in.points[i].normal_y) ||
115  !pcl_isfinite (cloud_in.points[i].normal_z))
116  continue;
117  cloud_out.points[j] = cloud_in.points[i];
118  index[j] = static_cast<int>(i);
119  j++;
120  }
121  if (j != cloud_in.points.size ())
122  {
123  // Resize to the correct size
124  cloud_out.points.resize (j);
125  index.resize (j);
126  }
127 
128  cloud_out.height = 1;
129  cloud_out.width = static_cast<uint32_t>(j);
130 }
131 
132 
133 #define PCL_INSTANTIATE_removeNaNFromPointCloud(T) template PCL_EXPORTS void pcl::removeNaNFromPointCloud<T>(const pcl::PointCloud<T>&, pcl::PointCloud<T>&, std::vector<int>&);
134 #define PCL_INSTANTIATE_removeNaNNormalsFromPointCloud(T) template PCL_EXPORTS void pcl::removeNaNNormalsFromPointCloud<T>(const pcl::PointCloud<T>&, pcl::PointCloud<T>&, std::vector<int>&);
135 
136 #endif // PCL_FILTERS_IMPL_FILTER_H_
137 
void removeNaNNormalsFromPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, std::vector< int > &index)
Removes points that have their normals invalid (i.e., equal to NaN)
Definition: filter.hpp:97
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
uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:413
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:407
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:410
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values).
Definition: point_cloud.h:418
uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:415