--- /dev/null
+#ifndef __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__
+#define __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__
+
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+#include <itkImageToVTKImageFilter.h>
+
+namespace cpPlugins
+{
+ namespace Extensions
+ {
+ namespace DataStructures
+ {
+ /**
+ */
+ template< typename P, unsigned int D >
+ struct ITKAndVTKImage
+ {
+ typedef itk::Image< P, D > TImage;
+ typedef itk::ImageToVTKImageFilter< TImage > TItk2Vtk;
+
+ typename TImage::Pointer ITK;
+ typename TItk2Vtk::Pointer VTK;
+
+ void SetItkImage( TImage* image )
+ {
+ this->ITK = image;
+ this->_Synch( );
+ }
+
+ std::string ReadFromFile( const std::string& filename )
+ {
+ typename itk::ImageFileReader< TImage >::Pointer r =
+ itk::ImageFileReader< TImage >::New( );
+ r->SetFileName( filename );
+ try
+ {
+ r->Update( );
+ }
+ catch( itk::ExceptionObject& err )
+ {
+ this->ITK = NULL;
+ return( err.GetDescription( ) );
+
+ } // fi
+ this->ITK = r->GetOutput( );
+ this->ITK->DisconnectPipeline( );
+ this->_Synch( );
+ return( "" );
+ }
+
+ std::string WriteToFile( const std::string& filename ) const
+ {
+ typename itk::ImageFileWriter< TImage >::Pointer w =
+ itk::ImageFileWriter< TImage >::New( );
+ w->SetFileName( filename );
+ w->SetInput( this->ITK );
+ try
+ {
+ w->Update( );
+ }
+ catch( itk::ExceptionObject& err )
+ {
+ return( err.GetDescription( ) );
+
+ } // fi
+ return( "" );
+ }
+
+ TImage* GetItkImage( )
+ { return( this->ITK ); }
+ vtkImageData* GetVtkImage( )
+ { return( this->VTK->GetOutput( ) ); }
+ const TImage* GetItkImage( ) const
+ { return( this->ITK ); }
+ const vtkImageData* GetVtkImage( ) const
+ { return( this->VTK->GetOutput( ) ); }
+ void DisconnectPipeline( )
+ { this->ITK->DisconnectPipeline( ); }
+
+ void _Synch( )
+ {
+ this->VTK = TItk2Vtk::New( );
+ this->VTK->SetInput( this->ITK );
+ this->VTK->Update( );
+ }
+
+ };
+
+ } // ecapseman
+
+ } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__ITKANDVTKIMAGE__H__
+
+// eof - $RCSfile$