Point Cloud Library (PCL)
1.12.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
filters
uniform_sampling.h
1
/*
2
* Software License Agreement (BSD License)
3
*
4
* Point Cloud Library (PCL) - www.pointclouds.org
5
* Copyright (c) 2010-2011, Willow Garage, Inc.
6
*
7
* All rights reserved.
8
*
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
11
* are met:
12
*
13
* * Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the following
17
* disclaimer in the documentation and/or other materials provided
18
* with the distribution.
19
* * Neither the name of Willow Garage, Inc. nor the names of its
20
* contributors may be used to endorse or promote products derived
21
* from this software without specific prior written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
* POSSIBILITY OF SUCH DAMAGE.
35
*
36
* $Id$
37
*
38
*/
39
40
#pragma once
41
42
#include <pcl/filters/filter.h>
43
44
#include <unordered_map>
45
46
namespace
pcl
47
{
48
/** \brief @b UniformSampling assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.
49
*
50
* The @b UniformSampling class creates a *3D voxel grid* (think about a voxel
51
* grid as a set of tiny 3D boxes in space) over the input point cloud data.
52
* Then, in each *voxel* (i.e., 3D box), all the points present will be
53
* approximated (i.e., *downsampled*) with the closest point to the center of the voxel.
54
*
55
* \author Radu Bogdan Rusu
56
* \ingroup filters
57
*/
58
template
<
typename
Po
int
T>
59
class
UniformSampling
:
public
Filter
<PointT>
60
{
61
using
PointCloud =
typename
Filter<PointT>::PointCloud
;
62
63
using
Filter
<PointT>
::filter_name_
;
64
using
Filter
<PointT>
::input_
;
65
using
Filter
<PointT>
::indices_
;
66
using
Filter
<PointT>
::removed_indices_
;
67
using
Filter
<PointT>
::extract_removed_indices_
;
68
using
Filter
<PointT>
::getClassName
;
69
70
public
:
71
using
Ptr
= shared_ptr<UniformSampling<PointT> >;
72
using
ConstPtr
= shared_ptr<const UniformSampling<PointT> >;
73
74
/** \brief Empty constructor. */
75
UniformSampling
(
bool
extract_removed_indices =
false
) :
76
Filter
<PointT>(extract_removed_indices),
77
leaves_
(),
78
leaf_size_
(
Eigen
::Vector4f::Zero ()),
79
inverse_leaf_size_
(
Eigen
::Vector4f::Zero ()),
80
min_b_
(
Eigen
::Vector4i::Zero ()),
81
max_b_
(
Eigen
::Vector4i::Zero ()),
82
div_b_
(
Eigen
::Vector4i::Zero ()),
83
divb_mul_
(
Eigen
::Vector4i::Zero ()),
84
search_radius_
(0)
85
{
86
filter_name_
=
"UniformSampling"
;
87
}
88
89
/** \brief Destructor. */
90
~UniformSampling
()
91
{
92
leaves_
.clear();
93
}
94
95
/** \brief Set the 3D grid leaf size.
96
* \param radius the 3D grid leaf size
97
*/
98
virtual
inline
void
99
setRadiusSearch
(
double
radius)
100
{
101
leaf_size_
[0] =
leaf_size_
[1] =
leaf_size_
[2] =
static_cast<
float
>
(radius);
102
// Avoid division errors
103
if
(
leaf_size_
[3] == 0)
104
leaf_size_
[3] = 1;
105
// Use multiplications instead of divisions
106
inverse_leaf_size_
= Eigen::Array4f::Ones () /
leaf_size_
.array ();
107
search_radius_
= radius;
108
}
109
110
protected
:
111
/** \brief Simple structure to hold an nD centroid and the number of points in a leaf. */
112
struct
Leaf
113
{
114
Leaf
() :
idx
(-1) { }
115
int
idx
;
116
};
117
118
/** \brief The 3D grid leaves. */
119
std::unordered_map<std::size_t, Leaf>
leaves_
;
120
121
/** \brief The size of a leaf. */
122
Eigen::Vector4f
leaf_size_
;
123
124
/** \brief Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons. */
125
Eigen::Array4f
inverse_leaf_size_
;
126
127
/** \brief The minimum and maximum bin coordinates, the number of divisions, and the division multiplier. */
128
Eigen::Vector4i
min_b_
,
max_b_
,
div_b_
,
divb_mul_
;
129
130
/** \brief The nearest neighbors search radius for each point. */
131
double
search_radius_
;
132
133
/** \brief Downsample a Point Cloud using a voxelized grid approach
134
* \param[out] output the resultant point cloud message
135
*/
136
void
137
applyFilter
(PointCloud &output)
override
;
138
};
139
}
140
141
#ifdef PCL_NO_PRECOMPILE
142
#include <pcl/filters/impl/uniform_sampling.hpp>
143
#endif
pcl::Filter::PointCloud
pcl::PointCloud< PointT > PointCloud
Definition
filter.h:87
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::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition
filter.h:174
pcl::Filter::filter_name_
std::string filter_name_
The filter name.
Definition
filter.h:158
pcl::Filter::removed_indices_
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition
filter.h:155
pcl::Filter::Filter
Filter(bool extract_removed_indices=false)
Empty constructor.
Definition
filter.h:95
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition
pcl_base.h:147
pcl::PCLBase::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition
pcl_base.h:150
pcl::UniformSampling::min_b_
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier.
Definition
uniform_sampling.h:128
pcl::UniformSampling::ConstPtr
shared_ptr< const UniformSampling< PointT > > ConstPtr
Definition
uniform_sampling.h:72
pcl::UniformSampling::leaf_size_
Eigen::Vector4f leaf_size_
The size of a leaf.
Definition
uniform_sampling.h:122
pcl::UniformSampling::inverse_leaf_size_
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
Definition
uniform_sampling.h:125
pcl::UniformSampling::search_radius_
double search_radius_
The nearest neighbors search radius for each point.
Definition
uniform_sampling.h:131
pcl::UniformSampling::~UniformSampling
~UniformSampling()
Destructor.
Definition
uniform_sampling.h:90
pcl::UniformSampling::leaves_
std::unordered_map< std::size_t, Leaf > leaves_
The 3D grid leaves.
Definition
uniform_sampling.h:119
pcl::UniformSampling::divb_mul_
Eigen::Vector4i divb_mul_
Definition
uniform_sampling.h:128
pcl::UniformSampling::setRadiusSearch
virtual void setRadiusSearch(double radius)
Set the 3D grid leaf size.
Definition
uniform_sampling.h:99
pcl::UniformSampling::UniformSampling
UniformSampling(bool extract_removed_indices=false)
Empty constructor.
Definition
uniform_sampling.h:75
pcl::UniformSampling::applyFilter
void applyFilter(PointCloud &output) override
Downsample a Point Cloud using a voxelized grid approach.
Definition
uniform_sampling.hpp:46
pcl::UniformSampling::div_b_
Eigen::Vector4i div_b_
Definition
uniform_sampling.h:128
pcl::UniformSampling::max_b_
Eigen::Vector4i max_b_
Definition
uniform_sampling.h:128
pcl::UniformSampling::Ptr
shared_ptr< UniformSampling< PointT > > Ptr
Definition
uniform_sampling.h:71
Eigen
Definition
bfgs.h:10
pcl
Definition
convolution.h:46
pcl::UniformSampling::Leaf::Leaf
Leaf()
Definition
uniform_sampling.h:114
pcl::UniformSampling::Leaf::idx
int idx
Definition
uniform_sampling.h:115