Point Cloud Library (PCL)  1.11.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 #pragma once
41 
42 #include <pcl/common/gaussian.h>
43 
44 namespace pcl
45 {
46 
47 template <typename PointT> void
49  std::function <float (const PointT& p)> field_accessor,
50  const Eigen::VectorXf& kernel,
51  pcl::PointCloud<float> &output) const
52 {
53  assert(kernel.size () % 2 == 1);
54  int kernel_width = kernel.size () -1;
55  int radius = kernel.size () / 2.0;
56  if(output.height < input.height || output.width < input.width)
57  {
58  output.width = input.width;
59  output.height = input.height;
60  output.resize (input.height * input.width);
61  }
62 
63  int i;
64  for(int j = 0; j < input.height; j++)
65  {
66  for (i = 0 ; i < radius ; i++)
67  output (i,j) = 0;
68 
69  for ( ; i < input.width - radius ; i++) {
70  output (i,j) = 0;
71  for (int k = kernel_width, l = i - radius; k >= 0 ; k--, l++)
72  output (i,j) += field_accessor (input (l,j)) * kernel[k];
73  }
74 
75  for ( ; i < input.width ; i++)
76  output (i,j) = 0;
77  }
78 }
79 
80 template <typename PointT> void
82  std::function <float (const PointT& p)> field_accessor,
83  const Eigen::VectorXf& kernel,
84  pcl::PointCloud<float> &output) const
85 {
86  assert(kernel.size () % 2 == 1);
87  int kernel_width = kernel.size () -1;
88  int radius = kernel.size () / 2.0;
89  if(output.height < input.height || output.width < input.width)
90  {
91  output.width = input.width;
92  output.height = input.height;
93  output.resize (input.height * input.width);
94  }
95 
96  int j;
97  for(int i = 0; i < input.width; i++)
98  {
99  for (j = 0 ; j < radius ; j++)
100  output (i,j) = 0;
101 
102  for ( ; j < input.height - radius ; j++) {
103  output (i,j) = 0;
104  for (int k = kernel_width, l = j - radius ; k >= 0 ; k--, l++)
105  {
106  output (i,j) += field_accessor (input (i,l)) * kernel[k];
107  }
108  }
109 
110  for ( ; j < input.height ; j++)
111  output (i,j) = 0;
112  }
113 }
114 
115 } // namespace pcl
116 
pcl
Definition: convolution.h:46
pcl::PointCloud::height
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:393
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:628
pcl::PointCloud::width
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:391
pcl::GaussianKernel::convolveRows
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.
pcl::PointCloud::resize
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition: point_cloud.h:455
pcl::GaussianKernel::convolveCols
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.
pcl::kernel
Definition: kernel.h:46