Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
convolution.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, 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  * $Id$
37  *
38  */
39 
40 #ifndef PCL_FILTERS_CONVOLUTION_H_
41 #define PCL_FILTERS_CONVOLUTION_H_
42 
43 #include <pcl/common/eigen.h>
44 #include <pcl/common/point_operators.h>
45 #include <pcl/point_cloud.h>
46 #include <pcl/exceptions.h>
47 #include <pcl/pcl_base.h>
48 
49 namespace pcl
50 {
51  namespace filters
52  {
53  /** Convolution is a mathematical operation on two functions f and g,
54  * producing a third function that is typically viewed as a modified
55  * version of one of the original functions.
56  * see http://en.wikipedia.org/wiki/Convolution.
57  *
58  * The class provides rows, column and separate convolving operations
59  * of a point cloud.
60  * Columns and separate convolution is only allowed on organised
61  * point clouds.
62  *
63  * When convolving, computing the rows and cols elements at 1/2 kernel
64  * width distance from the borders is not defined. We allow for 3
65  * policies:
66  * - Ignoring: elements at special locations are filled with zero
67  * (default behaviour)
68  * - Mirroring: the missing rows or columns are obtained through mirroring
69  * - Duplicating: the missing rows or columns are obtained through
70  * duplicating
71  *
72  * \author Nizar Sallem
73  * \ingroup filters
74  */
75 
76  template <typename PointIn, typename PointOut>
78  {
79  public:
84  typedef boost::shared_ptr< Convolution<PointIn, PointOut> > Ptr;
85  typedef boost::shared_ptr< const Convolution<PointIn, PointOut> > ConstPtr;
86 
87 
88  /// The borders policy available
90  {
94  };
95  /// Constructor
96  Convolution ();
97  /// Empty destructor
99  /** \brief Provide a pointer to the input dataset
100  * \param cloud the const boost shared pointer to a PointCloud message
101  * \remark Will perform a deep copy
102  */
103  inline void
104  setInputCloud (const PointCloudInConstPtr& cloud) { input_ = cloud; }
105  /** Set convolving kernel
106  * \param[in] kernel convolving element
107  */
108  inline void
109  setKernel (const Eigen::ArrayXf& kernel) { kernel_ = kernel; }
110  /// Set the borders policy
111  void
112  setBordersPolicy (int policy) { borders_policy_ = policy; }
113  /// Get the borders policy
114  int
115  getBordersPolicy () { return (borders_policy_); }
116  /** \remark this is critical so please read it carefully.
117  * In 3D the next point in (u,v) coordinate can be really far so a distance
118  * threshold is used to keep us from ghost points.
119  * The value you set here is strongly related to the sensor. A good value for
120  * kinect data is 0.001. Default is std::numeric<float>::infinity ()
121  * \param[in] threshold maximum allowed distance between 2 juxtaposed points
122  */
123  inline void
124  setDistanceThreshold (const float& threshold) { distance_threshold_ = threshold; }
125  /// \return the distance threshold
126  inline const float &
127  getDistanceThreshold () const { return (distance_threshold_); }
128  /** \brief Initialize the scheduler and set the number of threads to use.
129  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
130  */
131  inline void
132  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
133  /** Convolve a float image rows by a given kernel.
134  * \param[out] output the convolved cloud
135  * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
136  * output.cols () < input.cols () then output is resized to input sizes.
137  */
138  inline void
139  convolveRows (PointCloudOut& output);
140  /** Convolve a float image columns by a given kernel.
141  * \param[out] output the convolved image
142  * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
143  * output.cols () < input.cols () then output is resized to input sizes.
144  */
145  inline void
146  convolveCols (PointCloudOut& output);
147  /** Convolve point cloud with an horizontal kernel along rows
148  * then vertical kernel along columns : convolve separately.
149  * \param[in] h_kernel kernel for convolving rows
150  * \param[in] v_kernel kernel for convolving columns
151  * \param[out] output the convolved cloud
152  * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
153  * output.cols () < input.cols () then output is resized to input sizes.
154  */
155  inline void
156  convolve (const Eigen::ArrayXf& h_kernel, const Eigen::ArrayXf& v_kernel, PointCloudOut& output);
157  /** Convolve point cloud with same kernel along rows and columns separately.
158  * \param[out] output the convolved cloud
159  * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
160  * output.cols () < input.cols () then output is resized to input sizes.
161  */
162  inline void
163  convolve (PointCloudOut& output);
164 
165  protected:
166  /// \brief convolve rows and ignore borders
167  void
168  convolve_rows (PointCloudOut& output);
169  /// \brief convolve cols and ignore borders
170  void
171  convolve_cols (PointCloudOut& output);
172  /// \brief convolve rows and mirror borders
173  void
174  convolve_rows_mirror (PointCloudOut& output);
175  /// \brief convolve cols and mirror borders
176  void
177  convolve_cols_mirror (PointCloudOut& output);
178  /// \brief convolve rows and duplicate borders
179  void
180  convolve_rows_duplicate (PointCloudOut& output);
181  /// \brief convolve cols and duplicate borders
182  void
183  convolve_cols_duplicate (PointCloudOut& output);
184  /** init compute is an internal method called before computation
185  * \param[in] output
186  * \throw pcl::InitFailedException
187  */
188  void
189  initCompute (PointCloudOut& output);
190  private:
191  /** \return the result of convolution of point at (\ai, \aj)
192  * \note no test on finity is performed
193  */
194  inline PointOut
195  convolveOneRowDense (int i, int j);
196  /** \return the result of convolution of point at (\ai, \aj)
197  * \note no test on finity is performed
198  */
199  inline PointOut
200  convolveOneColDense (int i, int j);
201  /** \return the result of convolution of point at (\ai, \aj)
202  * \note only finite points within \a distance_threshold_ are accounted
203  */
204  inline PointOut
205  convolveOneRowNonDense (int i, int j);
206  /** \return the result of convolution of point at (\ai, \aj)
207  * \note only finite points within \a distance_threshold_ are accounted
208  */
209  inline PointOut
210  convolveOneColNonDense (int i, int j);
211 
212  /// Border policy
213  int borders_policy_;
214  /// Threshold distance between adjacent points
215  float distance_threshold_;
216  /// Pointer to the input cloud
217  PointCloudInConstPtr input_;
218  /// convolution kernel
219  Eigen::ArrayXf kernel_;
220  /// half kernel size
221  int half_width_;
222  /// kernel size - 1
223  int kernel_width_;
224  protected:
225  /** \brief The number of threads the scheduler should use. */
226  unsigned int threads_;
227 
228  void
229  makeInfinite (PointOut& p)
230  {
231  p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN ();
232  }
233  };
234  }
235 }
236 
237 #include <pcl/filters/impl/convolution.hpp>
238 
239 #endif
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
void convolve_cols_mirror(PointCloudOut &output)
convolve cols and mirror borders
unsigned int threads_
The number of threads the scheduler should use.
Definition: convolution.h:226
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
const float & getDistanceThreshold() const
Definition: convolution.h:127
void convolve_cols_duplicate(PointCloudOut &output)
convolve cols and duplicate borders
void convolve(const Eigen::ArrayXf &h_kernel, const Eigen::ArrayXf &v_kernel, PointCloudOut &output)
Convolve point cloud with an horizontal kernel along rows then vertical kernel along columns : convol...
void setBordersPolicy(int policy)
Set the borders policy.
Definition: convolution.h:112
pcl::PointCloud< PointOut > PointCloudOut
Definition: convolution.h:83
void setDistanceThreshold(const float &threshold)
Definition: convolution.h:124
void setKernel(const Eigen::ArrayXf &kernel)
Set convolving kernel.
Definition: convolution.h:109
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
PointCloudIn::Ptr PointCloudInPtr
Definition: convolution.h:81
void convolve_rows_duplicate(PointCloudOut &output)
convolve rows and duplicate borders
boost::shared_ptr< Convolution< PointIn, PointOut > > Ptr
Definition: convolution.h:84
Convolution is a mathematical operation on two functions f and g, producing a third function that is ...
Definition: convolution.h:77
void setInputCloud(const PointCloudInConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: convolution.h:104
BORDERS_POLICY
The borders policy available.
Definition: convolution.h:89
pcl::PointCloud< PointIn > PointCloudIn
Definition: convolution.h:80
void convolve_rows(PointCloudOut &output)
convolve rows and ignore borders
void convolve_rows_mirror(PointCloudOut &output)
convolve rows and mirror borders
~Convolution()
Empty destructor.
Definition: convolution.h:98
PointCloud represents the base class in PCL for storing collections of 3D points. ...
PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: convolution.h:82
Convolution()
Constructor.
Definition: convolution.hpp:47
void convolveRows(PointCloudOut &output)
Convolve a float image rows by a given kernel.
Definition: convolution.hpp:89
void convolveCols(PointCloudOut &output)
Convolve a float image columns by a given kernel.
void initCompute(PointCloudOut &output)
init compute is an internal method called before computation
Definition: convolution.hpp:58
int getBordersPolicy()
Get the borders policy.
Definition: convolution.h:115
void makeInfinite(PointOut &p)
Definition: convolution.h:229
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: convolution.h:132
void convolve_cols(PointCloudOut &output)
convolve cols and ignore borders
boost::shared_ptr< const Convolution< PointIn, PointOut > > ConstPtr
Definition: convolution.h:85