#include #include #ifdef cpPlugins_Interface_QT4 #include #include #include #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- std::set< std::string > cpPlugins::Interface::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::Interface::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::Interface::ProcessObject:: GetNumberOfInputs( ) const { return( this->m_Inputs.size( ) ); } // ------------------------------------------------------------------------- unsigned int cpPlugins::Interface::ProcessObject:: GetNumberOfOutputs( ) const { return( this->m_Outputs.size( ) ); } // ------------------------------------------------------------------------- cpPlugins::Interface:: ProcessObjectPort& cpPlugins::Interface::ProcessObject:: GetOutput( const std::string& id ) { static ProcessObjectPort 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::Interface:: ProcessObjectPort& cpPlugins::Interface::ProcessObject:: GetOutput( const std::string& id ) const { static const ProcessObjectPort null_port; auto i = this->m_Outputs.find( id ); if( i == this->m_Outputs.end( ) ) return( null_port ); else return( i->second ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::ProcessObject:: SetInput( const std::string& id, const ProcessObjectPort& 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::Interface::ProcessObject:: DisconnectInputs( ) { auto i = this->m_Inputs.begin( ); for( ; i != this->m_Inputs.end( ); ++i ) i->second = NULL; this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: DisconnectOutputs( ) { auto i = this->m_Outputs.begin( ); for( ; i != this->m_Outputs.end( ); ++i ) if( i->second.IsValid( ) ) i->second->DisconnectPipeline( ); this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: Disconnect( ) { this->DisconnectInputs( ); this->DisconnectOutputs( ); } // ------------------------------------------------------------------------- itk::ModifiedTimeType cpPlugins::Interface::ProcessObject:: GetMTime( ) const { auto params_time = this->m_Parameters->GetMTime( ); auto filter_time = this->Superclass::GetMTime( ); auto ipobj = this->GetITK< itk::ProcessObject >( ); if( ipobj == NULL ) { auto vpobj = this->GetVTK< vtkAlgorithm >( ); if( vpobj != NULL ) filter_time = ( const_cast< vtkAlgorithm* >( vpobj ) )->GetMTime( ); } else filter_time = ipobj->GetMTime( ); return( ( params_time < filter_time )? filter_time: params_time ); } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::ProcessObject:: Update( ) { std::string r = ""; // Force upstream updates _TDataContainer::iterator i = this->m_Inputs.begin( ); bool need_to_update = false; for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) { if( i->second.IsValid( ) ) { Self* src = dynamic_cast< Self* >( i->second->GetSource( ) ); if( src != NULL ) { need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) ); r = src->Update( ); } // fi } else r = "cpPlugins::Interface::ProcessObject: No input connected."; } // rof // Current update if( r == "" ) { if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) { r = this->_GenerateData( ); this->m_LastExecutionTime = this->GetMTime( ); } // fi } // fi // Return error description, if any return( r ); } // ------------------------------------------------------------------------- cpPlugins::Interface::ProcessObject:: ProcessObject( ) : Superclass( ), m_LastExecutionTime( 0 ), m_ParametersDialog( NULL ), m_MPRViewer( NULL ) { this->m_Parameters = TParameters::New( ); this->m_Parameters->SetProcessObject( this ); #ifdef cpPlugins_Interface_QT4 if( QApplication::instance( ) != NULL ) { this->m_ParametersDialog = new ParametersQtDialog( ); this->m_ParametersDialog->setParameters( this->m_Parameters ); } // fi #endif // cpPlugins_Interface_QT4 } // ------------------------------------------------------------------------- cpPlugins::Interface::ProcessObject:: ~ProcessObject( ) { this->Disconnect( ); if( this->m_ParametersDialog != NULL ) delete this->m_ParametersDialog; } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: _AddInput( const std::string& name ) { typedef typename _TDataContainer::value_type _TValue; auto i = this->m_Inputs.find( name ); if( i == this->m_Inputs.end( ) ) { i = this->m_Inputs.insert( _TValue( name, NULL ) ).first; this->Modified( ); } // fi } // eof - $RCSfile$