TuttleOFX  1
inner_product.hpp
Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://opensource.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef _TERRY_FILTER_INNERPRODUCT_HPP_
00010 #define _TERRY_FILTER_INNERPRODUCT_HPP_
00011 
00012 /*!
00013 /// \file               
00014 /// \brief Numeric algorithms
00015 /// \author Hailin Jin and Lubomir Bourdev \n
00016 ///         Adobe Systems Incorporated
00017 /// \date   2005-2007 \n Last updated on February 6, 2007
00018 */
00019 
00020 #include <terry/pixel_proxy.hpp>
00021 
00022 #include <boost/gil/gil_config.hpp>
00023 #include <boost/gil/pixel_iterator.hpp>
00024 #include <boost/gil/metafunctions.hpp>
00025 
00026 #include <cassert>
00027 #include <iterator>
00028 #include <algorithm>
00029 #include <numeric>
00030 
00031 namespace terry {
00032 
00033 using namespace boost::gil;
00034 namespace filter {
00035 
00036 namespace detail {
00037 template <std::size_t Size>
00038 struct inner_product_k_t
00039 {
00040     template <class _InputIterator1, class _InputIterator2, class _Tp,
00041               class _BinaryOperation1, class _BinaryOperation2>
00042         GIL_FORCEINLINE
00043     static _Tp apply( _InputIterator1 __first1, 
00044                       _InputIterator2 __first2, _Tp __init, 
00045                       _BinaryOperation1 __binary_op1,
00046                       _BinaryOperation2 __binary_op2)
00047         {
00048         __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
00049         return inner_product_k_t<Size-1>::template apply(__first1+1,__first2+1,__init,
00050                                                          __binary_op1, __binary_op2);
00051     }
00052 };
00053 
00054 template <>
00055 struct inner_product_k_t<0>
00056 {
00057     template <class _InputIterator1, class _InputIterator2, class _Tp,
00058               class _BinaryOperation1, class _BinaryOperation2>
00059         GIL_FORCEINLINE
00060     static _Tp apply( _InputIterator1 __first1, 
00061                       _InputIterator2 __first2, _Tp __init, 
00062                       _BinaryOperation1 __binary_op1,
00063                       _BinaryOperation2 __binary_op2 )
00064         {
00065         return __init;
00066     }
00067 };
00068 } // namespace detail
00069 
00070 /// static version of std::inner_product
00071 template <std::size_t Size,
00072           class _InputIterator1, class _InputIterator2, class _Tp,
00073           class _BinaryOperation1, class _BinaryOperation2>
00074 GIL_FORCEINLINE
00075 _Tp inner_product_k( _InputIterator1 __first1, 
00076                      _InputIterator2 __first2,
00077                      _Tp __init, 
00078                      _BinaryOperation1 __binary_op1,
00079                      _BinaryOperation2 __binary_op2 )
00080 {
00081     return detail::inner_product_k_t<Size>::template apply(__first1,__first2,__init,
00082                                                            __binary_op1, __binary_op2);
00083 }
00084 
00085 
00086 }
00087 }
00088 
00089 
00090 #endif
00091