]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/DataObject.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / DataObject.cxx
index 21b5f1d416d4dbfe0046e11b5799c333ead3f54d..0bbe13bdeb4973d0d23ee9b11c3f350aabcca5e5 100644 (file)
@@ -1,66 +1,71 @@
 #include <cpPlugins/Interface/DataObject.h>
 
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::DataObject::
-GetClassName( ) const
-{
-  return( "cpPlugins::Interface::DataObject" );
-}
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::DataObject::
-GetClassType( ) const
-{
-  return( "DataObject" );
-}
-
-// -------------------------------------------------------------------------
-itk::DataObject* cpPlugins::Interface::DataObject::
-GetRealDataObject( ) const
-{
-  return( this->m_RealDataObject );
-}
+#include <cpPlugins/Interface/ProcessObject.h>
+#include <itkDataObject.h>
+#include <vtkImageData.h>
+#include <vtkPolyData.h>
 
 // -------------------------------------------------------------------------
-void cpPlugins::Interface::DataObject::
-SetRealDataObject( itk::DataObject* dobj )
-{
-  this->m_RealDataObject = dobj;
-}
-
-// -------------------------------------------------------------------------
-cpPlugins::Interface::Object* cpPlugins::Interface::DataObject::
+cpPlugins::Interface::ProcessObject* cpPlugins::Interface::DataObject::
 GetSource( )
 {
-  return( this->m_Source );
+  auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
+  return( ptr->GetPointer( ) );
 }
 
 // -------------------------------------------------------------------------
-const cpPlugins::Interface::Object* cpPlugins::Interface::DataObject::
+const cpPlugins::Interface::ProcessObject* cpPlugins::Interface::DataObject::
 GetSource( ) const
 {
-  return( this->m_Source );
+  auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
+  return( ptr->GetPointer( ) );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::DataObject::
-SetSource( cpPlugins::Interface::Object* src )
+SetSource( cpPlugins::Interface::ProcessObject* src )
 {
-  this->m_Source = src;
+  auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
+  if( ptr->GetPointer( ) != src )
+  {
+    *ptr = src;
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::DataObject::
-DisconnectPipeline( )
+DisconnectFromPipeline( )
 {
-  if( this->m_RealDataObject.IsNotNull( ) )
+  // Disconnect input pipelines (ITK)
+  itk::DataObject* itk_obj = this->GetITK< itk::DataObject >( );
+  if( itk_obj != NULL )
+    itk_obj->DisconnectPipeline( );
+
+  // Disconnect input pipelines (VTK)
+  vtkImageData* vtk_image = this->GetVTK< vtkImageData >( );
+  vtkPolyData* vtk_pd = this->GetVTK< vtkPolyData >( );
+  if( vtk_image != NULL )
   {
-    this->m_RealDataObject->DisconnectPipeline( );
-    if( this->m_Source.IsNotNull( ) )
-      this->m_Source->Delete( );
-    this->Register( );
+    vtkSmartPointer< vtkImageData > d =
+      vtkSmartPointer< vtkImageData >::New( );
+    d->ShallowCopy( vtk_image );
+    this->m_VTKObject = d;
+  }
+  else if( vtk_pd != NULL )
+  {
+    vtkSmartPointer< vtkPolyData > d =
+      vtkSmartPointer< vtkPolyData >::New( );
+    d->ShallowCopy( vtk_pd );
+    this->m_VTKObject = d;
 
   } // fi
+
+  // Unbind source
+  auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
+  *ptr = NULL;
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
@@ -68,12 +73,17 @@ cpPlugins::Interface::DataObject::
 DataObject( )
   : Superclass( )
 {
+  this->m_Source = new ProcessObject::Pointer( );
 }
 
 // -------------------------------------------------------------------------
 cpPlugins::Interface::DataObject::
 ~DataObject( )
 {
+  /* TODO
+     auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
+     delete ptr;
+  */
 }
 
 // eof - $RCSfile$