1 /* =========================================================================
2 * @author ??? (???@javeriana.edu.co)
3 * @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
4 * =========================================================================
6 #include <cpPlugins/Pipeline/Object.h>
7 #include <itkLightObject.h>
10 #include <vtkObjectBase.h>
11 #include <vtkSmartPointer.h>
13 // -------------------------------------------------------------------------
14 cpPlugins::Pipeline::Object::
15 Object( const std::string& category )
17 m_Category( category ),
19 m_Type( Self::NeitherType )
23 // -------------------------------------------------------------------------
24 cpPlugins::Pipeline::Object::
27 this->_DeleteObject( );
30 // -------------------------------------------------------------------------
31 void* cpPlugins::Pipeline::Object::
34 return( this->m_Object );
37 // -------------------------------------------------------------------------
38 const void* cpPlugins::Pipeline::Object::
41 return( this->m_Object );
44 // -------------------------------------------------------------------------
45 itk::LightObject* cpPlugins::Pipeline::Object::
48 if( this->m_Object != NULL && this->m_Type == Self::ITKType )
50 itk::LightObject::Pointer* o =
51 reinterpret_cast< itk::LightObject::Pointer* >( this->m_Object );
52 return( o->GetPointer( ) );
58 // -------------------------------------------------------------------------
59 const itk::LightObject* cpPlugins::Pipeline::Object::
60 GetObjectAsITK( ) const
62 if( this->m_Object != NULL && this->m_Type == Self::ITKType )
64 const itk::LightObject::Pointer* o =
65 reinterpret_cast< const itk::LightObject::Pointer* >( this->m_Object );
66 return( o->GetPointer( ) );
72 // -------------------------------------------------------------------------
73 vtkObjectBase* cpPlugins::Pipeline::Object::
76 if( this->m_Object != NULL && this->m_Type == Self::VTKType )
78 vtkSmartPointer< vtkObjectBase >* o =
79 reinterpret_cast< vtkSmartPointer< vtkObjectBase >* >( this->m_Object );
80 return( o->GetPointer( ) );
86 // -------------------------------------------------------------------------
87 const vtkObjectBase* cpPlugins::Pipeline::Object::
88 GetObjectAsVTK( ) const
90 if( this->m_Object != NULL && this->m_Type == Self::VTKType )
92 const vtkSmartPointer< vtkObjectBase >* o =
93 reinterpret_cast< const vtkSmartPointer< vtkObjectBase >* >(
96 return( o->GetPointer( ) );
102 // -------------------------------------------------------------------------
103 const char* cpPlugins::Pipeline::Object::
104 GetClassName( ) const
106 return( this->m_Name.c_str( ) );
109 // -------------------------------------------------------------------------
110 const char* cpPlugins::Pipeline::Object::
111 GetClassCategory( ) const
113 return( this->m_Category.c_str( ) );
116 // -------------------------------------------------------------------------
117 void cpPlugins::Pipeline::Object::
118 SetClassName( const std::string& name )
123 // -------------------------------------------------------------------------
124 void cpPlugins::Pipeline::Object::
127 const itk::Object* i =
128 dynamic_cast< const itk::Object* >( this->GetObjectAsITK( ) );
130 dynamic_cast< vtkObject* >( this->GetObjectAsVTK( ) );
131 if( i != NULL ) i->Modified( );
132 if( v != NULL ) v->Modified( );
135 // -------------------------------------------------------------------------
136 void cpPlugins::Pipeline::Object::
139 typedef itk::LightObject::Pointer _TIPtr;
140 typedef vtkSmartPointer< vtkObjectBase > _TVPtr;
141 if( this->m_Object != NULL )
143 if( this->m_Type == Self::ITKType )
145 _TIPtr* o = reinterpret_cast< _TIPtr* >( this->m_Object );
148 else if( this->m_Type == Self::VTKType )
150 _TVPtr* o = reinterpret_cast< _TVPtr* >( this->m_Object );
154 this->m_Object = NULL;
159 // -------------------------------------------------------------------------
160 void cpPlugins::Pipeline::Object::
161 _SetObject( itk::LightObject* obj )
165 itk::LightObject::Pointer* p = new itk::LightObject::Pointer( obj );
167 this->m_Type = Self::ITKType;
171 this->_DeleteObject( );
172 this->m_Type = Self::NeitherType;
177 // -------------------------------------------------------------------------
178 void cpPlugins::Pipeline::Object::
179 _SetObject( vtkObjectBase* obj )
183 vtkSmartPointer< vtkObjectBase >* p =
184 new vtkSmartPointer< vtkObjectBase >( obj );
186 this->m_Type = Self::VTKType;
190 this->_DeleteObject( );
191 this->m_Type = Self::NeitherType;
196 // -------------------------------------------------------------------------
197 void cpPlugins::Pipeline::Object::
198 _SetObject( void* obj )
201 this->m_Object = obj;
203 this->_DeleteObject( );
204 this->m_Type = Self::NeitherType;