TuttleOFX  1
LensDistortPluginFactory.cpp
Go to the documentation of this file.
00001 #include "LensDistortPluginFactory.hpp"
00002 #include "LensDistortPlugin.hpp"
00003 #include "LensDistortOverlayInteract.hpp"
00004 
00005 #include <tuttle/plugin/context/SamplerDefinition.hpp>
00006 #include <tuttle/plugin/context/SamplerPluginFactory.hpp>
00007 
00008 #include <tuttle/plugin/exceptions.hpp>
00009 #include <terry/globals.hpp>
00010 
00011 #include <ofxsImageEffect.h>
00012 #include <ofxsMultiThread.h>
00013 
00014 namespace tuttle {
00015 namespace plugin {
00016 namespace lens {
00017 
00018 /**
00019  * @brief Function called to describe the plugin main features.
00020  * @param[in, out]   desc     Effect descriptor
00021  */
00022 void LensDistortPluginFactory::describe( OFX::ImageEffectDescriptor& desc )
00023 {
00024         desc.setLabels(
00025                 "TuttleLensDistort",
00026                 "LensDistort",
00027                 "Create or correct lens distortion." );
00028         desc.setPluginGrouping( "tuttle/image/process/geometry" );
00029 
00030         desc.setDescription( "Apply or correct a lens distortion on an image." );
00031 
00032         // add the supported contexts
00033         desc.addSupportedContext( OFX::eContextFilter );
00034         desc.addSupportedContext( OFX::eContextGeneral );
00035 
00036         // add supported pixel depths
00037         desc.addSupportedBitDepth( OFX::eBitDepthUByte );
00038         desc.addSupportedBitDepth( OFX::eBitDepthUShort );
00039         desc.addSupportedBitDepth( OFX::eBitDepthFloat );
00040 
00041         // set a few flags
00042         desc.setRenderThreadSafety( OFX::eRenderFullySafe );
00043         desc.setHostFrameThreading( false ); // The plugin is able to manage threading per frame
00044         desc.setSupportsTiles( true );
00045 
00046         desc.setOverlayInteractDescriptor( new OFX::DefaultEffectOverlayWrap<LensDistortOverlayDescriptor>() );
00047 }
00048 
00049 /**
00050  * @brief Function called to describe the plugin controls and features.
00051  * @param[in, out]   desc       Effect descriptor
00052  * @param[in]        context    Application context
00053  */
00054 void LensDistortPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc, OFX::EContext context )
00055 {
00056         // Create the mandated output clip
00057         OFX::ClipDescriptor* dstClip = desc.defineClip( kOfxImageEffectOutputClipName );
00058         dstClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00059         dstClip->addSupportedComponent( OFX::ePixelComponentRGB );
00060         dstClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00061         dstClip->setSupportsTiles( true );
00062 
00063         // create the mandated source clip
00064         OFX::ClipDescriptor* srcClip = desc.defineClip( kOfxImageEffectSimpleSourceClipName );
00065         srcClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00066         srcClip->addSupportedComponent( OFX::ePixelComponentRGB );
00067         srcClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00068         srcClip->setSupportsTiles( true );
00069 
00070         // declare an optional clip reference for RoD
00071         OFX::ClipDescriptor* srcRefClip = desc.defineClip( kClipOptionalSourceRef );
00072         srcRefClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00073         srcRefClip->addSupportedComponent( OFX::ePixelComponentRGB );
00074         srcRefClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00075         srcRefClip->setSupportsTiles( true );
00076         srcRefClip->setOptional( true );
00077         srcRefClip->setLabel( "ref" );
00078 
00079         OFX::BooleanParamDescriptor* reverse = desc.defineBooleanParam( kParamReverse );
00080         reverse->setLabel( "Reverse" );
00081         reverse->setDefault( false );
00082         reverse->setHint( "Invert the effect.\n"
00083                           "Distort becomes undistort, and vice versa." );
00084 
00085         // Controls
00086         OFX::BooleanParamDescriptor* displaySource = desc.defineBooleanParam( kParamDisplaySource );
00087         displaySource->setLabel( "Display Source" );
00088         displaySource->setDefault( false );
00089         displaySource->setHint( "Display the image source (usefull to parameter the distortion with lines overlays on the source image)." );
00090 
00091         OFX::ChoiceParamDescriptor* lensType = desc.defineChoiceParam( kParamLensType );
00092         lensType->setLabel( "Lens type" );
00093         lensType->appendOption( kParamLensTypeStandard );
00094         #ifndef TUTTLE_PRODUCTION
00095         lensType->appendOption( kParamLensTypeFishEye ); // not implemented yet...
00096         lensType->appendOption( kParamLensTypeAdvanced ); // not implemented yet...
00097                 #else
00098         lensType->setIsSecret( true );
00099         #endif
00100         lensType->setDefault( 0 );
00101 
00102         OFX::DoubleParamDescriptor* coef1 = desc.defineDoubleParam( kParamCoef1 );
00103         coef1->setLabel( "Main" );
00104         coef1->setDefault( 0.1 );
00105         coef1->setDisplayRange( -1.0, 1.0 );
00106         coef1->setHint( "Main distortion coeffecient\n"
00107                         ">0 : Barrel distortion\n"
00108                         "<0 : Pincushion distortion\n"
00109                         );
00110 
00111         OFX::DoubleParamDescriptor* coef2 = desc.defineDoubleParam( kParamCoef2 );
00112         coef2->setLabel( "Secondary" );
00113         coef2->setDefault( 0.0 );
00114         coef2->setDisplayRange( -1.0, 1.0 );
00115         coef2->setHint( "Secondary distortion coeffecient (usefull for fisheyes only)\n"
00116                         ">0 : Barrel distortion\n"
00117                         "<0 : Pincushion distortion\n"
00118                         );
00119         #ifdef TUTTLE_PRODUCTION
00120         coef2->setIsSecret( true );
00121         #endif
00122 
00123         OFX::DoubleParamDescriptor* squeeze = desc.defineDoubleParam( kParamSqueeze );
00124         squeeze->setLabel( "Squeeze" );
00125         #ifdef TUTTLE_PRODUCTION
00126         squeeze->setIsSecret( true );
00127         #endif
00128         //    squeeze->setDoubleType( eDoubleTypeNormalisedX );
00129         squeeze->setDefault( 1.0 );
00130         squeeze->setRange( 0.00001, 1.0 );
00131         squeeze->setDisplayRange( 0.01, 1.0 );
00132         squeeze->setHint( "Squeeze distortion coeffecient (usefull for bad quality lens...)" );
00133 
00134         OFX::Double2DParamDescriptor* asymmetric = desc.defineDouble2DParam( kParamAsymmetric );
00135         asymmetric->setLabel( "Asymmetric" );
00136         #ifdef TUTTLE_PRODUCTION
00137         asymmetric->setIsSecret( true );
00138         #endif
00139         //    asymmetric->setDoubleType( eDoubleTypeNormalisedXY );
00140         asymmetric->setDefault( 0.0, 0.0 );
00141         asymmetric->setRange( 0.0, 0.0, 1.0, 1.0 );
00142         asymmetric->setDisplayRange( 0.0, 0.0, 1.0, 1.0 );
00143         asymmetric->setHint( "asymmetric distortion coeffecient (usefull for bad quality lens...)" );
00144 
00145         OFX::Double2DParamDescriptor* center = desc.defineDouble2DParam( kParamCenter );
00146         center->setLabel( "Center" );
00147         center->setDoubleType( OFX::eDoubleTypePlain );
00148         center->setDefault( 0.0, 0.0 );
00149         center->setDisplayRange( -1.0, -1.0, 1.0, 1.0 );
00150         center->setHint( "Center parameter allows you to shift the center of distortion." );
00151 
00152         OFX::BooleanParamDescriptor* centerOverlay = desc.defineBooleanParam( kParamCenterOverlay );
00153         centerOverlay->setLabel( "Display distortion center" );
00154         centerOverlay->setDefault( false );
00155         centerOverlay->setEvaluateOnChange( false );
00156         centerOverlay->setHint( "Active distortion center point overlay." );
00157 
00158         OFX::ChoiceParamDescriptor* centerType = desc.defineChoiceParam( kParamCenterType );
00159         centerType->setLabel( "Center type" );
00160         #ifdef TUTTLE_PRODUCTION
00161         centerType->setIsSecret( true );
00162         #endif
00163         centerType->appendOption( kParamCenterTypeSource );
00164         centerType->appendOption( kParamCenterTypeRoW );
00165         centerType->setDefault( 0 );
00166         centerType->setHint( "Centered on source or output image." );
00167 
00168         OFX::DoubleParamDescriptor* preScale = desc.defineDoubleParam( kParamPreScale );
00169         preScale->setLabel( "Pre-scale" );
00170         //    preScale->setDoubleType( eDoubleTypeNormalisedXY );
00171         preScale->setDefault( 1.0 );
00172         preScale->setRange( 0.00001, std::numeric_limits<double>::max() );
00173         preScale->setDisplayRange( 0.0, 2.5 );
00174         preScale->setHint( "If the transformation of optics is high, you may need to change the scale of the result to be globally closer to the source image or preserve a good resolution." );
00175 
00176         OFX::DoubleParamDescriptor* postScale = desc.defineDoubleParam( kParamPostScale );
00177         postScale->setLabel( "Post-scale" );
00178         //    scale->setDoubleType( eDoubleTypeNormalisedXY );
00179         postScale->setDefault( 1.0 );
00180         postScale->setRange( 0.00001, std::numeric_limits<double>::max() );
00181         postScale->setDisplayRange( 0.0, 2.5 );
00182         postScale->setHint( "If the transformation of optics is high, you may need to change the scale of the result to be globally closer to the source image or preserve a good resolution." );
00183 
00184 
00185         // sampler parameters //
00186         describeSamplerParamsInContext( desc, context );
00187 
00188 
00189         OFX::ChoiceParamDescriptor* resizeRod = desc.defineChoiceParam( kParamResizeRod );
00190         resizeRod->setLabel( "Resize RoD" );
00191         resizeRod->appendOption( kParamResizeRodNo );
00192         resizeRod->appendOption( kParamResizeRodSourceRef );
00193         resizeRod->appendOption( kParamResizeRodMin );
00194         resizeRod->appendOption( kParamResizeRodMax );
00195         resizeRod->appendOption( kParamResizeRodManual );
00196         resizeRod->setDefault( 0 );
00197         resizeRod->setHint( "Resize output RoD" );
00198 
00199         OFX::DoubleParamDescriptor* scaleRod = desc.defineDoubleParam( kParamResizeRodManualScale );
00200         scaleRod->setLabel( "Scale RoD" );
00201         //    scaleRod->setDoubleType( eDoubleTypeNormalisedXY );
00202         //    scaleRod->setIsSecret( true );
00203         //    scaleRod->setEnabled( false );
00204         scaleRod->setDefault( 1.0 );
00205         scaleRod->setRange( 0.0, std::numeric_limits<double>::max() );
00206         scaleRod->setDisplayRange( 0, 2.5 );
00207         scaleRod->setHint( "Adjust the output RoD." );
00208 
00209         OFX::GroupParamDescriptor* displayOptions = desc.defineGroupParam( kParamDisplayOptions );
00210         displayOptions->setLabel( "Display options" );
00211         displayOptions->setHint( "Display options (change nothing on the image)" );
00212 
00213         OFX::BooleanParamDescriptor* displayGrid = desc.defineBooleanParam( kParamGridOverlay );
00214         displayGrid->setLabel( "Display grid" );
00215         displayGrid->setParent( *displayOptions );
00216         displayGrid->setDefault( false );
00217         displayGrid->setEvaluateOnChange( false );
00218         displayGrid->setHint( "Display the grid" );
00219 
00220         OFX::Double2DParamDescriptor* gridCenter = desc.defineDouble2DParam( kParamGridCenter );
00221         gridCenter->setLabel( "Grid center" );
00222         gridCenter->setDoubleType( OFX::eDoubleTypePlain );
00223         gridCenter->setParent( *displayOptions );
00224         gridCenter->setDefault( 0.0, 0.0 );
00225         gridCenter->setDisplayRange( -1.0, -1.0, 1.0, 1.0 );
00226         gridCenter->setEvaluateOnChange( false );
00227         gridCenter->setHint( "Allows you to shift the center of the  display grid." );
00228 
00229         OFX::BooleanParamDescriptor* gridCenterOverlay = desc.defineBooleanParam( kParamGridCenterOverlay );
00230         gridCenterOverlay->setLabel( "Display grid center" );
00231         gridCenterOverlay->setParent( *displayOptions );
00232         gridCenterOverlay->setDefault( false );
00233         gridCenterOverlay->setEvaluateOnChange( false );
00234         gridCenterOverlay->setHint( "Active grid center point overlay." );
00235 
00236         OFX::Double2DParamDescriptor* gridScale = desc.defineDouble2DParam( kParamGridScale );
00237         gridScale->setLabel( "Grid scale" );
00238         gridScale->setDoubleType( OFX::eDoubleTypePlain );
00239         gridScale->setParent( *displayOptions );
00240         gridScale->setDefault( 1.0, 1.0 );
00241         gridScale->setDisplayRange( -10.0, -10.0, 10.0, 10.0 );
00242         gridScale->setEvaluateOnChange( false );
00243         gridScale->setHint( "Allows you to scale the display grid." );
00244 
00245         OFX::GroupParamDescriptor* debugOptions = desc.defineGroupParam( kParamDebugOptions );
00246         debugOptions->setLabel( "Debug options" );
00247         debugOptions->setHint( "Debug options" );
00248         debugOptions->setParent( *displayOptions );
00249         #ifdef TUTTLE_PRODUCTION
00250         debugOptions->setIsSecret( true );
00251         #endif
00252 
00253         OFX::BooleanParamDescriptor* debugDisplayRoi = desc.defineBooleanParam( kParamDebugDisplayRoi );
00254         debugDisplayRoi->setLabel( "Display RoI" );
00255         #ifdef TUTTLE_PRODUCTION
00256         debugDisplayRoi->setIsSecret( true );
00257         #endif
00258         debugDisplayRoi->setParent( *debugOptions );
00259         debugDisplayRoi->setDefault( false );
00260         debugDisplayRoi->setEvaluateOnChange( false );
00261         debugDisplayRoi->setHint( "Display RoI" );
00262 }
00263 
00264 /**
00265  * @brief Function called to create a plugin effect instance
00266  * @param[in]   handle  effect handle
00267  * @param[in]   context    Application context
00268  * @return  plugin instance
00269  */
00270 OFX::ImageEffect* LensDistortPluginFactory::createInstance( OfxImageEffectHandle handle, OFX::EContext context )
00271 {
00272         return new LensDistortPlugin( handle );
00273 }
00274 
00275 }
00276 }
00277 }