TuttleOFX  1
Node.cpp
Go to the documentation of this file.
00001 #include "Node.hpp"
00002 #include "Graph.hpp"
00003 
00004 #include "Core.hpp"
00005 #include "ImageEffectNode.hpp"
00006 
00007 namespace tuttle {
00008 namespace host {
00009 
00010 INode* createNode( const std::string& pluginName )
00011 {
00012         ofx::imageEffect::OfxhImageEffectPlugin* plug = core().getImageEffectPluginById( pluginName );
00013 
00014         if( !plug )
00015         {
00016                 BOOST_THROW_EXCEPTION( exception::Logic()
00017                     << exception::user( "Plugin not found." )
00018                     //<< exception::dev( core().getImageEffectPluginCache() )
00019                     << exception::pluginIdentifier( pluginName ) );
00020         }
00021 
00022         plug->loadAndDescribeActions();
00023 
00024         ofx::imageEffect::OfxhImageEffectNode* plugInst = NULL;
00025         if( plug->supportsContext( kOfxImageEffectContextReader ) )
00026         {
00027                 plugInst = plug->createInstance( kOfxImageEffectContextReader );
00028         }
00029         else if( plug->supportsContext( kOfxImageEffectContextWriter ) )
00030         {
00031                 plugInst = plug->createInstance( kOfxImageEffectContextWriter );
00032         }
00033         else if( plug->supportsContext( kOfxImageEffectContextGeneral ) )
00034         {
00035                 plugInst = plug->createInstance( kOfxImageEffectContextGeneral );
00036         }
00037         else if( plug->supportsContext( kOfxImageEffectContextGenerator ) )
00038         {
00039                 plugInst = plug->createInstance( kOfxImageEffectContextGenerator );
00040         }
00041         else if( plug->supportsContext( kOfxImageEffectContextFilter ) )
00042         {
00043                 plugInst = plug->createInstance( kOfxImageEffectContextFilter );
00044         }
00045         else
00046         {
00047                 BOOST_THROW_EXCEPTION( exception::Logic()
00048                     << exception::user( "Plugin contexts not supported by the host. (" + pluginName + ")" ) );
00049         }
00050 
00051         if( !plugInst )
00052         {
00053                 BOOST_THROW_EXCEPTION( exception::Logic()
00054                     << exception::user( "Plugin not found. plugInst (" + pluginName + ")" ) );
00055         }
00056         ImageEffectNode* node = dynamic_cast<ImageEffectNode*>( plugInst );
00057         if( !node )
00058         {
00059                 BOOST_THROW_EXCEPTION( exception::Logic()
00060                     << exception::user( "Plugin not found (" + pluginName + ")." ) );
00061         }
00062         return node;
00063 }
00064 
00065 
00066 bool compute( const std::vector<NodeInit>& nodes, const ComputeOptions& options )
00067 {
00068         const_cast<ComputeOptions&>(options).setReturnBuffers( false );
00069         
00070         memory::MemoryCache emptyMemoryCache;
00071         return compute( emptyMemoryCache, nodes, options );
00072 }
00073 
00074 bool compute( memory::MemoryCache& memoryCache, const std::vector<NodeInit>& nodes, const ComputeOptions& options )
00075 {
00076         Graph g;
00077         g.addConnectedNodes( nodes );
00078         return g.compute( memoryCache, options );
00079 }
00080 
00081 
00082 NodeInit::NodeInit( const std::string& pluginName )
00083 {
00084         setNode( *createNode( pluginName ) );
00085 }
00086 
00087 NodeInit::NodeInit( INode& node )
00088 {
00089         setNode( node );
00090 }
00091 
00092 NodeInit& NodeInit::setParam( const std::string& paramName, ... )
00093 {
00094         va_list ap;
00095         va_start( ap, paramName );
00096 
00097         _node->getParam(paramName).setV( ap, ofx::attribute::eChangeUserEdited );
00098 
00099         va_end( ap );
00100         return *this;
00101 }
00102 
00103 NodeInit& NodeInit::setParamExp( const std::string& paramName, const std::string& paramExpValue )
00104 {
00105         _node->getParam(paramName).setValueFromExpression( paramExpValue, ofx::attribute::eChangeUserEdited );
00106         return *this;
00107 }
00108 
00109 }
00110 }