1 #ifndef __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__
2 #define __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__
5 #include <itkImageFileReader.h>
6 #include <itkImageFileWriter.h>
7 #include <itkImageToVTKImageFilter.h>
13 namespace DataStructures
17 template< typename P, unsigned int D >
20 typedef itk::Image< P, D > TImage;
21 typedef itk::ImageToVTKImageFilter< TImage > TItk2Vtk;
23 typename TImage::Pointer ITK;
24 typename TItk2Vtk::Pointer VTK;
26 void CopyInformation( const itk::ImageBase< D >* i )
28 this->ITK = TImage::New( );
29 this->ITK->SetLargestPossibleRegion( i->GetLargestPossibleRegion( ) );
30 this->ITK->SetRequestedRegion( i->GetRequestedRegion( ) );
31 this->ITK->SetBufferedRegion( i->GetBufferedRegion( ) );
32 this->ITK->SetSpacing( i->GetSpacing( ) );
33 this->ITK->SetOrigin( i->GetOrigin( ) );
34 this->ITK->SetDirection( i->GetDirection( ) );
35 this->ITK->Allocate( );
38 void SetItkImage( TImage* image )
44 std::string ReadFromFile( const std::string& filename )
46 typename itk::ImageFileReader< TImage >::Pointer r =
47 itk::ImageFileReader< TImage >::New( );
48 r->SetFileName( filename );
53 catch( itk::ExceptionObject& err )
56 return( err.GetDescription( ) );
59 this->ITK = r->GetOutput( );
60 this->ITK->DisconnectPipeline( );
65 std::string WriteToFile( const std::string& filename ) const
67 typename itk::ImageFileWriter< TImage >::Pointer w =
68 itk::ImageFileWriter< TImage >::New( );
69 w->SetFileName( filename );
70 w->SetInput( this->ITK );
75 catch( itk::ExceptionObject& err )
77 return( err.GetDescription( ) );
83 TImage* GetItkImage( )
84 { return( this->ITK ); }
85 vtkImageData* GetVtkImage( )
86 { return( this->VTK->GetOutput( ) ); }
87 const TImage* GetItkImage( ) const
88 { return( this->ITK ); }
89 const vtkImageData* GetVtkImage( ) const
90 { return( this->VTK->GetOutput( ) ); }
91 void DisconnectPipeline( )
92 { this->ITK->DisconnectPipeline( ); }
96 this->VTK = TItk2Vtk::New( );
97 this->VTK->SetInput( this->ITK );
109 #endif // __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__