TuttleOFX  1
SobelPluginFactory.cpp
Go to the documentation of this file.
00001 #include "SobelPluginFactory.hpp"
00002 #include "SobelPlugin.hpp"
00003 #include "SobelDefinitions.hpp"
00004 
00005 #include <ofxsImageEffect.h>
00006 
00007 namespace tuttle {
00008 namespace plugin {
00009 namespace sobel {
00010 
00011 static const bool kSupportTiles = true;
00012 
00013 
00014 /**
00015  * @brief Function called to describe the plugin main features.
00016  * @param[in, out] desc Effect descriptor
00017  */
00018 void SobelPluginFactory::describe( OFX::ImageEffectDescriptor& desc )
00019 {
00020         desc.setLabels( "TuttleSobel", "Sobel",
00021                             "Sobel" );
00022         desc.setPluginGrouping( "tuttle/image/process/filter" );
00023 
00024         // add the supported contexts, only filter at the moment
00025         desc.addSupportedContext( OFX::eContextFilter );
00026         desc.addSupportedContext( OFX::eContextGeneral );
00027 
00028         // add supported pixel depths
00029         desc.addSupportedBitDepth( OFX::eBitDepthUByte );
00030         desc.addSupportedBitDepth( OFX::eBitDepthUShort );
00031         desc.addSupportedBitDepth( OFX::eBitDepthFloat );
00032 
00033         // plugin flags
00034         desc.setSupportsTiles( kSupportTiles );
00035         desc.setRenderThreadSafety( OFX::eRenderFullySafe );
00036 }
00037 
00038 /**
00039  * @brief Function called to describe the plugin controls and features.
00040  * @param[in, out]   desc       Effect descriptor
00041  * @param[in]        context    Application context
00042  */
00043 void SobelPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc,
00044                                                   OFX::EContext context )
00045 {
00046         OFX::ClipDescriptor* srcClip = desc.defineClip( kOfxImageEffectSimpleSourceClipName );
00047         srcClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00048         srcClip->addSupportedComponent( OFX::ePixelComponentRGB );
00049         srcClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00050         srcClip->setSupportsTiles( kSupportTiles );
00051 
00052         OFX::ClipDescriptor* dstClip = desc.defineClip( kOfxImageEffectOutputClipName );
00053         dstClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00054         dstClip->addSupportedComponent( OFX::ePixelComponentRGB );
00055         dstClip->setSupportsTiles( kSupportTiles );
00056 
00057         OFX::Double2DParamDescriptor* size = desc.defineDouble2DParam( kParamSize );
00058         size->setLabel( "Size" );
00059         size->setDefault( 1.0, 1.0 );
00060         size->setRange( 0.0, 0.0, std::numeric_limits<double>::max(), std::numeric_limits<double>::max() );
00061         size->setDisplayRange( 0, 0, 10, 10 );
00062         size->setDoubleType( OFX::eDoubleTypeScale );
00063 
00064         OFX::GroupParamDescriptor* advanced = desc.defineGroupParam( kParamGroupAdvanced );
00065         advanced->setLabel( "Advanced" );
00066 
00067         OFX::BooleanParamDescriptor* unidimensional = desc.defineBooleanParam( kParamUnidimensional );
00068         unidimensional->setLabel( "Unidimensional" );
00069         unidimensional->setHint( "Instead of using a square convolution matrix, use 1D kernels." );
00070         unidimensional->setDefault( false );
00071         unidimensional->setParent( advanced );
00072 
00073         OFX::BooleanParamDescriptor* reverseKernel = desc.defineBooleanParam( kParamReverseKernel );
00074         reverseKernel->setLabel( "Reverse" );
00075         reverseKernel->setHint( "Reverse the kernel (convolution or correlation)." );
00076         reverseKernel->setDefault( false );
00077         reverseKernel->setParent( advanced );
00078 
00079         OFX::BooleanParamDescriptor* normalizedKernel = desc.defineBooleanParam( kParamNormalizedKernel );
00080         normalizedKernel->setLabel( "Normalized kernel" );
00081         normalizedKernel->setHint( "Use a normalized kernel to compute the gradient." );
00082         normalizedKernel->setDefault( true );
00083         normalizedKernel->setParent( advanced );
00084 
00085         OFX::DoubleParamDescriptor* kernelEpsilon = desc.defineDoubleParam( kParamKernelEpsilon );
00086         kernelEpsilon->setLabel( "Kernel espilon value" );
00087         kernelEpsilon->setHint( "Threshold at which we no longer consider the values of the function." );
00088         kernelEpsilon->setDefault( 0.01 );
00089         kernelEpsilon->setRange( std::numeric_limits<double>::epsilon(), 1 );
00090         kernelEpsilon->setDisplayRange( 0, 0.01 );
00091         kernelEpsilon->setParent( advanced );
00092 
00093         OFX::ChoiceParamDescriptor* pass = desc.defineChoiceParam( kParamPass );
00094         pass->setLabel( "Pass" );
00095         pass->setHint( "The sobel filter is computed using a 2D separable filter. So it consists in 2 passes.\n"
00096                        "By default we compute the 2 passes, but with this option you can separate each pass." );
00097         pass->appendOption( kParamPassFull );
00098         pass->appendOption( kParamPass1 );
00099         pass->appendOption( kParamPass2 );
00100         pass->setDefault( 0 );
00101         pass->setParent( advanced );
00102 
00103         OFX::ChoiceParamDescriptor* border = desc.defineChoiceParam( kParamBorder );
00104         border->setLabel( "Gradient border" );
00105         border->setHint( "Border method for gradient computation." );
00106         border->appendOption( kParamBorderMirror );
00107         border->appendOption( kParamBorderConstant );
00108         border->appendOption( kParamBorderBlack );
00109         border->appendOption( kParamBorderPadded );
00110 
00111         OFX::BooleanParamDescriptor* computeNorm = desc.defineBooleanParam( kParamComputeGradientNorm );
00112         computeNorm->setLabel( "Compute norm" );
00113         computeNorm->setHint( "To disable the norm computation, if you don't need it." );
00114         computeNorm->setDefault( true );
00115 
00116         OFX::BooleanParamDescriptor* normManhattan = desc.defineBooleanParam( kParamGradientNormManhattan );
00117         normManhattan->setLabel( "Use the manhattan norm" );
00118         normManhattan->setHint( "Use manhattan norm instead of standard one." );
00119         normManhattan->setDefault( false );
00120 
00121         OFX::BooleanParamDescriptor* computeGradientDirection = desc.defineBooleanParam( kParamComputeGradientDirection );
00122         computeGradientDirection->setLabel( "Gradient direction" );
00123         computeGradientDirection->setHint( "To disable the gradient direction computation, if you don't need it." );
00124         computeGradientDirection->setDefault( false );
00125 
00126         OFX::BooleanParamDescriptor* gradientDirectionAbs = desc.defineBooleanParam( kParamGradientDirectionAbs );
00127         gradientDirectionAbs->setLabel( "Angle between 0 and PI" );
00128         gradientDirectionAbs->setHint( "Limit gradient direction between 0 and PI." );
00129         gradientDirectionAbs->setDefault( true );
00130 
00131         OFX::PushButtonParamDescriptor* infosButton = desc.definePushButtonParam( kParamInfos );
00132         infosButton->setLabel( "Infos" );
00133 
00134         OFX::ChoiceParamDescriptor* outputComponent = desc.defineChoiceParam( kParamOutputComponent );
00135         outputComponent->setLabel( "Output component" );
00136         outputComponent->appendOption( OFX::getImageEffectHostDescription()->supportsPixelComponent(OFX::ePixelComponentRGB) ? kParamOutputComponentRGB : "---" );
00137         outputComponent->appendOption( OFX::getImageEffectHostDescription()->supportsPixelComponent(OFX::ePixelComponentRGBA) ? kParamOutputComponentRGBA : "---" );
00138         outputComponent->setDefault( 0 );
00139         outputComponent->setIsSecret( OFX::getImageEffectHostDescription()->_supportedComponents.size() == 1 );
00140 }
00141 
00142 /**
00143  * @brief Function called to create a plugin effect instance
00144  * @param[in] handle  Effect handle
00145  * @param[in] context Application context
00146  * @return  plugin instance
00147  */
00148 OFX::ImageEffect* SobelPluginFactory::createInstance( OfxImageEffectHandle handle,
00149                                                             OFX::EContext context )
00150 {
00151         return new SobelPlugin( handle );
00152 }
00153 
00154 }
00155 }
00156 }
00157