TuttleOFX
1
|
00001 #ifndef _TERRY_GENERATOR_CONSTANT_HPP_ 00002 #define _TERRY_GENERATOR_CONSTANT_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 P> 00013 // Models PixelValueConcept 00014 struct ConstantFunctor 00015 { 00016 typedef boost::gil::point2<double> point_t; 00017 typedef ConstantFunctor const_t; 00018 typedef P value_type; 00019 typedef value_type reference; 00020 typedef value_type const_reference; 00021 typedef point_t argument_type; 00022 typedef reference result_type; 00023 BOOST_STATIC_CONSTANT( bool, is_mutable = false ); 00024 00025 value_type _color; 00026 00027 ConstantFunctor() {} 00028 ConstantFunctor( const value_type& color ) 00029 : _color( color ) 00030 { 00031 } 00032 00033 result_type operator()( const point_t& ) const 00034 { 00035 return _color; 00036 } 00037 00038 }; 00039 00040 00041 template <typename Pixel> 00042 struct ConstantColorViewFactory 00043 { 00044 typedef terry::generator::ConstantFunctor<Pixel> ConstantFunctorT; 00045 typedef typename ConstantFunctorT::point_t Point; 00046 typedef boost::gil::virtual_2d_locator<ConstantFunctorT, false> Locator; 00047 typedef boost::gil::image_view<Locator> ConstantVirtualView; 00048 00049 static ConstantVirtualView getView( const Pixel& color ) 00050 { 00051 boost::function_requires<PixelLocatorConcept<Locator> >(); 00052 gil_function_requires < StepIteratorConcept<typename Locator::x_iterator> >(); 00053 00054 return ConstantVirtualView( Point( 1, 1 ), Locator( Point( 0, 0 ), Point( 1, 1 ), ConstantFunctorT( color ) ) ); 00055 } 00056 }; 00057 00058 template <typename Pixel> 00059 typename ConstantColorViewFactory<Pixel>::ConstantVirtualView constantColorView( const Pixel& color ) 00060 { 00061 return ConstantColorViewFactory<Pixel>::getView( color ); 00062 } 00063 00064 00065 } 00066 } 00067 00068 #endif