#include <cpPlugins/ProcessObject.h>
#include <cpPlugins/ParametersQtDialog.h>
#include <itkProcessObject.h>
-#include <chrono>
-
+#include <itkExceptionObject.h>
+#include <iostream>
// -------------------------------------------------------------------------
cpPlugins::Parameters* cpPlugins::ProcessObject::
GetParameters( )
this->DisconnectOutputs( );
}
+// -------------------------------------------------------------------------
+void cpPlugins::ProcessObject::
+Modified( ) const
+{
+ this->Superclass::Modified( );
+ this->m_LastExecutionSpan = -1;
+}
+
// -------------------------------------------------------------------------
itk::ModifiedTimeType cpPlugins::ProcessObject::
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
} // 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
}
// -------------------------------------------------------------------------
cpPlugins::ProcessObject::
ProcessObject( )
: Superclass( ),
- m_LastExecutionTime( 0 )
+ m_LastExecutionTime( 0 ),
+ m_LastExecutionSpan( -1 ),
+ m_PrintExecution( false ),
+ m_PrintExecutionStream( &( std::cout ) )
{
}
} // fi
}
+// -------------------------------------------------------------------------
+void cpPlugins::ProcessObject::
+_Error( const std::string& error )
+{
+ if( error != "" )
+ {
+ itkExceptionMacro(
+ "Error: \"" << this->GetClassCategory( ) << "::" <<
+ this->GetClassName( ) << "\": " << error
+ );
+
+ } // fi
+}
+
// eof - $RCSfile$