Point Cloud Library (PCL)  1.9.1
convolution.hpp
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 #ifndef PCL_2D_CONVOLUTION_IMPL_HPP
39 #define PCL_2D_CONVOLUTION_IMPL_HPP
40 
41 //////////////////////////////////////////////////////////////////////////////
42 template <typename PointT> void
44 {
45  int input_row = 0;
46  int input_col = 0;
47  // default boundary option : zero padding
48  output = *input_;
49 
50  int iw = static_cast<int> (input_->width),
51  ih = static_cast<int> (input_->height),
52  kw = static_cast<int> (kernel_.width),
53  kh = static_cast<int> (kernel_.height);
54  switch (boundary_options_)
55  {
56  default:
57  case BOUNDARY_OPTION_CLAMP:
58  {
59  for (int i = 0; i < ih; i++)
60  {
61  for (int j = 0; j < iw; j++)
62  {
63  float intensity = 0;
64  for (int k = 0; k < kh; k++)
65  {
66  for (int l = 0; l < kw; l++)
67  {
68  int ikkh = i + k - kh / 2, jlkw = j + l - kw / 2;
69  if (ikkh < 0)
70  input_row = 0;
71  else if (ikkh >= ih)
72  input_row = ih - 1;
73  else
74  input_row = ikkh;
75 
76  if (jlkw < 0)
77  input_col = 0;
78  else if (jlkw >= iw)
79  input_col = iw - 1;
80  else
81  input_col = jlkw;
82 
83  intensity += kernel_ (l, k).intensity * (*input_)(input_col, input_row).intensity;
84  }
85  }
86  output (j, i).intensity = intensity;
87  }
88  }
89  break;
90  }
91 
92  case BOUNDARY_OPTION_MIRROR:
93  {
94  for (int i = 0; i < ih; i++)
95  {
96  for (int j = 0; j < iw; j++)
97  {
98  float intensity = 0;
99  for (int k = 0; k < kh; k++)
100  {
101  for (int l = 0; l < kw; l++)
102  {
103  int ikkh = i + k - kh / 2, jlkw = j + l - kw / 2;
104  if (ikkh < 0)
105  input_row = -ikkh - 1;
106  else if (ikkh >= ih)
107  input_row = 2 * ih - 1 - ikkh;
108  else
109  input_row = ikkh;
110 
111  if (jlkw < 0)
112  input_col = -jlkw - 1;
113  else if (jlkw >= iw)
114  input_col = 2 * iw - 1 - jlkw;
115  else
116  input_col = jlkw;
117 
118  intensity += kernel_ (l, k).intensity * ((*input_)(input_col, input_row).intensity);
119  }
120  }
121  output (j, i).intensity = intensity;
122  }
123  }
124  break;
125  }
126 
127  case BOUNDARY_OPTION_ZERO_PADDING:
128  {
129  for (int i = 0; i < ih; i++)
130  {
131  for (int j = 0; j < iw; j++)
132  {
133  float intensity = 0;
134  for (int k = 0; k < kh; k++)
135  {
136  for (int l = 0; l < kw; l++)
137  {
138  int ikkh = i + k - kh / 2, jlkw = j + l - kw / 2;
139  if (ikkh < 0 || ikkh >= ih || jlkw < 0 || jlkw >= iw)
140  continue;
141  else
142  intensity += kernel_ (l, k).intensity * ((*input_)(jlkw, ikkh).intensity);
143  }
144  }
145  output (j, i).intensity = intensity;
146  }
147  }
148  break;
149  }
150  } // switch
151 }
152 
153 #endif
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void filter(pcl::PointCloud< PointT > &output)
Performs 2D convolution of the input point cloud with the kernel.
Definition: convolution.hpp:43