TuttleOFX
1
|
00001 #ifndef _TERRY_GENERATOR_COLORBARS_HPP_ 00002 #define _TERRY_GENERATOR_COLORBARS_HPP_ 00003 00004 #include <boost/gil/utilities.hpp> 00005 00006 #include <cmath> 00007 00008 namespace terry { 00009 namespace generator { 00010 00011 // Models a Unary Function 00012 template <typename Pixel> 00013 // Models PixelValueConcept 00014 struct ColorBarsFunctor 00015 { 00016 //typedef point2<ptrdiff_t> point_t; 00017 typedef boost::gil::point2<double> point_t; 00018 00019 typedef ColorBarsFunctor const_t; 00020 typedef Pixel value_type; 00021 typedef value_type reference; 00022 typedef value_type const_reference; 00023 typedef point_t argument_type; 00024 typedef reference result_type; 00025 BOOST_STATIC_CONSTANT( bool, is_mutable = false ); 00026 00027 int width1; 00028 int width2; 00029 int width3; 00030 int width4; 00031 int width5; 00032 int width6; 00033 00034 float level; 00035 00036 ColorBarsFunctor() {} 00037 ColorBarsFunctor( int width, bool is75percents ) : 00038 width1 ( 1.0 / 7 * width ), 00039 width2 ( 2.0 / 7 * width ), 00040 width3 ( 3.0 / 7 * width ), 00041 width4 ( 4.0 / 7 * width ), 00042 width5 ( 5.0 / 7 * width ), 00043 width6 ( 6.0 / 7 * width ), 00044 level ( is75percents ? 0.75 : 1.0 ) 00045 {} 00046 00047 Pixel operator()( const point_t& p ) const 00048 { 00049 Pixel pixel; 00050 00051 float red = 0.0; 00052 float green = 0.0; 00053 float blue = 0.0; 00054 00055 if( p.x < width4 ) 00056 { 00057 green = level; 00058 } 00059 if( p.x < width2 || ( p.x >= width4 && p.x < width6 ) ) 00060 { 00061 red = level; 00062 } 00063 if( p.x < width1 || ( p.x >= width2 && p.x < width3 ) || ( p.x >= width4 && p.x < width5 ) || ( p.x >= width6 ) ) 00064 { 00065 blue = level; 00066 } 00067 00068 color_convert( rgba32f_pixel_t( red, green, blue, 1 ), pixel ); 00069 return pixel; 00070 } 00071 00072 }; 00073 00074 } 00075 } 00076 00077 #endif