Point Cloud Library (PCL)  1.9.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/boost.h>
41 #include <pcl/filters/filter_indices.h>
42 #include <ctime>
43 #include <climits>
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  typedef typename PointCloud::Ptr PointCloudPtr;
65  typedef typename pcl::PointCloud<NormalT>::ConstPtr NormalsConstPtr;
66 
67  public:
68 
69  typedef boost::shared_ptr<NormalSpaceSampling<PointT, NormalT> > Ptr;
70  typedef boost::shared_ptr<const NormalSpaceSampling<PointT, NormalT> > ConstPtr;
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  , rng_uniform_distribution_ (nullptr)
81  {
82  filter_name_ = "NormalSpaceSampling";
83  }
84 
85  /** \brief Destructor. */
87  {
88  delete rng_uniform_distribution_;
89  }
90 
91  /** \brief Set number of indices to be sampled.
92  * \param[in] sample the number of sample indices
93  */
94  inline void
95  setSample (unsigned int sample)
96  { sample_ = sample; }
97 
98  /** \brief Get the value of the internal \a sample parameter. */
99  inline unsigned int
100  getSample () const
101  { return (sample_); }
102 
103  /** \brief Set seed of random function.
104  * \param[in] seed the input seed
105  */
106  inline void
107  setSeed (unsigned int seed)
108  { seed_ = seed; }
109 
110  /** \brief Get the value of the internal \a seed parameter. */
111  inline unsigned int
112  getSeed () const
113  { return (seed_); }
114 
115  /** \brief Set the number of bins in x, y and z direction
116  * \param[in] binsx number of bins in x direction
117  * \param[in] binsy number of bins in y direction
118  * \param[in] binsz number of bins in z direction
119  */
120  inline void
121  setBins (unsigned int binsx, unsigned int binsy, unsigned int binsz)
122  {
123  binsx_ = binsx;
124  binsy_ = binsy;
125  binsz_ = binsz;
126  }
127 
128  /** \brief Get the number of bins in x, y and z direction
129  * \param[out] binsx number of bins in x direction
130  * \param[out] binsy number of bins in y direction
131  * \param[out] binsz number of bins in z direction
132  */
133  inline void
134  getBins (unsigned int& binsx, unsigned int& binsy, unsigned int& binsz) const
135  {
136  binsx = binsx_;
137  binsy = binsy_;
138  binsz = binsz_;
139  }
140 
141  /** \brief Set the normals computed on the input point cloud
142  * \param[in] normals the normals computed for the input cloud
143  */
144  inline void
145  setNormals (const NormalsConstPtr &normals) { input_normals_ = normals; }
146 
147  /** \brief Get the normals computed on the input point cloud */
148  inline NormalsConstPtr
149  getNormals () const { return (input_normals_); }
150 
151  protected:
152  /** \brief Number of indices that will be returned. */
153  unsigned int sample_;
154  /** \brief Random number seed. */
155  unsigned int seed_;
156 
157  /** \brief Number of bins in x direction. */
158  unsigned int binsx_;
159  /** \brief Number of bins in y direction. */
160  unsigned int binsy_;
161  /** \brief Number of bins in z direction. */
162  unsigned int binsz_;
163 
164  /** \brief The normals computed at each point in the input cloud */
165  NormalsConstPtr input_normals_;
166 
167  /** \brief Sample of point indices into a separate PointCloud
168  * \param[out] output the resultant point cloud
169  */
170  void
171  applyFilter (PointCloud &output) override;
172 
173  /** \brief Sample of point indices
174  * \param[out] indices the resultant point cloud indices
175  */
176  void
177  applyFilter (std::vector<int> &indices) override;
178 
179  bool
180  initCompute ();
181 
182  private:
183  /** \brief Finds the bin number of the input normal, returns the bin number
184  * \param[in] normal the input normal
185  * \param[in] nbins total number of bins
186  */
187  unsigned int
188  findBin (const float *normal, unsigned int nbins);
189 
190  /** \brief Checks of the entire bin is sampled, returns true or false
191  * \param[out] array flag which says whether a point is sampled or not
192  * \param[in] start_index the index to the first point of the bin in array.
193  * \param[in] length number of points in the bin
194  */
195  bool
196  isEntireBinSampled (boost::dynamic_bitset<> &array, unsigned int start_index, unsigned int length);
197 
198  /** \brief Uniform random distribution. */
199  boost::variate_generator<boost::mt19937, boost::uniform_int<uint32_t> > *rng_uniform_distribution_;
200  };
201 }
202 
203 #ifdef PCL_NO_PRECOMPILE
204 #include <pcl/filters/impl/normal_space.hpp>
205 #endif
NormalsConstPtr getNormals() const
Get the normals computed on the input point cloud.
Definition: normal_space.h:149
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:121
unsigned int binsx_
Number of bins in x direction.
Definition: normal_space.h:158
PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:73
boost::shared_ptr< NormalSpaceSampling< PointT, NormalT > > Ptr
Definition: normal_space.h:69
unsigned int binsy_
Number of bins in y direction.
Definition: normal_space.h:160
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
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:134
unsigned int binsz_
Number of bins in z direction.
Definition: normal_space.h:162
unsigned int seed_
Random number seed.
Definition: normal_space.h:155
NormalSpaceSampling samples the input point cloud in the space of normal directions computed at every...
Definition: normal_space.h:51
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:427
FilterIndices represents the base class for filters that are about binary point removal.
unsigned int sample_
Number of indices that will be returned.
Definition: normal_space.h:153
PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:72
unsigned int getSample() const
Get the value of the internal sample parameter.
Definition: normal_space.h:100
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:428
PointCloud represents the base class in PCL for storing collections of 3D points. ...
~NormalSpaceSampling()
Destructor.
Definition: normal_space.h:86
NormalsConstPtr input_normals_
The normals computed at each point in the input cloud.
Definition: normal_space.h:165
void applyFilter(PointCloud &output) override
Sample of point indices into a separate PointCloud.
void setSeed(unsigned int seed)
Set seed of random function.
Definition: normal_space.h:107
void setSample(unsigned int sample)
Set number of indices to be sampled.
Definition: normal_space.h:95
std::string filter_name_
The filter name.
Definition: filter.h:164
NormalSpaceSampling()
Empty constructor.
Definition: normal_space.h:73
void setNormals(const NormalsConstPtr &normals)
Set the normals computed on the input point cloud.
Definition: normal_space.h:145
unsigned int getSeed() const
Get the value of the internal seed parameter.
Definition: normal_space.h:112
boost::shared_ptr< const NormalSpaceSampling< PointT, NormalT > > ConstPtr
Definition: normal_space.h:70