]> Creatis software - creaImageIO.git/commitdiff
*** empty log message ***
authorFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Thu, 5 May 2011 09:19:12 +0000 (09:19 +0000)
committerFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Thu, 5 May 2011 09:19:12 +0000 (09:19 +0000)
src/creaImageIOWxISimpleDlg.hpp

index 518ff9339a0a3411ab77d5526ba00250aba732cb..2993b1e27a7c23f0c31bc0ef37115035d703582b 100644 (file)
 #include <itkDICOMSeriesFileNames.h>
 #include <itkNumericSeriesFileNames.h>
 #include <itkVectorImage.h>
-//#include "itkImageToVTKImageFilter.h"
+#include <itkMetaImageIO.h>
 #include <itkOrientedImage.h>
 #include <vtkImageReader2.h>
+#include <vtkMetaImageReader.h>
 #include <boost/filesystem/path.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/utility.hpp>
@@ -323,60 +324,51 @@ namespace creaImageIO
                        {
                            typename TImage::Pointer image = m_Iresults[0];
                        
-                                // Size and dims for Input Image
-                               typedef itk::Size<4> iSize;
-                               typedef const itk::Size<4>::SizeValueType iSizeVal;
-                               iSize size = image->GetLargestPossibleRegion().GetSize();
-                               iSizeVal *dims_size  = size.GetSize();
-
-                                // Output Type
-                                typedef itk::Image<unsigned char,3> ImageOutputType;  
-                            typedef itk::ImageSeriesWriter<TImage, ImageOutputType >  SeriesWriterType;
-                 
-                               /* typedef itk::VectorImage<short, 3> VectorImageType;
-                                VectorImageType::Pointer vect = VectorImageType::New();
-                                vect.*/
-
-
-                                SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
-                                seriesWriter->SetInput( image);
+                                if(image->GetImageDimension() == 4)
+                                {
+                                        // size of fourth dimension 
+                                        int dsize = image->GetLargestPossibleRegion().GetSize(3);
+                                        // Output Type
+                                        typedef itk::Image<unsigned char,3> ImageOutputType;  
+                                        typedef itk::ImageSeriesWriter<TImage, ImageOutputType >  SeriesWriterType;
+                                        typedef itk::MetaImageIO MetaImageType;
+                                        MetaImageType::Pointer metaIO;
+                                        SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
                        
-                                // from JPR file to generate output files
-                                typedef itk::NumericSeriesFileNames NamesGeneratorType;
-                                NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
-                                namesGenerator->SetStartIndex(0);
-                                namesGenerator->SetEndIndex(dims_size[3]-1);
-                                namesGenerator->SetIncrementIndex(1);
-                                std::string format = i_dir;
-                            format += "/image%03d.vtk";
-                                namesGenerator->SetSeriesFormat( format.c_str() );
-                                const std::vector<std::string> names = namesGenerator->GetFileNames();
-                                seriesWriter->SetFileNames( names );
-                       
-                                try
-                               {
-                                       seriesWriter->Update();
-                                       vtkImageReader2 *vReader = vtkImageReader2::New();
-                                       vReader->SetFilePrefix(".vtk");
-                                       std::vector<std::string>::const_iterator it = names.begin();
-//                                     for(unsigned int i = 0 ;i < dims_size[3]; i++)
-                                       for( ;it !=  names.end(); ++it)
+                                        // from JPR file to generate output files
+                                        typedef itk::NumericSeriesFileNames NamesGeneratorType;
+                                        NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
+                                        namesGenerator->SetStartIndex(0);
+                                        namesGenerator->SetEndIndex(dsize-1); 
+                                        namesGenerator->SetIncrementIndex(1);
+                                        std::string format = i_dir;
+                                        format += "/image%03d.mhd";
+                                        namesGenerator->SetSeriesFormat( format.c_str() );
+                                       
+                                        const std::vector<std::string> names = namesGenerator->GetFileNames();
+                                        seriesWriter->SetFileNames( names );
+                                        seriesWriter->SetInput(image);
+                                        seriesWriter->SetImageIO(metaIO);
+                                        try
                                        {
-                                               std::string name(*it);
-                                               vReader->SetFileName("d://temp2//image000.vtk");//name.c_str());
-                                               vReader->Update();
-                                               crea::VtkBasicSlicer(vReader->GetOutput());
-                                               m_Vresults.push_back(vReader->GetOutput());
+                                               seriesWriter->Update();
+                                               vtkMetaImageReader *vReader = vtkMetaImageReader::New();
+                                               std::vector<std::string>::const_iterator it = names.begin();
+                                               for( ;it !=  names.end(); ++it)
+                                               {
+                                                       vReader->SetFileName((*it).c_str());
+                                                       vReader->Update();
+                                                       m_Vresults.push_back(vReader->GetOutput());
+                                               }
                                        }
-                               }
-                               catch( itk::ExceptionObject & excp )
-                               {
-                                       std::cerr << "Exception thrown while writing the series " << std::endl;
-                                       std::cerr << excp << std::endl;
-                                       //return EXIT_FAILURE;
-                               }
-                               
-                 }
+                                       catch( itk::ExceptionObject & excp )
+                                       {
+                                               std::cerr << "Exception thrown while writing the series " << std::endl;
+                                               std::cerr << excp << std::endl;
+                                               //return EXIT_FAILURE;
+                                       }
+                                }
+                         }
 
          }