Point Cloud Library (PCL)  1.11.0-dev
filter_indices.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: filter.hpp 1800 2011-07-15 11:45:31Z marton $
35  *
36  */
37 
38 #ifndef PCL_FILTERS_IMPL_FILTER_INDICES_H_
39 #define PCL_FILTERS_IMPL_FILTER_INDICES_H_
40 
41 #include <pcl/pcl_macros.h>
42 #include <pcl/filters/filter_indices.h>
43 
44 template <typename PointT> void
46  std::vector<int> &index)
47 {
48  // Reserve enough space for the indices
49  index.resize (cloud_in.points.size ());
50 
51  // If the data is dense, we don't need to check for NaN
52  if (cloud_in.is_dense)
53  {
54  for (int j = 0; j < static_cast<int> (cloud_in.points.size ()); ++j)
55  index[j] = j;
56  }
57  else
58  {
59  int j = 0;
60  for (int i = 0; i < static_cast<int> (cloud_in.points.size ()); ++i)
61  {
62  if (!std::isfinite (cloud_in.points[i].x) ||
63  !std::isfinite (cloud_in.points[i].y) ||
64  !std::isfinite (cloud_in.points[i].z))
65  continue;
66  index[j] = i;
67  j++;
68  }
69  if (j != static_cast<int> (cloud_in.points.size ()))
70  {
71  // Resize to the correct size
72  index.resize (j);
73  }
74  }
75 }
76 
77 template<typename PointT> void
79 {
80  std::vector<int> indices;
81  if (keep_organized_)
82  {
83  if (!extract_removed_indices_)
84  {
85  PCL_WARN ("[pcl::FilterIndices<PointT>::applyFilter] extract_removed_indices_ was set to 'true' to keep the point cloud organized.\n");
86  extract_removed_indices_ = true;
87  }
88  applyFilter (indices);
89 
90  output = *input_;
91 
92  // To preserve legacy behavior, only coordinates xyz are filtered.
93  // Copying a PointXYZ initialized with the user_filter_value_ into a generic
94  // PointT, ensures only the xyz coordinates, if they exist at destination,
95  // are overwritten.
96  const PointXYZ ufv (user_filter_value_, user_filter_value_, user_filter_value_);
97  for (const auto ri : *removed_indices_) // ri = removed index
98  copyPoint(ufv, output[ri]);
99  if (!std::isfinite (user_filter_value_))
100  output.is_dense = false;
101  }
102  else
103  {
104  output.is_dense = true;
105  applyFilter (indices);
106  pcl::copyPointCloud (*input_, indices, output);
107  }
108 }
109 
110 
111 #define PCL_INSTANTIATE_removeNanFromPointCloud(T) template PCL_EXPORTS void pcl::removeNaNFromPointCloud<T>(const pcl::PointCloud<T>&, std::vector<int>&);
112 #define PCL_INSTANTIATE_FilterIndices(T) template class PCL_EXPORTS pcl::FilterIndices<T>;
113 
114 #endif // PCL_FILTERS_IMPL_FILTER_INDICES_H_
115 
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl::PointCloud::points
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:411
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::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:121
pcl::copyPoint
void copyPoint(const PointInT &point_in, PointOutT &point_out)
Copy the fields of a source point into a target point.
Definition: copy_point.hpp:137
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition: point_types.hpp:300
pcl::PointCloud::is_dense
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
Definition: point_cloud.h:419
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