]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ProcessObject.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
index f639d7f59e3ea2b5686950a48151e98b0d05ef73..557c18844aeff8acee79a656e06a26a14b6cd661 100644 (file)
@@ -1,34 +1,44 @@
 #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
 
 // -------------------------------------------------------------------------
 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!!!
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::Interface::ProcessObject::
-TParameters* cpPlugins::Interface::ProcessObject::
-GetParameters( )
+void cpPlugins::Interface::ProcessObject::
+SetVTK( vtkObjectBase* o )
+{
+  // Polymorphism: do nothing -> this is a filter!!!
+}
+
+// -------------------------------------------------------------------------
+std::set< std::string > cpPlugins::Interface::ProcessObject::
+GetInputsNames( ) const
 {
-  return( this->m_Parameters.GetPointer( ) );
+  std::set< std::string > names;
+  for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
+    names.insert( i->first );
+  return( names );
 }
 
 // -------------------------------------------------------------------------
-const cpPlugins::Interface::ProcessObject::
-TParameters* cpPlugins::Interface::ProcessObject::
-GetParameters( ) const
+std::set< std::string > cpPlugins::Interface::ProcessObject::
+GetOutputsNames( ) const
 {
-  return( this->m_Parameters.GetPointer( ) );
+  std::set< std::string > names;
+  for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
+    names.insert( i->first );
+  return( names );
 }
 
 // -------------------------------------------------------------------------
@@ -46,111 +56,184 @@ GetNumberOfOutputs( ) const
 }
 
 // -------------------------------------------------------------------------
-std::vector< std::string > cpPlugins::Interface::ProcessObject::
-GetInputsNames( ) const
+cpPlugins::Interface::
+OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
+GetOutput( const std::string& id )
 {
-  std::vector< std::string > r;
-  auto dIt = this->m_Inputs.begin( );
-  for( ; dIt != this->m_Inputs.end( ); ++dIt )
-    r.push_back( dIt->first );
-  return( r );
+  static OutputProcessObjectPort 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 );
 }
 
 // -------------------------------------------------------------------------
-std::vector< std::string > cpPlugins::Interface::ProcessObject::
-GetOutputsNames( ) const
+const cpPlugins::Interface::
+OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
+GetOutput( const std::string& id ) const
 {
-  std::vector< std::string > r;
-  auto dIt = this->m_Outputs.begin( );
-  for( ; dIt != this->m_Outputs.end( ); ++dIt )
-    r.push_back( dIt->first );
-  return( 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 );
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
+cpPlugins::Interface::
+DataObject* cpPlugins::Interface::ProcessObject::
+GetInputData( const std::string& id )
 {
-  _TDataContainer::iterator i = this->m_Inputs.find( id );
+  auto i = this->m_Inputs.find( id );
   if( i != this->m_Inputs.end( ) )
-  {
-    i->second = dobj;
-    this->Modified( );
+    return( dynamic_cast< DataObject* >( i->second.GetPointer( ) ) );
+  else
+    return( NULL );
+}
 
-  } // fi
+// -------------------------------------------------------------------------
+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 );
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Interface::ProcessObject::
-Update( )
+cpPlugins::Interface::
+DataObject* cpPlugins::Interface::ProcessObject::
+GetOutputData( const std::string& id )
 {
-  std::string r = "";
+  auto i = this->m_Outputs.find( id );
+  if( i != this->m_Outputs.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::
+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 );
+}
 
-  } // rof
+// -------------------------------------------------------------------------
+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.GetPointer( ) != port.GetPointer( ) )
+    {
+      i->second = port;
+      this->Modified( );
 
-  // Current update
-  if( r == "" )
-    r = this->_GenerateData( );
+    } // 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( );
 }
 
 // -------------------------------------------------------------------------
-bool cpPlugins::Interface::ProcessObject::
-ExecConfigurationDialog( QWidget* parent )
+void cpPlugins::Interface::ProcessObject::
+Disconnect( )
 {
-  bool r = false;
+  this->DisconnectInputs( );
+  this->DisconnectOutputs( );
+}
 
-#ifdef cpPlugins_Interface_QT4
+// -------------------------------------------------------------------------
+itk::ModifiedTimeType cpPlugins::Interface::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 );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::ProcessObject::
+Update( )
+{
+  std::string r = "";
 
-  if( this->m_ParametersDialog == NULL )
+  // Force upstream updates
+  auto i = this->m_Inputs.begin( );
+  bool need_to_update = false;
+  for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
   {
-    this->m_ParametersDialog = new ParametersQtDialog( parent );
-    this->m_ParametersDialog->setTitle(
-      this->GetClassName( ) + std::string( " basic configuration" )
-      );
-    this->m_ParametersDialog->setParameters( this->m_Parameters );
+    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( );
 
-  } // fi
+      } // fi
+
+    } // fi
+
+  } // rof
 
-  if( !( this->m_ParametersDialog->IsModal( ) ) )
+  // Current update
+  if( r == "" )
   {
-    this->m_ParametersDialog->show( );
-    r = true;
-  }
-  else
-    r = ( this->m_ParametersDialog->exec( ) == 1 );
+    if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
+    {
+      r = this->_GenerateData( );
+      this->m_LastExecutionTime = this->GetMTime( );
 
-  /*
-    r = cpPlugins::Interface::ParametersQtDialog(
-    this->m_Parameters,
-    this->GetClassName( ) + std::string( " basic configuration" ),
-    parent
-    );
-    if( r )
-  */
+    } // fi
 
-#endif // cpPlugins_Interface_QT4
+  } // fi
 
+  // Return error description, if any
   return( r );
 }
 
@@ -158,27 +241,43 @@ ExecConfigurationDialog( QWidget* parent )
 cpPlugins::Interface::ProcessObject::
 ProcessObject( )
   : Superclass( ),
-    m_ITKObject( NULL ),
-    m_VTKObject( NULL ),
-    m_ParametersDialog( NULL )
+    m_LastExecutionTime( 0 ),
+    m_ParametersDialog( 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( )
 {
-  if( this->m_ParametersDialog == NULL )
+  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( );
+
+  } // fi
 }
 
 // eof - $RCSfile$