TuttleOFX  1
resample_subimage.hpp
Go to the documentation of this file.
00001 #ifndef _TERRY_SAMPLER_RESAMPLE_SUBIMAGE_HPP_
00002 #define _TERRY_SAMPLER_RESAMPLE_SUBIMAGE_HPP_
00003 
00004 #include "resample.hpp"
00005 
00006 #include <terry/geometry/affine.hpp>
00007 
00008 
00009 namespace terry {
00010 
00011 /**
00012  * @brief Copy into the destination a rotated rectangular region from the source, rescaling it to fit into the destination
00013  *
00014  * Extract into dst the rotated bounds [src_min..src_max] rotated at 'angle' from the source view 'src'
00015  * The source coordinates are in the coordinate space of the source image
00016  * Note that the views could also be variants (i.e. any_image_view)
00017  */
00018 template <typename Sampler, typename SrcMetaView, typename DstMetaView> 
00019 void resample_subimage( const SrcMetaView& src, const DstMetaView& dst,
00020                         double src_min_x, double src_min_y,
00021                         double src_max_x, double src_max_y,
00022                         double angle, const Sampler& sampler=Sampler() )
00023 {
00024     const double src_width  = std::max<double>( src_max_x - src_min_x - 1, 1 );
00025     const double src_height = std::max<double>( src_max_y - src_min_y - 1, 1 );
00026     const double dst_width  = std::max<double>( dst.width()-1, 1 );
00027     const double dst_height = std::max<double>( dst.height()-1, 1 );
00028 
00029     const matrix3x2<double> mat = 
00030           matrix3x2<double>::get_translate( -dst_width/2.0, -dst_height/2.0 ) *
00031           matrix3x2<double>::get_scale( src_width / dst_width, src_height / dst_height ) *
00032           matrix3x2<double>::get_rotate( -angle ) *
00033           matrix3x2<double>::get_translate( src_min_x + src_width/2.0, src_min_y + src_height/2.0 );
00034 
00035     resample_pixels( src, dst, mat, sampler );
00036 }
00037 
00038 /**
00039  * @brief Copy the source view into the destination, scaling to fit.
00040  */
00041 template <typename Sampler, typename SrcMetaView, typename DstMetaView> 
00042 void resize_view( const SrcMetaView& src, const DstMetaView& dst, const Sampler& sampler=Sampler() )
00043 {
00044     resample_subimage( src, dst, 0, 0, src.width(), src.height(), 0, sampler );
00045 }
00046 
00047 
00048 }
00049 
00050 #endif
00051