TuttleOFX  1
checkerboard.hpp
Go to the documentation of this file.
00001 #ifndef _TERRY_GENERATOR_CHECKERBOARD_HPP_
00002 #define _TERRY_GENERATOR_CHECKERBOARD_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 CheckerboardFunctor
00015 {
00016         //typedef point2<ptrdiff_t>    point_t;
00017         typedef boost::gil::point2<double>    point_t;
00018 
00019         typedef CheckerboardFunctor const_t;
00020         typedef P 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         value_type _in_color, _out_color;
00028         point_t _tile_size, _tile_size_2;
00029 
00030         CheckerboardFunctor() {}
00031         CheckerboardFunctor( const point_t& tileSize, const value_type& in_color, const value_type& out_color )
00032                 : _in_color   ( in_color )
00033                 , _out_color  ( out_color )
00034                 , _tile_size  ( tileSize )
00035                 , _tile_size_2( tileSize * 2.0 )
00036         {
00037                 
00038         }
00039 
00040         result_type operator()( const point_t& p ) const
00041         {
00042                 const point_t mp( fmod( p.x, _tile_size_2.x ), fmod( p.y, _tile_size_2.y ) );
00043 
00044                 /*
00045                 TUTTLE_LOG_TRACE( "__________" );
00046                 TUTTLE_LOG_TRACE( "p.x: " << p.x << " p.y: " << p.y );
00047                 TUTTLE_LOG_TRACE( "mp.x: " << mp.x << " mp.y: " << mp.y );
00048                 TUTTLE_LOG_TRACE( "_tile_size.x: " << _tile_size.x << " _tile_size.y: " << _tile_size.y );*/
00049                 
00050                 if( ( mp.x > _tile_size.x ) != ( mp.y > _tile_size.y ) )
00051                         return _in_color;
00052                 return _out_color;
00053         }
00054 
00055 };
00056 
00057 }
00058 }
00059 
00060 #endif