]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Image.hxx
bd8ee0411f7500550db29c85d8553870d4a1c001
[cpPlugins.git] / lib / cpPlugins / Interface / Image.hxx
1 #ifndef __CPPLUGINS__INTERFACE__IMAGE__HXX__
2 #define __CPPLUGINS__INTERFACE__IMAGE__HXX__
3
4 #define ITK_MANUAL_INSTANTIATION
5 #include <itkImageToVTKImageFilter.h>
6
7 // -------------------------------------------------------------------------
8 template< class I >
9 void cpPlugins::Interface::Image::
10 SetITKImage( itk::DataObject* object )
11 {
12   // Check if input object has the desired type
13   I* image = dynamic_cast< I* >( object );
14   if( image == NULL )
15     return;
16
17   // Connect it to VTK
18   typename itk::ImageToVTKImageFilter< I >::Pointer f =
19     itk::ImageToVTKImageFilter< I >::New( );
20   f->SetInput( image );
21   f->Update( );
22
23   // Keep objects
24   this->m_ITKObject = object;
25   this->m_VTKObject = f->GetOutput( );
26   this->m_ITKvVTKConnection = f;
27   this->Modified( );
28 }
29
30 // -------------------------------------------------------------------------
31 template< class I >
32 I* cpPlugins::Interface::Image::
33 GetITKImage( )
34 {
35   return( dynamic_cast< I* >( this->m_ITKObject.GetPointer( ) ) );
36 }
37
38 // -------------------------------------------------------------------------
39 template< class I >
40 const I* cpPlugins::Interface::Image::
41 GetITKImage( ) const
42 {
43   return( dynamic_cast< const I* >( this->m_ITKObject.GetPointer( ) ) );
44 }
45
46 #endif // __CPPLUGINS__INTERFACE__IMAGE__HXX__
47
48 // eof - $RCSfile$