Point Cloud Library (PCL)  1.9.1-dev
convolution.h
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 #pragma once
39 
40 #include <pcl/pcl_base.h>
41 #include <pcl/pcl_macros.h>
42 #include <pcl/filters/filter.h>
43 #include <pcl/point_types.h>
44 
45 namespace pcl
46 {
47  /**
48  * This typedef is used to represent a point cloud containing edge information
49  */
50  struct EIGEN_ALIGN16 PointXYZIEdge
51  {
52  PCL_ADD_POINT4D; // preferred way of adding a XYZ+padding
53  float magnitude;
54  float direction;
55  float magnitude_x;
56  float magnitude_y;
57  PCL_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
58  }; // enforce SSE padding for correct memory alignment
59 
60  /** \brief A 2D convolution class. */
61  template <typename PointT>
62  class Convolution : public Filter<PointT>
63  {
64  public:
66 
67  /**
68  * Extra pixels are added to the input image so that convolution can be performed over the entire image.
69  *
70  * (kernel_height/2) rows are added before the first row and after the last row
71  * (kernel_width/2) columns are added before the first column and after the last column
72  * border options define what values are set for these extra rows and columns
73  *
74  * Assume that the three rows of right edge of the image looks like this:
75  * .. 3 2 1
76  * .. 6 5 4
77  * .. 9 8 7
78  *
79  * BOUNDARY_OPTION_CLAMP : the extra pixels are set to the pixel value of the boundary pixel
80  * This option makes it seem as if it were:
81  * .. 3 2 1| 1 1 1 ..
82  * .. 6 5 4| 4 4 4 ..
83  * .. 9 8 7| 7 7 7 ..
84  *
85  * BOUNDARY_OPTION_MIRROR : the input image is mirrored at the boundary.
86  * This option makes it seem as if it were:
87  * .. 3 2 1| 1 2 3 ..
88  * .. 6 5 4| 4 5 6 ..
89  * .. 9 8 7| 7 8 9 ..
90  *
91  * BOUNDARY_OPTION_ZERO_PADDING : the extra pixels are simply set to 0
92  * This option makes it seem as if it were:
93  * .. 3 2 1| 0 0 0 ..
94  * .. 6 5 4| 0 0 0 ..
95  * .. 9 8 7| 0 0 0 ..
96  *
97  * Note that the input image is not actually extended in size. Instead, based on these options,
98  * the convolution is performed differently at the border pixels.
99  */
101  {
104  BOUNDARY_OPTION_ZERO_PADDING
105  };
106 
108  {
109  boundary_options_ = BOUNDARY_OPTION_CLAMP;
110  }
111 
112  /** \brief Sets the kernel to be used for convolution
113  * \param[in] kernel convolution kernel passed by reference
114  */
115  inline void
117  {
118  kernel_ = kernel;
119  }
120 
121  /**
122  * \param[in] boundary_options enum indicating the boundary options to be used for convolution
123  */
124  inline void
126  {
127  boundary_options_ = boundary_options;
128  }
129 
130  /** \brief Performs 2D convolution of the input point cloud with the kernel.
131  * Uses clamp as the default boundary option.
132  * \param[out] output Output point cloud passed by reference
133  */
134  void
135  filter (pcl::PointCloud<PointT> &output);
136 
137  protected:
138  /** \brief This is an over-ride function for the pcl::Filter interface. */
139  void
141 
142  private:
143  BOUNDARY_OPTIONS_ENUM boundary_options_;
144  pcl::PointCloud<PointT> kernel_;
145  };
146 }
147 
148 #include <pcl/2d/impl/convolution.hpp>
149 
151  (float, x, x)
152  (float, y, y)
153  (float, z, z)
154  (float, magnitude, magnitude)
155  (float, direction, direction)
156  (float, magnitude_x, magnitude_x)
157  (float, magnitude_y, magnitude_y)
158 )
void applyFilter(pcl::PointCloud< PointT > &) override
This is an over-ride function for the pcl::Filter interface.
Definition: convolution.h:140
A 2D convolution class.
Definition: convolution.h:62
This typedef is used to represent a point cloud containing edge information.
Definition: convolution.h:50
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void setBoundaryOptions(BOUNDARY_OPTIONS_ENUM boundary_options)
Definition: convolution.h:125
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: pcl_macros.h:344
Filter represents the base filter class.
Definition: filter.h:83
BOUNDARY_OPTIONS_ENUM
Extra pixels are added to the input image so that convolution can be performed over the entire image...
Definition: convolution.h:100
POINT_CLOUD_REGISTER_POINT_STRUCT(pcl::_PointXYZLAB,(float, x, x)(float, y, y)(float, z, z)(float, L, L)(float, a, a)(float, b, b)) namespace pcl
Definition: gicp6d.h:78
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void setKernel(const pcl::PointCloud< PointT > &kernel)
Sets the kernel to be used for convolution.
Definition: convolution.h:116