Point Cloud Library (PCL)  1.14.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 #include <cassert>
44 
45 namespace pcl
46 {
47 
48 template <typename PointT> void
50  std::function <float (const PointT& p)> field_accessor,
51  const Eigen::VectorXf& kernel,
52  pcl::PointCloud<float> &output) const
53 {
54  assert(kernel.size () % 2 == 1);
55  int kernel_width = kernel.size () -1;
56  int radius = kernel.size () / 2.0;
57  if(output.height < input.height || output.width < input.width)
58  {
59  output.width = input.width;
60  output.height = input.height;
61  output.resize (input.height * input.width);
62  }
63 
64  int i;
65  for(int j = 0; j < input.height; j++)
66  {
67  for (i = 0 ; i < radius ; i++)
68  output (i,j) = 0;
69 
70  for ( ; i < input.width - radius ; i++) {
71  output (i,j) = 0;
72  for (int k = kernel_width, l = i - radius; k >= 0 ; k--, l++)
73  output (i,j) += field_accessor (input (l,j)) * kernel[k];
74  }
75 
76  for ( ; i < input.width ; i++)
77  output (i,j) = 0;
78  }
79 }
80 
81 template <typename PointT> void
83  std::function <float (const PointT& p)> field_accessor,
84  const Eigen::VectorXf& kernel,
85  pcl::PointCloud<float> &output) const
86 {
87  assert(kernel.size () % 2 == 1);
88  int kernel_width = kernel.size () -1;
89  int radius = kernel.size () / 2.0;
90  if(output.height < input.height || output.width < input.width)
91  {
92  output.width = input.width;
93  output.height = input.height;
94  output.resize (input.height * input.width);
95  }
96 
97  int j;
98  for(int i = 0; i < input.width; i++)
99  {
100  for (j = 0 ; j < radius ; j++)
101  output (i,j) = 0;
102 
103  for ( ; j < input.height - radius ; j++) {
104  output (i,j) = 0;
105  for (int k = kernel_width, l = j - radius ; k >= 0 ; k--, l++)
106  {
107  output (i,j) += field_accessor (input (i,l)) * kernel[k];
108  }
109  }
110 
111  for ( ; j < input.height ; j++)
112  output (i,j) = 0;
113  }
114 }
115 
116 } // namespace pcl
117 
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.
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.
Definition: point_cloud.h:173
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition: point_cloud.h:462
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:398
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:400
A point structure representing Euclidean xyz coordinates, and the RGB color.