X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FProcessObject.cxx;h=72897d6729a615ca3368a85a62c434297e8063cf;hb=6ffc11d77924d6ab7e94db95d41105982ac73e00;hp=6f3bd34e3d8e537e47282613974ae73f87548272;hpb=24dc7fa44ff75dc9336d703b8243ce1e52ff3429;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index 6f3bd34..72897d6 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,79 +1,44 @@ #include +#include #ifdef cpPlugins_Interface_QT4 +#include #include +#include #endif // cpPlugins_Interface_QT4 -#include - // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -Modified( ) const -{ - if( this->m_ITKObject.IsNotNull( ) ) - this->m_ITKObject->Modified( ); - if( this->m_VTKObject.GetPointer( ) != NULL ) - this->m_VTKObject->Modified( ); - this->Superclass::Modified( ); -} - -// ------------------------------------------------------------------------- -bool cpPlugins::Interface::ProcessObject:: -IsInteractive( ) const +SetITK( itk::LightObject* o ) { - 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 ); + // Polymorphism: do nothing -> this is a filter!!! } // ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -TParameters* cpPlugins::Interface::ProcessObject:: -GetParameters( ) -{ - return( this->m_Parameters.GetPointer( ) ); -} - -// ------------------------------------------------------------------------- -const cpPlugins::Interface::ProcessObject:: -TParameters* cpPlugins::Interface::ProcessObject:: -GetParameters( ) const -{ - return( this->m_Parameters.GetPointer( ) ); -} - -// ------------------------------------------------------------------------- -cpPlugins::Interface:: -Plugins* cpPlugins::Interface::ProcessObject:: -GetPlugins( ) +void cpPlugins::Interface::ProcessObject:: +SetVTK( vtkObjectBase* o ) { - return( this->m_Plugins ); + // Polymorphism: do nothing -> this is a filter!!! } // ------------------------------------------------------------------------- -const cpPlugins::Interface:: -Plugins* cpPlugins::Interface::ProcessObject:: -GetPlugins( ) const +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetInputsNames( ) const { - return( this->m_Plugins ); + std::set< std::string > names; + for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) + names.insert( i->first ); + return( names ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetPlugins( Plugins* p ) +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetOutputsNames( ) const { - this->m_Plugins = p; + std::set< std::string > names; + for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i ) + names.insert( i->first ); + return( names ); } // ------------------------------------------------------------------------- @@ -91,111 +56,136 @@ GetNumberOfOutputs( ) const } // ------------------------------------------------------------------------- -std::vector< std::string > cpPlugins::Interface::ProcessObject:: -GetInputsNames( ) const +cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) { - 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 ); + 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 ); } // ------------------------------------------------------------------------- -std::vector< std::string > cpPlugins::Interface::ProcessObject:: -GetOutputsNames( ) const +const cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) const { - 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 ); + 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:: -SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj ) +bool cpPlugins::Interface::ProcessObject:: +SetInput( const std::string& id, const OutputProcessObjectPort& port ) { - _TDataContainer::iterator i = this->m_Inputs.find( id ); + auto i = this->m_Inputs.find( id ); if( i != this->m_Inputs.end( ) ) { - i->second = dobj; - this->Modified( ); + if( i->second.GetPointer( ) != port.GetPointer( ) ) + { + i->second = port; + this->Modified( ); - } // fi + } // fi + return( true ); + } + else + return( false ); } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::ProcessObject:: -Update( ) +void cpPlugins::Interface::ProcessObject:: +DisconnectInputs( ) { - std::string r = ""; - - // Force upstream updates - _TDataContainer::iterator i = this->m_Inputs.begin( ); - for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) - { - Self* src = dynamic_cast< Self* >( i->second->GetSource( ) ); - if( src != NULL ) - r = src->Update( ); - - } // rof - - // Current update - if( r == "" ) - r = this->_GenerateData( ); - - // Return error description, if any - return( r ); + auto i = this->m_Inputs.begin( ); + for( ; i != this->m_Inputs.end( ); ++i ) + i->second = NULL; + this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: DisconnectOutputs( ) { - _TDataContainer::iterator i = this->m_Outputs.begin( ); + auto i = this->m_Outputs.begin( ); for( ; i != this->m_Outputs.end( ); ++i ) - if( i->second.IsNotNull( ) ) - i->second->DisconnectPipeline( ); + if( i->second.IsValid( ) ) + i->second->DisconnectFromPipeline( ); + this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -AddInteractor( vtkRenderWindowInteractor* interactor ) +Disconnect( ) { -#ifdef cpPlugins_Interface_QT4 - this->m_ParametersDialog->addInteractor( interactor ); -#endif // cpPlugins_Interface_QT4 + this->DisconnectInputs( ); + this->DisconnectOutputs( ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -DialogResult cpPlugins::Interface::ProcessObject:: -ExecConfigurationDialog( QWidget* parent ) +itk::ModifiedTimeType cpPlugins::Interface::ProcessObject:: +GetMTime( ) const { - DialogResult r = Self::DialogResult_Cancel; - -#ifdef cpPlugins_Interface_QT4 + auto params_time = this->m_Parameters->GetMTime( ); + auto filter_time = this->Superclass::GetMTime( ); + return( ( params_time < filter_time )? params_time: filter_time ); +} - this->m_ParametersDialog->setParent( NULL ); - this->m_ParametersDialog->setParameters( this->m_Parameters ); +// ------------------------------------------------------------------------- +std::string cpPlugins::Interface::ProcessObject:: +Update( ) +{ + std::string r = ""; - if( !( this->m_ParametersDialog->IsModal( ) ) ) + // Force upstream updates + auto i = this->m_Inputs.begin( ); + bool need_to_update = false; + for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) { - this->m_ParametersDialog->show( ); - r = Self::DialogResult_Modal; - } - else + bool iv = i->second.IsValid( ); + bool ir = i->second.IsRequired( ); + if( !iv && ir ) + r = + "ProcessObject: Required input \"" + + i->first + "@" + this->GetClassName( ) + + "\" is not valid (=NULL)."; + if( iv && r == "" ) + { + 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 == "" ) { - 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 +193,44 @@ 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( ); + 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$