#include <cpPlugins/Interface/ProcessObject.h>
+#include <itkProcessObject.h>
#ifdef cpPlugins_Interface_QT4
#include <QApplication>
#include <cpPlugins/Interface/ParametersQtDialog.h>
+#include <cpPlugins/Interface/SimpleMPRWidget.h>
#endif // cpPlugins_Interface_QT4
-#include <vtkRenderWindowInteractor.h>
-
// -------------------------------------------------------------------------
void cpPlugins::Interface::ProcessObject::
-Modified( ) const
+SetITK( itk::LightObject* o )
{
- if( this->m_ITKObject.IsNotNull( ) )
- this->m_ITKObject->Modified( );
- if( this->m_VTKObject.GetPointer( ) != NULL )
- this->m_VTKObject->Modified( );
- this->Superclass::Modified( );
+ // Polymorphism: do nothing -> this is a filter!!!
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::ProcessObject::
-GetInputsNames( std::set< std::string >& names ) const
+SetVTK( vtkObjectBase* o )
{
- names.clear( );
- auto dIt = this->m_Inputs.begin( );
- for( ; dIt != this->m_Inputs.end( ); ++dIt )
- names.insert( dIt->first );
+ // Polymorphism: do nothing -> this is a filter!!!
}
// -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-GetOutputsNames( std::set< std::string >& names ) const
+std::set< std::string > cpPlugins::Interface::ProcessObject::
+GetInputsNames( ) const
{
- names.clear( );
- auto dIt = this->m_Outputs.begin( );
- for( ; dIt != this->m_Outputs.end( ); ++dIt )
- names.insert( dIt->first );
+ std::set< std::string > names;
+ for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
+ names.insert( i->first );
+ return( names );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::ProcessObject::
-SetOutputObjectName(
- const std::string& new_object_name, const std::string& output_name
- )
+std::set< std::string > cpPlugins::Interface::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 );
+}
+
+// -------------------------------------------------------------------------
+unsigned int cpPlugins::Interface::ProcessObject::
+GetNumberOfInputs( ) const
+{
+ return( this->m_Inputs.size( ) );
+}
+
+// -------------------------------------------------------------------------
+unsigned int cpPlugins::Interface::ProcessObject::
+GetNumberOfOutputs( ) const
+{
+ return( this->m_Outputs.size( ) );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::
+OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
+GetOutput( const std::string& id )
{
- auto oIt = this->m_Outputs.find( output_name );
- if( oIt != this->m_Outputs.end( ) )
+ static OutputProcessObjectPort null_port;
+ auto i = this->m_Outputs.find( id );
+ if( i == this->m_Outputs.end( ) )
{
- this->m_OutputObjectsNames[ output_name ] = new_object_name;
- this->Modified( );
- return( true );
+ null_port = NULL;
+ return( null_port );
}
else
- return( false );
+ return( i->second );
}
// -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
+const cpPlugins::Interface::
+OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
+GetOutput( const std::string& id ) const
{
- _TDataContainer::iterator i = this->m_Inputs.find( id );
- if( i != this->m_Inputs.end( ) )
- {
- i->second = dobj;
- this->Modified( );
-
- } // fi
+ 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 );
}
// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::ProcessObject::
-Update( )
+cpPlugins::Interface::
+DataObject* cpPlugins::Interface::ProcessObject::
+GetInputData( const std::string& id )
{
- std::string r = "";
+ auto i = this->m_Inputs.find( id );
+ if( i != this->m_Inputs.end( ) )
+ return( dynamic_cast< DataObject* >( i->second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
- // 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( );
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::
+DataObject* cpPlugins::Interface::ProcessObject::
+GetInputData( const std::string& id ) const
+{
+ auto i = this->m_Inputs.find( id );
+ if( i != this->m_Inputs.end( ) )
+ return( dynamic_cast< const DataObject* >( i->second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
- } // rof
+// -------------------------------------------------------------------------
+cpPlugins::Interface::
+DataObject* cpPlugins::Interface::ProcessObject::
+GetOutputData( const std::string& id )
+{
+ auto i = this->m_Outputs.find( id );
+ if( i != this->m_Outputs.end( ) )
+ return( dynamic_cast< DataObject* >( i->second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
- // Current update
- if( r == "" )
- r = this->_GenerateData( );
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::
+DataObject* cpPlugins::Interface::ProcessObject::
+GetOutputData( const std::string& id ) const
+{
+ auto i = this->m_Outputs.find( id );
+ if( i != this->m_Outputs.end( ) )
+ return( dynamic_cast< const DataObject* >( i->second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
- // Configure output names
- auto oIt = this->m_Outputs.begin( );
- for( ; oIt != this->m_Outputs.end( ); ++oIt )
+// -------------------------------------------------------------------------
+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( ) )
{
- auto nIt = this->m_OutputObjectsNames.find( oIt->first );
- if( nIt != this->m_OutputObjectsNames.end( ) )
- oIt->second->SetName( nIt->second );
+ if( i->second.GetPointer( ) != port.GetPointer( ) )
+ {
+ i->second = port;
+ this->Modified( );
- } // rof
+ } // fi
+ return( true );
+ }
+ else
+ return( false );
+}
- // Return error description, if any
- return( r );
+// -------------------------------------------------------------------------
+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( )
{
- _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
- if( this->m_ParametersDialog == NULL )
- this->m_ParametersDialog = new ParametersQtDialog( );
- this->m_ParametersDialog->addInteractor( interactor );
-#endif // cpPlugins_Interface_QT4
- this->m_Interactors.insert( interactor );
+ 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;
+ auto params_time = this->m_Parameters->GetMTime( );
+ auto filter_time = this->Superclass::GetMTime( );
+ return( ( params_time < filter_time )? params_time: filter_time );
+}
-#ifdef cpPlugins_Interface_QT4
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::ProcessObject::
+Update( )
+{
+ std::string r = "";
- if( QApplication::instance( ) != NULL )
+ // Force upstream updates
+ auto i = this->m_Inputs.begin( );
+ bool need_to_update = false;
+ for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
{
- if( this->m_ParametersDialog == NULL )
- this->m_ParametersDialog = new ParametersQtDialog( );
- this->m_ParametersDialog->setTitle(
- this->GetClassName( ) + std::string( " basic configuration" )
- );
+ 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( );
- this->m_ParametersDialog->setParent( NULL );
- this->m_ParametersDialog->setParameters( this->m_Parameters );
+ } // fi
- if( !( this->m_ParametersDialog->IsModal( ) ) )
- {
- this->m_ParametersDialog->show( );
- r = Self::DialogResult_Modal;
- }
- else
+ } // fi
+
+ } // rof
+
+ // Current update
+ if( r == "" )
+ {
+ if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
{
- if( this->m_ParametersDialog->exec( ) == 1 )
- r = Self::DialogResult_NoModal;
- else
- r = Self::DialogResult_Cancel;
+ r = this->_GenerateData( );
+ this->m_LastExecutionTime = this->GetMTime( );
} // fi
- }
- else
- r = Self::DialogResult_Cancel;
-#endif // cpPlugins_Interface_QT4
+ } // fi
+ // Return error description, if any
return( r );
}
cpPlugins::Interface::ProcessObject::
ProcessObject( )
: Superclass( ),
- m_ITKObject( NULL ),
- m_VTKObject( NULL ),
+ m_LastExecutionTime( 0 ),
m_ParametersDialog( NULL ),
- m_Plugins( 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 )
+_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( ) )
+ {
+ this->m_Inputs[ name ] = InputProcessObjectPort( required );
+ this->Modified( );
-// -------------------------------------------------------------------------
-CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 );
+ } // fi
+}
// eof - $RCSfile$