X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FProcessObject.cxx;h=72897d6729a615ca3368a85a62c434297e8063cf;hb=6ffc11d77924d6ab7e94db95d41105982ac73e00;hp=a595e0ec3f71d60df5c583d4d7d9b29bd72d0696;hpb=1adce86c283e253ec41f762652bc477d56d617a5;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index a595e0e..72897d6 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,41 +1,44 @@ #include -#include +#include -// ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -ProcessObject( ) - : Superclass( ), - m_OutputsDisconnected( false ) -{ -} +#ifdef cpPlugins_Interface_QT4 +#include +#include +#include +#endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -~ProcessObject( ) +void cpPlugins::Interface::ProcessObject:: +SetITK( itk::LightObject* o ) { - this->_DeleteOutputs( ); + // Polymorphism: do nothing -> this is a filter!!! } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::ProcessObject:: -GetClassName( ) const +void cpPlugins::Interface::ProcessObject:: +SetVTK( vtkObjectBase* o ) { - return( "cpPlugins::Interface::ProcessObject" ); + // Polymorphism: do nothing -> this is a filter!!! } // ------------------------------------------------------------------------- -const cpPlugins::Interface::ProcessObject:: -TParameters& cpPlugins::Interface::ProcessObject:: -GetDefaultParameters( ) const +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetInputsNames( ) const { - return( this->m_DefaultParameters ); + 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:: -SetParameters( const TParameters& params ) +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetOutputsNames( ) const { - this->m_Parameters = params; + std::set< std::string > names; + for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i ) + names.insert( i->first ); + return( names ); } // ------------------------------------------------------------------------- @@ -52,97 +55,182 @@ GetNumberOfOutputs( ) const return( this->m_Outputs.size( ) ); } +// ------------------------------------------------------------------------- +cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) +{ + 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:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) const +{ + 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 ); +} + +// ------------------------------------------------------------------------- +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.GetPointer( ) != port.GetPointer( ) ) + { + i->second = port; + this->Modified( ); + + } // fi + return( true ); + } + else + return( false ); +} + // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -SetNumberOfInputs( unsigned int n ) +DisconnectInputs( ) { - this->m_Inputs.clear( ); - this->m_Inputs.resize( n, NULL ); + auto i = this->m_Inputs.begin( ); + for( ; i != this->m_Inputs.end( ); ++i ) + i->second = NULL; + this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -SetNumberOfOutputs( unsigned int n ) +DisconnectOutputs( ) { - this->_DeleteOutputs( ); - this->m_Outputs.clear( ); - this->m_Outputs.resize( n, NULL ); - this->m_OutputsDisconnected = false; + 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:: -SetInput( - unsigned int idx, const cpPlugins::Interface::DataObject* dobj - ) +Disconnect( ) { - if( idx < this->m_Inputs.size( ) ) - this->m_Inputs[ idx ] = dobj; + this->DisconnectInputs( ); + this->DisconnectOutputs( ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::DataObject* cpPlugins::Interface::ProcessObject:: -GetOutput( unsigned int idx ) +itk::ModifiedTimeType cpPlugins::Interface::ProcessObject:: +GetMTime( ) const { - if( idx < this->m_Outputs.size( ) ) - return( this->m_Outputs[ idx ] ); - else - return( NULL ); + auto params_time = this->m_Parameters->GetMTime( ); + auto filter_time = this->Superclass::GetMTime( ); + return( ( params_time < filter_time )? params_time: filter_time ); } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::ProcessObject:: Update( ) { + std::string r = ""; + // Force upstream updates - for( unsigned int idx = 0; idx < this->m_Inputs.size( ); ++idx ) - this->m_Inputs[ idx ]->GetSource( )->Update( ); + auto i = this->m_Inputs.begin( ); + bool need_to_update = false; + for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) + { + 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 - std::string ret = this->_GenerateData( ); - this->m_OutputsDisconnected = false; + 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( ret ); + return( r ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -DisconnectOutputs( ) +cpPlugins::Interface::ProcessObject:: +ProcessObject( ) + : Superclass( ), + m_LastExecutionTime( 0 ), + m_ParametersDialog( NULL ), + m_MPRViewer( NULL ) { - this->m_OutputsDisconnected = true; - for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx ) - if( this->m_Outputs[ idx ] != NULL ) - this->m_Outputs[ idx ]->GetDataObject( )->DisconnectPipeline( ); -} + this->m_Parameters = TParameters::New( ); + this->m_Parameters->SetProcessObject( this ); -// ------------------------------------------------------------------------- -itk::DataObject* cpPlugins::Interface::ProcessObject:: -_GetInput( unsigned int idx ) -{ - if( idx < this->m_Inputs.size( ) ) - return( this->m_Inputs[ idx ]->GetDataObject( ) ); - else - return( NULL ); +#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 } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -_SetOutput( unsigned int idx, itk::DataObject* dobj ) +cpPlugins::Interface::ProcessObject:: +~ProcessObject( ) { - if( idx < this->m_Outputs.size( ) ) - if( this->m_Outputs[ idx ] != NULL ) - this->m_Outputs[ idx ]->SetDataObject( dobj ); + this->Disconnect( ); + if( this->m_ParametersDialog != NULL ) + delete this->m_ParametersDialog; } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -_DeleteOutputs( ) +_AddInput( const std::string& name, bool required ) { - if( !( this->m_OutputsDisconnected ) ) - for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx ) - if( this->m_Outputs[ idx ] != NULL ) - delete this->m_Outputs[ idx ]; + 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$