X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FProcessObject.cxx;h=72897d6729a615ca3368a85a62c434297e8063cf;hb=6ffc11d77924d6ab7e94db95d41105982ac73e00;hp=cd88ea67ba637162b0938bd3474eb5a37cc9294b;hpb=8c23766af88a29c3e830299dffc4b95d9fe61df9;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index cd88ea6..72897d6 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,38 +1,44 @@ #include +#include -// ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -ProcessObject( ) - : Superclass( ) -{ -} +#ifdef cpPlugins_Interface_QT4 +#include +#include +#include +#endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -~ProcessObject( ) +void cpPlugins::Interface::ProcessObject:: +SetITK( itk::LightObject* o ) { + // 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 ); } // ------------------------------------------------------------------------- @@ -50,42 +56,181 @@ GetNumberOfOutputs( ) const } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetInput( - unsigned int idx, const cpPlugins::Interface::DataObject* dobj - ) +cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) { - if( idx < this->m_Inputs.size( ) ) - this->m_Inputs[ idx ] = dobj; + 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 ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::DataObject* cpPlugins::Interface::ProcessObject:: -GetOutput( unsigned int idx ) const +const cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) const { - if( idx < this->m_Outputs.size( ) ) - return( this->m_Outputs[ idx ] ); + static const OutputProcessObjectPort null_port; + auto i = this->m_Outputs.find( id ); + if( i == this->m_Outputs.end( ) ) + return( null_port ); else - return( NULL ); + 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:: +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->DisconnectFromPipeline( ); + 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( ); + 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->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( ); + if( r == "" ) + { + if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) + { + r = this->_GenerateData( ); + this->m_LastExecutionTime = this->GetMTime( ); + + } // fi - // Sync outputs - for( unsigned int odx = 0; odx < this->m_Outputs.size( ); ++odx ) - this->m_Outputs->SetSource( this ); + } // fi - return( ret ); + // 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, bool required ) +{ + 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$