Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
filters
impl
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/filters/filter_indices.h>
42
43
template
<
typename
Po
int
T>
void
44
pcl::removeNaNFromPointCloud
(
const
pcl::PointCloud<PointT>
&cloud_in,
45
Indices
&index)
46
{
47
// Reserve enough space for the indices
48
index.resize (cloud_in.
size
());
49
50
// If the data is dense, we don't need to check for NaN
51
if
(cloud_in.
is_dense
)
52
{
53
for
(
int
j = 0; j < static_cast<int> (cloud_in.
size
()); ++j)
54
index[j] = j;
55
}
56
else
57
{
58
int
j = 0;
59
for
(
int
i = 0; i < static_cast<int> (cloud_in.
size
()); ++i)
60
{
61
if
(!std::isfinite (cloud_in[i].x) ||
62
!std::isfinite (cloud_in[i].y) ||
63
!std::isfinite (cloud_in[i].z))
64
continue
;
65
index[j] = i;
66
j++;
67
}
68
if
(j !=
static_cast<
int
>
(cloud_in.
size
()))
69
{
70
// Resize to the correct size
71
index.resize (j);
72
}
73
}
74
}
75
76
template
<
typename
Po
int
T>
void
77
pcl::FilterIndices<PointT>::applyFilter
(
PointCloud
&output)
78
{
79
Indices
indices;
80
if
(
keep_organized_
)
81
{
82
if
(!
extract_removed_indices_
)
83
{
84
PCL_WARN (
"[pcl::FilterIndices<PointT>::applyFilter] extract_removed_indices_ was set to 'true' to keep the point cloud organized.\n"
);
85
extract_removed_indices_
=
true
;
86
}
87
applyFilter
(indices);
88
89
output = *
input_
;
90
91
// To preserve legacy behavior, only coordinates xyz are filtered.
92
// Copying a PointXYZ initialized with the user_filter_value_ into a generic
93
// PointT, ensures only the xyz coordinates, if they exist at destination,
94
// are overwritten.
95
const
PointXYZ
ufv (
user_filter_value_
,
user_filter_value_
,
user_filter_value_
);
96
for
(
const
auto
ri : *
removed_indices_
)
// ri = removed index
97
copyPoint
(ufv, output[ri]);
98
if
(!std::isfinite (
user_filter_value_
))
99
output.
is_dense
=
false
;
100
}
101
else
102
{
103
applyFilter
(indices);
104
pcl::copyPointCloud
(*
input_
, indices, output);
105
}
106
}
107
108
109
#define PCL_INSTANTIATE_removeNanFromPointCloud(T) template PCL_EXPORTS void pcl::removeNaNFromPointCloud<T>(const pcl::PointCloud<T>&, Indices&);
110
#define PCL_INSTANTIATE_FilterIndices(T) template class PCL_EXPORTS pcl::FilterIndices<T>;
111
112
#endif
// PCL_FILTERS_IMPL_FILTER_INDICES_H_
113
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::Filter::removed_indices_
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition
filter.h:155
pcl::FilterIndices::user_filter_value_
float user_filter_value_
The user given value that the filtered point dimensions should be set to (default = NaN).
Definition
filter_indices.h:173
pcl::FilterIndices::keep_organized_
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
Definition
filter_indices.h:170
pcl::FilterIndices::applyFilter
virtual void applyFilter(Indices &indices)=0
Abstract filter method for point cloud indices.
pcl::FilterIndices::PointCloud
pcl::PointCloud< PointT > PointCloud
Definition
filter_indices.h:78
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition
pcl_base.h:147
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition
point_cloud.h:174
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:404
pcl::PointCloud::size
std::size_t size() const
Definition
point_cloud.h:444
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::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:142
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::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition
types.h:133
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition
point_types.hpp:322