TuttleOFX  1
rainbow.hpp
Go to the documentation of this file.
00001 #ifndef _TERRY_GENERATOR_RAINBOW_HPP_
00002 #define _TERRY_GENERATOR_RAINBOW_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 RainbowFunctor
00022 {
00023     //typedef point2<ptrdiff_t>    point_t;
00024     typedef boost::gil::point2<double>    point_t;
00025 
00026     typedef RainbowFunctor 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 
00037     RainbowFunctor() {}
00038     RainbowFunctor( const point_t& tileSize ) :
00039         tile_size( tileSize ),
00040         scale( 1.0 / tileSize.x )
00041     {}
00042 
00043     Pixel operator()( const point_t& p ) const
00044     {
00045         Pixel pixel;
00046 
00047         float h = p.x / ( tile_size.x - 1 );
00048         float s = 1.0;
00049         float l = p.y / ( tile_size.y - 1 );
00050 
00051         using namespace hsl_color_space;
00052 
00053         hsl32f_pixel_t hsl( h, s, l );
00054         rgb32f_pixel_t rgb;
00055         rgba32f_pixel_t rgba;
00056 
00057         color_convert( hsl, rgb );
00058         color_convert( rgb, rgba );
00059         color_convert( rgba, pixel );
00060 
00061         return pixel;
00062     }
00063 
00064 };
00065 
00066 }
00067 }
00068 
00069 #endif