Point Cloud Library (PCL) 1.12.1
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#pragma once
39
40#include <pcl/pcl_exports.h> // for PCL_EXPORTS
41#include <pcl/common/point_tests.h> // for pcl::isFinite
42#include <pcl/filters/filter.h>
43
44//////////////////////////////////////////////////////////////////////////
45template <typename PointT> void
47 pcl::PointCloud<PointT> &cloud_out,
48 Indices &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.resize (cloud_in.size ());
55 cloud_out.sensor_origin_ = cloud_in.sensor_origin_;
56 cloud_out.sensor_orientation_ = cloud_in.sensor_orientation_;
57 }
58 // Reserve enough space for the indices
59 index.resize (cloud_in.size ());
60
61 // If the data is dense, we don't need to check for NaN
62 if (cloud_in.is_dense)
63 {
64 // Simply copy the data
65 cloud_out = cloud_in;
66 for (std::size_t j = 0; j < cloud_out.size (); ++j)
67 index[j] = j;
68 }
69 else
70 {
71 std::size_t j = 0;
72 for (std::size_t i = 0; i < cloud_in.size (); ++i)
73 {
74 if (!std::isfinite (cloud_in[i].x) ||
75 !std::isfinite (cloud_in[i].y) ||
76 !std::isfinite (cloud_in[i].z))
77 continue;
78 cloud_out[j] = cloud_in[i];
79 index[j] = i;
80 j++;
81 }
82 if (j != cloud_in.size ())
83 {
84 // Resize to the correct size
85 cloud_out.resize (j);
86 index.resize (j);
87 }
88
89 cloud_out.height = 1;
90 cloud_out.width = static_cast<std::uint32_t>(j);
91
92 // Removing bad points => dense (note: 'dense' doesn't mean 'organized')
93 cloud_out.is_dense = true;
94 }
95}
96
97//////////////////////////////////////////////////////////////////////////
98template <typename PointT> void
100 pcl::PointCloud<PointT> &cloud_out,
101 Indices &index)
102{
103 // If the clouds are not the same, prepare the output
104 if (&cloud_in != &cloud_out)
105 {
106 cloud_out.header = cloud_in.header;
107 cloud_out.resize (cloud_in.size ());
108 cloud_out.sensor_origin_ = cloud_in.sensor_origin_;
109 cloud_out.sensor_orientation_ = cloud_in.sensor_orientation_;
110 }
111 // Reserve enough space for the indices
112 index.resize (cloud_in.size ());
113 std::size_t j = 0;
114
115 // Assume cloud is dense
116 cloud_out.is_dense = true;
117
118 for (std::size_t i = 0; i < cloud_in.size (); ++i)
119 {
120 if (!std::isfinite (cloud_in[i].normal_x) ||
121 !std::isfinite (cloud_in[i].normal_y) ||
122 !std::isfinite (cloud_in[i].normal_z))
123 continue;
124 if (cloud_out.is_dense && !pcl::isFinite(cloud_in[i]))
125 cloud_out.is_dense = false;
126 cloud_out[j] = cloud_in[i];
127 index[j] = i;
128 j++;
129 }
130 if (j != cloud_in.size ())
131 {
132 // Resize to the correct size
133 cloud_out.resize (j);
134 index.resize (j);
135 }
136
137 cloud_out.height = 1;
138 cloud_out.width = j;
139}
140
141
142#define PCL_INSTANTIATE_removeNaNFromPointCloud(T) template PCL_EXPORTS void pcl::removeNaNFromPointCloud<T>(const pcl::PointCloud<T>&, pcl::PointCloud<T>&, Indices&);
143#define PCL_INSTANTIATE_removeNaNNormalsFromPointCloud(T) template PCL_EXPORTS void pcl::removeNaNNormalsFromPointCloud<T>(const pcl::PointCloud<T>&, pcl::PointCloud<T>&, Indices&);
144
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
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:403
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition: point_cloud.h:462
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
Definition: point_cloud.h:408
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:398
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:392
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:400
std::size_t size() const
Definition: point_cloud.h:443
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
Definition: point_cloud.h:406
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
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
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
Definition: point_tests.h:55
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133