DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
VectorImageToVTKXMLImageConverter.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image to VTK XML Image Converter
4 
5  Copyright (c) Pew-Thian Yap. All rights reserved.
6  See http://www.unc.edu/~ptyap/ for details.
7 
8  This software is distributed WITHOUT ANY WARRANTY; without even
9  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10  PURPOSE. See the above copyright notices for more information.
11 
12  =========================================================================*/
13 
14 #include <iostream>
15 #include <string.h>
16 
17 #include "itkVectorImage.h"
18 #include "itkImageFileReader.h"
19 
20 #include "vtkSmartPointer.h"
21 #include "vtkXMLImageDataWriter.h"
23 
24 #include "utl.h"
25 #include "VectorImageToVTKXMLImageConverterCLP.h"
26 
27 int
28 main(int argc, char *argv[])
29 {
30  PARSE_ARGS;
31 
32  // Define Variables
33  const static unsigned int Dimension = 3;
34  typedef double PixelType;
35  typedef itk::VectorImage<PixelType, Dimension> ImageType;
36  typedef itk::ImageFileReader<ImageType> ReaderType;
37  typedef vtkSmartPointer<vtkXMLImageDataWriter> WriterType;
38  WriterType writer = WriterType::New();
39 
40  // Read data
41  ImageType::Pointer image = ImageType::New();
42  itk::ReadVectorImage(_InputFile, image);
43 
44  // Converter
45  typedef itk::ImageToVTKImageDataFilter<ImageType> ConverterType;
46  ConverterType::Pointer converter = ConverterType::New();
47  converter->SetInput( image );
48  converter->Update();
49 
50  // Write file
51  try
52  {
53  std::cout << "Writing file: " << _OutputFile << std::endl;
54  writer->SetInputData( converter->GetOutput() );
55  writer->SetFileName( _OutputFile.c_str() );
56  writer->Write();
57  }
58  catch ( itk::ExceptionObject & err )
59  {
60  std::cerr << "ExceptionObject caught!" << std::endl;
61  std::cerr << err << std::endl;
62  return EXIT_FAILURE;
63  }
64 
65  return EXIT_SUCCESS;
66 }
67 
Converts an ITK image to VTK image data.
helper functions specifically used in dmritool
void ReadVectorImage(const std::string &filename, SmartPointer< VectorImage< PixelType, 3 > > &image, const std::string &printInfo="Reading Image:")
Definition: utl.h:66
int main(int argc, char *argv[])