//////////////////////////////////////////////////////////////////////
// Return the results vector //
//////////////////////////////////////////////////////////////////////
- template <typename TImage>
- std::vector<typename TImage::Pointer> WxISimpleDlg<TImage>::getImagesSelected()
- {
- return m_Iresults;
- }
-
- template <typename TImage>
- void WxISimpleDlg<TImage>::readImg(const std::string &i_name)
- {
- // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images
- // uncomment to test
- /*typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
- itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(i_name.c_str(), itk::ImageIOFactory::ReadMode);
- imageIO->SetFileName(i_name.c_str());
- imageIO->ReadImageInformation();
- ScalarPixelType pixelType = imageIO->GetComponentType();
- const size_t dims = imageIO->GetNumberOfDimensions();*/
-
- typedef itk::ImageFileReader<TImage> ReaderType;
- typename ReaderType::Pointer reader = ReaderType::New();
- reader->SetFileName( i_name );
- try
- {
- reader->Update();
- }
- catch( itk::ExceptionObject & err )
- {
- std::cout << "Caught an exception reading" << i_name << ": " << std::endl;
- std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl;
- throw err;
- }
- catch(...)
- {
- std::cout << "Error while reading image " << i_name << std::endl;
- throw;
- }
- m_Iresults.push_back(reader->GetOutput());
- }
-
-
-
- template <typename TImage>
- void WxISimpleDlg<TImage>::readDicomImg(const std::vector<std::string> &i_names)
- {
- typedef itk::GDCMImageIO GDCMType;
- typedef itk::DICOMSeriesFileNames dicnames;
- GDCMType::Pointer gdcmIO = GDCMType::New();
- dicnames::Pointer generator = dicnames::New();
-// generator->SetInput(i_names);
- typedef itk::ImageSeriesReader<TImage> ReaderType;
- typename ReaderType::Pointer reader = ReaderType::New();
- reader->SetImageIO(gdcmIO);
- reader->SetFileNames(i_names);
- // reader->SetFileName( i_name );
- try
- {
- reader->Update();
- }
- catch( itk::ExceptionObject & err )
- {
- // std::cout << "Caught an exception reading" << i_name << ": " << std::endl;
- std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl;
- throw err;
- }
- catch(...)
- {
- //std::cout << "Error while reading image " << i_name << std::endl;
- throw;
- }
- m_Iresults.push_back(reader->GetOutput());
- }
-
-
-
-
- template <typename TImage>
- void WxISimpleDlg<TImage>::split3Din3Dvtk()
- {
- if ((m_Iresults).size() != 0)
- {
- typedef itk::ImageToVTKImageFilter< TImage > ConnectorType;
- ConnectorType::Pointer connector = ConnectorType::New();
- for(unsigned int i = 0 ;i < m_Iresults.size(); i++)
- {
- connector->SetInput(m_Iresults[i]);
- connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
- connector->Update();
- vtkImageData *im = vtkImageData::New();
- im->ShallowCopy(connector->GetOutput());
- im->Update();
- m_Vresults.push_back(im);
- }
- }
- }
-
-
-
- template <typename TImage>
- void WxISimpleDlg<TImage>::split4Din3Dvtk(const std::string &i_dir)
- {
- if ((m_Iresults).size() != 0)
- {
- typename TImage::Pointer image = m_Iresults[0];
-
- 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(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
- {
- 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;
- }
- }
- }
- }
+ template <typename TImage>
+ std::vector<typename TImage::Pointer> WxISimpleDlg<TImage>::getImagesSelected()
+ {
+ return m_Iresults;
+ }
+
+ template <typename TImage>
+ void WxISimpleDlg<TImage>::readImg(const std::string &i_name)
+ {
+ // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images
+ // uncomment to test
+ /*typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
+ itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(i_name.c_str(), itk::ImageIOFactory::ReadMode);
+ imageIO->SetFileName(i_name.c_str());
+ imageIO->ReadImageInformation();
+ ScalarPixelType pixelType = imageIO->GetComponentType();
+ const size_t dims = imageIO->GetNumberOfDimensions();*/
+
+ typedef itk::ImageFileReader<TImage> ReaderType;
+ typename ReaderType::Pointer reader = ReaderType::New();
+ reader->SetFileName( i_name );
+ try
+ {
+ reader->Update();
+ }
+ catch( itk::ExceptionObject & err )
+ {
+ std::cout << "Caught an exception reading" << i_name << ": " << std::endl;
+ std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl;
+ throw err;
+ }
+ catch(...)
+ {
+ std::cout << "Error while reading image " << i_name << std::endl;
+ throw;
+ }
+ m_Iresults.push_back(reader->GetOutput());
+
+ }
+
+
+
+ template <typename TImage>
+ void WxISimpleDlg<TImage>::readDicomImg(const std::vector<std::string> &i_names)
+ {
+ typedef itk::GDCMImageIO GDCMType;
+ typedef itk::DICOMSeriesFileNames dicnames;
+ GDCMType::Pointer gdcmIO = GDCMType::New();
+ dicnames::Pointer generator = dicnames::New();
+// generator->SetInput(i_names);
+ typedef itk::ImageSeriesReader<TImage> ReaderType;
+ typename ReaderType::Pointer reader = ReaderType::New();
+ reader->SetImageIO(gdcmIO);
+ reader->SetFileNames(i_names);
+ // reader->SetFileName( i_name );
+ try
+ {
+ reader->Update();
+ }
+ catch( itk::ExceptionObject & err )
+ {
+ // std::cout << "Caught an exception reading" << i_name << ": " << std::endl;
+ std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl;
+ throw err;
+ }
+ catch(...)
+ {
+ //std::cout << "Error while reading image " << i_name << std::endl;
+ throw;
+ }
+ m_Iresults.push_back(reader->GetOutput());
+
+ }
+
+
+
+
+ template <typename TImage>
+ void WxISimpleDlg<TImage>::split3Din3Dvtk()
+ {
+ if ((m_Iresults).size() != 0)
+ {
+ typedef itk::ImageToVTKImageFilter< TImage > ConnectorType;
+ ConnectorType::Pointer connector = ConnectorType::New();
+ for(unsigned int i = 0 ;i < m_Iresults.size(); i++)
+ {
+ connector->SetInput(m_Iresults[i]);
+ connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
+ connector->Update();
+ vtkImageData *im = vtkImageData::New();
+ im->ShallowCopy(connector->GetOutput());
+ im->Update();
+ m_Vresults.push_back(im);
+ }
+ }
+ }
+
+
+
+ template <typename TImage>
+ void WxISimpleDlg<TImage>::split4Din3Dvtk(const std::string &i_dir)
+ {
+ if ((m_Iresults).size() != 0)
+ {
+ typename TImage::Pointer image = m_Iresults[0];
+
+ if(image->GetImageDimension() == 4)
+ {
+ boost::any a1(image);
+ m_AnyImages.push_back(a1);
+ // 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(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
+ {
+ 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;
+ }
+ }
+ }
+
+ }
}// namespace end