X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FProcessObject.cxx;h=364816a4d094ae5c2df701dec48228ecc929ae05;hb=6226e722a440b16cd35bb126353f6a14ff86bccf;hp=6f3bd34e3d8e537e47282613974ae73f87548272;hpb=d6f15d4cb764982e2b09060a9c0f38636891590c;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index 6f3bd34..364816a 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,128 +1,130 @@ #include +#include #ifdef cpPlugins_Interface_QT4 +#include #include +#include #endif // cpPlugins_Interface_QT4 -#include - // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -Modified( ) const +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetInputsNames( ) const { - if( this->m_ITKObject.IsNotNull( ) ) - this->m_ITKObject->Modified( ); - if( this->m_VTKObject.GetPointer( ) != NULL ) - this->m_VTKObject->Modified( ); - this->Superclass::Modified( ); + std::set< std::string > names; + for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) + names.insert( i->first ); + return( names ); } // ------------------------------------------------------------------------- -bool cpPlugins::Interface::ProcessObject:: -IsInteractive( ) const +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetOutputsNames( ) const { - std::vector< std::string > names; - this->m_Parameters->GetNames( names ); - bool res = false; - auto i = names.begin( ); - for( ; i != names.end( ); ++i ) - { - TParameters::Type t = this->m_Parameters->GetType( *i ); - res |= ( t == TParameters::Point ); - res |= ( t == TParameters::Index ); - res |= ( t == TParameters::PointList ); - res |= ( t == TParameters::IndexList ); - - } // rof - return( res ); + std::set< std::string > names; + for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i ) + names.insert( i->first ); + return( names ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -TParameters* cpPlugins::Interface::ProcessObject:: -GetParameters( ) +unsigned int cpPlugins::Interface::ProcessObject:: +GetNumberOfInputs( ) const { - return( this->m_Parameters.GetPointer( ) ); + return( this->m_Inputs.size( ) ); } // ------------------------------------------------------------------------- -const cpPlugins::Interface::ProcessObject:: -TParameters* cpPlugins::Interface::ProcessObject:: -GetParameters( ) const +unsigned int cpPlugins::Interface::ProcessObject:: +GetNumberOfOutputs( ) const { - return( this->m_Parameters.GetPointer( ) ); + return( this->m_Outputs.size( ) ); } // ------------------------------------------------------------------------- cpPlugins::Interface:: -Plugins* cpPlugins::Interface::ProcessObject:: -GetPlugins( ) +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) { - return( this->m_Plugins ); + static OutputProcessObjectPort 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:: -Plugins* cpPlugins::Interface::ProcessObject:: -GetPlugins( ) const +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) const { - return( this->m_Plugins ); + static const OutputProcessObjectPort null_port; + auto i = this->m_Outputs.find( id ); + if( i == this->m_Outputs.end( ) ) + return( null_port ); + else + return( i->second ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetPlugins( Plugins* p ) +bool cpPlugins::Interface::ProcessObject:: +SetInput( const std::string& id, const OutputProcessObjectPort& port ) { - this->m_Plugins = p; -} + auto i = this->m_Inputs.find( id ); + if( i != this->m_Inputs.end( ) ) + { + if( i->second.GetPointer( ) != port.GetPointer( ) ) + { + i->second = port; + this->Modified( ); -// ------------------------------------------------------------------------- -unsigned int cpPlugins::Interface::ProcessObject:: -GetNumberOfInputs( ) const -{ - return( this->m_Inputs.size( ) ); + } // fi + return( true ); + } + else + return( false ); } // ------------------------------------------------------------------------- -unsigned int cpPlugins::Interface::ProcessObject:: -GetNumberOfOutputs( ) const +void cpPlugins::Interface::ProcessObject:: +DisconnectInputs( ) { - return( this->m_Outputs.size( ) ); + auto i = this->m_Inputs.begin( ); + for( ; i != this->m_Inputs.end( ); ++i ) + i->second = NULL; + this->Modified( ); } // ------------------------------------------------------------------------- -std::vector< std::string > cpPlugins::Interface::ProcessObject:: -GetInputsNames( ) const +void cpPlugins::Interface::ProcessObject:: +DisconnectOutputs( ) { - std::vector< std::string > r; - auto dIt = this->m_Inputs.begin( ); - for( ; dIt != this->m_Inputs.end( ); ++dIt ) - r.push_back( dIt->first ); - return( r ); + auto i = this->m_Outputs.begin( ); + for( ; i != this->m_Outputs.end( ); ++i ) + if( i->second.IsValid( ) ) + i->second->DisconnectFromPipeline( ); + this->Modified( ); } // ------------------------------------------------------------------------- -std::vector< std::string > cpPlugins::Interface::ProcessObject:: -GetOutputsNames( ) const +void cpPlugins::Interface::ProcessObject:: +Disconnect( ) { - std::vector< std::string > r; - auto dIt = this->m_Outputs.begin( ); - for( ; dIt != this->m_Outputs.end( ); ++dIt ) - r.push_back( dIt->first ); - return( r ); + this->DisconnectInputs( ); + this->DisconnectOutputs( ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj ) +itk::ModifiedTimeType cpPlugins::Interface::ProcessObject:: +GetMTime( ) const { - _TDataContainer::iterator i = this->m_Inputs.find( id ); - if( i != this->m_Inputs.end( ) ) - { - i->second = dobj; - this->Modified( ); - - } // fi + auto params_time = this->m_Parameters->GetMTime( ); + auto filter_time = this->Superclass::GetMTime( ); + return( ( params_time < filter_time )? params_time: filter_time ); } // ------------------------------------------------------------------------- @@ -132,70 +134,37 @@ Update( ) std::string r = ""; // Force upstream updates - _TDataContainer::iterator i = this->m_Inputs.begin( ); + auto i = this->m_Inputs.begin( ); + bool need_to_update = false; for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) { - Self* src = dynamic_cast< Self* >( i->second->GetSource( ) ); - if( src != NULL ) - r = src->Update( ); + 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 + + } // fi } // rof // Current update if( r == "" ) - r = this->_GenerateData( ); - - // Return error description, if any - return( r ); -} - -// ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -DisconnectOutputs( ) -{ - _TDataContainer::iterator i = this->m_Outputs.begin( ); - for( ; i != this->m_Outputs.end( ); ++i ) - if( i->second.IsNotNull( ) ) - i->second->DisconnectPipeline( ); -} - -// ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -AddInteractor( vtkRenderWindowInteractor* interactor ) -{ -#ifdef cpPlugins_Interface_QT4 - this->m_ParametersDialog->addInteractor( interactor ); -#endif // cpPlugins_Interface_QT4 -} - -// ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -DialogResult cpPlugins::Interface::ProcessObject:: -ExecConfigurationDialog( QWidget* parent ) -{ - DialogResult r = Self::DialogResult_Cancel; - -#ifdef cpPlugins_Interface_QT4 - - this->m_ParametersDialog->setParent( NULL ); - this->m_ParametersDialog->setParameters( this->m_Parameters ); - - if( !( this->m_ParametersDialog->IsModal( ) ) ) - { - this->m_ParametersDialog->show( ); - r = Self::DialogResult_Modal; - } - else { - if( this->m_ParametersDialog->exec( ) == 1 ) - r = Self::DialogResult_NoModal; - else - r = Self::DialogResult_Cancel; + if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) + { + r = this->_GenerateData( ); + this->m_LastExecutionTime = this->GetMTime( ); - } // fi + } // fi -#endif // cpPlugins_Interface_QT4 + } // fi + // Return error description, if any return( r ); } @@ -203,32 +172,45 @@ ExecConfigurationDialog( QWidget* parent ) cpPlugins::Interface::ProcessObject:: ProcessObject( ) : Superclass( ), - m_ITKObject( NULL ), - m_VTKObject( NULL ), - m_Plugins( NULL ) + m_LastExecutionTime( 0 ), + m_ParametersDialog( NULL ), + m_MPRViewer( NULL ) { this->m_Parameters = TParameters::New( ); this->m_Parameters->SetProcessObject( this ); - this->m_ParametersDialog = new ParametersQtDialog( ); - this->m_ParametersDialog->setTitle( - this->GetClassName( ) + std::string( " basic configuration" ) - ); +#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( ) { - delete this->m_ParametersDialog; + this->Disconnect( ); + if( this->m_ParametersDialog != NULL ) + delete this->m_ParametersDialog; } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -_AddInput( const std::string& name ) +_AddInput( const std::string& name, bool required ) { - this->m_Inputs[ name ] = NULL; - this->Modified( ); +// typedef typename _TInputs::value_type _TValue; + auto i = this->m_Inputs.find( name ); + if( i == this->m_Inputs.end( ) ) + { + InputProcessObjectPort new_port( required ); + this->m_Inputs[ name ] = new_port; + this->Modified( ); + + } // fi } // eof - $RCSfile$