TuttleOFX
1
|
00001 #ifndef _TERRY_SAMPLER_RESAMPLE_HPP_ 00002 #define _TERRY_SAMPLER_RESAMPLE_HPP_ 00003 00004 #include <terry/math/Rect.hpp> 00005 00006 #include <terry/sampler/all.hpp> 00007 #include <terry/sampler/details.hpp> 00008 #include <terry/sampler/sampler.hpp> 00009 00010 00011 namespace terry { 00012 namespace sampler { 00013 00014 /** 00015 * @brief Set each pixel in the destination view as the result of a sampling function over the transformed coordinates of the source view 00016 * @ingroup ImageAlgorithms 00017 * 00018 * The provided implementation works for 2D image views only 00019 */ 00020 template< 00021 typename Sampler, // Models SamplerConcept 00022 typename SrcView, // Models RandomAccess2DImageViewConcept 00023 typename DstView, // Models MutableRandomAccess2DImageViewConcept 00024 typename MapFn, 00025 typename Progress> 00026 // Models MappingFunctionConcept 00027 void resample_pixels_progress( 00028 const SrcView& src_view, const DstView& dst_view, 00029 const MapFn& dst_to_src, const terry::Rect<std::ssize_t>& procWindow, 00030 const EParamFilterOutOfImage& outOfImageProcess, 00031 Progress& p, 00032 Sampler sampler = Sampler() ) 00033 { 00034 typedef typename DstView::point_t Point2; 00035 typedef typename DstView::value_type Pixel; 00036 00037 terry::point2<std::ssize_t> procWindowSize = procWindow.size(); 00038 00039 Point2 dst_p; 00040 Pixel black; 00041 color_convert( boost::gil::rgba32f_pixel_t( 0.0, 0.0, 0.0, 0.0 ), black ); 00042 for( dst_p.y = procWindow.y1; dst_p.y < procWindow.y2; ++dst_p.y ) 00043 { 00044 typename DstView::x_iterator xit = dst_view.row_begin( dst_p.y ); 00045 for( dst_p.x = procWindow.x1; dst_p.x < procWindow.x2; ++dst_p.x ) 00046 { 00047 00048 if( ! sample( sampler, src_view, transform( dst_to_src, dst_p ), xit[dst_p.x], outOfImageProcess ) ) 00049 { 00050 xit[dst_p.x] = black; // if it is outside of the source image 00051 } 00052 } 00053 if( p.progressForward( procWindowSize.x ) ) 00054 return; 00055 } 00056 } 00057 00058 } 00059 } 00060 00061 #endif 00062