TuttleOFX  1
PinningOverlayInteract.cpp
Go to the documentation of this file.
00001  #include "PinningOverlayInteract.hpp"
00002 #include "PinningDefinitions.hpp"
00003 #include "PinningPlugin.hpp"
00004 #include <tuttle/plugin/opengl/gl.h>
00005 #include <tuttle/plugin/numeric/coordinateSystem.hpp>
00006 #include <tuttle/plugin/interact/interact.hpp>
00007 #include <tuttle/plugin/interact/overlay.hpp>
00008 #include <tuttle/plugin/interact/ParamPoint.hpp>
00009 #include <tuttle/plugin/interact/ParamPointRelativePoint.hpp>
00010 #include <tuttle/plugin/interact/ParamPoint.hpp>
00011 
00012 #include <ofxsImageEffect.h>
00013 #include <ofxsInteract.h>
00014 
00015 #include <boost/gil/gil_all.hpp>
00016 
00017 #include <vector>
00018 
00019 namespace tuttle {
00020 namespace plugin {
00021 namespace pinning {
00022 
00023 using namespace boost::numeric::ublas;
00024 
00025 /*
00026 template<class TFrame, ECoordinateSystem coord>
00027 class Manipulator : public interact::ParamPoint<TFrame, coord>
00028 {
00029 public:
00030     Manipulator( const interact::InteractInfos& infos, OFX::Double2DParam* param, const TFrame& frame, const OFX::ChoiceParam* paramMode )
00031                 : interact::ParamPoint<TFrame, coord>( infos, param, frame )
00032                 , _paramMode(paramMode)
00033         {}
00034         ~Manipulator() {}
00035 
00036         interact::MotionType intersect( const OFX::PenArgs& args )
00037         {
00038             // getPosition() / args.penPosition
00039             interact::MotionType m;
00040             m._axis = interact::eAxisXY;
00041             switch( static_cast<EParamManipulatorMode>(_paramMode->getValue()) )
00042             {
00043                 case eParamManipulatorModeTranslate:
00044                 {
00045                     m._mode = interact::eMotionTranslate;
00046                     break;
00047                 }
00048                 case eParamManipulatorModeRotate:
00049                 {
00050                     m._mode = interact::eMotionRotate;
00051                     break;
00052                 }
00053                 case eParamManipulatorModeScale:
00054                 {
00055                     m._mode = interact::eMotionScale;
00056                     break;
00057                 }
00058             }
00059             return m;
00060         }
00061 private:
00062     const OFX::ChoiceParam* _paramMode;
00063 };
00064 */
00065 
00066 PinningOverlayInteract::PinningOverlayInteract( OfxInteractHandle handle, OFX::ImageEffect* effect )
00067         : OFX::OverlayInteract( handle )
00068         , _infos( effect )
00069         , _interactScene( *effect, _infos )
00070 {
00071         _effect = effect;
00072         _plugin = static_cast<PinningPlugin*>( _effect );
00073 
00074         _interactScene.push_back( new interact::ParamPoint<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointOut0, _plugin->_clipSrc ),
00075                                                           new interact::IsActiveBooleanParamFunctor<>( _plugin->_paramOverlayOut ),
00076                                                           new interact::ColorRGBParam(_plugin->_paramOverlayOutColor) );
00077         _interactScene.push_back( new interact::ParamPoint<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointOut1, _plugin->_clipSrc ),
00078                                                           new interact::IsActiveBooleanParamFunctor<>( _plugin->_paramOverlayOut ),
00079                                                           new interact::ColorRGBParam(_plugin->_paramOverlayOutColor) );
00080         _interactScene.push_back( new interact::ParamPoint<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointOut2, _plugin->_clipSrc ),
00081                                                           new interact::IsActiveBooleanParamFunctor<>( _plugin->_paramOverlayOut ),
00082                                                           new interact::ColorRGBParam(_plugin->_paramOverlayOutColor) );
00083         interact::AndActiveFunctor<>* activeOut3 = new interact::AndActiveFunctor<>();
00084         activeOut3->push_back( new interact::IsActiveBooleanParamFunctor<>( _plugin->_paramOverlayOut ) );
00085         activeOut3->push_back( new interact::IsNotSecretParamFunctor<>( _plugin->_paramPointOut3 ) );
00086         _interactScene.push_back( new interact::ParamPoint<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointOut3, _plugin->_clipSrc ),
00087                                                           activeOut3,
00088                                                           new interact::ColorRGBParam(_plugin->_paramOverlayOutColor) );
00089 
00090         _interactScene.push_back( new interact::ParamPoint<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointIn0, _plugin->_clipSrc ),
00091                                                           new interact::IsActiveBooleanParamFunctor<>( _plugin->_paramOverlayIn ),
00092                                                           new interact::ColorRGBParam(_plugin->_paramOverlayInColor) );
00093         _interactScene.push_back( new interact::ParamPoint<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointIn1, _plugin->_clipSrc ),
00094                                                           new interact::IsActiveBooleanParamFunctor<>( _plugin->_paramOverlayIn ),
00095                                                           new interact::ColorRGBParam(_plugin->_paramOverlayInColor) );
00096         _interactScene.push_back( new interact::ParamPoint<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointIn2, _plugin->_clipSrc ),
00097                                                           new interact::IsActiveBooleanParamFunctor<>( _plugin->_paramOverlayIn ),
00098                                                           new interact::ColorRGBParam(_plugin->_paramOverlayInColor) );
00099         interact::AndActiveFunctor<>* activeIn3 = new interact::AndActiveFunctor<>();
00100         activeIn3->push_back( new interact::IsActiveBooleanParamFunctor<>( _plugin->_paramOverlayOut ) );
00101         activeIn3->push_back( new interact::IsNotSecretParamFunctor<>( _plugin->_paramPointIn3 ) );
00102         _interactScene.push_back( new interact::ParamPoint<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointIn3, _plugin->_clipSrc ),
00103                                                           activeIn3,
00104                                                           new interact::ColorRGBParam(_plugin->_paramOverlayInColor) );
00105 
00106 /*
00107         _interactScene.setManipulator(
00108               new Manipulator<interact::FrameClip, eCoordinateSystemXXcn>( _infos, _plugin->_paramPointCentre, _plugin->_clipSrc, _plugin->_ParamManipulatorMode ),
00109               new interact::ColorRGBParam(_plugin->_paramOverlayCentreColor)
00110          );
00111       */
00112 }
00113 
00114 bool PinningOverlayInteract::draw( const OFX::DrawArgs& args )
00115 {
00116         if( !_plugin->_paramOverlay->getValue() || !_plugin->_clipSrc->isConnected() )
00117                 return false;
00118 
00119         typedef boost::gil::point2<Scalar> Point2;
00120 //      static const float lineWidth = 2.0;
00121         bool displaySomething        = false;
00122 
00123         displaySomething |= _interactScene.draw( args );
00124 
00125         return displaySomething;
00126 }
00127 
00128 
00129 /*
00130 bool PinningOverlayInteract::keyDown( const OFX::KeyArgs& args )
00131 {
00132    if( (args.keySymbol == kOfxKey_Control_L) || (args.keySymbol == kOfxKey_Control_R) )
00133    {
00134          _keyPressed_ctrl = true;
00135    }
00136 }
00137 
00138 bool PinningOverlayInteract::keyUp( const OFX::KeyArgs& args )
00139 {
00140   if( (args.keySymbol == kOfxKey_Control_L) || (args.keySymbol == kOfxKey_Control_R) )
00141 
00142    {
00143          _keyPressed_ctrl = false;
00144    }
00145 }
00146 
00147 bool PinningOverlayInteract::keyRepeat( const OFX::KeyArgs& args )
00148 {
00149 
00150 }
00151 */
00152 bool PinningOverlayInteract::penMotion( const OFX::PenArgs& args )
00153 {
00154         return _interactScene.penMotion( args );
00155 }
00156 
00157 bool PinningOverlayInteract::penDown( const OFX::PenArgs& args )
00158 {
00159         return _interactScene.penDown( args );
00160 }
00161 
00162 bool PinningOverlayInteract::penUp( const OFX::PenArgs& args )
00163 {
00164     return _interactScene.penUp( args );
00165 }
00166 
00167 /*
00168 void PinningOverlayInteract::calculCentre( const std::vector< bounded_vector<double, 2> > pSelect)
00169 {
00170         double minX,maxX,minY,maxY = 0.0;
00171         
00172         for( unsigned int i=0 ; i<pSelect.size() ; ++i)
00173         {
00174                 if(minX > pSelect[i][0] )
00175                 {
00176                         minX = pSelect[i][0];
00177                 }
00178                 if(maxX < pSelect[i][0] )
00179                 {
00180                         maxX = pSelect[i][0];
00181                 }
00182                 if(minY > pSelect[i][1] )
00183                 {
00184                         minY = pSelect[i][1];
00185                 }
00186                 if(maxY < pSelect[i][1] )
00187                 {
00188                         maxY = pSelect[i][1];
00189                 }
00190         }
00191         _plugin->_paramPointCentre->setValue((minX + maxX)/2, (minY + maxY)/2);
00192 }
00193 
00194 void PinningOverlayInteract::rotatePts( std::vector< bounded_vector<double, 2> > pSelect, double angle)
00195 {
00196         //calcul centre
00197         //OfxPointD centre;
00198         //centre = calculCentre(pSelect);
00199         
00200         for( unsigned int i=0 ; i<pSelect.size() ; ++i)
00201         {
00202             //deplace a l'origine
00203             pSelect[i][0] -=  _plugin->_paramPointCentre->getValue().x;
00204             pSelect[i][1] -=  _plugin->_paramPointCentre->getValue().y;
00205 
00206         
00207             //effectue la rotation
00208             pSelect[i][0] = pSelect[i][0]*cos(angle) - pSelect[i][1]*sin(angle);
00209             pSelect[i][1] = pSelect[i][0]*sin(angle) - pSelect[i][1]*cos(angle);
00210         
00211             //retour position initiale
00212             pSelect[i][0] +=  _plugin->_paramPointCentre->getValue().x;
00213             pSelect[i][1] +=  _plugin->_paramPointCentre->getValue().y;
00214         }
00215 }
00216 
00217 void PinningOverlayInteract::scalePts( std::vector< bounded_vector<double, 2> > pSelect, double coef)
00218 {
00219 
00220         for( unsigned int i=0 ; i<pSelect.size() ; ++i)
00221         {
00222             //deplace a l'origine
00223             pSelect[i][0] -=  _plugin->_paramPointCentre->getValue().x;
00224             pSelect[i][1] -=  _plugin->_paramPointCentre->getValue().y;
00225 
00226             //effectue le scale
00227             pSelect[i][0] *= coef;
00228             pSelect[i][1] *= coef;
00229 
00230             //retour position initiale
00231             pSelect[i][0] +=  _plugin->_paramPointCentre->getValue().x;
00232             pSelect[i][1] +=  _plugin->_paramPointCentre->getValue().y;
00233         }
00234 }
00235 */
00236 
00237 }
00238 }
00239 }
00240 
00241