Point Cloud Library (PCL)  1.14.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 
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_ ()
85  , input_normals_ ()
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
shared_ptr< Filter< PointT > > Ptr
Definition: filter.h:83
shared_ptr< const Filter< PointT > > ConstPtr
Definition: filter.h:84
std::string filter_name_
The filter name.
Definition: filter.h:158
FilterIndices represents the base class for filters that are about binary point removal.
NormalSpaceSampling samples the input point cloud in the space of normal directions computed at every...
Definition: normal_space.h:52
unsigned int getSeed() const
Get the value of the internal seed parameter.
Definition: normal_space.h:111
NormalsConstPtr getNormals() const
Get the normals computed on the input point cloud.
Definition: normal_space.h:148
unsigned int binsy_
Number of bins in y direction.
Definition: normal_space.h:159
void setSeed(unsigned int seed)
Set seed of random function.
Definition: normal_space.h:106
NormalsConstPtr input_normals_
The normals computed at each point in the input cloud.
Definition: normal_space.h:164
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:120
NormalSpaceSampling()
Empty constructor.
Definition: normal_space.h:73
unsigned int seed_
Random number seed.
Definition: normal_space.h:154
unsigned int getSample() const
Get the value of the internal sample parameter.
Definition: normal_space.h:99
void applyFilter(Indices &indices) override
Sample of point indices.
unsigned int binsz_
Number of bins in z direction.
Definition: normal_space.h:161
void setNormals(const NormalsConstPtr &normals)
Set the normals computed on the input point cloud.
Definition: normal_space.h:144
NormalSpaceSampling(bool extract_removed_indices)
Constructor.
Definition: normal_space.h:78
void setSample(unsigned int sample)
Set number of indices to be sampled.
Definition: normal_space.h:94
unsigned int sample_
Number of indices that will be returned.
Definition: normal_space.h:152
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:133
unsigned int binsx_
Number of bins in x direction.
Definition: normal_space.h:157
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.