TuttleOFX
1
|
00001 #include "INode.hpp" 00002 00003 #include "ImageEffectNode.hpp" 00004 00005 #include <tuttle/host/graph/ProcessVertexData.hpp> 00006 #include <tuttle/host/graph/ProcessVertexAtTimeData.hpp> 00007 00008 #include <boost/foreach.hpp> 00009 #include <boost/algorithm/string/join.hpp> 00010 #include <boost/lexical_cast.hpp> 00011 00012 namespace tuttle { 00013 namespace host { 00014 00015 INode::~INode() {} 00016 00017 ImageEffectNode& INode::asImageEffectNode( ) 00018 { 00019 return dynamic_cast<ImageEffectNode&> ( *this ); 00020 } 00021 00022 const ImageEffectNode& INode::asImageEffectNode( ) const 00023 { 00024 return dynamic_cast<const ImageEffectNode&> ( *this ); 00025 } 00026 00027 std::string INode::getVersionStr() const 00028 { 00029 std::vector<int> vInt = getVersion(); 00030 std::vector<std::string> vStr; 00031 BOOST_FOREACH( const int v, vInt ) 00032 { 00033 vStr.push_back( boost::lexical_cast<std::string>(v) ); 00034 } 00035 return boost::algorithm::join( vStr, "." ); 00036 } 00037 00038 void INode::setProcessData( Data* data ) 00039 { 00040 _data = data; 00041 } 00042 00043 void INode::setProcessDataAtTime( DataAtTime* dataAtTime ) 00044 { 00045 TUTTLE_TLOG( TUTTLE_TRACE, "setProcessDataAtTime \"" << getName() << "\" at " << dataAtTime->_time ); 00046 _dataAtTime[dataAtTime->_time] = dataAtTime; 00047 } 00048 00049 void INode::clearProcessDataAtTime() 00050 { 00051 _dataAtTime.clear(); 00052 } 00053 00054 void INode::setBeforeRenderCallback( Callback *cb ) 00055 { 00056 _beforeRenderCallback = cb; 00057 } 00058 00059 void INode::beforeRenderCallback( INode &node, DataAtTime &data ) 00060 { 00061 if( _beforeRenderCallback ) 00062 { 00063 _beforeRenderCallback->call(node, data._time); 00064 } 00065 } 00066 00067 INode::Data& INode::getData() 00068 { 00069 if( !_data ) 00070 { 00071 BOOST_THROW_EXCEPTION( exception::Bug() 00072 << exception::dev("Process data not set.") 00073 << exception::nodeName( getName() ) ); 00074 } 00075 return *_data; 00076 } 00077 00078 const INode::Data& INode::getData() const 00079 { 00080 if( !_data ) 00081 { 00082 BOOST_THROW_EXCEPTION( exception::Bug() 00083 << exception::dev("Process data not set.") 00084 << exception::nodeName( getName() ) ); 00085 } 00086 return *_data; 00087 } 00088 00089 bool INode::hasData( const OfxTime time ) const 00090 { 00091 DataAtTimeMap::const_iterator it = _dataAtTime.find( time ); 00092 return it != _dataAtTime.end(); 00093 } 00094 00095 const INode::DataAtTime& INode::getData( const OfxTime time ) const 00096 { 00097 //TUTTLE_TLOG( TUTTLE_TRACE, "- INode::getData(" << time << ") of " << getName() ); 00098 DataAtTimeMap::const_iterator it = _dataAtTime.find( time ); 00099 if( it == _dataAtTime.end() ) 00100 { 00101 std::ostringstream ss; 00102 ss << "Defined times : "; 00103 BOOST_FOREACH( const DataAtTimeMap::value_type& v, _dataAtTime ) 00104 { 00105 ss << v.first << ", "; 00106 } 00107 BOOST_THROW_EXCEPTION( exception::Bug() 00108 << exception::dev() + "Process data at time not set.\n" 00109 + ss.str() 00110 << exception::nodeName( getName() ) 00111 //<< exception::pluginIdentifier( getPlugin().getIdentifier() ) 00112 << exception::time( time ) ); 00113 } 00114 return *it->second; 00115 } 00116 00117 INode::DataAtTime& INode::getData( const OfxTime time ) 00118 { 00119 return const_cast<DataAtTime&>( const_cast<const This*>(this)->getData(time) ); 00120 } 00121 00122 const INode::DataAtTime& INode::getFirstData() const 00123 { 00124 DataAtTimeMap::const_iterator it = _dataAtTime.begin(); 00125 if( it == _dataAtTime.end() ) 00126 { 00127 BOOST_THROW_EXCEPTION( exception::Bug() 00128 << exception::dev() + "Process data empty." 00129 << exception::nodeName( getName() ) ); 00130 } 00131 return *it->second; 00132 } 00133 00134 INode::DataAtTime& INode::getFirstData() 00135 { 00136 return const_cast<DataAtTime&>( const_cast<const This*>(this)->getFirstData() ); 00137 } 00138 00139 const INode::DataAtTime& INode::getLastData() const 00140 { 00141 DataAtTimeMap::const_reverse_iterator it = _dataAtTime.rbegin(); 00142 if( it == _dataAtTime.rend() ) 00143 { 00144 BOOST_THROW_EXCEPTION( exception::Bug() 00145 << exception::dev() + "Process data empty." 00146 << exception::nodeName( getName() ) ); 00147 } 00148 return *it->second; 00149 } 00150 00151 INode::DataAtTime& INode::getLastData() 00152 { 00153 return const_cast<DataAtTime&>( const_cast<const This*>(this)->getLastData() ); 00154 } 00155 00156 std::ostream& operator<<( std::ostream& os, const INode& v ) 00157 { 00158 return v.print(os); 00159 } 00160 00161 } 00162 }