]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/DataObject.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / DataObject.cxx
1 #include <cpPlugins/Interface/DataObject.h>
2
3 #include <cpPlugins/Interface/ProcessObject.h>
4 #include <itkDataObject.h>
5 #include <vtkImageData.h>
6 #include <vtkPolyData.h>
7
8 // -------------------------------------------------------------------------
9 cpPlugins::Interface::ProcessObject* cpPlugins::Interface::DataObject::
10 GetSource( )
11 {
12   auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
13   return( ptr->GetPointer( ) );
14 }
15
16 // -------------------------------------------------------------------------
17 const cpPlugins::Interface::ProcessObject* cpPlugins::Interface::DataObject::
18 GetSource( ) const
19 {
20   auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
21   return( ptr->GetPointer( ) );
22 }
23
24 // -------------------------------------------------------------------------
25 void cpPlugins::Interface::DataObject::
26 SetSource( cpPlugins::Interface::ProcessObject* src )
27 {
28   auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
29   if( ptr->GetPointer( ) != src )
30   {
31     *ptr = src;
32     this->Modified( );
33
34   } // fi
35 }
36
37 // -------------------------------------------------------------------------
38 void cpPlugins::Interface::DataObject::
39 DisconnectFromPipeline( )
40 {
41   // Disconnect input pipelines (ITK)
42   itk::DataObject* itk_obj = this->GetITK< itk::DataObject >( );
43   if( itk_obj != NULL )
44     itk_obj->DisconnectPipeline( );
45
46   // Disconnect input pipelines (VTK)
47   vtkImageData* vtk_image = this->GetVTK< vtkImageData >( );
48   vtkPolyData* vtk_pd = this->GetVTK< vtkPolyData >( );
49   if( vtk_image != NULL )
50   {
51     vtkSmartPointer< vtkImageData > d =
52       vtkSmartPointer< vtkImageData >::New( );
53     d->ShallowCopy( vtk_image );
54     this->m_VTKObject = d;
55   }
56   else if( vtk_pd != NULL )
57   {
58     vtkSmartPointer< vtkPolyData > d =
59       vtkSmartPointer< vtkPolyData >::New( );
60     d->ShallowCopy( vtk_pd );
61     this->m_VTKObject = d;
62
63   } // fi
64
65   // Unbind source
66   auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
67   *ptr = NULL;
68   this->Modified( );
69 }
70
71 // -------------------------------------------------------------------------
72 cpPlugins::Interface::DataObject::
73 DataObject( )
74   : Superclass( )
75 {
76   this->m_Source = new ProcessObject::Pointer( );
77 }
78
79 // -------------------------------------------------------------------------
80 cpPlugins::Interface::DataObject::
81 ~DataObject( )
82 {
83   /* TODO
84      auto ptr = reinterpret_cast< ProcessObject::Pointer* >( this->m_Source );
85      delete ptr;
86   */
87 }
88
89 // eof - $RCSfile$