+++ /dev/null
-#include <cpPlugins/BaseObjects/ProcessObject.h>
-#include <itkProcessObject.h>
-#include <itkExceptionObject.h>
-#include <cpPlugins/Utility.h>
-#include <cpPlugins/BaseObjects/Events.h>
-#include <cpPlugins/QT/ParametersDialog.h>
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-PrintExecutionOn( )
-{
- this->SetPrintExecution( true );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-PrintExecutionOff( )
-{
- this->SetPrintExecution( false );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::BaseObjects::ProcessObject::
-GetPrintExecution( ) const
-{
- return( this->m_PrintExecution );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::BaseObjects::ProcessObject::
-SetPrintExecution( bool v )
-{
- this->m_PrintExecution = v;
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-SetPrintExecutionStream( std::ofstream* s )
-{
- this->m_PrintExecutionStream = s;
-}
-
-// -------------------------------------------------------------------------
-cpPlugins::BaseObjects::Parameters*
-cpPlugins::BaseObjects::ProcessObject::
-GetParameters( )
-{
- return( &( this->m_Parameters ) );
-}
-
-// -------------------------------------------------------------------------
-const cpPlugins::BaseObjects::Parameters*
-cpPlugins::BaseObjects::ProcessObject::
-GetParameters( ) const
-{
- return( &( this->m_Parameters ) );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-SetITK( itk::LightObject* o )
-{
- // Polymorphism: do nothing -> this is a filter!!!
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-SetVTK( vtkObjectBase* o )
-{
- // Polymorphism: do nothing -> this is a filter!!!
-}
-
-// -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::BaseObjects::ProcessObject::
-GetInputsNames( ) const
-{
- std::set< std::string > names;
- for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
- names.insert( i->first );
- return( names );
-}
-
-// -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::BaseObjects::ProcessObject::
-GetOutputsNames( ) const
-{
- std::set< std::string > names;
- for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
- names.insert( i->first );
- return( names );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::BaseObjects::ProcessObject::
-HasInput( const std::string& n ) const
-{
- auto i = this->m_Inputs.find( n );
- return( i != this->m_Inputs.end( ) );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::BaseObjects::ProcessObject::
-HasOutput( const std::string& n ) const
-{
- auto i = this->m_Outputs.find( n );
- return( i != this->m_Outputs.end( ) );
-}
-
-// -------------------------------------------------------------------------
-unsigned int cpPlugins::BaseObjects::ProcessObject::
-GetNumberOfInputs( ) const
-{
- return( this->m_Inputs.size( ) );
-}
-
-// -------------------------------------------------------------------------
-unsigned int cpPlugins::BaseObjects::ProcessObject::
-GetNumberOfOutputs( ) const
-{
- return( this->m_Outputs.size( ) );
-}
-
-// -------------------------------------------------------------------------
-unsigned int cpPlugins::BaseObjects::ProcessObject::
-GetInputSize( const std::string& n ) const
-{
- auto it = this->m_Inputs.find( n );
- if( it != this->m_Inputs.end( ) )
- return( it->second->Size( ) );
- else
- return( 0 );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::BaseObjects::ProcessObject::
-IsInputMultiple( const std::string& n ) const
-{
- auto i = this->m_Inputs.find( n );
- if( i != this->m_Inputs.end( ) )
- return( dynamic_cast< MultipleInputsPort* >( i->second ) != NULL );
- else
- return( false );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-AddInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o )
-{
- auto it = this->m_Inputs.find( n );
- if( it != this->m_Inputs.end( ) )
- it->second->Add( o );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-SetInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o )
-{
- this->AddInput( n, o );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-DisconnectInput( const std::string& n, unsigned int id )
-{
- auto inIt = this->m_Inputs.find( n );
- if( inIt != this->m_Inputs.end( ) )
- {
- auto multi = dynamic_cast< MultipleInputsPort* >( inIt->second );
- auto single = dynamic_cast< InputPort* >( inIt->second );
- if( multi != NULL )
- multi->Delete( id );
- else if( single != NULL )
- single->Add( NULL );
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-DisconnectInputs( )
-{
- for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
- i->second->Clear( );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-DisconnectOutputs( )
-{
- for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
- if( i->second->IsValid( ) )
- i->second->Get( )->DisconnectFromPipeline( );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-Disconnect( )
-{
- this->DisconnectInputs( );
- this->DisconnectOutputs( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-Modified( ) const
-{
- this->Superclass::Modified( );
-
- cpPlugins::BaseObjects::Events::Modified evt;
- evt.Time = this->m_LastExecutionTime;
- evt.Span = this->m_LastExecutionSpan;
- this->InvokeEvent( evt );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-Update( )
-{
- // Force upstream updates
- bool update = ( this->m_LastExecutionTime < this->GetMTime( ) );
- try
- {
- for( auto input : this->m_Inputs )
- {
- for( unsigned int i = 0; i < input.second->Size( ); ++i )
- {
- auto obj = input.second->Get( i );
- if( obj != NULL )
- {
- auto src = obj->GetSource( );
- if( src != NULL )
- {
- src->Update( );
- update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
-
- } // fi
- }
- else
- {
- if( input.second->IsRequired( ) )
- this->_Error(
- std::string( "Required input \"" ) + input.first +
- std::string( "\" in filter \"" ) +
- this->m_Name +
- std::string( "\" is not valid." )
- );
-
- } // fi
-
- } // rof
-
- } // rof
- }
- catch( std::exception& err )
- {
- this->_Error( err.what( ) );
-
- } // yrt
-
- if( update || this->m_ExplicitExecution )
- {
- // Show a message, if needed...
- if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
- {
- *( this->m_PrintExecutionStream )
- << "cpPlugins: Updating \""
- << this->GetName( ) << " ("
- << this->GetClassCategory( ) << ":" << this->GetClassName( )
- << ")\"... ";
- this->m_PrintExecutionStream->flush( );
-
- } // fi
-
- // Execute filter's algorithm and keep information about time
- try
- {
- auto t_start = cpPlugins_CHRONO;
- this->_GenerateData( );
- auto t_end = cpPlugins_CHRONO;
- this->Modified( );
- this->m_LastExecutionSpan = long( t_end - t_start );
- this->m_LastExecutionTime = this->GetMTime( );
-
- // End the message, if needed...
- if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
- {
- *( this->m_PrintExecutionStream )
- << "done in "
- << double( this->m_LastExecutionSpan ) / double( 1000 )
- << " s." << std::endl;
-
- } // fi
- }
- catch( std::exception& err )
- {
- this->_Error( err.what( ) );
-
- } // yrt
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-QDialog* cpPlugins::BaseObjects::ProcessObject::
-CreateQDialog( )
-{
-#ifdef cpPlugins_QT4
- cpPlugins::QT::ParametersDialog* dlg = NULL;
- if( QApplication::instance( ) != NULL )
- {
- dlg = new cpPlugins::QT::ParametersDialog( );
- dlg->setProcessObject( this );
-
- } // fi
- return( dlg );
-#else // cpPlugins_QT4
- return( NULL );
-#endif // cpPlugins_QT4
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-AddInteractor( vtkRenderWindowInteractor* i )
-{
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::BaseObjects::ProcessObject::
-IsInteractive( )
-{
- return( false );
-}
-
-// -------------------------------------------------------------------------
-cpPlugins::BaseObjects::ProcessObject::
-ProcessObject( )
- : Superclass( ),
- m_Name( "" ),
- m_PluginName( "" ),
- m_ExplicitExecution( false ),
- m_LastExecutionTime( 0 ),
- m_LastExecutionSpan( -1 ),
- m_PrintExecution( false ),
- m_PrintExecutionStream( &( std::cout ) )
-{
- this->m_Parameters.SetProcessObject( this );
-}
-
-// -------------------------------------------------------------------------
-cpPlugins::BaseObjects::ProcessObject::
-~ProcessObject( )
-{
- for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
- delete i->second;
- for( auto o = this->m_Outputs.begin( ); o != this->m_Outputs.end( ); ++o )
- delete o->second;
-
- this->m_Inputs.clear( );
- this->m_Outputs.clear( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::BaseObjects::ProcessObject::
-_Error( const std::string& error )
-{
- if( error != "" )
- itkExceptionMacro(
- "Error: \"" << this->m_Name << "\": " << error
- );
-}
-
-// eof - $RCSfile$