#include #include #include #include #include // ------------------------------------------------------------------------- cpPlugins::BaseObjects::Parameters* cpPlugins::BaseObjects::ProcessObject:: GetParameters( ) { return( &( this->m_Parameters ) ); } // ------------------------------------------------------------------------- const cpPlugins::BaseObjects::Parameters* cpPlugins::BaseObjects::ProcessObject:: GetParameters( ) const { return( &( this->m_Parameters ) ); } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: SetITK( itk::LightObject* o ) { // Polymorphism: do nothing -> this is a filter!!! } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: SetVTK( vtkObjectBase* o ) { // Polymorphism: do nothing -> this is a filter!!! } // ------------------------------------------------------------------------- std::set< std::string > cpPlugins::BaseObjects::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::BaseObjects::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::BaseObjects::ProcessObject:: GetNumberOfInputs( ) const { return( this->m_Inputs.size( ) ); } // ------------------------------------------------------------------------- unsigned int cpPlugins::BaseObjects::ProcessObject:: GetNumberOfOutputs( ) const { return( this->m_Outputs.size( ) ); } // ------------------------------------------------------------------------- unsigned int cpPlugins::BaseObjects::ProcessObject:: GetInputSize( const std::string& n ) const { auto it = this->m_Inputs.find( n ); if( it != this->m_Inputs.end( ) ) return( it->second->Size( ) ); else return( 0 ); } // ------------------------------------------------------------------------- bool cpPlugins::BaseObjects::ProcessObject:: IsInputMultiple( const std::string& n ) const { auto i = this->m_Inputs.find( n ); if( i != this->m_Inputs.end( ) ) return( dynamic_cast< MultipleInputsPort* >( i->second ) != NULL ); else return( false ); } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: AddInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o ) { auto it = this->m_Inputs.find( n ); if( it != this->m_Inputs.end( ) ) it->second->Add( o ); } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: SetInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o ) { this->AddInput( n, o ); } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: DisconnectInputs( ) { for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) i->second->Clear( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: DisconnectOutputs( ) { for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i ) if( i->second->IsValid( ) ) i->second->Get( )->DisconnectFromPipeline( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: Disconnect( ) { this->DisconnectInputs( ); this->DisconnectOutputs( ); } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: Modified( ) const { this->Superclass::Modified( ); this->m_LastExecutionSpan = -1; } // ------------------------------------------------------------------------- itk::ModifiedTimeType cpPlugins::BaseObjects::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::BaseObjects::ProcessObject:: Update( ) { // Force upstream updates bool need_to_update = this->m_ExplicitExecution; for( auto i = this->m_Inputs.begin( ); 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 ) { unsigned int n = i->second->Size( ); for( unsigned int j = 0; j < n; ++j ) { Self* src = i->second->Get( j )->GetSource( ); if( src != NULL ) { need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) ); src->Update( ); } // fi } // rof } // 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->GetName( ) << " (" << this->GetClassCategory( ) << ":" << this->GetClassName( ) << ")\"... "; this->m_PrintExecutionStream->flush( ); } // fi auto t_start = cpPlugins_CHRONO; this->_GenerateData( ); this->Modified( ); 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 } // ------------------------------------------------------------------------- QDialog* cpPlugins::BaseObjects::ProcessObject:: CreateQDialog( ) { #ifdef cpPlugins_QT4 cpPlugins::QT::ParametersDialog* dlg = NULL; if( QApplication::instance( ) != NULL ) { dlg = new cpPlugins::QT::ParametersDialog( ); dlg->setProcessObject( this ); } // fi return( dlg ); #else // cpPlugins_QT4 return( NULL ); #endif // cpPlugins_QT4 } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: AddInteractor( vtkRenderWindowInteractor* i ) { if( this->m_Interactors.insert( i ).second ) this->Modified( ); } // ------------------------------------------------------------------------- bool cpPlugins::BaseObjects::ProcessObject:: IsInteractive( ) { return( false ); } // ------------------------------------------------------------------------- cpPlugins::BaseObjects::ProcessObject:: ProcessObject( ) : Superclass( ), m_Name( "" ), m_PluginName( "" ), m_ExplicitExecution( false ), m_LastExecutionTime( 0 ), m_LastExecutionSpan( -1 ), m_PrintExecution( false ), m_PrintExecutionStream( &( std::cout ) ) { } // ------------------------------------------------------------------------- cpPlugins::BaseObjects::ProcessObject:: ~ProcessObject( ) { for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) delete i->second; for( auto o = this->m_Outputs.begin( ); o != this->m_Outputs.end( ); ++o ) delete o->second; this->m_Inputs.clear( ); this->m_Outputs.clear( ); } // ------------------------------------------------------------------------- void cpPlugins::BaseObjects::ProcessObject:: _Error( const std::string& error ) { if( error != "" ) { itkExceptionMacro( "Error: \"" << this->GetClassCategory( ) << "::" << this->GetClassName( ) << "\": " << error ); } // fi } // eof - $RCSfile$