X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FProcessObject.cxx;h=050a2571269bd51040ad24feb4e85cbd1c7574bc;hb=e2fb8817731f6231d34941a208e46b36dad425b2;hp=f684a6ba54c287220694534372bd3184b62783bc;hpb=b10dac9333e7c909a7adf9394e079bbdf07893ec;p=cpPlugins.git diff --git a/lib/cpPlugins/ProcessObject.cxx b/lib/cpPlugins/ProcessObject.cxx index f684a6b..050a257 100644 --- a/lib/cpPlugins/ProcessObject.cxx +++ b/lib/cpPlugins/ProcessObject.cxx @@ -1,8 +1,8 @@ #include #include #include -#include - +#include +#include // ------------------------------------------------------------------------- cpPlugins::Parameters* cpPlugins::ProcessObject:: GetParameters( ) @@ -190,6 +190,14 @@ Disconnect( ) this->DisconnectOutputs( ); } +// ------------------------------------------------------------------------- +void cpPlugins::ProcessObject:: +Modified( ) const +{ + this->Superclass::Modified( ); + this->m_LastExecutionSpan = -1; +} + // ------------------------------------------------------------------------- itk::ModifiedTimeType cpPlugins::ProcessObject:: GetMTime( ) const @@ -200,30 +208,28 @@ GetMTime( ) const } // ------------------------------------------------------------------------- -std::string cpPlugins::ProcessObject:: +void cpPlugins::ProcessObject:: Update( ) { - std::string r = ""; - // Force upstream updates auto i = this->m_Inputs.begin( ); bool need_to_update = false; - for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) + for( ; i != this->m_Inputs.end( ); ++i ) { bool iv = i->second.IsValid( ); bool ir = i->second.IsRequired( ); if( !iv && ir ) - r = - "ProcessObject: Required input \"" + - i->first + "@" + this->GetClassName( ) + - "\" is not valid (=NULL)."; - if( iv && r == "" ) + this->_Error( + std::string( "Required input \"" ) + i->first + + std::string( "\" is not valid." ) + ); + if( iv ) { Self* src = dynamic_cast< Self* >( i->second->GetSource( ) ); if( src != NULL ) { need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) ); - r = src->Update( ); + src->Update( ); } // fi @@ -232,33 +238,34 @@ Update( ) } // rof // Current update - if( r == "" ) + if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) { - if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) + if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL ) { - std::cout + *( this->m_PrintExecutionStream ) << "cpPlugins: Updating \"" - << this->GetClassName( ) << ":" << this->GetClassCategory( ) + << this->GetClassCategory( ) << ":" << this->GetClassName( ) << "\"... "; - std::cout.flush( ); - long start = - std::chrono::duration_cast< std::chrono::milliseconds >( - std::chrono::system_clock::now( ).time_since_epoch( ) - ).count( ); - r = this->_GenerateData( ); - long end = - std::chrono::duration_cast< std::chrono::milliseconds >( - std::chrono::system_clock::now( ).time_since_epoch( ) - ).count( ); - this->m_LastExecutionTime = this->GetMTime( ); - std::cout << "done in " << ( ( end - start ) / 1000 ) << "s!" << std::endl; + this->m_PrintExecutionStream->flush( ); } // fi - } // fi + auto t_start = cpPlugins_CHRONO; + this->_GenerateData( ); + auto t_end = cpPlugins_CHRONO; + this->m_LastExecutionSpan = long( t_end - t_start ); + this->m_LastExecutionTime = this->GetMTime( ); + + if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL ) + { + *( this->m_PrintExecutionStream ) + << "done in " + << double( this->m_LastExecutionSpan ) / double( 1000 ) + << " s." << std::endl; - // Return error description, if any - return( r ); + } // fi + + } // fi } // ------------------------------------------------------------------------- @@ -297,7 +304,10 @@ SetInteractionObjects( const std::vector< void* >& objs ) cpPlugins::ProcessObject:: ProcessObject( ) : Superclass( ), - m_LastExecutionTime( 0 ) + m_LastExecutionTime( 0 ), + m_LastExecutionSpan( -1 ), + m_PrintExecution( false ), + m_PrintExecutionStream( &( std::cout ) ) { } @@ -320,4 +330,18 @@ _AddInput( const std::string& name, bool required ) } // fi } +// ------------------------------------------------------------------------- +void cpPlugins::ProcessObject:: +_Error( const std::string& error ) +{ + if( error != "" ) + { + itkExceptionMacro( + "Error: \"" << this->GetClassCategory( ) << "::" << + this->GetClassName( ) << "\": " << error + ); + + } // fi +} + // eof - $RCSfile$