TuttleOFX
1
|
00001 #ifndef _TERRY_COLOR_GRADIENT_HPP_ 00002 #define _TERRY_COLOR_GRADIENT_HPP_ 00003 00004 #include <terry/channel.hpp> 00005 00006 #include <boost/math/constants/constants.hpp> 00007 00008 00009 namespace terry { 00010 namespace color { 00011 00012 /** 00013 * @brief Compute the direction from the (x, y) coordinates of the input vector. 00014 */ 00015 template< typename Channel> 00016 struct channel_gradientDirection_t 00017 { 00018 GIL_FORCEINLINE 00019 void operator()( const Channel& x, const Channel& y, Channel& res ) const 00020 { 00021 res = std::atan2( (double)y, (double)x ); 00022 } 00023 }; 00024 00025 /** 00026 * @brief Compute the direction from the (x, y) coordinates of the input vector, limited between 0 and PI. 00027 */ 00028 template< typename Channel> 00029 struct channel_gradientDirectionAbs_t 00030 { 00031 GIL_FORCEINLINE 00032 void operator()( const Channel& x, const Channel& y, Channel& res ) const 00033 { 00034 channel_gradientDirection_t<Channel>()(x, y, res); 00035 if( res < 0 ) 00036 res += boost::math::constants::pi<typename channel_base_type<Channel>::type>(); 00037 } 00038 }; 00039 00040 } 00041 } 00042 00043 #endif