TuttleOFX  1
MathOperatorPlugin.cpp
Go to the documentation of this file.
00001 #include "MathOperatorPlugin.hpp"
00002 #include "MathOperatorProcess.hpp"
00003 #include "MathOperatorDefinitions.hpp"
00004 
00005 #include <boost/gil/gil_all.hpp>
00006 
00007 namespace tuttle {
00008 namespace plugin {
00009 namespace mathOperator {
00010 
00011 
00012 MathOperatorPlugin::MathOperatorPlugin( OfxImageEffectHandle handle )
00013 : ImageEffectGilPlugin( handle )
00014 {
00015         _operator        = fetchChoiceParam( kMathOperatorOperator );
00016         _mathOperatorType   = fetchChoiceParam( kMathOperatorType );
00017 
00018         _master          = fetchDoubleParam( kMasterValue );
00019         _red             = fetchDoubleParam( kRedValue );
00020         _green           = fetchDoubleParam( kGreenValue );
00021         _blue            = fetchDoubleParam( kBlueValue );
00022         _alpha           = fetchDoubleParam( kAlphaValue );
00023 
00024         _redSelect       = fetchBooleanParam( kRedChannel );
00025         _greenSelect     = fetchBooleanParam( kGreenChannel );
00026         _blueSelect      = fetchBooleanParam( kBlueChannel );
00027         _alphaSelect     = fetchBooleanParam( kAlphaChannel );
00028 
00029         updateInterface();
00030 }
00031 
00032 MathOperatorProcessParams<MathOperatorPlugin::Scalar> MathOperatorPlugin::getProcessParams( const OfxPointD& renderScale ) const
00033 {
00034         MathOperatorProcessParams<Scalar> params;
00035         EMathOperatorType type;
00036 
00037         params.op  = static_cast<EMathOperatorMathOperator>( _operator->getValue() );
00038 
00039         type   = static_cast<EMathOperatorType>( _mathOperatorType->getValue() );
00040         
00041         params.bRProcess = _redSelect   -> getValue();
00042         params.bGProcess = _greenSelect -> getValue();
00043         params.bBProcess = _blueSelect  -> getValue();
00044         params.bAProcess = _alphaSelect -> getValue();
00045 
00046         switch( type )
00047         {
00048                 case eMathOperatorTypeRgba:
00049                         switch( params.op )
00050                         {
00051                                 case eMathOperatorOperatorPlus     :
00052                                 case eMathOperatorOperatorMultiply :
00053                                 case eMathOperatorOperatorPow      :
00054                                         params.iRMathOperator             =
00055                                                 params.iGMathOperator         =
00056                                                         params.iBMathOperator     =
00057                                                                 params.iAMathOperator = _master->getValue();
00058                                         break;
00059                                 case eMathOperatorOperatorSqrt     :
00060                                 case eMathOperatorOperatorLog      :
00061                                 case eMathOperatorOperatorLn       :
00062                                         params.iRMathOperator             =
00063                                                 params.iGMathOperator         =
00064                                                         params.iBMathOperator     =
00065                                                                 params.iAMathOperator = 1.0; // means process channels
00066                                         break;
00067                         }
00068 
00069                         break;
00070                 case eMathOperatorTypeRgb:
00071                         switch( params.op )
00072                         {
00073                                 case eMathOperatorOperatorPlus     :
00074                                 case eMathOperatorOperatorMultiply :
00075                                 case eMathOperatorOperatorPow      :
00076                                         params.iRMathOperator             =
00077                                                 params.iGMathOperator         =
00078                                                         params.iBMathOperator     = _master->getValue();
00079                                                                 params.iAMathOperator = 1.0;
00080                                         break;
00081                                 case eMathOperatorOperatorSqrt     :
00082                                 case eMathOperatorOperatorLog      :
00083                                 case eMathOperatorOperatorLn       :
00084                                         params.iRMathOperator             =
00085                                                 params.iGMathOperator         =
00086                                                         params.iBMathOperator     = 1.0; // means process channels
00087                                         params.iAMathOperator = 0.0; // means not process the alpha channel
00088                                         break;
00089                         }
00090 
00091                         if( params.op == eMathOperatorOperatorPlus ) params.iAMathOperator = 0.0;
00092                         params.bAProcess = false;
00093 
00094                 case eMathOperatorTypeChannels:
00095                         switch( params.op )
00096                         {
00097                                 case eMathOperatorOperatorPlus     :
00098                                 case eMathOperatorOperatorMultiply :
00099                                 case eMathOperatorOperatorPow      :
00100                                         params.iRMathOperator = _red   -> getValue();
00101                                         params.iGMathOperator = _green -> getValue();
00102                                         params.iBMathOperator = _blue  -> getValue();
00103                                         params.iAMathOperator = _alpha -> getValue();
00104                                         break;
00105                                 case eMathOperatorOperatorSqrt     :
00106                                 case eMathOperatorOperatorLog      :
00107                                 case eMathOperatorOperatorLn       :
00108                                         params.iRMathOperator             =
00109                                                 params.iGMathOperator         =
00110                                                         params.iBMathOperator     = 1.0; // means process channels
00111                                         params.iAMathOperator = 0.0; // means not process the alpha channel
00112                                         break;
00113                         }
00114 
00115                         break;
00116         }
00117         return params;
00118 }
00119 
00120 void MathOperatorPlugin::changedParam( const OFX::InstanceChangedArgs &args, const std::string &paramName )
00121 {
00122         if( paramName == kMathOperatorType )
00123         {
00124                 updateInterface();
00125         }
00126 }
00127 
00128 //bool MathOperatorPlugin::getRegionOfDefinition( const OFX::RegionOfDefinitionArguments& args, OfxRectD& rod )
00129 //{
00130 //      MathOperatorProcessParams<Scalar> params = getProcessParams();
00131 //      OfxRectD srcRod = _clipSrc->getCanonicalRod( args.time );
00132 //
00133 //      switch( params._border )
00134 //      {
00135 //              case eParamBorderPadded:
00136 //                      rod.x1 = srcRod.x1 + 1;
00137 //                      rod.y1 = srcRod.y1 + 1;
00138 //                      rod.x2 = srcRod.x2 - 1;
00139 //                      rod.y2 = srcRod.y2 - 1;
00140 //                      return true;
00141 //              default:
00142 //                      break;
00143 //      }
00144 //      return false;
00145 //}
00146 //
00147 //void MathOperatorPlugin::getRegionsOfInterest( const OFX::RegionsOfInterestArguments& args, OFX::RegionOfInterestSetter& rois )
00148 //{
00149 //      MathOperatorProcessParams<Scalar> params = getProcessParams();
00150 //      OfxRectD srcRod = _clipSrc->getCanonicalRod( args.time );
00151 //
00152 //      OfxRectD srcRoi;
00153 //      srcRoi.x1 = srcRod.x1 - 1;
00154 //      srcRoi.y1 = srcRod.y1 - 1;
00155 //      srcRoi.x2 = srcRod.x2 + 1;
00156 //      srcRoi.y2 = srcRod.y2 + 1;
00157 //      rois.setRegionOfInterest( *_clipSrc, srcRoi );
00158 //}
00159 
00160 bool MathOperatorPlugin::isIdentity( const OFX::RenderArguments& args, OFX::Clip*& identityClip, double& identityTime )
00161 {
00162 //      MathOperatorProcessParams<Scalar> params = getProcessParams();
00163 //      if( params._in == params._out )
00164 //      {
00165 //              identityClip = _clipSrc;
00166 //              identityTime = args.time;
00167 //              return true;
00168 //      }
00169         return false;
00170 }
00171 
00172 /**
00173  * @brief The overridden render function
00174  * @param[in]   args     Rendering parameters
00175  */
00176 void MathOperatorPlugin::render( const OFX::RenderArguments &args )
00177 {
00178         doGilRender<MathOperatorProcess>( *this, args );
00179 }
00180 
00181 void MathOperatorPlugin::updateInterface()
00182 {
00183         bool bMaster = false;
00184         bool bRGBA   = false;
00185         bool bAlpha  = false;
00186         switch( getMathOperatorType() )
00187         {
00188                 case eMathOperatorTypeRgba:
00189                         bMaster = false;
00190                         bRGBA   = true;
00191                         bAlpha  = false;
00192                         break;
00193                 case eMathOperatorTypeRgb:
00194                         bMaster = false;
00195                         bRGBA   = true;
00196                         bAlpha  = true;
00197                         break;
00198                 case eMathOperatorTypeChannels:
00199                         bMaster = true;
00200                         bRGBA   = false;
00201                         bAlpha  = false;
00202                         break;
00203         }
00204         _master      -> setIsSecretAndDisabled( bMaster );
00205         _red         -> setIsSecretAndDisabled( bRGBA );
00206         _green       -> setIsSecretAndDisabled( bRGBA );
00207         _blue        -> setIsSecretAndDisabled( bRGBA );
00208         _alpha       -> setIsSecretAndDisabled( bRGBA );
00209 
00210         _alphaSelect -> setIsSecretAndDisabled( bAlpha );
00211 }
00212 
00213 
00214 }
00215 }
00216 }