TuttleOFX  1
pow.hpp
Go to the documentation of this file.
00001 #ifndef _TERRY_NUMERIC_POW_HPP_
00002 #define _TERRY_NUMERIC_POW_HPP_
00003 
00004 #include <terry/globals.hpp>
00005 
00006 #include <boost/gil/channel.hpp>
00007 #include <boost/gil/pixel.hpp>
00008 #include <boost/math/special_functions/pow.hpp>
00009 
00010 #include <functional>
00011 
00012 namespace terry {
00013 using namespace boost::gil;
00014 
00015 namespace numeric {
00016 
00017 /// \ingroup ChannelNumericOperations
00018 /// structure to compute pow on a channel
00019 /// this is a generic implementation; user should specialize it for better performance
00020 template <typename Channel, int n,typename ChannelR>
00021 struct channel_pow_t : public std::unary_function<Channel,ChannelR> {
00022         GIL_FORCEINLINE
00023     ChannelR operator()(typename channel_traits<Channel>::const_reference ch) const {
00024         return boost::math::pow<n>(ChannelR(ch));
00025     }
00026 };
00027 
00028 /// \ingroup PixelNumericOperations
00029 /// \brief construct to compute pow on a pixel
00030 template <typename PixelRef, int n, typename PixelR=PixelRef> // models pixel concept
00031 struct pixel_pow_t {
00032         GIL_FORCEINLINE
00033     PixelR operator () (const PixelRef& p) const {
00034         PixelR result;
00035         static_transform(p,result, channel_pow_t<typename channel_type<PixelRef>::type,
00036                                                                          n,
00037                                                                                                  typename channel_type<PixelR>::type>());
00038         return result;
00039     }
00040 };
00041 
00042 /// \ingroup ChannelNumericOperations
00043 /// structure to compute pow of a scalar by the pixel value
00044 /// this is a generic implementation; user should specialize it for better performance
00045 template <typename Channel,typename Scalar,typename ChannelR>
00046 struct channel_scalar_pow_t : public std::binary_function<Channel,Scalar,ChannelR> {
00047         GIL_FORCEINLINE
00048     ChannelR operator()(typename channel_traits<Channel>::const_reference ch,
00049                         const Scalar& s) const {
00050         typedef typename floating_channel_type_t<ChannelR>::type ChannelRFloat;
00051         return std::pow(s, ChannelRFloat(ch));
00052     }
00053 };
00054 
00055 /// \ingroup PixelNumericOperations
00056 /// \brief construct to compute pow of a scalar by the pixel value
00057 template <typename PixelRef, // models pixel concept
00058           typename Scalar,   // models a scalar type
00059           typename PixelR=PixelRef>   // models pixel value concept
00060 struct pixel_scalar_pow_t {
00061         GIL_FORCEINLINE
00062     PixelR operator () (const PixelRef& p,
00063                         const Scalar& s) const {
00064         PixelR result;
00065         static_transform(p,result,
00066                            std::bind2nd(channel_scalar_pow_t<typename channel_type<PixelRef>::type,
00067                                                                  Scalar,
00068                                                                  typename channel_type<PixelR>::type>(),s));
00069         return result;
00070     }
00071 };
00072 
00073 }
00074 }
00075 
00076 #endif