TuttleOFX
1
|
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::IMemoryCache& memoryCache, const std::vector<NodeInit>& nodes, const ComputeOptions& options ) 00075 { 00076 return compute( memoryCache, nodes, options, core().getMemoryCache() ); 00077 } 00078 00079 bool compute( memory::IMemoryCache& memoryCache, const std::vector<NodeInit>& nodes, const ComputeOptions& options, memory::IMemoryCache& internMemoryCache ) 00080 { 00081 Graph g; 00082 g.addConnectedNodes( nodes ); 00083 return g.compute( memoryCache, NodeListArg(), options, internMemoryCache ); 00084 } 00085 00086 00087 NodeInit::NodeInit( const std::string& pluginName ) 00088 { 00089 setNode( *createNode( pluginName ) ); 00090 } 00091 00092 NodeInit::NodeInit( INode& node ) 00093 { 00094 setNode( node ); 00095 } 00096 00097 NodeInit& NodeInit::setParam( const std::string& paramName, ... ) 00098 { 00099 va_list ap; 00100 va_start( ap, paramName ); 00101 00102 _node->getParam(paramName).setV( ap, ofx::attribute::eChangeUserEdited ); 00103 00104 va_end( ap ); 00105 return *this; 00106 } 00107 00108 NodeInit& NodeInit::setParamExp( const std::string& paramName, const std::string& paramExpValue ) 00109 { 00110 _node->getParam(paramName).setValueFromExpression( paramExpValue, ofx::attribute::eChangeUserEdited ); 00111 return *this; 00112 } 00113 00114 00115 void NodeInit::setBeforeRenderCallback(Callback *cb){_node->setBeforeRenderCallback(cb);} 00116 00117 } 00118 }