TuttleOFX
1
|
00001 #ifndef _TERRY_GENERATOR_COLORCUBE_HPP_ 00002 #define _TERRY_GENERATOR_COLORCUBE_HPP_ 00003 00004 #include <boost/gil/utilities.hpp> 00005 00006 #include <terry/numeric/operations.hpp> 00007 #include <terry/numeric/operations_assign.hpp> 00008 #include <terry/numeric/assign.hpp> 00009 #include <terry/numeric/init.hpp> 00010 00011 #include <cmath> 00012 00013 namespace terry { 00014 namespace generator { 00015 00016 // Models a Unary Function 00017 template <typename Pixel> 00018 // Models PixelValueConcept 00019 struct ColorCubeFunctor 00020 { 00021 typedef boost::gil::point2<double> point_t; 00022 00023 typedef ColorCubeFunctor const_t; 00024 typedef Pixel value_type; 00025 typedef value_type reference; 00026 typedef value_type const_reference; 00027 typedef point_t argument_type; 00028 typedef reference result_type; 00029 BOOST_STATIC_CONSTANT( bool, is_mutable = false ); 00030 00031 point_t tileSize; 00032 double scale; 00033 size_t step; 00034 00035 ColorCubeFunctor() {} 00036 ColorCubeFunctor( const point_t& tileSize, const size_t step ) : 00037 tileSize( tileSize ), 00038 scale( 1.0 / tileSize.x ), 00039 step ( step ) 00040 {} 00041 00042 Pixel operator()( const point_t& p ) const 00043 { 00044 double x = scale * p.x - 0.5; 00045 double y = scale * p.y - 0.5; 00046 00047 if( std::abs( x ) > 0.5 || std::abs( y ) > 0.5 ) 00048 { 00049 Pixel pixel; 00050 numeric::pixel_zeros_t<Pixel>( )( pixel ); 00051 return pixel; 00052 } 00053 00054 size_t cubeStep = sqrt( (float) step ); 00055 Pixel pixel; 00056 00057 float red = 0.0; 00058 float green = 0.0; 00059 float blue = 0.0; 00060 00061 float xStep = floor( scale * p.x * cubeStep ); 00062 float yStep = floor( scale * p.y * cubeStep ); 00063 00064 red = floor( scale * p.x * step * cubeStep ) / ( step - 1 ) - xStep - xStep * 1 / ( step - 1 ); 00065 green = floor( scale * p.y * step * cubeStep ) / ( step - 1 ) - yStep - yStep * 1 / ( step - 1 ); 00066 blue = xStep / ( step - 1 ) + cubeStep * yStep / ( step - 1 ); 00067 00068 color_convert( rgba32f_pixel_t( red, green, blue, 1 ), pixel ); 00069 return pixel; 00070 } 00071 00072 }; 00073 00074 } 00075 } 00076 00077 #endif