1 #ifndef __CPEXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__
2 #define __CPEXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__
5 #include <itkImageFileReader.h>
6 #include <itkImageFileWriter.h>
7 #include <itkImageToVTKImageFilter.h>
11 namespace DataStructures
15 template< typename P, unsigned int D >
18 typedef itk::Image< P, D > TImage;
19 typedef itk::ImageToVTKImageFilter< TImage > TItk2Vtk;
21 typename TImage::Pointer ITK;
22 typename TItk2Vtk::Pointer VTK;
24 void CopyInformation( const itk::ImageBase< D >* i )
26 this->ITK = TImage::New( );
27 this->ITK->SetLargestPossibleRegion( i->GetLargestPossibleRegion( ) );
28 this->ITK->SetRequestedRegion( i->GetRequestedRegion( ) );
29 this->ITK->SetBufferedRegion( i->GetBufferedRegion( ) );
30 this->ITK->SetSpacing( i->GetSpacing( ) );
31 this->ITK->SetOrigin( i->GetOrigin( ) );
32 this->ITK->SetDirection( i->GetDirection( ) );
33 this->ITK->Allocate( );
36 void SetItkImage( TImage* image )
42 std::string ReadFromFile( const std::string& filename )
44 typename itk::ImageFileReader< TImage >::Pointer r =
45 itk::ImageFileReader< TImage >::New( );
46 r->SetFileName( filename );
51 catch( itk::ExceptionObject& err )
54 return( err.GetDescription( ) );
57 this->ITK = r->GetOutput( );
58 this->ITK->DisconnectPipeline( );
63 std::string WriteToFile( const std::string& filename ) const
65 typename itk::ImageFileWriter< TImage >::Pointer w =
66 itk::ImageFileWriter< TImage >::New( );
67 w->SetFileName( filename );
68 w->SetInput( this->ITK );
73 catch( itk::ExceptionObject& err )
75 return( err.GetDescription( ) );
81 TImage* GetItkImage( )
82 { return( this->ITK ); }
83 vtkImageData* GetVtkImage( )
84 { return( this->VTK->GetOutput( ) ); }
85 const TImage* GetItkImage( ) const
86 { return( this->ITK ); }
87 const vtkImageData* GetVtkImage( ) const
88 { return( this->VTK->GetOutput( ) ); }
89 void DisconnectPipeline( )
90 { this->ITK->DisconnectPipeline( ); }
94 this->VTK = TItk2Vtk::New( );
95 this->VTK->SetInput( this->ITK );
105 #endif // __CPEXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__