TuttleOFX  1
fill.hpp
Go to the documentation of this file.
00001 // Copyright Tom Brinkman 2008. Distributed under the Boost
00002 // Software License, Version 1.0. (See accompanying
00003 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00004 
00005 #ifndef _fill_hpp_
00006 #define _fill_hpp_
00007 
00008 #include <boost/function.hpp>
00009 #include <boost/gil/gil_all.hpp>
00010 
00011 namespace layer
00012 {
00013 
00014 template <typename view_t>
00015 struct fill
00016 {
00017         typedef typename view_t::value_type value_type_t;
00018         value_type_t color;
00019         fill(value_type_t color) : color(color) {}
00020 
00021         void operator()(view_t& view)
00022         {
00023                 boost::gil::fill_pixels(view,color);
00024         }
00025 };
00026 
00027 template <typename view_t>
00028 struct fill_horizontal
00029 {
00030         typedef boost::function<void (view_t&)> funct_t;
00031         double value1;
00032         double value2;
00033         double minvalue;
00034         double maxvalue;
00035         funct_t funct;
00036         fill_horizontal(funct_t funct, double value1, double value2, double minvalue, double maxvalue) :
00037                 funct(funct), minvalue(minvalue), maxvalue(maxvalue), value1(value1), value2(value2) {}
00038 
00039         void operator()(view_t& view)
00040         {
00041                 using namespace boost::gil;
00042 
00043                 double diff = maxvalue-minvalue;
00044                 if (diff == 0)
00045                         return;
00046 
00047                 double rval = 1-((value1-minvalue)/(diff));
00048                 int y1 = (int)(rval*(view.height()-1));
00049 
00050                 rval = 1-((value2-minvalue)/(diff));
00051                 int y2 = (int)(rval*(view.height()-1));
00052 
00053                 int yt = (std::min)(y1,y2);
00054                 int yb = (std::max)(y1,y2);
00055 
00056                 view_t v2 = subimage_view(view,0,yt,view.width(),yb-yt);
00057                 funct(v2);
00058         }
00059 };
00060 
00061 }
00062 
00063 #endif