Point Cloud Library (PCL)  1.9.1-dev
gaussian.hpp
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_GAUSSIAN_KERNEL_IMPL
41 #define PCL_GAUSSIAN_KERNEL_IMPL
42 
43 #include <pcl/exceptions.h>
44 
45 template <typename PointT> void
47  std::function <float (const PointT& p)> field_accessor,
48  const Eigen::VectorXf& kernel,
49  pcl::PointCloud<float> &output) const
50 {
51  assert(kernel.size () % 2 == 1);
52  int kernel_width = kernel.size () -1;
53  int radius = kernel.size () / 2.0;
54  if(output.height < input.height || output.width < input.width)
55  {
56  output.width = input.width;
57  output.height = input.height;
58  output.points.resize (input.height * input.width);
59  }
60 
61  int i;
62  for(int j = 0; j < input.height; j++)
63  {
64  for (i = 0 ; i < radius ; i++)
65  output (i,j) = 0;
66 
67  for ( ; i < input.width - radius ; i++) {
68  output (i,j) = 0;
69  for (int k = kernel_width, l = i - radius; k >= 0 ; k--, l++)
70  output (i,j) += field_accessor (input (l,j)) * kernel[k];
71  }
72 
73  for ( ; i < input.width ; i++)
74  output (i,j) = 0;
75  }
76 }
77 
78 template <typename PointT> void
80  std::function <float (const PointT& p)> field_accessor,
81  const Eigen::VectorXf& kernel,
82  pcl::PointCloud<float> &output) const
83 {
84  assert(kernel.size () % 2 == 1);
85  int kernel_width = kernel.size () -1;
86  int radius = kernel.size () / 2.0;
87  if(output.height < input.height || output.width < input.width)
88  {
89  output.width = input.width;
90  output.height = input.height;
91  output.points.resize (input.height * input.width);
92  }
93 
94  int j;
95  for(int i = 0; i < input.width; i++)
96  {
97  for (j = 0 ; j < radius ; j++)
98  output (i,j) = 0;
99 
100  for ( ; j < input.height - radius ; j++) {
101  output (i,j) = 0;
102  for (int k = kernel_width, l = j - radius ; k >= 0 ; k--, l++)
103  {
104  output (i,j) += field_accessor (input (i,l)) * kernel[k];
105  }
106  }
107 
108  for ( ; j < input.height ; j++)
109  output (i,j) = 0;
110  }
111 }
112 
113 #endif
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:423
uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:428
uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:426
void convolveRows(const pcl::PointCloud< float > &input, const Eigen::VectorXf &kernel, pcl::PointCloud< float > &output) const
Convolve a float image rows by a given kernel.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void convolveCols(const pcl::PointCloud< float > &input, const Eigen::VectorXf &kernel, pcl::PointCloud< float > &output) const
Convolve a float image columns by a given kernel.
A point structure representing Euclidean xyz coordinates, and the RGB color.