|
Point Cloud Library (PCL)
1.5.1
|
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: integral_image2D.h 4702 2012-02-23 09:39:33Z gedikli $ 00037 */ 00038 00039 #ifndef PCL_INTEGRAL_IMAGE2D_H_ 00040 #define PCL_INTEGRAL_IMAGE2D_H_ 00041 00042 #include <vector> 00043 00044 namespace pcl 00045 { 00046 template <typename DataType> 00047 struct IntegralImageTypeTraits 00048 { 00049 typedef DataType Type; 00050 typedef DataType IntegralType; 00051 }; 00052 00053 template <> 00054 struct IntegralImageTypeTraits<float> 00055 { 00056 typedef float Type; 00057 typedef double IntegralType; 00058 }; 00059 00060 template <> 00061 struct IntegralImageTypeTraits<char> 00062 { 00063 typedef char Type; 00064 typedef int IntegralType; 00065 }; 00066 00067 template <> 00068 struct IntegralImageTypeTraits<short> 00069 { 00070 typedef short Type; 00071 typedef long IntegralType; 00072 }; 00073 00074 template <> 00075 struct IntegralImageTypeTraits<unsigned short> 00076 { 00077 typedef unsigned short Type; 00078 typedef unsigned long IntegralType; 00079 }; 00080 00081 template <> 00082 struct IntegralImageTypeTraits<unsigned char> 00083 { 00084 typedef unsigned char Type; 00085 typedef unsigned int IntegralType; 00086 }; 00087 00088 template <> 00089 struct IntegralImageTypeTraits<int> 00090 { 00091 typedef int Type; 00092 typedef long IntegralType; 00093 }; 00094 00095 template <> 00096 struct IntegralImageTypeTraits<unsigned int> 00097 { 00098 typedef unsigned int Type; 00099 typedef unsigned long IntegralType; 00100 }; 00101 00105 template <class DataType, unsigned Dimension> 00106 class IntegralImage2D 00107 { 00108 public: 00109 static const unsigned second_order_size = (Dimension * (Dimension + 1)) >> 1; 00110 typedef Eigen::Matrix<typename IntegralImageTypeTraits<DataType>::IntegralType, Dimension, 1> ElementType; 00111 typedef Eigen::Matrix<typename IntegralImageTypeTraits<DataType>::IntegralType, second_order_size, 1> SecondOrderType; 00112 00116 IntegralImage2D (bool compute_second_order_integral_images) 00117 : width_ (1) 00118 , height_ (1) 00119 , compute_second_order_integral_images_ (compute_second_order_integral_images) 00120 { 00121 } 00122 00124 virtual 00125 ~IntegralImage2D () { } 00126 00130 void 00131 setSecondOrderComputation (bool compute_second_order_integral_images); 00132 00140 void 00141 setInput (const DataType * data, 00142 unsigned width, unsigned height, unsigned element_stride, unsigned row_stride); 00143 00150 inline ElementType 00151 getFirstOrderSum (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const; 00152 00159 inline SecondOrderType 00160 getSecondOrderSum (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const; 00161 00168 inline unsigned 00169 getFiniteElementsCount (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const; 00170 private: 00171 typedef Eigen::Matrix<typename IntegralImageTypeTraits<DataType>::Type, Dimension, 1> InputType; 00172 00178 void 00179 computeIntegralImages (const DataType * data, unsigned row_stride, unsigned element_stride); 00180 00181 std::vector<ElementType, Eigen::aligned_allocator<ElementType> > first_order_integral_image_; 00182 std::vector<SecondOrderType, Eigen::aligned_allocator<SecondOrderType> > second_order_integral_image_; 00183 std::vector<unsigned> finite_values_integral_image_; 00184 00186 unsigned width_; 00188 unsigned height_; 00189 00191 bool compute_second_order_integral_images_; 00192 }; 00193 00197 template <class DataType> 00198 class IntegralImage2D <DataType, 1> 00199 { 00200 public: 00201 static const unsigned second_order_size = 1; 00202 typedef typename IntegralImageTypeTraits<DataType>::IntegralType ElementType; 00203 typedef typename IntegralImageTypeTraits<DataType>::IntegralType SecondOrderType; 00204 00208 IntegralImage2D (bool compute_second_order_integral_images) 00209 : width_ (1), height_ (1), compute_second_order_integral_images_ (compute_second_order_integral_images) 00210 { 00211 } 00212 00214 virtual 00215 ~IntegralImage2D () { } 00216 00224 void 00225 setInput (const DataType * data, 00226 unsigned width, unsigned height, unsigned element_stride, unsigned row_stride); 00227 00234 inline ElementType 00235 getFirstOrderSum (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const; 00236 00243 inline SecondOrderType 00244 getSecondOrderSum (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const; 00245 00252 inline unsigned 00253 getFiniteElementsCount (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const; 00254 private: 00255 // typedef typename IntegralImageTypeTraits<DataType>::Type InputType; 00256 00262 void 00263 computeIntegralImages (const DataType * data, unsigned row_stride, unsigned element_stride); 00264 00265 std::vector<ElementType, Eigen::aligned_allocator<ElementType> > first_order_integral_image_; 00266 std::vector<SecondOrderType, Eigen::aligned_allocator<SecondOrderType> > second_order_integral_image_; 00267 std::vector<unsigned> finite_values_integral_image_; 00268 00270 unsigned width_; 00272 unsigned height_; 00273 00275 bool compute_second_order_integral_images_; 00276 }; 00277 } 00278 00279 #include <pcl/features/impl/integral_image2D.hpp> 00280 00281 #endif // PCL_INTEGRAL_IMAGE2D_H_ 00282
1.8.0