TuttleOFX
1
|
00001 #include "WarpPluginFactory.hpp" 00002 #include "WarpPlugin.hpp" 00003 #include "WarpDefinitions.hpp" 00004 #include "WarpOverlayInteract.hpp" 00005 00006 #include <tuttle/plugin/ImageGilProcessor.hpp> 00007 #include <tuttle/plugin/exceptions.hpp> 00008 00009 #include <limits> 00010 #include <ofxsMultiThread.h> 00011 #include <boost/gil/gil_all.hpp> 00012 #include <boost/scoped_ptr.hpp> 00013 #include <boost/lexical_cast.hpp> 00014 00015 namespace tuttle { 00016 namespace plugin { 00017 namespace warp { 00018 00019 /** 00020 * @brief Function called to describe the plugin main features. 00021 * @param[in, out] desc Effect descriptor 00022 */ 00023 void WarpPluginFactory::describe( OFX::ImageEffectDescriptor& desc ) 00024 { 00025 desc.setLabels( "TuttleWarp", "Warp", 00026 "Warp" ); 00027 desc.setPluginGrouping( "tuttle/image/process/geometry" ); 00028 00029 // add the supported contexts, only filter at the moment 00030 desc.addSupportedContext( OFX::eContextFilter ); 00031 desc.addSupportedContext( OFX::eContextGeneral ); 00032 00033 // add supported pixel depths 00034 desc.addSupportedBitDepth( OFX::eBitDepthUByte ); 00035 desc.addSupportedBitDepth( OFX::eBitDepthUShort ); 00036 desc.addSupportedBitDepth( OFX::eBitDepthFloat ); 00037 00038 // plugin flags 00039 desc.setSupportsTiles( false ); 00040 desc.setOverlayInteractDescriptor( new OFX::DefaultEffectOverlayWrap<WarpEffectOverlayDescriptor > ( ) ); 00041 } 00042 00043 /** 00044 * @brief Function called to describe the plugin controls and features. 00045 * @param[in, out] desc Effect descriptor 00046 * @param[in] context Application context 00047 */ 00048 void WarpPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc, 00049 OFX::EContext context ) 00050 { 00051 OFX::ClipDescriptor* srcClip = desc.defineClip( kOfxImageEffectSimpleSourceClipName ); 00052 srcClip->addSupportedComponent( OFX::ePixelComponentRGBA ); 00053 srcClip->addSupportedComponent( OFX::ePixelComponentAlpha ); 00054 srcClip->setSupportsTiles( false ); 00055 00056 OFX::ClipDescriptor* srcBClip = desc.defineClip( kClipSourceB ); 00057 srcBClip->addSupportedComponent( OFX::ePixelComponentRGBA ); 00058 srcBClip->addSupportedComponent( OFX::ePixelComponentAlpha ); 00059 srcBClip->setOptional( true ); 00060 srcBClip->setSupportsTiles( false ); 00061 00062 OFX::ClipDescriptor* dstClip = desc.defineClip( kOfxImageEffectOutputClipName ); 00063 dstClip->addSupportedComponent( OFX::ePixelComponentRGBA ); 00064 dstClip->addSupportedComponent( OFX::ePixelComponentAlpha ); 00065 00066 //////////////////// Options //////////////////// 00067 00068 OFX::PushButtonParamDescriptor* reset = desc.definePushButtonParam( kParamReset ); 00069 reset->setLabel( "Reset" ); 00070 00071 OFX::PushButtonParamDescriptor* setKey = desc.definePushButtonParam( kParamSetKey ); 00072 setKey->setLabel( "SetKey" ); 00073 00074 OFX::PushButtonParamDescriptor* nextCurve = desc.definePushButtonParam( kParamNextCurve ); 00075 nextCurve->setLabel( "NextCurve" ); 00076 00077 OFX::DoubleParamDescriptor* transition = desc.defineDoubleParam( kParamTransition ); 00078 transition->setLabel( "Transition" ); 00079 transition->setHint( "Coefficient de transition" ); 00080 transition->setDefault( 1.0 ); 00081 transition->setRange( 0.0, 1.0 ); 00082 transition->setDisplayRange( 0.0, 1.0 ); 00083 00084 //Settings 00085 { 00086 OFX::GroupParamDescriptor* groupSettings = desc.defineGroupParam( kParamGroupSettings ); 00087 groupSettings->setLabel( "Settings" ); 00088 00089 OFX::ChoiceParamDescriptor* method = desc.defineChoiceParam( kParamMethod ); 00090 method->setLabel( "Method" ); 00091 method->appendOption( kParamMethodCreation ); 00092 method->appendOption( kParamMethodDelete ); 00093 method->appendOption( kParamMethodMove ); 00094 method->setDefault( 0 ); 00095 method->setHint( "Points method" ); 00096 method->setEvaluateOnChange( false ); 00097 method->setParent( groupSettings ); 00098 00099 OFX::IntParamDescriptor* nbPoints = desc.defineIntParam( kParamNbPoints ); 00100 nbPoints->setDefault( 0 ); 00101 nbPoints->setRange( 0, kMaxNbPoints - 1 ); 00102 nbPoints->setIsSecret( true ); 00103 nbPoints->setParent( groupSettings ); 00104 00105 OFX::BooleanParamDescriptor * curveBegin[kMaxNbPoints]; 00106 for( std::size_t cptCBegin = 0; cptCBegin < kMaxNbPoints; ++cptCBegin ) 00107 { 00108 std::string resultCBegin = boost::lexical_cast<std::string > ( cptCBegin ); 00109 curveBegin[cptCBegin] = desc.defineBooleanParam( kParamCurveBegin + resultCBegin ); 00110 curveBegin[cptCBegin]->setDefault( false ); 00111 curveBegin[cptCBegin]->setParent( groupSettings ); 00112 curveBegin[cptCBegin]->setIsSecret( true ); 00113 } 00114 00115 OFX::BooleanParamDescriptor* inverse = desc.defineBooleanParam( kParamInverse ); 00116 inverse->setLabel( "Inverse" ); 00117 inverse->setDefault( false ); 00118 inverse->setParent( groupSettings ); 00119 00120 OFX::DoubleParamDescriptor* rigidity = desc.defineDoubleParam( kParamRigiditeTPS ); 00121 rigidity->setLabel( "Rigidity" ); 00122 rigidity->setHint( "TPS Rigidity coefficient" ); 00123 rigidity->setDefault( 0.0 ); 00124 // rigidity->setRange( 0.0, std::numeric_limits<double>::max( ) ); 00125 rigidity->setDisplayRange( 0.0, 10.0 ); 00126 rigidity->setParent( groupSettings ); 00127 00128 OFX::IntParamDescriptor* nbPointsBezier = desc.defineIntParam( kParamNbPointsBezier ); 00129 nbPointsBezier->setLabel( "Bezier" ); 00130 nbPointsBezier->setHint( "Nombre de points dessinant la courbe de bezier" ); 00131 nbPointsBezier->setDefault( 5 ); 00132 nbPointsBezier->setRange( 0, std::numeric_limits<int>::max( ) ); 00133 nbPointsBezier->setDisplayRange( 1, 20 ); 00134 nbPointsBezier->setParent( groupSettings ); 00135 00136 //Overlay Points et tangentes 00137 OFX::GroupParamDescriptor* groupOverlay = desc.defineGroupParam( kParamGroupOverlay ); 00138 groupOverlay->setLabel( "Overlay points et tangentes" ); 00139 00140 OFX::BooleanParamDescriptor* overlay = desc.defineBooleanParam( kParamOverlay ); 00141 overlay->setLabel( "Overlay" ); 00142 overlay->setHint( "Affiche la scene entière ou non" ); 00143 overlay->setDefault( true ); 00144 overlay->setEvaluateOnChange( false ); 00145 overlay->setParent( groupOverlay ); 00146 00147 OFX::BooleanParamDescriptor* overlayIn = desc.defineBooleanParam( kParamOverlayIn ); 00148 overlayIn->setLabel( "Points In" ); 00149 overlayIn->setHint( "Affiche les points d'entrée sur la scène" ); 00150 overlayIn->setDefault( true ); 00151 overlayIn->setEvaluateOnChange( false ); 00152 overlayIn->setParent( groupOverlay ); 00153 00154 OFX::BooleanParamDescriptor* overlayTgtIn = desc.defineBooleanParam( kParamOverlayTgtIn ); 00155 overlayTgtIn->setLabel( "Bezier et tangentes In" ); 00156 overlayTgtIn->setHint( "Affiche la courbe de Bezier et ses tangentes en fonction des points In" ); 00157 overlayTgtIn->setDefault( true ); 00158 overlayTgtIn->setEvaluateOnChange( false ); 00159 overlayTgtIn->setParent( groupOverlay ); 00160 00161 OFX::BooleanParamDescriptor* overlayOut = desc.defineBooleanParam( kParamOverlayOut ); 00162 overlayOut->setLabel( "Points Out" ); 00163 overlayOut->setHint( "Affiche les points de sortie sur la scène" ); 00164 overlayOut->setDefault( false ); 00165 overlayOut->setEvaluateOnChange( false ); 00166 overlayOut->setParent( groupOverlay ); 00167 00168 OFX::BooleanParamDescriptor* overlayTgtOut = desc.defineBooleanParam( kParamOverlayTgtOut ); 00169 overlayTgtOut->setLabel( "Bezier et tangentes Out" ); 00170 overlayTgtOut->setHint( "Affiche la courbe de Bezier et ses tangentes en fonction des points Out" ); 00171 overlayTgtOut->setDefault( false ); 00172 overlayTgtOut->setEvaluateOnChange( false ); 00173 overlayTgtOut->setParent( groupOverlay ); 00174 } 00175 00176 //////////////////// IN Points //////////////////// 00177 { 00178 OFX::GroupParamDescriptor* groupIn = desc.defineGroupParam( kParamGroupIn ); 00179 groupIn->setLabel( "Input points" ); 00180 groupIn->setOpen( false ); 00181 00182 OFX::RGBParamDescriptor* ouverlayInColor = desc.defineRGBParam( kParamOverlayInColor ); 00183 ouverlayInColor->setLabel( "Color" ); 00184 ouverlayInColor->setHint( "Input point overlay color" ); 00185 ouverlayInColor->setDefault( 1.0, 0.0, 0.0 ); 00186 ouverlayInColor->setEvaluateOnChange( false ); 00187 ouverlayInColor->setParent( groupIn ); 00188 00189 OFX::Double2DParamDescriptor * pIn[kMaxNbPoints]; 00190 for( std::size_t cptIn = 0; cptIn < kMaxNbPoints; ++cptIn ) 00191 { 00192 std::string resultIn = boost::lexical_cast<std::string > ( cptIn ); 00193 pIn[cptIn] = desc.defineDouble2DParam( kParamPointIn + resultIn ); 00194 pIn[cptIn]->setLabel( "In " + resultIn ); 00195 pIn[cptIn]->setHint( "Input point " + resultIn ); 00196 pIn[cptIn]->setDefault( positionOrigine, positionOrigine ); 00197 pIn[cptIn]->setParent( groupIn ); 00198 } 00199 } 00200 00201 //////////////////// TGT Points IN//////////////////// 00202 { 00203 OFX::GroupParamDescriptor* groupTgtIn = desc.defineGroupParam( kParamGroupTgtIn ); 00204 groupTgtIn->setLabel( "Tangente points In" ); 00205 groupTgtIn->setOpen( false ); 00206 00207 OFX::RGBParamDescriptor* ouverlayTgtInColor = desc.defineRGBParam( kParamOverlayTgtInColor ); 00208 ouverlayTgtInColor->setLabel( "Color In" ); 00209 ouverlayTgtInColor->setHint( "Tangente point overlay In color" ); 00210 ouverlayTgtInColor->setDefault( 0.95, 0.4, 0.4 ); 00211 ouverlayTgtInColor->setEvaluateOnChange( false ); 00212 ouverlayTgtInColor->setParent( groupTgtIn ); 00213 00214 OFX::Double2DParamDescriptor * pTgtIn[kMaxNbPoints * 2]; 00215 for( std::size_t cptTgtIn = 0; cptTgtIn < kMaxNbPoints * 2; ++cptTgtIn ) 00216 { 00217 std::string resultTgtIn = boost::lexical_cast<std::string > ( cptTgtIn ); 00218 pTgtIn[cptTgtIn] = desc.defineDouble2DParam( kParamPointTgtIn + resultTgtIn ); 00219 pTgtIn[cptTgtIn]->setLabel( "Tgt In " + resultTgtIn ); 00220 pTgtIn[cptTgtIn]->setHint( "Tgt point In " + resultTgtIn ); 00221 pTgtIn[cptTgtIn]->setDefault( positionOrigine, positionOrigine ); 00222 pTgtIn[cptTgtIn]->setParent( groupTgtIn ); 00223 } 00224 00225 //////////////////// OUT Points //////////////////// 00226 OFX::GroupParamDescriptor* groupOut = desc.defineGroupParam( kParamGroupOut ); 00227 groupOut->setLabel( "Output points" ); 00228 groupOut->setOpen( false ); 00229 00230 OFX::RGBParamDescriptor* ouverlayOutColor = desc.defineRGBParam( kParamOverlayOutColor ); 00231 ouverlayOutColor->setLabel( "Color" ); 00232 ouverlayOutColor->setHint( "Output point overlay color" ); 00233 ouverlayOutColor->setDefault( 0.0, 0.0, 1.0 ); 00234 ouverlayOutColor->setEvaluateOnChange( false ); 00235 ouverlayOutColor->setParent( groupOut ); 00236 00237 OFX::Double2DParamDescriptor * pOut[kMaxNbPoints]; 00238 for( std::size_t cptOut = 0; cptOut < kMaxNbPoints; ++cptOut ) 00239 { 00240 std::string resultOut = boost::lexical_cast<std::string > ( cptOut ); 00241 pOut[cptOut] = desc.defineDouble2DParam( kParamPointOut + resultOut ); 00242 pOut[cptOut]->setLabel( "In " + resultOut ); 00243 pOut[cptOut]->setHint( "Input point " + resultOut ); 00244 pOut[cptOut]->setDefault( positionOrigine, positionOrigine ); 00245 pOut[cptOut]->setParent( groupOut ); 00246 } 00247 } 00248 00249 //////////////////// TGT Points Out//////////////////// 00250 { 00251 OFX::GroupParamDescriptor* groupTgtOut = desc.defineGroupParam( kParamGroupTgtOut ); 00252 groupTgtOut->setLabel( "Tangente points Out" ); 00253 groupTgtOut->setOpen( false ); 00254 00255 OFX::RGBParamDescriptor* ouverlayTgtOutColor = desc.defineRGBParam( kParamOverlayTgtOutColor ); 00256 ouverlayTgtOutColor->setLabel( "Color Out" ); 00257 ouverlayTgtOutColor->setHint( "Tangente point overlay Out color" ); 00258 ouverlayTgtOutColor->setDefault( 0.2, 0.45, 0.95 ); 00259 ouverlayTgtOutColor->setEvaluateOnChange( false ); 00260 ouverlayTgtOutColor->setParent( groupTgtOut ); 00261 00262 OFX::Double2DParamDescriptor * pTgtOut[kMaxNbPoints * 2]; 00263 for( std::size_t cptTgtOut = 0; cptTgtOut < kMaxNbPoints * 2; ++cptTgtOut ) 00264 { 00265 std::string resultTgtOut = boost::lexical_cast<std::string > ( cptTgtOut ); 00266 pTgtOut[cptTgtOut] = desc.defineDouble2DParam( kParamPointTgtOut + resultTgtOut ); 00267 pTgtOut[cptTgtOut]->setLabel( "Tgt Out " + resultTgtOut ); 00268 pTgtOut[cptTgtOut]->setHint( "Tgt point Out " + resultTgtOut ); 00269 pTgtOut[cptTgtOut]->setDefault( positionOrigine, positionOrigine ); 00270 pTgtOut[cptTgtOut]->setParent( groupTgtOut ); 00271 } 00272 } 00273 } 00274 00275 /** 00276 * @brief Function called to create a plugin effect instance 00277 * @param[in] handle Effect handle 00278 * @param[in] context Application context 00279 * @return plugin instance 00280 */ 00281 OFX::ImageEffect* WarpPluginFactory::createInstance( OfxImageEffectHandle handle, 00282 OFX::EContext context ) 00283 { 00284 return new WarpPlugin( handle ); 00285 } 00286 00287 } 00288 } 00289 } 00290