X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FProcessObject.cxx;h=364816a4d094ae5c2df701dec48228ecc929ae05;hb=6226e722a440b16cd35bb126353f6a14ff86bccf;hp=5434319fb09c1d9e7a8b47169e15185d83cda862;hpb=1b600247da314fe62d007ca8a0ce24d0006931f4;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index 5434319..364816a 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,4 +1,5 @@ #include +#include #ifdef cpPlugins_Interface_QT4 #include @@ -6,16 +7,13 @@ #include #endif // cpPlugins_Interface_QT4 -#include - // ------------------------------------------------------------------------- std::set< std::string > cpPlugins::Interface::ProcessObject:: GetInputsNames( ) const { std::set< std::string > names; - auto dIt = this->m_Inputs.begin( ); - for( ; dIt != this->m_Inputs.end( ); ++dIt ) - names.insert( dIt->first ); + for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) + names.insert( i->first ); return( names ); } @@ -24,9 +22,8 @@ std::set< std::string > cpPlugins::Interface::ProcessObject:: GetOutputsNames( ) const { std::set< std::string > names; - auto dIt = this->m_Outputs.begin( ); - for( ; dIt != this->m_Outputs.end( ); ++dIt ) - names.insert( dIt->first ); + for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i ) + names.insert( i->first ); return( names ); } @@ -45,120 +42,129 @@ GetNumberOfOutputs( ) const } // ------------------------------------------------------------------------- -bool cpPlugins::Interface::ProcessObject:: -SetInput( - const std::string& id, cpPlugins::Interface::DataObject::Pointer* dobj - ) +cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) { - _TDataContainer::iterator i = this->m_Inputs.find( id ); - if( i != this->m_Inputs.end( ) ) + static OutputProcessObjectPort null_port; + auto i = this->m_Outputs.find( id ); + if( i == this->m_Outputs.end( ) ) { - i->second = dobj; - this->Modified( ); - return( true ); + null_port = NULL; + return( null_port ); } else - return( false ); + return( i->second ); } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::ProcessObject:: -Update( ) +const cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) const { - std::string r = ""; + 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 ); +} - // Force upstream updates - _TDataContainer::iterator i = this->m_Inputs.begin( ); - for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::ProcessObject:: +SetInput( const std::string& id, const OutputProcessObjectPort& port ) +{ + auto i = this->m_Inputs.find( id ); + if( i != this->m_Inputs.end( ) ) { - if( i->second->IsNotNull( ) ) + if( i->second.GetPointer( ) != port.GetPointer( ) ) { - Self* src = dynamic_cast< Self* >( ( *( i->second ) )->GetSource( ) ); - if( src != NULL ) - r = src->Update( ); - } - else - r = "cpPlugins::Interface::ProcessObject: No input connected."; - - } // rof - - // Current update - if( r == "" ) - r = this->_GenerateData( ); + i->second = port; + this->Modified( ); - // Return error description, if any - return( r ); + } // fi + return( true ); + } + else + return( false ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -DisconnectOutputs( ) +DisconnectInputs( ) { - _TDataContainer::iterator i = this->m_Outputs.begin( ); - for( ; i != this->m_Outputs.end( ); ++i ) - if( i->second->IsNotNull( ) ) - ( *( i->second ) )->DisconnectPipeline( ); -} - -// ------------------------------------------------------------------------- -vtkRenderWindowInteractor* cpPlugins::Interface::ProcessObject:: -GetSingleInteractor( ) -{ - return( this->m_SingleInteractor ); + auto i = this->m_Inputs.begin( ); + for( ; i != this->m_Inputs.end( ); ++i ) + i->second = NULL; + this->Modified( ); } // ------------------------------------------------------------------------- -const vtkRenderWindowInteractor* cpPlugins::Interface::ProcessObject:: -GetSingleInteractor( ) const +void cpPlugins::Interface::ProcessObject:: +DisconnectOutputs( ) { - return( this->m_SingleInteractor ); + auto i = this->m_Outputs.begin( ); + for( ; i != this->m_Outputs.end( ); ++i ) + if( i->second.IsValid( ) ) + i->second->DisconnectFromPipeline( ); + this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -SetSingleInteractor( vtkRenderWindowInteractor* interactor ) +Disconnect( ) { - this->m_SingleInteractor = interactor; + this->DisconnectInputs( ); + this->DisconnectOutputs( ); } // ------------------------------------------------------------------------- -cpPlugins::Interface:: -SimpleMPRWidget* cpPlugins::Interface::ProcessObject:: -GetMPRViewer( ) +itk::ModifiedTimeType cpPlugins::Interface::ProcessObject:: +GetMTime( ) const { - return( this->m_MPRViewer ); + auto params_time = this->m_Parameters->GetMTime( ); + auto filter_time = this->Superclass::GetMTime( ); + return( ( params_time < filter_time )? params_time: filter_time ); } // ------------------------------------------------------------------------- -const cpPlugins::Interface:: -SimpleMPRWidget* cpPlugins::Interface::ProcessObject:: -GetMPRViewer( ) const +std::string cpPlugins::Interface::ProcessObject:: +Update( ) { - return( this->m_MPRViewer ); -} + std::string r = ""; -// ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetMPRViewer( cpPlugins::Interface::SimpleMPRWidget* wdg ) -{ - this->m_MPRViewer = wdg; -} + // Force upstream updates + auto 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( ); -// ------------------------------------------------------------------------- -bool cpPlugins::Interface::ProcessObject:: -ExecConfigurationDialog( QWidget* parent ) -{ - bool r = false; -#ifdef cpPlugins_Interface_QT4 - if( this->m_ParametersDialog != NULL ) + } // fi + + } // fi + + } // rof + + // Current update + if( r == "" ) { - this->m_ParametersDialog->setParent( NULL ); - this->m_ParametersDialog->setParameters( this->m_Parameters ); - r = ( this->m_ParametersDialog->exec( ) == 1 ); - } - else - r = false; -#endif // cpPlugins_Interface_QT4 + 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 ); } @@ -166,6 +172,7 @@ ExecConfigurationDialog( QWidget* parent ) cpPlugins::Interface::ProcessObject:: ProcessObject( ) : Superclass( ), + m_LastExecutionTime( 0 ), m_ParametersDialog( NULL ), m_MPRViewer( NULL ) { @@ -174,7 +181,11 @@ ProcessObject( ) #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 } @@ -182,32 +193,21 @@ ProcessObject( ) cpPlugins::Interface::ProcessObject:: ~ProcessObject( ) { -#ifdef cpPlugins_Interface_QT4 + this->Disconnect( ); if( this->m_ParametersDialog != NULL ) delete this->m_ParametersDialog; -#endif // cpPlugins_Interface_QT4 - - /* - auto iIt = this->m_Inputs.begin( ); - for( ; iIt != this->m_Inputs.end( ); ++iIt ) - delete iIt->second; - this->m_Inputs.clear( ); - */ - - auto oIt = this->m_Outputs.begin( ); - for( ; oIt != this->m_Outputs.end( ); ++oIt ) - delete oIt->second; - this->m_Outputs.clear( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -_AddInput( const std::string& name ) +_AddInput( const std::string& name, bool required ) { +// typedef typename _TInputs::value_type _TValue; auto i = this->m_Inputs.find( name ); if( i == this->m_Inputs.end( ) ) { - this->m_Inputs[ name ] = NULL; + InputProcessObjectPort new_port( required ); + this->m_Inputs[ name ] = new_port; this->Modified( ); } // fi