]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 3 Jul 2015 23:26:11 +0000 (18:26 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 3 Jul 2015 23:26:11 +0000 (18:26 -0500)
lib/cpPlugins/Extensions/DataStructures/ITKAndVTKImage.h [new file with mode: 0644]

diff --git a/lib/cpPlugins/Extensions/DataStructures/ITKAndVTKImage.h b/lib/cpPlugins/Extensions/DataStructures/ITKAndVTKImage.h
new file mode 100644 (file)
index 0000000..faab21b
--- /dev/null
@@ -0,0 +1,99 @@
+#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$