TuttleOFX  1
SeExprProcess.tcc
Go to the documentation of this file.
00001 namespace tuttle {
00002 namespace plugin {
00003 namespace seExpr {
00004 
00005 template<class View>
00006 SeExprProcess<View>::SeExprProcess( SeExprPlugin &effect )
00007         : ImageGilProcessor<View>( effect, eImageOrientationIndependant )
00008         , _plugin( effect )
00009 {
00010         this->setNoMultiThreading();
00011 }
00012 
00013 template<class View>
00014 void SeExprProcess<View>::setup( const OFX::RenderArguments& args )
00015 {
00016         ImageGilProcessor<View>::setup( args );
00017         _params = _plugin.getProcessParams( args.renderScale );
00018 
00019         rod = _plugin._clipDst->getCanonicalRod( args.time );
00020 
00021         _time = args.time;
00022         
00023         TUTTLE_TLOG( TUTTLE_INFO, _params._code );
00024 
00025         ImageSynthExpr expr( _params._code );
00026         expr.vars["u"] = ImageSynthExpr::Var( _params._paramTextureOffset.x );
00027         expr.vars["v"] = ImageSynthExpr::Var( _params._paramTextureOffset.y );
00028         expr.vars["w"] = ImageSynthExpr::Var( rod.x2 - rod.x1 );
00029         expr.vars["h"] = ImageSynthExpr::Var( rod.y2 - rod.y1 );
00030         expr.vars["frame"] = ImageSynthExpr::Var( _time );
00031 
00032         bool valid = expr.isValid();
00033         if( !valid )
00034         {
00035                 TUTTLE_LOG( TUTTLE_ERROR, "Invalid expression" );
00036                 TUTTLE_LOG( TUTTLE_ERROR, expr.parseError() );
00037         }
00038 }
00039 
00040 
00041 /**
00042  * @brief Function called by rendering thread each time a process must be done.
00043  * @param[in] procWindowRoW  Processing window
00044  */
00045 template<class View>
00046 void SeExprProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW )
00047 {
00048         using namespace boost::gil;
00049         OfxRectI procWindowOutput = this->translateRoWToOutputClipCoordinates( procWindowRoW );
00050         const OfxPointI procWindowSize = {
00051                 procWindowRoW.x2 - procWindowRoW.x1,
00052                 procWindowRoW.y2 - procWindowRoW.y1
00053         };
00054 
00055         ImageSynthExpr expr( _params._code );
00056         expr.vars["u"] = ImageSynthExpr::Var( _params._paramTextureOffset.x );
00057         expr.vars["v"] = ImageSynthExpr::Var( _params._paramTextureOffset.y );
00058         expr.vars["w"] = ImageSynthExpr::Var( rod.x2 - rod.x1 );
00059         expr.vars["h"] = ImageSynthExpr::Var( rod.y2 - rod.y1 );
00060         expr.vars["frame"] = ImageSynthExpr::Var( _time );
00061 
00062         double one_over_width  = 1.0 / procWindowSize.x;
00063         double one_over_height = 1.0 / procWindowSize.y;
00064         double& u = expr.vars["u"].val;
00065         double& v = expr.vars["v"].val;
00066 
00067         for( int y = procWindowOutput.y1;
00068                          y < procWindowOutput.y2;
00069                          ++y )
00070         {
00071                 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y );
00072                 for( int x = procWindowOutput.x1;
00073                          x < procWindowOutput.x2;
00074                          ++x, ++dst_it )
00075                 {
00076                         u = one_over_width  * ( x + .5 - _params._paramTextureOffset.x );
00077                         v = one_over_height * ( y + .5 - _params._paramTextureOffset.y );
00078                         SeVec3d result = expr.evaluate();
00079 
00080                         color_convert( rgba32f_pixel_t( (float)result[0], (float)result[1], (float)result[2], 1.0 ), *dst_it );
00081                 }
00082                 if( this->progressForward( procWindowSize.x ) )
00083                         return;
00084         }
00085 }
00086 
00087 }
00088 }
00089 }