00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 template <class DataType, class IIDataType>
00039 pcl::IntegralImage2D<DataType, IIDataType>::IntegralImage2D (
00040 DataType * data, const int width, const int height,
00041 const int dimensions, const bool compute_second_order_integral_images,
00042 const int element_stride,const int row_stride) : width_(width), height_(height),
00043 dimensions_(dimensions),
00044 element_stride_(element_stride),
00045 row_stride_(row_stride),
00046 are_second_order_ii_available_(compute_second_order_integral_images)
00047 {
00048
00049 for (int dimension_index = 0; dimension_index < dimensions; ++dimension_index)
00050 {
00051 IIDataType * data_array = new IIDataType[width*height];
00052
00053 first_order_integral_images_.push_back(data_array);
00054 }
00055
00056 if (compute_second_order_integral_images)
00057 {
00058 for (int dimension_index1 = 0; dimension_index1 < dimensions; ++dimension_index1)
00059 {
00060 second_order_integral_images_.push_back(::std::vector< IIDataType* >());
00061 for (int dimension_index2 = 0; dimension_index2 < dimensions; ++dimension_index2)
00062 {
00063 IIDataType * data_array = new IIDataType[width*height];
00064
00065 second_order_integral_images_[dimension_index1].push_back(data_array);
00066 }
00067 }
00068 }
00069
00070
00071
00072 if (dimensions_ == 1)
00073 {
00074 this->computeIntegralImagesOneDimensional (data);
00075 }
00076 else
00077 {
00078 this->computeIntegralImages (data);
00079 }
00080 }
00081
00082
00083
00084 template <class DataType, class IIDataType>
00085 pcl::IntegralImage2D<DataType, IIDataType>::~IntegralImage2D()
00086 {
00087 for (unsigned int index = 0; index < first_order_integral_images_.size(); ++index)
00088 {
00089 delete[] (first_order_integral_images_[index]);
00090 }
00091 for (unsigned int index1 = 0; index1 < second_order_integral_images_.size(); ++index1)
00092 {
00093 for (unsigned int index2 = 0; index2 < second_order_integral_images_[index1].size(); ++index2)
00094 {
00095 delete[] (second_order_integral_images_[index1][index2]);
00096 }
00097 }
00098 }
00099
00100
00101
00102 template <class DataType, class IIDataType> IIDataType
00103 pcl::IntegralImage2D<DataType, IIDataType>::getSum (
00104 const int start_x, const int start_y,
00105 const int width, const int height,
00106 const int dimension_index )
00107 {
00108 const int l_ulX = start_x;
00109 const int l_ulY = start_y;
00110 const int l_lrX = start_x + width;
00111 const int l_lrY = start_y + height;
00112
00113 return
00114 (first_order_integral_images_[dimension_index][l_ulY*width_ + l_ulX]
00115 + first_order_integral_images_[dimension_index][l_lrY*width_ + l_lrX]
00116 - first_order_integral_images_[dimension_index][l_lrY*width_ + l_ulX]
00117 - first_order_integral_images_[dimension_index][l_ulY*width_ + l_lrX]);
00118 }
00119
00120
00121
00122 template <class DataType, class IIDataType> IIDataType
00123 pcl::IntegralImage2D<DataType, IIDataType>::getSum (
00124 const int start_x, const int start_y,
00125 const int width, const int height,
00126 const int dimension_index1, const int dimension_index2)
00127 {
00128 const int l_ulX = start_x;
00129 const int l_ulY = start_y;
00130 const int l_lrX = start_x + width;
00131 const int l_lrY = start_y + height;
00132
00133 return second_order_integral_images_[dimension_index1][dimension_index2][l_ulY*width_ + l_ulX]
00134 + second_order_integral_images_[dimension_index1][dimension_index2][l_lrY*width_ + l_lrX]
00135 - second_order_integral_images_[dimension_index1][dimension_index2][l_lrY*width_ + l_ulX]
00136 - second_order_integral_images_[dimension_index1][dimension_index2][l_ulY*width_ + l_lrX];
00137 }
00138
00139
00140
00141 template <class DataType, class IIDataType> void
00142 pcl::IntegralImage2D<DataType, IIDataType>::computeIntegralImages (DataType *data)
00143 {
00144
00145 {
00146 const int row_index = 0;
00147 const int col_index = 0;
00148 for (int dimension_index = 0; dimension_index < dimensions_; ++dimension_index)
00149 {
00150 const IIDataType data_value = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_ + dimension_index]);
00151
00152 first_order_integral_images_[dimension_index][row_index*width_ + col_index] = data_value;
00153
00154 if (are_second_order_ii_available_)
00155 {
00156 for (int dimension_index2 = 0; dimension_index2 < dimensions_; ++dimension_index2)
00157 {
00158 const IIDataType data_value2 = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_ + dimension_index2]);
00159
00160 second_order_integral_images_[dimension_index][dimension_index2][row_index*width_ + col_index] = data_value*data_value2;
00161 }
00162 }
00163 }
00164 }
00165
00166
00167 {
00168 const int row_index = 0;
00169 for (int col_index = 1; col_index < width_; ++col_index)
00170 {
00171 for (int dimension_index = 0; dimension_index < dimensions_; ++dimension_index)
00172 {
00173 const IIDataType data_value = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_ + dimension_index]);
00174
00175 first_order_integral_images_[dimension_index][row_index*width_ + col_index] = data_value
00176 + first_order_integral_images_[dimension_index][row_index*width_ + (col_index-1)];
00177
00178 if (are_second_order_ii_available_)
00179 {
00180 for (int dimension_index2 = 0; dimension_index2 < dimensions_; ++dimension_index2)
00181 {
00182 const IIDataType data_value2 = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_ + dimension_index2]);
00183
00184 second_order_integral_images_[dimension_index][dimension_index2][row_index*width_ + col_index] = data_value*data_value2
00185 + second_order_integral_images_[dimension_index][dimension_index2][row_index*width_ + (col_index-1)];
00186 }
00187 }
00188 }
00189 }
00190 }
00191
00192
00193 {
00194 const int col_index = 0;
00195 for (int row_index = 1; row_index < height_; ++row_index)
00196 {
00197 for (int dimension_index = 0; dimension_index < dimensions_; ++dimension_index)
00198 {
00199 const IIDataType data_value = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_ + dimension_index]);
00200
00201 first_order_integral_images_[dimension_index][row_index*width_ + col_index] = data_value
00202 + first_order_integral_images_[dimension_index][(row_index-1)*width_ + col_index];
00203
00204 if (are_second_order_ii_available_)
00205 {
00206 for (int dimension_index2 = 0; dimension_index2 < dimensions_; ++dimension_index2)
00207 {
00208 const IIDataType data_value2 = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_ + dimension_index2]);
00209
00210 second_order_integral_images_[dimension_index][dimension_index2][row_index*width_ + col_index] = data_value*data_value2
00211 + second_order_integral_images_[dimension_index][dimension_index2][(row_index-1)*width_ + col_index];
00212 }
00213 }
00214 }
00215 }
00216 }
00217
00218
00219 for (int row_index = 1; row_index < height_; ++row_index)
00220 {
00221 for (int col_index = 1; col_index < width_; ++col_index)
00222 {
00223 for (int dimension_index = 0; dimension_index < dimensions_; ++dimension_index)
00224 {
00225 const IIDataType data_value = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_ + dimension_index]);
00226
00227 first_order_integral_images_[dimension_index][row_index*width_ + col_index] = data_value
00228 + first_order_integral_images_[dimension_index][row_index*width_ + (col_index-1)]
00229 + first_order_integral_images_[dimension_index][(row_index-1)*width_ + col_index]
00230 - first_order_integral_images_[dimension_index][(row_index-1)*width_ + (col_index-1)];
00231
00232 if (are_second_order_ii_available_)
00233 {
00234 for (int dimension_index2 = 0; dimension_index2 < dimensions_; ++dimension_index2)
00235 {
00236 const IIDataType data_value2 = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_ + dimension_index2]);
00237
00238 second_order_integral_images_[dimension_index][dimension_index2][row_index*width_ + col_index] = data_value*data_value2
00239 + second_order_integral_images_[dimension_index][dimension_index2][row_index*width_ + (col_index-1)]
00240 + second_order_integral_images_[dimension_index][dimension_index2][(row_index-1)*width_ + col_index]
00241 - second_order_integral_images_[dimension_index][dimension_index2][(row_index-1)*width_ + (col_index-1)];
00242 }
00243 }
00244 }
00245 }
00246 }
00247 }
00248
00249
00250
00251 template <class DataType, class IIDataType> void
00252 pcl::IntegralImage2D<DataType, IIDataType>::computeIntegralImagesOneDimensional (DataType *data)
00253 {
00254 IIDataType * first_order_integral_image = first_order_integral_images_[0];
00255 IIDataType * second_order_integral_image = NULL;
00256 if (are_second_order_ii_available_)
00257 {
00258 second_order_integral_image = second_order_integral_images_[0][0];
00259 }
00260
00261
00262 {
00263 const int row_index = 0;
00264 const int col_index = 0;
00265
00266 const IIDataType data_value = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_]);
00267
00268 first_order_integral_image[row_index*width_ + col_index] = data_value;
00269
00270 if (are_second_order_ii_available_)
00271 {
00272 second_order_integral_image[row_index*width_ + col_index] = data_value*data_value;
00273 }
00274 }
00275
00276
00277 {
00278 const int row_index = 0;
00279 for (int col_index = 1; col_index < width_; ++col_index)
00280 {
00281 const IIDataType data_value = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_]);
00282
00283 first_order_integral_image[row_index*width_ + col_index] = data_value
00284 + first_order_integral_image[row_index*width_ + (col_index-1)];
00285
00286 if (are_second_order_ii_available_)
00287 {
00288 second_order_integral_image[row_index*width_ + col_index] = data_value*data_value
00289 + second_order_integral_image[row_index*width_ + (col_index-1)];
00290 }
00291 }
00292 }
00293
00294
00295 {
00296 const int col_index = 0;
00297 for (int row_index = 1; row_index < height_; ++row_index)
00298 {
00299 const IIDataType data_value = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_]);
00300
00301 first_order_integral_image[row_index*width_ + col_index] = data_value
00302 + first_order_integral_image[(row_index-1)*width_ + col_index];
00303
00304 if (are_second_order_ii_available_)
00305 {
00306 second_order_integral_image[row_index*width_ + col_index] = data_value*data_value
00307 + second_order_integral_image[(row_index-1)*width_ + col_index];
00308 }
00309 }
00310 }
00311
00312
00313 for (int row_index = 1; row_index < height_; ++row_index)
00314 {
00315 for (int col_index = 1; col_index < width_; ++col_index)
00316 {
00317 const IIDataType data_value = static_cast<IIDataType>(data[row_index*row_stride_ + col_index*element_stride_]);
00318
00319 first_order_integral_image[row_index*width_ + col_index] = data_value
00320 - first_order_integral_image[(row_index-1)*width_ + (col_index-1)]
00321 + first_order_integral_image[(row_index-1)*width_ + col_index]
00322 + first_order_integral_image[row_index*width_ + (col_index-1)];
00323
00324 if (are_second_order_ii_available_)
00325 {
00326 second_order_integral_image[row_index*width_ + col_index] = data_value*data_value
00327 + second_order_integral_image[row_index*width_ + (col_index-1)]
00328 + second_order_integral_image[(row_index-1)*width_ + col_index]
00329 - second_order_integral_image[(row_index-1)*width_ + (col_index-1)];
00330 }
00331 }
00332 }
00333 }
00334