]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ProcessObject.cxx
little error on Windows solved
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
index c710a8ff823a1cbb912c6389cddbb8a984e03fe5..364816a4d094ae5c2df701dec48228ecc929ae05 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 );
 }
 
@@ -45,118 +42,129 @@ GetNumberOfOutputs( ) const
 }
 
 // -------------------------------------------------------------------------
-bool cpPlugins::Interface::ProcessObject::
-SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
+cpPlugins::Interface::
+OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
+GetOutput( const std::string& id )
 {
-  _TDataContainer::iterator i = this->m_Inputs.find( id );
-  if( i != this->m_Inputs.end( ) )
+  static OutputProcessObjectPort null_port;
+  auto i = this->m_Outputs.find( id );
+  if( i == this->m_Outputs.end( ) )
   {
-    i->second = dobj;
-    this->Modified( );
-    return( true );
+    null_port = NULL;
+    return( null_port );
   }
   else
-    return( false );
+    return( i->second );
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Interface::ProcessObject::
-Update( )
+const cpPlugins::Interface::
+OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
+GetOutput( const std::string& id ) const
 {
-  std::string r = "";
+  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 );
+}
 
-  // Force upstream updates
-  _TDataContainer::iterator i = this->m_Inputs.begin( );
-  for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
+// -------------------------------------------------------------------------
+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.IsNotNull( ) )
+    if( i->second.GetPointer( ) != port.GetPointer( ) )
     {
-      Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
-      if( src != NULL )
-        r = src->Update( );
-    }
-    else
-      r = "cpPlugins::Interface::ProcessObject: No input connected.";
-    
-  } // rof
+      i->second = port;
+      this->Modified( );
 
-  // Current update
-  if( r == "" )
-    r = this->_GenerateData( );
-
-  // Return error description, if any
-  return( r );
+    } // fi
+    return( true );
+  }
+  else
+    return( false );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ProcessObject::
-DisconnectOutputs( )
-{
-  _TDataContainer::iterator i = this->m_Outputs.begin( );
-  for( ; i != this->m_Outputs.end( ); ++i )
-    if( i->second.IsNotNull( ) )
-      i->second->DisconnectPipeline( );
-}
-
-// -------------------------------------------------------------------------
-vtkRenderWindowInteractor* cpPlugins::Interface::ProcessObject::
-GetSingleInteractor( )
+DisconnectInputs( )
 {
-  return( this->m_SingleInteractor );
+  auto i = this->m_Inputs.begin( );
+  for( ; i != this->m_Inputs.end( ); ++i )
+    i->second = NULL;
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
-const vtkRenderWindowInteractor* cpPlugins::Interface::ProcessObject::
-GetSingleInteractor( ) const
+void cpPlugins::Interface::ProcessObject::
+DisconnectOutputs( )
 {
-  return( this->m_SingleInteractor );
+  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::
-SetSingleInteractor( vtkRenderWindowInteractor* interactor )
+Disconnect( )
 {
-  this->m_SingleInteractor = interactor;
+  this->DisconnectInputs( );
+  this->DisconnectOutputs( );
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::Interface::
-SimpleMPRWidget* cpPlugins::Interface::ProcessObject::
-GetMPRViewer( )
+itk::ModifiedTimeType cpPlugins::Interface::ProcessObject::
+GetMTime( ) const
 {
-  return( this->m_MPRViewer );
+  auto params_time = this->m_Parameters->GetMTime( );
+  auto filter_time = this->Superclass::GetMTime( );
+  return( ( params_time < filter_time )? params_time: filter_time );
 }
 
 // -------------------------------------------------------------------------
-const cpPlugins::Interface::
-SimpleMPRWidget* cpPlugins::Interface::ProcessObject::
-GetMPRViewer( ) const
+std::string cpPlugins::Interface::ProcessObject::
+Update( )
 {
-  return( this->m_MPRViewer );
-}
+  std::string r = "";
 
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetMPRViewer( cpPlugins::Interface::SimpleMPRWidget* wdg )
-{
-  this->m_MPRViewer = wdg;
-}
+  // Force upstream updates
+  auto 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( );
 
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::ProcessObject::
-ExecConfigurationDialog( QWidget* parent )
-{
-  bool r = false;
-#ifdef cpPlugins_Interface_QT4
-  if( this->m_ParametersDialog != NULL )
+      } // fi
+
+    } // fi
+
+  } // rof
+
+  // 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 );
 }
 
@@ -164,6 +172,7 @@ ExecConfigurationDialog( QWidget* parent )
 cpPlugins::Interface::ProcessObject::
 ProcessObject( )
   : Superclass( ),
+    m_LastExecutionTime( 0 ),
     m_ParametersDialog( NULL ),
     m_MPRViewer( NULL )
 {
@@ -172,7 +181,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
 }
 
@@ -180,18 +193,24 @@ ProcessObject( )
 cpPlugins::Interface::ProcessObject::
 ~ProcessObject( )
 {
-#ifdef cpPlugins_Interface_QT4
+  this->Disconnect( );
   if( this->m_ParametersDialog != NULL )
     delete this->m_ParametersDialog;
-#endif // cpPlugins_Interface_QT4
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ProcessObject::
-_AddInput( const std::string& name )
+_AddInput( const std::string& name, bool required )
 {
-  this->m_Inputs[ name ] = NULL;
-  this->Modified( );
+//  typedef typename _TInputs::value_type _TValue;
+  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$