TuttleOFX  1
AnisotropicTensorsPluginFactory.cpp
Go to the documentation of this file.
00001 #include "AnisotropicTensorsDefinition.hpp"
00002 #include "AnisotropicTensorsMargin.hpp"
00003 #include "AnisotropicTensorsPlugin.hpp"
00004 #include "AnisotropicTensorsProcess.hpp"
00005 
00006 #include <tuttle/plugin/ImageGilProcessor.hpp>
00007 
00008 namespace tuttle {
00009 namespace plugin {
00010 namespace anisotropicFilter {
00011 namespace tensors {
00012 
00013 /**
00014  * @brief Function called to describe the plugin main features.
00015  * @param[in, out]   desc     Effect descriptor
00016  */
00017 void AnisotropicTensorsPluginFactory::describe( OFX::ImageEffectDescriptor &desc )
00018 {
00019     // basic labels
00020         desc.setLabels(
00021                 "TuttleAnisotropicTensors",
00022                 "AnisotropicTensors",
00023                 "Generates structure tensors image" );
00024         desc.setPluginGrouping( "tuttle/image/process/filter" );
00025         
00026         desc.setDescription(
00027 "Generates structure tensors image, to use as input of the AnisotropicDiffusion.\n"
00028 "\n"
00029 "\n"
00030 "Tensors are used to get geographic information (edges and directions). "
00031 "In this map, you will see horizontal edges shown with red color, vertical edges shown in blue and finally, when the blur must be isotropic, "
00032 "the color is pink (blur along X and Y directions). The main goal is to get pink on uniform noisy area:"
00033 "Structure tensors is just used to see how edges are detected, "
00034 "diffuse tensors map is the final tensor map used by the AnisotropicDiffusion.\n"
00035 "\n"
00036 "Inputs:\n"
00037 "- Source: Source image.\n"
00038 "\n"
00039 "Parameters:\n"
00040 "- Display effect margin: Margin used by the algorithm to avoid border effect.\n"
00041 "- Alpha: pre-blurring of the edge detection. Can be interpreted as the noise scale. "
00042 "If too high, it detects noise as edges, if too low, it removes tiny edges. "
00043 "Play this parameter with geometry factor and thresholding quantization.\n"
00044 "- Sigma: post-blurring of the edge detection. Interpreted as regularity of the tensor valued geometry.\n"
00045 "- Geometry factor: tends to transform noise to pink when falling near 0.\n"
00046 "- Thresholding quantization: Quantization of the structure tensor, to eliminate noise effect.\n"
00047 "- Sharpness: set how much you want to preserve edges.\n"
00048 "- Anisotropy: anisotropy factor. Increase the value to get more fluid blurring.\n"
00049                 );
00050 
00051     // add the supported contexts, only filter at the moment
00052     desc.addSupportedContext( OFX::eContextFilter );
00053 
00054     // add supported pixel depths
00055     desc.addSupportedBitDepth( OFX::eBitDepthUByte );
00056     desc.addSupportedBitDepth( OFX::eBitDepthUShort );
00057     desc.addSupportedBitDepth( OFX::eBitDepthFloat );
00058 
00059     // set a few flags
00060     desc.setSingleInstance( false );
00061     desc.setHostFrameThreading( false );
00062     desc.setSupportsMultiResolution( true );
00063     desc.setSupportsTiles( kSupportTiles );
00064     desc.setTemporalClipAccess( false );
00065     desc.setRenderTwiceAlways( false );
00066     desc.setSupportsMultipleClipPARs( false );
00067 
00068     desc.setOverlayInteractDescriptor( new OFX::DefaultEffectOverlayWrap<TensorsMarginOverlay> ( ) );
00069 }
00070 
00071 /**
00072  * @brief Function called to describe the plugin controls and features.
00073  * @param[in, out]   desc       Effect descriptor
00074  * @param[in]        context    Application context
00075  */
00076 void AnisotropicTensorsPluginFactory::describeInContext( OFX::ImageEffectDescriptor &desc,
00077                                                      OFX::EContext context )
00078 {
00079     // Source clip only in the filter context
00080     // create the mandated source clip
00081         OFX::ClipDescriptor* srcClip = desc.defineClip( kOfxImageEffectSimpleSourceClipName );
00082     srcClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00083     srcClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00084     srcClip->setTemporalClipAccess( false );
00085     srcClip->setSupportsTiles( kSupportTiles );
00086     srcClip->setIsMask( false );
00087 
00088     // Create the mandated output clip
00089         OFX::ClipDescriptor* dstClip = desc.defineClip( kOfxImageEffectOutputClipName );
00090     dstClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00091     dstClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00092     dstClip->setSupportsTiles( kSupportTiles );
00093 
00094     // Controls
00095     OFX::BooleanParamDescriptor* algo = desc.defineBooleanParam( kParamDisplayStructureTensors );
00096         algo->setLabel( "Display Structure Tensors" );
00097     algo->setDefault( false );
00098         
00099     OFX::BooleanParamDescriptor* margin = desc.defineBooleanParam( kParamDisplayEffectMargin );
00100         margin->setLabel( "Display Effect Margin" );
00101     margin->setDefault( false );
00102     margin->setEvaluateOnChange( false );
00103 
00104     OFX::GroupParamDescriptor* groupParamsStrTensors = desc.defineGroupParam( kParamGroupStructureTensors );
00105         groupParamsStrTensors->setLabel( "Structure tensors parameters" );
00106         
00107     OFX::DoubleParamDescriptor* alpha = desc.defineDoubleParam( kParamAlpha );
00108     alpha->setLabel( "Alpha" );
00109     alpha->setParent( *groupParamsStrTensors );
00110     alpha->setDefault( kDefaultAlphaValue );
00111     alpha->setHint( "Image pre-blurring (noise scale)" );
00112     alpha->setRange( 0.1, 100.0 );
00113     alpha->setDisplayRange( 0.1, 10.0 );
00114         
00115     OFX::DoubleParamDescriptor* sigma = desc.defineDoubleParam( kParamSigma );
00116     sigma->setLabel( "Sigma" );
00117     sigma->setParent( *groupParamsStrTensors );
00118     sigma->setDefault( kDefaultSigmaValue );
00119     sigma->setRange( 0.1, 100.0 );
00120     sigma->setDisplayRange( 0.1, 10.0 );
00121     sigma->setHint( "Regularity of the tensor-valued geometry" );
00122         
00123     OFX::DoubleParamDescriptor* geom_fact = desc.defineDoubleParam( kParamGeometryFactor );
00124     geom_fact->setLabel( "Geometry Factor" );
00125     geom_fact->setParent( *groupParamsStrTensors );
00126     geom_fact->setDefault( kDefaultGeomFactValue );
00127     geom_fact->setRange( -1000.0, 1000.0 );
00128     geom_fact->setDisplayRange( -10.0, 10.0 );
00129         
00130     OFX::DoubleParamDescriptor* threshold = desc.defineDoubleParam( kParamThresholdingQuantization );
00131     threshold->setLabel( "Thresholding Quantization" );
00132     threshold->setParent( *groupParamsStrTensors );
00133     threshold->setDefault( kDefaultGeomFactValue );
00134     threshold->setDisplayRange( 0.0, 10.0 );
00135     threshold->setHint( "Tresholding quantization to remove noise on uniform areas" );
00136 
00137     
00138         OFX::GroupParamDescriptor* groupParamsDifTensors = desc.defineGroupParam( kParamGroupDiffuseTensors );
00139         groupParamsDifTensors->setLabel( "Diffuse tensors parameters" );
00140         
00141     OFX::ChoiceParamDescriptor* stAlgo = desc.defineChoiceParam( kParamEdgeDetectAlgo );
00142         stAlgo->setLabel( "Edge Detection Algorithm" );
00143     stAlgo->setParent( *groupParamsDifTensors );
00144     stAlgo->appendOption( "Precise forward/backward finite differences" );
00145     stAlgo->appendOption( "Harris edge detector" );
00146     stAlgo->appendOption( "Canny-deriche filter (derivative order 1)" );
00147     stAlgo->setDefault( kDefaultTensorsAlgo );
00148     stAlgo->setIsSecret( false );
00149         
00150     OFX::DoubleParamDescriptor* sharpness = desc.defineDoubleParam( kParamSharpness );
00151     sharpness->setLabel( "Sharpness" );
00152     sharpness->setParent( *groupParamsDifTensors );
00153     sharpness->setDefault( kDefaultSharpnessValue );
00154     sharpness->setRange( 0.0, 10000.0 );
00155     sharpness->setDisplayRange( 0.0, 10.0 );
00156     sharpness->setHint( "Contour preservation" );
00157         
00158     OFX::DoubleParamDescriptor* anisotropy = desc.defineDoubleParam( kParamAnisotropy );
00159     anisotropy->setLabel( "Anisotropy" );
00160     anisotropy->setParent( *groupParamsDifTensors );
00161     anisotropy->setDefault( kDefaultAnisotropyValue );
00162     anisotropy->setRange( 0.0, 1.0 );
00163     anisotropy->setDisplayRange( 0.0, 1.0 );
00164     //    anisotropy->setIsSecret(true);
00165     anisotropy->setHint( "Smoothing anisotropy" );
00166 }
00167 
00168 /**
00169  * @brief Function called to create a plugin effect instance
00170  * @param[in]   handle  effect handle
00171  * @param[in]   context    Application context
00172  * @return  plugin instance
00173  */
00174 OFX::ImageEffect* AnisotropicTensorsPluginFactory::createInstance( OfxImageEffectHandle handle,
00175                                                                OFX::EContext context )
00176 {
00177     return new TensorsPlugin( handle );
00178 }
00179 
00180 }
00181 }
00182 }
00183 }