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