TuttleOFX  1
WarpAlgorithm.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_PLUGIN_WARP_ALGORITHM_HPP_
00002 #define _TUTTLE_PLUGIN_WARP_ALGORITHM_HPP_
00003 
00004 #include "TPS/tps.hpp"
00005 
00006 #include <terry/channel.hpp>
00007 #include <terry/numeric/operations.hpp>
00008 #include <terry/numeric/assign.hpp>
00009 
00010 
00011 namespace boost {
00012 namespace gil {
00013 
00014 template <typename F, typename F2>
00015 inline boost::gil::point2<F> transform( const tuttle::plugin::warp::TPS_Morpher<F>& op, const boost::gil::point2<F2>& src )
00016 {
00017         return op( src );
00018 }
00019 
00020 }
00021 }
00022 
00023 
00024 namespace tuttle {
00025 namespace plugin {
00026 namespace warp {
00027 
00028 template<typename Pixel>
00029 struct pixel_merge_t
00030 {
00031    const double _ratioA;
00032    const double _ratioB;
00033 
00034    pixel_merge_t( const double ratio )
00035    : _ratioA(1.0-ratio),
00036     _ratioB(ratio)
00037    {
00038    }
00039 
00040    GIL_FORCEINLINE
00041    Pixel operator()( const Pixel& srcA, const Pixel& srcB ) const
00042    {
00043        using namespace boost::gil;
00044        using namespace terry::numeric;
00045        Pixel res;
00046        // res = (srcA * _ratioA) + (srcB * _ratioB)
00047        pixel_assigns_t<Pixel,Pixel>()(
00048            pixel_plus_t<Pixel,Pixel,Pixel>()(
00049                pixel_multiplies_scalar_t<Pixel,double,Pixel>()(
00050                    srcA,
00051                    _ratioA
00052                    ),
00053                pixel_multiplies_scalar_t<Pixel,double,Pixel>()(
00054                    srcB,
00055                    _ratioB
00056                    )
00057                ),
00058            res );
00059        return res;
00060    }
00061 };
00062 
00063 }
00064 }
00065 }
00066 
00067 #endif