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