]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ProcessObject.hxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.hxx
index 50c03ce82cdfc0fb4c7a13fc2bd1f30424a56b5d..9c5b764c5f79e3bacf89fb88e0def60ed48252fb 100644 (file)
@@ -4,42 +4,35 @@
 // -------------------------------------------------------------------------
 template< class T >
 T* cpPlugins::Interface::ProcessObject::
-GetITK( )
+GetInputData( const std::string& id )
 {
-  return( dynamic_cast< T* >( this->m_ITKObject.GetPointer( ) ) );
-}
-
-// -------------------------------------------------------------------------
-template< class T >
-const T* cpPlugins::Interface::ProcessObject::
-GetITK( ) const
-{
-  return( dynamic_cast< const T* >( this->m_ITKObject.GetPointer( ) ) );
-}
-
-// -------------------------------------------------------------------------
-template< class T >
-T* cpPlugins::Interface::ProcessObject::
-GetVTK( )
-{
-  return( dynamic_cast< T* >( this->m_VTKObject.GetPointer( ) ) );
+  auto i = this->m_Inputs.find( id );
+  if( i != this->m_Inputs.end( ) )
+    return( dynamic_cast< T* >( i->second.GetPointer( ) ) );
+  else
+    return( NULL );
 }
 
 // -------------------------------------------------------------------------
 template< class T >
 const T* cpPlugins::Interface::ProcessObject::
-GetVTK( ) const
+GetInputData( const std::string& id ) const
 {
-  return( dynamic_cast< const T* >( this->m_VTKObject.GetPointer( ) ) );
+  auto i = this->m_Inputs.find( id );
+  if( i != this->m_Inputs.end( ) )
+    return( dynamic_cast< const T* >( i->second.GetPointer( ) ) );
+  else
+    return( NULL );
 }
 
 // -------------------------------------------------------------------------
 template< class T >
 T* cpPlugins::Interface::ProcessObject::
-GetInput( unsigned int idx )
+GetOutputData( const std::string& id )
 {
-  if( idx < this->m_Inputs.size( ) )
-    return( dynamic_cast< T* >( this->m_Inputs[ idx ].GetPointer( ) ) );
+  auto i = this->m_Outputs.find( id );
+  if( i != this->m_Outputs.end( ) )
+    return( dynamic_cast< T* >( i->second.GetPointer( ) ) );
   else
     return( NULL );
 }
@@ -47,38 +40,30 @@ GetInput( unsigned int idx )
 // -------------------------------------------------------------------------
 template< class T >
 const T* cpPlugins::Interface::ProcessObject::
-GetInput( unsigned int idx ) const
+GetOutputData( const std::string& id ) const
 {
-  if( idx < this->m_Inputs.size( ) )
-    return(
-      dynamic_cast< const T* >( this->m_Inputs[ idx ].GetPointer( ) )
-      );
+  auto i = this->m_Outputs.find( id );
+  if( i != this->m_Outputs.end( ) )
+    return( dynamic_cast< const T* >( i->second.GetPointer( ) ) );
   else
     return( NULL );
 }
 
 // -------------------------------------------------------------------------
-template< class T >
-T* cpPlugins::Interface::ProcessObject::
-GetOutput( unsigned int idx )
+template< class O >
+void cpPlugins::Interface::ProcessObject::
+_AddOutput( const std::string& name )
 {
-  if( idx < this->m_Outputs.size( ) )
-    return( dynamic_cast< T* >( this->m_Outputs[ idx ].GetPointer( ) ) );
-  else
-    return( NULL );
-}
+  typedef typename _TDataContainer::value_type _TValue;
+  auto i = this->m_Outputs.find( name );
+  if( i == this->m_Outputs.end( ) )
+  {
+    typename O::Pointer o = O::New( );
+    o->SetSource( this );
+    this->m_Outputs[ name ] = o;
+    this->Modified( );
 
-// -------------------------------------------------------------------------
-template< class T >
-const T* cpPlugins::Interface::ProcessObject::
-GetOutput( unsigned int idx ) const
-{
-  if( idx < this->m_Outputs.size( ) )
-    return(
-      dynamic_cast< const T* >( this->m_Outputs[ idx ].GetPointer( ) )
-      );
-  else
-    return( NULL );
+  } // fi
 }
 
 // -------------------------------------------------------------------------
@@ -86,13 +71,14 @@ template< class F >
 F* cpPlugins::Interface::ProcessObject::
 _CreateITK( )
 {
-  F* filter = dynamic_cast< F* >( this->m_ITKObject.GetPointer( ) );
+  F* filter = this->GetITK< F >( );
   if( filter == NULL )
   {
-    typename F::Pointer ptr = F::New( );
-    this->m_ITKObject = ptr;
-    filter = ptr.GetPointer( );
-    this->m_VTKObject = NULL;
+    typename F::Pointer filter_ptr = F::New( );
+    this->SetITK( filter_ptr.GetPointer( ) );
+    this->SetVTK( NULL );
+    filter = filter_ptr.GetPointer( );
+    this->Modified( );
 
   } // fi
   return( filter );
@@ -103,28 +89,19 @@ template< class F >
 F* cpPlugins::Interface::ProcessObject::
 _CreateVTK( )
 {
-  F* filter = dynamic_cast< F* >( this->m_VTKObject.GetPointer( ) );
+  F* filter = this->GetVTK< F >( );
   if( filter == NULL )
   {
-    filter = F::New( );
-    this->m_VTKObject = filter;
-    this->m_ITKObject = NULL;
+    vtkSmartPointer< F > filter_ptr = vtkSmartPointer< F >::New( );
+    this->SetITK( NULL );
+    this->SetVTK( filter_ptr );
+    filter = filter_ptr.GetPointer( );
+    this->Modified( );
 
   } // fi
   return( filter );
 }
 
-// -------------------------------------------------------------------------
-template< class O >
-void cpPlugins::Interface::ProcessObject::
-_MakeOutput( unsigned int idx )
-{
-  if( idx >= this->m_Outputs.size( ) )
-    return;
-  this->m_Outputs[ idx ] = O::New( );
-  this->m_Outputs[ idx ]->SetSource( this );
-}
-
 #endif // __CPPLUGINS__INTERFACE__PROCESSOBJECT__HXX__
 
 // eof - $RCSfile$