TuttleOFX  1
LocalMaximaProcess.tcc
Go to the documentation of this file.
00001 #include "LocalMaximaPlugin.hpp"
00002 
00003 #include <tuttle/plugin/exceptions.hpp>
00004 #include <tuttle/plugin/numeric/rectOp.hpp>
00005 #include <tuttle/plugin/ofxToGil/rect.hpp>
00006 
00007 #include <terry/globals.hpp>
00008 #include <terry/filter/localMaxima.hpp>
00009 #include <terry/algorithm/transform_pixels_progress.hpp>
00010 #include <terry/numeric/operations.hpp>
00011 
00012 #include <boost/gil/image_view_factory.hpp>
00013 #include <boost/gil/algorithm.hpp>
00014 
00015 #include <boost/math/constants/constants.hpp>
00016 
00017 namespace tuttle {
00018 namespace plugin {
00019 namespace localmaxima {
00020 
00021 template<class SView, class DView>
00022 LocalMaximaProcess<SView, DView>::LocalMaximaProcess( LocalMaximaPlugin &effect )
00023 : ImageGilFilterProcessor<SView, DView>( effect, eImageOrientationIndependant )
00024 , _plugin( effect )
00025 {
00026 }
00027 
00028 template<class SView, class DView>
00029 void LocalMaximaProcess<SView, DView>::setup( const OFX::RenderArguments& args )
00030 {
00031         ImageGilFilterProcessor<SView, DView>::setup( args );
00032         _params = _plugin.getProcessParams( args.renderScale );
00033 }
00034 
00035 /**
00036  * @brief Function called by rendering thread each time a process must be done.
00037  * @param[in] procWindowRoW  Processing window
00038  */
00039 template<class SView, class DView>
00040 void LocalMaximaProcess<SView, DView>::multiThreadProcessImages( const OfxRectI& procWindowRoW )
00041 {
00042         using namespace terry;
00043         using namespace terry::algorithm;
00044         using namespace terry::numeric;
00045         
00046         namespace bm = boost::math;
00047         
00048         typedef point2<std::ptrdiff_t> Point2;
00049         
00050         const OfxRectI procWindowOutput = translateRegion( procWindowRoW, this->_dstPixelRod );
00051         const OfxPointI procWindowSize = {
00052                 procWindowRoW.x2 - procWindowRoW.x1,
00053                 procWindowRoW.y2 - procWindowRoW.y1
00054         };
00055         
00056         static const unsigned int border = 1;
00057         const OfxRectI srcRodCrop = rectangleReduce( this->_srcPixelRod, border );
00058         const OfxRectI procWindowRoWCrop = rectanglesIntersection( procWindowRoW, srcRodCrop );
00059 
00060 //      const OfxRectI procWindowOutputCrop = translateRegion( procWindowRoWCrop, this->_dstPixelRod );
00061 
00062         if( _params._border == eParamBorderBlack )
00063         {
00064                 DView dst = subimage_view( this->_dstView, procWindowOutput.x1, procWindowOutput.y1,
00065                                                                                                   procWindowSize.x, procWindowSize.y );
00066 
00067                 // fill borders
00068                 DPixel pixelZero; pixel_zeros_t<DPixel>()( pixelZero );
00069                 boost::gil::fill_pixels( dst, pixelZero );
00070         }
00071 
00072         transform_pixels_locator_progress(
00073                 this->_srcView, ofxToGil(this->_srcPixelRod),
00074                 this->_dstView, ofxToGil(this->_dstPixelRod),
00075                 ofxToGil(procWindowRoWCrop),
00076                 terry::filter::pixel_locator_gradientLocalMaxima_t<SView,DView>(this->_srcView),
00077                 this->getOfxProgress()
00078                 );
00079 }
00080 
00081 }
00082 }
00083 }