Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filter.hpp
Go to the documentation of this file.
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 Willow Garage, Inc. 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: filter.hpp 5806 2012-05-30 00:20:35Z rusu $
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 
44 template <typename PointT> void
46  std::vector<int> &index)
47 {
48  // If the clouds are not the same, prepare the output
49  if (&cloud_in != &cloud_out)
50  {
51  cloud_out.header = cloud_in.header;
52  cloud_out.points.resize (cloud_in.points.size ());
53  }
54  // Reserve enough space for the indices
55  index.resize (cloud_in.points.size ());
56  size_t j = 0;
57 
58  // If the data is dense, we don't need to check for NaN
59  if (cloud_in.is_dense)
60  {
61  // Simply copy the data
62  cloud_out = cloud_in;
63  for (j = 0; j < cloud_out.points.size (); ++j)
64  index[j] = static_cast<int>(j);
65  }
66  else
67  {
68  for (size_t i = 0; i < cloud_in.points.size (); ++i)
69  {
70  if (!pcl_isfinite (cloud_in.points[i].x) ||
71  !pcl_isfinite (cloud_in.points[i].y) ||
72  !pcl_isfinite (cloud_in.points[i].z))
73  continue;
74  cloud_out.points[j] = cloud_in.points[i];
75  index[j] = static_cast<int>(i);
76  j++;
77  }
78  if (j != cloud_in.points.size ())
79  {
80  // Resize to the correct size
81  cloud_out.points.resize (j);
82  index.resize (j);
83  cloud_out.height = 1;
84  cloud_out.width = static_cast<uint32_t>(j);
85  }
86  // Removing bad points => dense (note: 'dense' doesn't mean 'organized')
87  cloud_out.is_dense = true;
88  }
89 }
90 
91 #define PCL_INSTANTIATE_removeNanFromPointCloud(T) template PCL_EXPORTS void pcl::removeNaNFromPointCloud<T>(const pcl::PointCloud<T>&, pcl::PointCloud<T>&, std::vector<int>&);
92 
93 #endif // PCL_FILTERS_IMPL_FILTER_H_
94