TuttleOFX  1
init.hpp
Go to the documentation of this file.
00001 #ifndef _TERRY_NUMERIC_INIT_HPP_
00002 #define _TERRY_NUMERIC_INIT_HPP_
00003 
00004 #include <terry/globals.hpp>
00005 
00006 #include <boost/gil/channel.hpp>
00007 #include <boost/gil/pixel.hpp>
00008 
00009 #include <functional>
00010 
00011 namespace terry {
00012 using namespace boost::gil;
00013 
00014 namespace numeric {
00015 
00016 
00017 /// \ingroup ChannelNumericOperations
00018 /// structure for setting a channel to zero
00019 /// this is a generic implementation; user should specialize it for better performance
00020 template <typename Channel>
00021 struct channel_zeros_t : public std::unary_function<Channel,Channel> {
00022         GIL_FORCEINLINE
00023     typename channel_traits<Channel>::reference
00024     operator()(typename channel_traits<Channel>::reference ch) const {
00025         return ch=Channel(0);
00026     }
00027 };
00028 
00029 
00030 /// \ingroup PixelNumericOperations
00031 /// \brief construct for setting a pixel to zero (for whatever zero means)
00032 template <typename PixelRef> // models pixel concept
00033 struct pixel_zeros_t {
00034         GIL_FORCEINLINE
00035     PixelRef& operator () (PixelRef& p) const {
00036         static_for_each(p,channel_zeros_t<typename channel_type<PixelRef>::type>());
00037         return p;
00038     }
00039 };
00040 
00041 template <typename Pixel>
00042 GIL_FORCEINLINE
00043 Pixel& pixel_zeros(Pixel& p)
00044 {
00045     return pixel_zeros_t<Pixel>()(p);
00046 }
00047 
00048 template <typename Pixel>
00049 GIL_FORCEINLINE
00050 Pixel pixel_zeros()
00051 {
00052         Pixel p;
00053         return pixel_zeros_t<Pixel>()(p);
00054 }
00055 
00056 /// \ingroup ChannelNumericOperations
00057 /// structure for setting a channel to one
00058 /// this is a generic implementation; user should specialize it for better performance
00059 template <typename Channel>
00060 struct channel_ones_t : public std::unary_function<Channel,Channel> {
00061         GIL_FORCEINLINE
00062     typename channel_traits<Channel>::reference
00063     operator()(typename channel_traits<Channel>::reference ch) const {
00064         return ch=Channel(1);
00065     }
00066 };
00067 
00068 
00069 /// \ingroup PixelNumericOperations
00070 /// \brief construct for setting a pixel to zero (for whatever zero means)
00071 template <typename PixelRef> // models pixel concept
00072 struct pixel_ones_t {
00073         GIL_FORCEINLINE
00074     PixelRef& operator () (PixelRef& p) const {
00075         static_for_each(p,channel_ones_t<typename channel_type<PixelRef>::type>());
00076         return p;
00077     }
00078 };
00079 
00080 template <typename Pixel>
00081 GIL_FORCEINLINE
00082 Pixel& pixel_ones(Pixel& p)
00083 {
00084     return pixel_ones_t<Pixel>()(p);
00085 }
00086 
00087 template <typename Pixel>
00088 GIL_FORCEINLINE
00089 Pixel pixel_ones()
00090 {
00091         Pixel p;
00092         return pixel_ones_t<Pixel>()(p);
00093 }
00094 
00095 }
00096 }
00097 
00098 #endif