]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ProcessObject.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
index 5434319fb09c1d9e7a8b47169e15185d83cda862..1128fe10444ab89c454748101ccfeec30da93e27 100644 (file)
@@ -1,4 +1,5 @@
 #include <cpPlugins/Interface/ProcessObject.h>
+#include <itkProcessObject.h>
 
 #ifdef cpPlugins_Interface_QT4
 #include <QApplication>
@@ -6,16 +7,13 @@
 #include <cpPlugins/Interface/SimpleMPRWidget.h>
 #endif // cpPlugins_Interface_QT4
 
-#include <vtkRenderWindowInteractor.h>
-
 // -------------------------------------------------------------------------
 std::set< std::string > cpPlugins::Interface::ProcessObject::
 GetInputsNames( ) const
 {
   std::set< std::string > names;
-  auto dIt = this->m_Inputs.begin( );
-  for( ; dIt != this->m_Inputs.end( ); ++dIt )
-    names.insert( dIt->first );
+  for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
+    names.insert( i->first );
   return( names );
 }
 
@@ -24,9 +22,8 @@ std::set< std::string > cpPlugins::Interface::ProcessObject::
 GetOutputsNames( ) const
 {
   std::set< std::string > names;
-  auto dIt = this->m_Outputs.begin( );
-  for( ; dIt != this->m_Outputs.end( ); ++dIt )
-    names.insert( dIt->first );
+  for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
+    names.insert( i->first );
   return( names );
 }
 
@@ -44,16 +41,43 @@ GetNumberOfOutputs( ) const
   return( this->m_Outputs.size( ) );
 }
 
+// -------------------------------------------------------------------------
+cpPlugins::Interface::
+ProcessObjectPort& cpPlugins::Interface::ProcessObject::
+GetOutput( const std::string& id )
+{
+  static ProcessObjectPort 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::
+ProcessObjectPort& cpPlugins::Interface::ProcessObject::
+GetOutput( const std::string& id ) const
+{
+  static const ProcessObjectPort 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, cpPlugins::Interface::DataObject::Pointer* dobj
-  )
+SetInput( const std::string& id, const ProcessObjectPort& port )
 {
-  _TDataContainer::iterator i = this->m_Inputs.find( id );
+  auto i = this->m_Inputs.find( id );
   if( i != this->m_Inputs.end( ) )
   {
-    i->second = dobj;
+    i->second = port;
     this->Modified( );
     return( true );
   }
@@ -62,103 +86,92 @@ SetInput(
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Interface::ProcessObject::
-Update( )
+void cpPlugins::Interface::ProcessObject::
+DisconnectInputs( )
 {
-  std::string r = "";
-
-  // Force upstream updates
-  _TDataContainer::iterator i = this->m_Inputs.begin( );
-  for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
-  {
-    if( i->second->IsNotNull( ) )
-    {
-      Self* src = dynamic_cast< Self* >( ( *( i->second ) )->GetSource( ) );
-      if( src != NULL )
-        r = src->Update( );
-    }
-    else
-      r = "cpPlugins::Interface::ProcessObject: No input connected.";
-    
-  } // rof
-
-  // Current update
-  if( r == "" )
-    r = this->_GenerateData( );
-
-  // Return error description, if any
-  return( r );
+  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->DisconnectPipeline( );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
-vtkRenderWindowInteractor* cpPlugins::Interface::ProcessObject::
-GetSingleInteractor( )
+void cpPlugins::Interface::ProcessObject::
+Disconnect( )
 {
-  return( this->m_SingleInteractor );
+  this->DisconnectInputs( );
+  this->DisconnectOutputs( );
 }
 
 // -------------------------------------------------------------------------
-const vtkRenderWindowInteractor* cpPlugins::Interface::ProcessObject::
-GetSingleInteractor( ) const
+itk::ModifiedTimeType cpPlugins::Interface::ProcessObject::
+GetMTime( ) const
 {
-  return( this->m_SingleInteractor );
+  auto params_time = this->m_Parameters->GetMTime( );
+  auto filter_time = this->Superclass::GetMTime( );
+  auto ipobj = this->GetITK< itk::ProcessObject >( );
+  if( ipobj == NULL )
+  {
+    auto vpobj = this->GetVTK< vtkAlgorithm >( );
+    if( vpobj != NULL )
+      filter_time = ( const_cast< vtkAlgorithm* >( vpobj ) )->GetMTime( );
+  }
+  else
+    filter_time = ipobj->GetMTime( );
+  return( ( params_time < filter_time )? filter_time: params_time );
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetSingleInteractor( vtkRenderWindowInteractor* interactor )
+std::string cpPlugins::Interface::ProcessObject::
+Update( )
 {
-  this->m_SingleInteractor = interactor;
-}
+  static 
+  std::string r = "";
 
-// -------------------------------------------------------------------------
-cpPlugins::Interface::
-SimpleMPRWidget* cpPlugins::Interface::ProcessObject::
-GetMPRViewer( )
-{
-  return( this->m_MPRViewer );
-}
+  // Force upstream updates
+  _TDataContainer::iterator i = this->m_Inputs.begin( );
+  bool need_to_update = false;
+  for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
+  {
+    if( i->second.IsValid( ) )
+    {
+      Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
+      if( src != NULL )
+      {
+        need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
+        r = src->Update( );
 
-// -------------------------------------------------------------------------
-const cpPlugins::Interface::
-SimpleMPRWidget* cpPlugins::Interface::ProcessObject::
-GetMPRViewer( ) const
-{
-  return( this->m_MPRViewer );
-}
+      } // fi
+    }
+    else
+      r = "cpPlugins::Interface::ProcessObject: No input connected.";
 
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetMPRViewer( cpPlugins::Interface::SimpleMPRWidget* wdg )
-{
-  this->m_MPRViewer = wdg;
-}
+  } // rof
 
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::ProcessObject::
-ExecConfigurationDialog( QWidget* parent )
-{
-  bool r = false;
-#ifdef cpPlugins_Interface_QT4
-  if( this->m_ParametersDialog != NULL )
+  // Current update
+  if( r == "" )
   {
-    this->m_ParametersDialog->setParent( NULL );
-    this->m_ParametersDialog->setParameters( this->m_Parameters );
-    r = ( this->m_ParametersDialog->exec( ) == 1 );
-  }
-  else
-    r = false;
-#endif // cpPlugins_Interface_QT4
+    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( r );
 }
 
@@ -166,6 +179,7 @@ ExecConfigurationDialog( QWidget* parent )
 cpPlugins::Interface::ProcessObject::
 ProcessObject( )
   : Superclass( ),
+    m_LastExecutionTime( 0 ),
     m_ParametersDialog( NULL ),
     m_MPRViewer( NULL )
 {
@@ -174,7 +188,11 @@ ProcessObject( )
 
 #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
 }
 
@@ -182,35 +200,19 @@ ProcessObject( )
 cpPlugins::Interface::ProcessObject::
 ~ProcessObject( )
 {
-#ifdef cpPlugins_Interface_QT4
+  this->Disconnect( );
   if( this->m_ParametersDialog != NULL )
     delete this->m_ParametersDialog;
-#endif // cpPlugins_Interface_QT4
-
-  /*
-    auto iIt = this->m_Inputs.begin( );
-    for( ; iIt != this->m_Inputs.end( ); ++iIt )
-    delete iIt->second;
-    this->m_Inputs.clear( );
-  */
-
-  auto oIt = this->m_Outputs.begin( );
-  for( ; oIt != this->m_Outputs.end( ); ++oIt )
-    delete oIt->second;
-  this->m_Outputs.clear( );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ProcessObject::
 _AddInput( const std::string& name )
 {
+  typedef typename _TDataContainer::value_type _TValue;
   auto i = this->m_Inputs.find( name );
   if( i == this->m_Inputs.end( ) )
-  {
-    this->m_Inputs[ name ] = NULL;
-    this->Modified( );
-
-  } // fi
+    i = this->m_Inputs.insert( _TValue( name, NULL ) ).first;
 }
 
 // eof - $RCSfile$