Point Cloud Library (PCL)  1.11.1-dev
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 
45 namespace 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  {
61 
63  using PointCloudPtr = typename PointCloud::Ptr;
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  : sample_ (std::numeric_limits<unsigned int>::max ())
75  , seed_ (static_cast<unsigned int> (time (nullptr)))
76  , binsx_ ()
77  , binsy_ ()
78  , binsz_ ()
79  , input_normals_ ()
80  {
81  filter_name_ = "NormalSpaceSampling";
82  }
83 
84  /** \brief Set number of indices to be sampled.
85  * \param[in] sample the number of sample indices
86  */
87  inline void
88  setSample (unsigned int sample)
89  { sample_ = sample; }
90 
91  /** \brief Get the value of the internal \a sample parameter. */
92  inline unsigned int
93  getSample () const
94  { return (sample_); }
95 
96  /** \brief Set seed of random function.
97  * \param[in] seed the input seed
98  */
99  inline void
100  setSeed (unsigned int seed)
101  { seed_ = seed; }
102 
103  /** \brief Get the value of the internal \a seed parameter. */
104  inline unsigned int
105  getSeed () const
106  { return (seed_); }
107 
108  /** \brief Set the number of bins in x, y and z direction
109  * \param[in] binsx number of bins in x direction
110  * \param[in] binsy number of bins in y direction
111  * \param[in] binsz number of bins in z direction
112  */
113  inline void
114  setBins (unsigned int binsx, unsigned int binsy, unsigned int binsz)
115  {
116  binsx_ = binsx;
117  binsy_ = binsy;
118  binsz_ = binsz;
119  }
120 
121  /** \brief Get the number of bins in x, y and z direction
122  * \param[out] binsx number of bins in x direction
123  * \param[out] binsy number of bins in y direction
124  * \param[out] binsz number of bins in z direction
125  */
126  inline void
127  getBins (unsigned int& binsx, unsigned int& binsy, unsigned int& binsz) const
128  {
129  binsx = binsx_;
130  binsy = binsy_;
131  binsz = binsz_;
132  }
133 
134  /** \brief Set the normals computed on the input point cloud
135  * \param[in] normals the normals computed for the input cloud
136  */
137  inline void
138  setNormals (const NormalsConstPtr &normals) { input_normals_ = normals; }
139 
140  /** \brief Get the normals computed on the input point cloud */
141  inline NormalsConstPtr
142  getNormals () const { return (input_normals_); }
143 
144  protected:
145  /** \brief Number of indices that will be returned. */
146  unsigned int sample_;
147  /** \brief Random number seed. */
148  unsigned int seed_;
149 
150  /** \brief Number of bins in x direction. */
151  unsigned int binsx_;
152  /** \brief Number of bins in y direction. */
153  unsigned int binsy_;
154  /** \brief Number of bins in z direction. */
155  unsigned int binsz_;
156 
157  /** \brief The normals computed at each point in the input cloud */
158  NormalsConstPtr input_normals_;
159 
160  /** \brief Sample of point indices
161  * \param[out] indices the resultant point cloud indices
162  */
163  void
164  applyFilter (std::vector<int> &indices) override;
165 
166  bool
167  initCompute ();
168 
169  private:
170  /** \brief Finds the bin number of the input normal, returns the bin number
171  * \param[in] normal the input normal
172  */
173  unsigned int
174  findBin (const float *normal);
175 
176  /** \brief Checks of the entire bin is sampled, returns true or false
177  * \param[out] array flag which says whether a point is sampled or not
178  * \param[in] start_index the index to the first point of the bin in array.
179  * \param[in] length number of points in the bin
180  */
181  bool
182  isEntireBinSampled (boost::dynamic_bitset<> &array, unsigned int start_index, unsigned int length);
183 
184  /** \brief Random engine */
185  std::mt19937 rng_;
186  };
187 }
188 
189 #ifdef PCL_NO_PRECOMPILE
190 #include <pcl/filters/impl/normal_space.hpp>
191 #endif
pcl::NormalSpaceSampling::getNormals
NormalsConstPtr getNormals() const
Get the normals computed on the input point cloud.
Definition: normal_space.h:142
pcl::NormalSpaceSampling::initCompute
bool initCompute()
Definition: normal_space.hpp:48
pcl
Definition: convolution.h:46
pcl::NormalSpaceSampling::getBins
void getBins(unsigned int &binsx, unsigned int &binsy, unsigned int &binsz) const
Get the number of bins in x, y and z direction.
Definition: normal_space.h:127
pcl::Filter::Ptr
shared_ptr< Filter< PointT > > Ptr
Definition: filter.h:83
pcl::NormalSpaceSampling::setBins
void setBins(unsigned int binsx, unsigned int binsy, unsigned int binsz)
Set the number of bins in x, y and z direction.
Definition: normal_space.h:114
pcl::PCLBase::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
pcl::NormalSpaceSampling::setNormals
void setNormals(const NormalsConstPtr &normals)
Set the normals computed on the input point cloud.
Definition: normal_space.h:138
pcl::PCLBase::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
pcl::NormalSpaceSampling::binsx_
unsigned int binsx_
Number of bins in x direction.
Definition: normal_space.h:151
pcl::NormalSpaceSampling::binsy_
unsigned int binsy_
Number of bins in y direction.
Definition: normal_space.h:153
pcl::NormalSpaceSampling::binsz_
unsigned int binsz_
Number of bins in z direction.
Definition: normal_space.h:155
pcl::NormalSpaceSampling::seed_
unsigned int seed_
Random number seed.
Definition: normal_space.h:148
pcl::NormalSpaceSampling::sample_
unsigned int sample_
Number of indices that will be returned.
Definition: normal_space.h:146
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::NormalSpaceSampling::getSeed
unsigned int getSeed() const
Get the value of the internal seed parameter.
Definition: normal_space.h:105
pcl::NormalSpaceSampling
NormalSpaceSampling samples the input point cloud in the space of normal directions computed at every...
Definition: normal_space.h:51
pcl::NormalSpaceSampling::applyFilter
void applyFilter(std::vector< int > &indices) override
Sample of point indices.
Definition: normal_space.hpp:91
pcl::Filter::ConstPtr
shared_ptr< const Filter< PointT > > ConstPtr
Definition: filter.h:84
pcl::NormalSpaceSampling::input_normals_
NormalsConstPtr input_normals_
The normals computed at each point in the input cloud.
Definition: normal_space.h:158
pcl::FilterIndices
FilterIndices represents the base class for filters that are about binary point removal.
Definition: filter_indices.h:74
pcl::NormalSpaceSampling::NormalSpaceSampling
NormalSpaceSampling()
Empty constructor.
Definition: normal_space.h:73
pcl::Filter::filter_name_
std::string filter_name_
The filter name.
Definition: filter.h:158
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::NormalSpaceSampling::getSample
unsigned int getSample() const
Get the value of the internal sample parameter.
Definition: normal_space.h:93
pcl::NormalSpaceSampling::setSeed
void setSeed(unsigned int seed)
Set seed of random function.
Definition: normal_space.h:100
pcl::NormalSpaceSampling::setSample
void setSample(unsigned int sample)
Set number of indices to be sampled.
Definition: normal_space.h:88