#include #include #include #include // ------------------------------------------------------------------------- cpPlugins::Parameters* cpPlugins::ProcessObject:: GetParameters( ) { return( &( this->m_Parameters ) ); } // ------------------------------------------------------------------------- const cpPlugins::Parameters* cpPlugins::ProcessObject:: GetParameters( ) const { return( &( this->m_Parameters ) ); } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: SetITK( itk::LightObject* o ) { // Polymorphism: do nothing -> this is a filter!!! } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: SetVTK( vtkObjectBase* o ) { // Polymorphism: do nothing -> this is a filter!!! } // ------------------------------------------------------------------------- std::set< std::string > cpPlugins::ProcessObject:: GetInputsNames( ) const { std::set< std::string > names; for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) names.insert( i->first ); return( names ); } // ------------------------------------------------------------------------- std::set< std::string > cpPlugins::ProcessObject:: GetOutputsNames( ) const { std::set< std::string > names; for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i ) names.insert( i->first ); return( names ); } // ------------------------------------------------------------------------- unsigned int cpPlugins::ProcessObject:: GetNumberOfInputs( ) const { return( this->m_Inputs.size( ) ); } // ------------------------------------------------------------------------- unsigned int cpPlugins::ProcessObject:: GetNumberOfOutputs( ) const { return( this->m_Outputs.size( ) ); } // ------------------------------------------------------------------------- cpPlugins:: OutputPort& cpPlugins::ProcessObject:: GetOutputPort( const std::string& id ) { static OutputPort null_port; auto i = this->m_Outputs.find( id ); if( i == this->m_Outputs.end( ) ) { null_port = NULL; return( null_port ); } else return( i->second ); } // ------------------------------------------------------------------------- const cpPlugins:: OutputPort& cpPlugins::ProcessObject:: GetOutputPort( const std::string& id ) const { static const OutputPort null_port; auto i = this->m_Outputs.find( id ); if( i == this->m_Outputs.end( ) ) return( null_port ); else return( i->second ); } // ------------------------------------------------------------------------- bool cpPlugins::ProcessObject:: SetInputPort( const std::string& id, const OutputPort& port ) { auto i = this->m_Inputs.find( id ); if( i != this->m_Inputs.end( ) ) { if( i->second.GetPointer( ) != port.GetPointer( ) ) { i->second = port; this->Modified( ); } // fi return( true ); } else return( false ); } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: DisconnectInputs( ) { auto i = this->m_Inputs.begin( ); for( ; i != this->m_Inputs.end( ); ++i ) i->second = NULL; this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: DisconnectOutputs( ) { auto i = this->m_Outputs.begin( ); for( ; i != this->m_Outputs.end( ); ++i ) if( i->second.IsValid( ) ) i->second->DisconnectFromPipeline( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: Disconnect( ) { this->DisconnectInputs( ); this->DisconnectOutputs( ); } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: Modified( ) const { this->Superclass::Modified( ); this->m_LastExecutionSpan = -1; } // ------------------------------------------------------------------------- itk::ModifiedTimeType cpPlugins::ProcessObject:: GetMTime( ) const { auto params_time = this->m_Parameters.GetMTime( ); auto filter_time = this->Superclass::GetMTime( ); return( ( params_time > filter_time )? params_time: filter_time ); } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: Update( ) { // Force upstream updates auto i = this->m_Inputs.begin( ); bool need_to_update = false; for( ; i != this->m_Inputs.end( ); ++i ) { bool iv = i->second.IsValid( ); bool ir = i->second.IsRequired( ); if( !iv && ir ) 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( ) ); src->Update( ); } // fi } // fi } // rof // Current update if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) { if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL ) { *( this->m_PrintExecutionStream ) << "cpPlugins: Updating \"" << this->GetClassCategory( ) << ":" << this->GetClassName( ) << "\"... "; this->m_PrintExecutionStream->flush( ); } // 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; } // fi } // fi } // ------------------------------------------------------------------------- cpPlugins::ParametersQtDialog* cpPlugins::ProcessObject:: CreateQtDialog( ) { #ifdef cpPlugins_QT4 ParametersQtDialog* dlg = NULL; if( QApplication::instance( ) != NULL ) { dlg = new ParametersQtDialog( ); dlg->setProcessObject( this ); } // fi return( dlg ); #else // cpPlugins_QT4 return( NULL ); #endif // cpPlugins_QT4 } // ------------------------------------------------------------------------- bool cpPlugins::ProcessObject:: IsInteractive( ) { return( false ); } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: SetInteractionObjects( const std::vector< void* >& objs ) { // Do nothing } // ------------------------------------------------------------------------- cpPlugins::ProcessObject:: ProcessObject( ) : Superclass( ), m_LastExecutionTime( 0 ), m_LastExecutionSpan( -1 ), m_PrintExecution( false ), m_PrintExecutionStream( &( std::cout ) ) { } // ------------------------------------------------------------------------- cpPlugins::ProcessObject:: ~ProcessObject( ) { } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: _AddInput( const std::string& name, bool required ) { auto i = this->m_Inputs.find( name ); if( i == this->m_Inputs.end( ) ) { this->m_Inputs[ name ] = InputPort( required ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- void cpPlugins::ProcessObject:: _Error( const std::string& error ) { if( error != "" ) { itkExceptionMacro( "Error: \"" << this->GetClassCategory( ) << "::" << this->GetClassName( ) << "\": " << error ); } // fi } // eof - $RCSfile$