|
Point Cloud Library (PCL)
1.4.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: convolution.hpp 3656 2011-12-26 22:54:50Z nizar $ 00037 * 00038 */ 00039 00040 #ifndef PCL_COMMON_CONVOLUTION_IMPL_HPP 00041 #define PCL_COMMON_CONVOLUTION_IMPL_HPP 00042 00043 template <typename PointOperatorsType> void 00044 pcl::common::Convolution<PointOperatorsType>::initCompute () 00045 { 00046 if(kernel_width_ % 2 == 0) 00047 PCL_THROW_EXCEPTION (InitFailedException, 00048 "[pcl::common::Convolution::initCompute] convolving element width must be odd."); 00049 00050 half_width_ = kernel_width_ / 2; 00051 00052 switch (borders_policy_) 00053 { 00054 case IGNORE : break; 00055 case MIRROR : 00056 { 00057 spring_.setInputCloud (input_); 00058 spring_.setAmount (half_width_); 00059 spring_.setExpandPolicy (borders_policy_); 00060 spring_.setDirection (convolve_direction_); 00061 spring_.expand (); 00062 } break; 00063 case DUPLICATE : 00064 { 00065 spring_.setInputCloud (input_); 00066 spring_.setAmount (half_width_); 00067 spring_.setExpandPolicy (borders_policy_); 00068 spring_.setDirection (convolve_direction_); 00069 spring_.expand (); 00070 } break; 00071 default: 00072 PCL_THROW_EXCEPTION (InitFailedException, 00073 "[pcl::common::Convolution::initCompute] unknown border policy"); 00074 break; 00075 } 00076 00077 if (&(*input_) != &(*output_)) 00078 { 00079 if (output_->height < input_->height || output_->width < input_->width) 00080 { 00081 output_->resize (input_->width * input_->height); 00082 output_->width = input_->width; 00083 output_->height = input_->height; 00084 } 00085 } 00086 else 00087 input_.reset (new PointCloudOut (*input_)); 00088 } 00089 00090 template <typename PointOperatorsType> inline void 00091 pcl::common::Convolution<PointOperatorsType>::convolve_rows (const Eigen::ArrayXf& kernel, 00092 PointCloudOutPtr& output) 00093 { 00094 int i, h(input_->height), w(input_->width), last(w - half_width_); 00095 for(int j = 0; j < h; j++) 00096 { 00097 for (i = 0; i < half_width_; i++) 00098 (*output_) (i,j) = operators_ (); 00099 00100 for ( ; i < last; i++) { 00101 (*output_) (i,j) = operators_ (); 00102 for (int k = kernel_width_ - 1, l = i - half_width_; k >= 0 ; k--, l++) 00103 operators_.plus_assign ((*output_) (i,j), 00104 operators_.dot (operators_ ((*input_) (l,j)), kernel [k])); 00105 } 00106 00107 for ( ; i < w; i++) 00108 (*output_) (i,j) = operators_ (); 00109 } 00110 } 00111 00112 template <typename PointOperatorsType> inline void 00113 pcl::common::Convolution<PointOperatorsType>::convolve_cols (const Eigen::ArrayXf& kernel, 00114 PointCloudOutPtr& output) 00115 { 00116 int j, h(input_->height), w(input_->width), last(h - half_width_); 00117 for(int i = 0; i < w; i++) 00118 { 00119 for (j = 0; j < half_width_; j++) 00120 (*output_) (i,j) = operators_ (); 00121 00122 for ( ; j < last; j++) { 00123 (*output_) (i,j) = operators_ (); 00124 for (int k = kernel_width_, l = j - half_width_; k >= 0; k--, l++) 00125 { 00126 operators_.plus_assign ((*output_) (i,j), 00127 operators_.dot (operators_ ((*input_) (i,l)), kernel [k])); 00128 } 00129 } 00130 00131 for ( ; j < h; j++) 00132 (*output_) (i,j) = operators_ (); 00133 } 00134 } 00135 00136 #endif
1.7.6.1