]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ProcessObject.cxx
Integration of new functionalities into ProcessObject and DataObject
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
index 79fc2ab7f84880c3cdb59bdd002d38e8abc94f34..a595e0ec3f71d60df5c583d4d7d9b29bd72d0696 100644 (file)
@@ -4,7 +4,8 @@
 // -------------------------------------------------------------------------
 cpPlugins::Interface::ProcessObject::
 ProcessObject( )
-  : Superclass( )
+  : Superclass( ),
+    m_OutputsDisconnected( false )
 {
 }
 
@@ -12,6 +13,7 @@ ProcessObject( )
 cpPlugins::Interface::ProcessObject::
 ~ProcessObject( )
 {
+  this->_DeleteOutputs( );
 }
 
 // -------------------------------------------------------------------------
@@ -62,12 +64,10 @@ SetNumberOfInputs( unsigned int n )
 void cpPlugins::Interface::ProcessObject::
 SetNumberOfOutputs( unsigned int n )
 {
+  this->_DeleteOutputs( );
   this->m_Outputs.clear( );
-  this->m_Outputs.resize( n );
-
-  // Sync outputs with this source
-  for( unsigned int odx = 0; odx < this->m_Outputs.size( ); ++odx )
-    this->m_Outputs[ odx ].SetSource( this );
+  this->m_Outputs.resize( n, NULL );
+  this->m_OutputsDisconnected = false;
 }
 
 // -------------------------------------------------------------------------
@@ -85,7 +85,7 @@ cpPlugins::Interface::DataObject* cpPlugins::Interface::ProcessObject::
 GetOutput( unsigned int idx )
 {
   if( idx < this->m_Outputs.size( ) )
-    return( &( this->m_Outputs[ idx ] ) );
+    return( this->m_Outputs[ idx ] );
   else
     return( NULL );
 }
@@ -100,11 +100,22 @@ Update( )
 
   // Current update
   std::string ret = this->_GenerateData( );
+  this->m_OutputsDisconnected = false;
 
   // Return error description, if any
   return( ret );
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ProcessObject::
+DisconnectOutputs( )
+{
+  this->m_OutputsDisconnected = true;
+  for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx )
+    if( this->m_Outputs[ idx ] != NULL )
+      this->m_Outputs[ idx ]->GetDataObject( )->DisconnectPipeline( );
+}
+
 // -------------------------------------------------------------------------
 itk::DataObject* cpPlugins::Interface::ProcessObject::
 _GetInput( unsigned int idx )
@@ -120,7 +131,18 @@ void cpPlugins::Interface::ProcessObject::
 _SetOutput( unsigned int idx, itk::DataObject* dobj )
 {
   if( idx < this->m_Outputs.size( ) )
-    this->m_Outputs[ idx ].SetDataObject( dobj );
+    if( this->m_Outputs[ idx ] != NULL )
+      this->m_Outputs[ idx ]->SetDataObject( dobj );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ProcessObject::
+_DeleteOutputs( )
+{
+  if( !( this->m_OutputsDisconnected ) )
+    for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx )
+      if( this->m_Outputs[ idx ] != NULL )
+        delete this->m_Outputs[ idx ];
 }
 
 // eof - $RCSfile$