Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
integral_image2D.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, 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 Willow Garage, Inc. 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  * $Id: integral_image2D.h 6144 2012-07-04 22:06:28Z rusu $
37  */
38 
39 #ifndef PCL_INTEGRAL_IMAGE2D_H_
40 #define PCL_INTEGRAL_IMAGE2D_H_
41 
42 #include <vector>
43 
44 namespace pcl
45 {
46  template <typename DataType>
48  {
49  typedef DataType Type;
50  typedef DataType IntegralType;
51  };
52 
53  template <>
55  {
56  typedef float Type;
57  typedef double IntegralType;
58  };
59 
60  template <>
62  {
63  typedef char Type;
64  typedef int IntegralType;
65  };
66 
67  template <>
69  {
70  typedef short Type;
71  typedef long IntegralType;
72  };
73 
74  template <>
75  struct IntegralImageTypeTraits<unsigned short>
76  {
77  typedef unsigned short Type;
78  typedef unsigned long IntegralType;
79  };
80 
81  template <>
82  struct IntegralImageTypeTraits<unsigned char>
83  {
84  typedef unsigned char Type;
85  typedef unsigned int IntegralType;
86  };
87 
88  template <>
90  {
91  typedef int Type;
92  typedef long IntegralType;
93  };
94 
95  template <>
96  struct IntegralImageTypeTraits<unsigned int>
97  {
98  typedef unsigned int Type;
99  typedef unsigned long IntegralType;
100  };
101 
105  template <class DataType, unsigned Dimension>
107  {
108  public:
109  static const unsigned second_order_size = (Dimension * (Dimension + 1)) >> 1;
110  typedef Eigen::Matrix<typename IntegralImageTypeTraits<DataType>::IntegralType, Dimension, 1> ElementType;
111  typedef Eigen::Matrix<typename IntegralImageTypeTraits<DataType>::IntegralType, second_order_size, 1> SecondOrderType;
112 
116  IntegralImage2D (bool compute_second_order_integral_images) :
117  first_order_integral_image_ (),
118  second_order_integral_image_ (),
119  finite_values_integral_image_ (),
120  width_ (1),
121  height_ (1),
122  compute_second_order_integral_images_ (compute_second_order_integral_images)
123  {
124  }
125 
127  virtual
129 
133  void
134  setSecondOrderComputation (bool compute_second_order_integral_images);
135 
143  void
144  setInput (const DataType * data,
145  unsigned width, unsigned height, unsigned element_stride, unsigned row_stride);
146 
153  inline ElementType
154  getFirstOrderSum (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const;
155 
162  inline ElementType
163  getFirstOrderSumSE (unsigned start_x, unsigned start_y, unsigned end_x, unsigned end_y) const;
164 
171  inline SecondOrderType
172  getSecondOrderSum (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const;
173 
180  inline SecondOrderType
181  getSecondOrderSumSE (unsigned start_x, unsigned start_y, unsigned end_x, unsigned end_y) const;
182 
189  inline unsigned
190  getFiniteElementsCount (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const;
191 
198  inline unsigned
199  getFiniteElementsCountSE (unsigned start_x, unsigned start_y, unsigned end_x, unsigned end_y) const;
200 
201  private:
202  typedef Eigen::Matrix<typename IntegralImageTypeTraits<DataType>::Type, Dimension, 1> InputType;
203 
209  void
210  computeIntegralImages (const DataType * data, unsigned row_stride, unsigned element_stride);
211 
212  std::vector<ElementType, Eigen::aligned_allocator<ElementType> > first_order_integral_image_;
213  std::vector<SecondOrderType, Eigen::aligned_allocator<SecondOrderType> > second_order_integral_image_;
214  std::vector<unsigned> finite_values_integral_image_;
215 
217  unsigned width_;
219  unsigned height_;
220 
222  bool compute_second_order_integral_images_;
223  };
224 
228  template <class DataType>
229  class IntegralImage2D <DataType, 1>
230  {
231  public:
232  static const unsigned second_order_size = 1;
235 
239  IntegralImage2D (bool compute_second_order_integral_images) :
240  first_order_integral_image_ (),
241  second_order_integral_image_ (),
242  finite_values_integral_image_ (),
243  width_ (1), height_ (1),
244  compute_second_order_integral_images_ (compute_second_order_integral_images)
245  {
246  }
247 
249  virtual
251 
259  void
260  setInput (const DataType * data,
261  unsigned width, unsigned height, unsigned element_stride, unsigned row_stride);
262 
269  inline ElementType
270  getFirstOrderSum (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const;
271 
278  inline ElementType
279  getFirstOrderSumSE (unsigned start_x, unsigned start_y, unsigned end_x, unsigned end_y) const;
280 
287  inline SecondOrderType
288  getSecondOrderSum (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const;
289 
296  inline SecondOrderType
297  getSecondOrderSumSE (unsigned start_x, unsigned start_y, unsigned end_x, unsigned end_y) const;
298 
305  inline unsigned
306  getFiniteElementsCount (unsigned start_x, unsigned start_y, unsigned width, unsigned height) const;
307 
314  inline unsigned
315  getFiniteElementsCountSE (unsigned start_x, unsigned start_y, unsigned end_x, unsigned end_y) const;
316 
317  private:
318  // typedef typename IntegralImageTypeTraits<DataType>::Type InputType;
319 
325  void
326  computeIntegralImages (const DataType * data, unsigned row_stride, unsigned element_stride);
327 
328  std::vector<ElementType, Eigen::aligned_allocator<ElementType> > first_order_integral_image_;
329  std::vector<SecondOrderType, Eigen::aligned_allocator<SecondOrderType> > second_order_integral_image_;
330  std::vector<unsigned> finite_values_integral_image_;
331 
333  unsigned width_;
335  unsigned height_;
336 
338  bool compute_second_order_integral_images_;
339  };
340  }
341 
343 
344 #endif // PCL_INTEGRAL_IMAGE2D_H_
345