TuttleOFX
1
|
00001 #ifndef _TERRY_GENERATOR_COLORWHEEL_HPP_ 00002 #define _TERRY_GENERATOR_COLORWHEEL_HPP_ 00003 00004 #include <boost/gil/color_convert.hpp> 00005 #include <boost/gil/extension/color/hsl.hpp> 00006 #include <boost/math/constants/constants.hpp> 00007 00008 #include <terry/numeric/operations.hpp> 00009 #include <terry/numeric/operations_assign.hpp> 00010 #include <terry/numeric/assign.hpp> 00011 #include <terry/numeric/init.hpp> 00012 00013 #include <cmath> 00014 00015 namespace terry { 00016 namespace generator { 00017 00018 // Models a Unary Function 00019 template <typename Pixel> 00020 // Models PixelValueConcept 00021 struct ColorWheelFunctor 00022 { 00023 //typedef point2<ptrdiff_t> point_t; 00024 typedef boost::gil::point2<double> point_t; 00025 00026 typedef ColorWheelFunctor const_t; 00027 typedef Pixel value_type; 00028 typedef value_type reference; 00029 typedef value_type const_reference; 00030 typedef point_t argument_type; 00031 typedef reference result_type; 00032 BOOST_STATIC_CONSTANT( bool, is_mutable = false ); 00033 00034 point_t tile_size; 00035 double scale; 00036 bool blackCenter; 00037 00038 ColorWheelFunctor() {} 00039 ColorWheelFunctor( const point_t& tileSize, const bool blackCenter = false ) : 00040 tile_size( tileSize ), 00041 scale( 1.0 / tileSize.x ), 00042 blackCenter( blackCenter ) 00043 {} 00044 00045 Pixel operator()( const point_t& p ) const 00046 { 00047 double x = scale * p.x - 0.5; 00048 double y = scale * p.y - 0.5; 00049 00050 Pixel pixel; 00051 00052 if( sqrt( y * y + x * x ) > 0.5 ) 00053 { 00054 numeric::pixel_zeros_t<Pixel>( )( pixel ); 00055 return pixel; 00056 } 00057 00058 float h = - atan( y / x ); 00059 float s = 1.0; 00060 float l = 1.0; 00061 00062 if( x >= 0 ) 00063 { 00064 h += boost::math::constants::pi<double>() ; 00065 } 00066 h /= ( 2.0 * boost::math::constants::pi<double>() ); 00067 00068 l = sqrt( y * y + x * x ); 00069 00070 using namespace hsl_color_space; 00071 00072 hsl32f_pixel_t hsl( h, s, l ); 00073 rgb32f_pixel_t rgb; 00074 rgb32f_pixel_t white( 1.0, 1.0, 1.0 ); 00075 rgba32f_pixel_t rgba; 00076 00077 color_convert( hsl, rgb ); 00078 00079 if( ! blackCenter ) 00080 { 00081 rgb = numeric::pixel_minus_t< rgb32f_pixel_t, rgb32f_pixel_t, rgb32f_pixel_t>()( white, rgb ); 00082 } 00083 00084 color_convert( rgb, rgba ); 00085 color_convert( rgba, pixel ); 00086 00087 return pixel; 00088 } 00089 00090 }; 00091 00092 } 00093 } 00094 00095 #endif