#include <cpPlugins/BaseObjects/ProcessObject.h>
-#include <cpPlugins/QT/ParametersDialog.h>
-#include <cpExtensions/Utility.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*
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
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( )
Modified( ) const
{
this->Superclass::Modified( );
- this->m_LastExecutionSpan = -1;
-}
-// -------------------------------------------------------------------------
-itk::ModifiedTimeType cpPlugins::BaseObjects::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 );
+ cpPlugins::BaseObjects::Events::Modified evt;
+ evt.Time = this->m_LastExecutionTime;
+ evt.Span = this->m_LastExecutionSpan;
+ this->InvokeEvent( evt );
}
// -------------------------------------------------------------------------
Update( )
{
// Force upstream updates
- bool need_to_update = this->m_ExplicitExecution;
- for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
+ bool update = ( this->m_LastExecutionTime < this->GetMTime( ) );
+ for( auto input : this->m_Inputs )
{
- bool iv = i->second->IsValid( );
- bool ir = i->second->IsRequired( );
- if( !iv && ir )
- this->_Error(
- std::string( "Required input \"" ) + i->first +
- std::string( "\" is not valid." )
- );
- if( iv )
+ for( unsigned int i = 0; i < input.second->Size( ); ++i )
{
- unsigned int n = i->second->Size( );
- for( unsigned int j = 0; j < n; ++j )
+ auto obj = input.second->Get( i );
+ if( obj != NULL )
{
- Self* src = i->second->Get( j )->GetSource( );
+ auto src = obj->GetSource( );
if( src != NULL )
{
- need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
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." )
+ );
- } // rof
+ } // fi
- } // fi
+ } // rof
} // rof
- // Current update
- if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
+ if( update || this->m_ExplicitExecution )
{
+ // Show a message, if needed...
if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
{
*( this->m_PrintExecutionStream )
} // fi
- auto t_start = cpExtensions_CHRONO;
+ // Execute filter's algorithm and keep information about time
+ auto t_start = cpPlugins_CHRONO;
this->_GenerateData( );
- auto t_end = cpExtensions_CHRONO;
+ 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 )
void cpPlugins::BaseObjects::ProcessObject::
AddInteractor( vtkRenderWindowInteractor* i )
{
- if( this->m_Interactors.insert( i ).second )
- this->Modified( );
}
// -------------------------------------------------------------------------
m_PrintExecution( false ),
m_PrintExecutionStream( &( std::cout ) )
{
+ this->m_Parameters.SetProcessObject( this );
}
// -------------------------------------------------------------------------