]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Pipeline/Object.cxx
...
[cpPlugins.git] / lib / cpPlugins / Pipeline / Object.cxx
1 /* =========================================================================
2  * @author ??? (???@javeriana.edu.co)
3  * @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
4  * =========================================================================
5  */
6 #include <cpPlugins/Pipeline/Object.h>
7 #include <itkLightObject.h>
8 #include <itkObject.h>
9 #include <vtkObject.h>
10 #include <vtkObjectBase.h>
11 #include <vtkSmartPointer.h>
12
13 // -------------------------------------------------------------------------
14 cpPlugins::Pipeline::Object::
15 Object( const std::string& category )
16   : m_Name( "" ),
17     m_Category( category ),
18     m_Object( NULL ),
19     m_Type( Self::NeitherType )
20 {
21 }
22
23 // -------------------------------------------------------------------------
24 cpPlugins::Pipeline::Object::
25 ~Object( )
26 {
27   this->_DeleteObject( );
28 }
29
30 // -------------------------------------------------------------------------
31 void* cpPlugins::Pipeline::Object::
32 GetObject( )
33 {
34   return( this->m_Object );
35 }
36
37 // -------------------------------------------------------------------------
38 const void* cpPlugins::Pipeline::Object::
39 GetObject( ) const
40 {
41   return( this->m_Object );
42 }
43
44 // -------------------------------------------------------------------------
45 itk::LightObject* cpPlugins::Pipeline::Object::
46 GetObjectAsITK( )
47 {
48   if( this->m_Object != NULL && this->m_Type == Self::ITKType )
49   {
50     itk::LightObject::Pointer* o =
51       reinterpret_cast< itk::LightObject::Pointer* >( this->m_Object );
52     return( o->GetPointer( ) );
53   }
54   else
55     return( NULL );
56 }
57
58 // -------------------------------------------------------------------------
59 const itk::LightObject* cpPlugins::Pipeline::Object::
60 GetObjectAsITK( ) const
61 {
62   if( this->m_Object != NULL && this->m_Type == Self::ITKType )
63   {
64     const itk::LightObject::Pointer* o =
65       reinterpret_cast< const itk::LightObject::Pointer* >( this->m_Object );
66     return( o->GetPointer( ) );
67   }
68   else
69     return( NULL );
70 }
71
72 // -------------------------------------------------------------------------
73 vtkObjectBase* cpPlugins::Pipeline::Object::
74 GetObjectAsVTK( )
75 {
76   if( this->m_Object != NULL && this->m_Type == Self::VTKType )
77   {
78     vtkSmartPointer< vtkObjectBase >* o =
79       reinterpret_cast< vtkSmartPointer< vtkObjectBase >* >( this->m_Object );
80     return( o->GetPointer( ) );
81   }
82   else
83     return( NULL );
84 }
85
86 // -------------------------------------------------------------------------
87 const vtkObjectBase* cpPlugins::Pipeline::Object::
88 GetObjectAsVTK( ) const
89 {
90   if( this->m_Object != NULL && this->m_Type == Self::VTKType )
91   {
92     const vtkSmartPointer< vtkObjectBase >* o =
93       reinterpret_cast< const vtkSmartPointer< vtkObjectBase >* >(
94         this->m_Object
95         );
96     return( o->GetPointer( ) );
97   }
98   else
99     return( NULL );
100 }
101
102 // -------------------------------------------------------------------------
103 const char* cpPlugins::Pipeline::Object::
104 GetClassName( ) const
105 {
106   return( this->m_Name.c_str( ) );
107 }
108
109 // -------------------------------------------------------------------------
110 const char* cpPlugins::Pipeline::Object::
111 GetClassCategory( ) const
112 {
113   return( this->m_Category.c_str( ) );
114 }
115
116 // -------------------------------------------------------------------------
117 void cpPlugins::Pipeline::Object::
118 SetClassName( const std::string& name )
119 {
120   this->m_Name = name;
121 }
122
123 // -------------------------------------------------------------------------
124 void cpPlugins::Pipeline::Object::
125 Modified( )
126 {
127   const itk::Object* i =
128     dynamic_cast< const itk::Object* >( this->GetObjectAsITK( ) );
129   vtkObject* v =
130     dynamic_cast< vtkObject* >( this->GetObjectAsVTK( ) );
131   if( i != NULL ) i->Modified( );
132   if( v != NULL ) v->Modified( );
133 }
134
135 // -------------------------------------------------------------------------
136 void cpPlugins::Pipeline::Object::
137 _DeleteObject( )
138 {
139   typedef itk::LightObject::Pointer _TIPtr;
140   typedef vtkSmartPointer< vtkObjectBase > _TVPtr;
141   if( this->m_Object != NULL )
142   {
143     if( this->m_Type == Self::ITKType )
144     {
145       _TIPtr* o = reinterpret_cast< _TIPtr* >( this->m_Object );
146       delete o;
147     }
148     else if( this->m_Type == Self::VTKType )
149     {
150       _TVPtr* o = reinterpret_cast< _TVPtr* >( this->m_Object );
151       delete o;
152
153     } // fi
154     this->m_Object = NULL;
155
156   } // fi
157 }
158
159 // -------------------------------------------------------------------------
160 void cpPlugins::Pipeline::Object::
161 _SetObject( itk::LightObject* obj )
162 {
163   if( obj != NULL )
164   {
165     itk::LightObject::Pointer* p = new itk::LightObject::Pointer( obj );
166     this->m_Object = p;
167     this->m_Type = Self::ITKType;
168   }
169   else
170   {
171     this->_DeleteObject( );
172     this->m_Type = Self::NeitherType;
173
174   } // fi
175 }
176
177 // -------------------------------------------------------------------------
178 void cpPlugins::Pipeline::Object::
179 _SetObject( vtkObjectBase* obj )
180 {
181   if( obj != NULL )
182   {
183     vtkSmartPointer< vtkObjectBase >* p =
184       new vtkSmartPointer< vtkObjectBase >( obj );
185     this->m_Object = p;
186     this->m_Type = Self::VTKType;
187   }
188   else
189   {
190     this->_DeleteObject( );
191     this->m_Type = Self::NeitherType;
192
193   } // fi
194 }
195
196 // -------------------------------------------------------------------------
197 void cpPlugins::Pipeline::Object::
198 _SetObject( void* obj )
199 {
200   if( obj != NULL )
201     this->m_Object = obj;
202   else
203     this->_DeleteObject( );
204   this->m_Type = Self::NeitherType;
205 }
206
207 // eof - $RCSfile$