Point Cloud Library (PCL) 1.15.1
Loading...
Searching...
No Matches
normal_space.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2012-, Open Perception, 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 the copyright holder(s) 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 */
37
38#pragma once
39
40#include <pcl/filters/filter_indices.h>
41#include <boost/dynamic_bitset.hpp> // for dynamic_bitset
42#include <ctime>
43#include <random> // std::mt19937
44
45namespace pcl
46{
47 /** \brief @b NormalSpaceSampling samples the input point cloud in the space of normal directions computed at every point.
48 * \ingroup filters
49 */
50 template<typename PointT, typename NormalT>
51 class NormalSpaceSampling : public FilterIndices<PointT>
52 {
53 using FilterIndices<PointT>::filter_name_;
54 using FilterIndices<PointT>::getClassName;
55 using FilterIndices<PointT>::indices_;
56 using FilterIndices<PointT>::input_;
61
62 using PointCloud = typename FilterIndices<PointT>::PointCloud;
63 using PointCloudPtr = typename PointCloud::Ptr;
64 using PointCloudConstPtr = typename PointCloud::ConstPtr;
65 using NormalsConstPtr = typename pcl::PointCloud<NormalT>::ConstPtr;
66
67 public:
68
69 using Ptr = shared_ptr<NormalSpaceSampling<PointT, NormalT> >;
70 using ConstPtr = shared_ptr<const NormalSpaceSampling<PointT, NormalT> >;
71
72 /** \brief Empty constructor. */
74
75 /** \brief Constructor.
76 * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed.
77 */
78 explicit NormalSpaceSampling (bool extract_removed_indices)
79 : FilterIndices<PointT> (extract_removed_indices)
80 , sample_ (std::numeric_limits<unsigned int>::max ())
81 , seed_ (static_cast<unsigned int> (time (nullptr)))
82 , binsx_ ()
83 , binsy_ ()
84 , binsz_ ()
86 {
87 filter_name_ = "NormalSpaceSampling";
88 }
89
90 /** \brief Set number of indices to be sampled.
91 * \param[in] sample the number of sample indices
92 */
93 inline void
94 setSample (unsigned int sample)
95 { sample_ = sample; }
96
97 /** \brief Get the value of the internal \a sample parameter. */
98 inline unsigned int
99 getSample () const
100 { return (sample_); }
101
102 /** \brief Set seed of random function.
103 * \param[in] seed the input seed
104 */
105 inline void
106 setSeed (unsigned int seed)
107 { seed_ = seed; }
108
109 /** \brief Get the value of the internal \a seed parameter. */
110 inline unsigned int
111 getSeed () const
112 { return (seed_); }
113
114 /** \brief Set the number of bins in x, y and z direction
115 * \param[in] binsx number of bins in x direction
116 * \param[in] binsy number of bins in y direction
117 * \param[in] binsz number of bins in z direction
118 */
119 inline void
120 setBins (unsigned int binsx, unsigned int binsy, unsigned int binsz)
121 {
122 binsx_ = binsx;
123 binsy_ = binsy;
124 binsz_ = binsz;
125 }
126
127 /** \brief Get the number of bins in x, y and z direction
128 * \param[out] binsx number of bins in x direction
129 * \param[out] binsy number of bins in y direction
130 * \param[out] binsz number of bins in z direction
131 */
132 inline void
133 getBins (unsigned int& binsx, unsigned int& binsy, unsigned int& binsz) const
134 {
135 binsx = binsx_;
136 binsy = binsy_;
137 binsz = binsz_;
138 }
139
140 /** \brief Set the normals computed on the input point cloud
141 * \param[in] normals the normals computed for the input cloud
142 */
143 inline void
144 setNormals (const NormalsConstPtr &normals) { input_normals_ = normals; }
145
146 /** \brief Get the normals computed on the input point cloud */
147 inline NormalsConstPtr
148 getNormals () const { return (input_normals_); }
149
150 protected:
151 /** \brief Number of indices that will be returned. */
152 unsigned int sample_;
153 /** \brief Random number seed. */
154 unsigned int seed_;
155
156 /** \brief Number of bins in x direction. */
157 unsigned int binsx_;
158 /** \brief Number of bins in y direction. */
159 unsigned int binsy_;
160 /** \brief Number of bins in z direction. */
161 unsigned int binsz_;
162
163 /** \brief The normals computed at each point in the input cloud */
164 NormalsConstPtr input_normals_;
165
166 /** \brief Sample of point indices
167 * \param[out] indices the resultant point cloud indices
168 */
169 void
170 applyFilter (Indices &indices) override;
171
172 bool
173 initCompute ();
174
175 private:
176 /** \brief Finds the bin number of the input normal, returns the bin number
177 * \param[in] normal the input normal
178 */
179 unsigned int
180 findBin (const float *normal);
181
182 /** \brief Checks of the entire bin is sampled, returns true or false
183 * \param[out] array flag which says whether a point is sampled or not
184 * \param[in] start_index the index to the first point of the bin in array.
185 * \param[in] length number of points in the bin
186 */
187 bool
188 isEntireBinSampled (boost::dynamic_bitset<> &array, unsigned int start_index, unsigned int length);
189
190 /** \brief Random engine */
191 std::mt19937 rng_;
192 };
193}
194
195#ifdef PCL_NO_PRECOMPILE
196#include <pcl/filters/impl/normal_space.hpp>
197#endif
bool extract_removed_indices_
Set to true if we want to return the indices of the removed points.
Definition filter.h:161
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition filter.h:174
std::string filter_name_
The filter name.
Definition filter.h:158
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition filter.h:155
float user_filter_value_
The user given value that the filtered point dimensions should be set to (default = NaN).
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
FilterIndices(bool extract_removed_indices=false)
Constructor.
pcl::PointCloud< PointT > PointCloud
unsigned int getSeed() const
Get the value of the internal seed parameter.
NormalsConstPtr getNormals() const
Get the normals computed on the input point cloud.
unsigned int binsy_
Number of bins in y direction.
void setSeed(unsigned int seed)
Set seed of random function.
NormalsConstPtr input_normals_
The normals computed at each point in the input cloud.
void setBins(unsigned int binsx, unsigned int binsy, unsigned int binsz)
Set the number of bins in x, y and z direction.
NormalSpaceSampling()
Empty constructor.
unsigned int seed_
Random number seed.
unsigned int getSample() const
Get the value of the internal sample parameter.
void applyFilter(Indices &indices) override
Sample of point indices.
unsigned int binsz_
Number of bins in z direction.
void setNormals(const NormalsConstPtr &normals)
Set the normals computed on the input point cloud.
NormalSpaceSampling(bool extract_removed_indices)
Constructor.
void setSample(unsigned int sample)
Set number of indices to be sampled.
unsigned int sample_
Number of indices that will be returned.
shared_ptr< const NormalSpaceSampling< PointT, NormalT > > ConstPtr
void getBins(unsigned int &binsx, unsigned int &binsy, unsigned int &binsz) const
Get the number of bins in x, y and z direction.
unsigned int binsx_
Number of bins in x direction.
shared_ptr< NormalSpaceSampling< PointT, NormalT > > Ptr
PointCloudConstPtr input_
The input point cloud dataset.
Definition pcl_base.h:147
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:150
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133