DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
VTKXMLImageToVectorImageConverter.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: VTK XML Image to 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 "itkImageFileWriter.h"
19 
20 #include "vtkSmartPointer.h"
21 #include "vtkXMLImageDataReader.h"
22 #include "vtkImageData.h"
24 
25 #include "VTKXMLImageToVectorImageConverterCLP.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> OutputImageType;
36  typedef vtkSmartPointer<vtkXMLImageDataReader> ReaderType;
37  typedef itk::ImageFileWriter<OutputImageType> WriterType;
38  ReaderType reader = ReaderType::New();
39  WriterType::Pointer writer = WriterType::New();
40 
41  // Read data
42  reader->SetFileName( _InputFile.c_str() );
43  try
44  {
45  std::cout << "Reading file: " << _InputFile << std::endl;
46  reader->Update();
47  reader->GetOutput()->Register(reader);
48 // reader->GetOutput()->GetPointData()->SetActiveScalars( "scalars" );
49 // reader->GetOutput()->GetPointData()->SetActiveAttribute(0, vtkDataSetAttributes::SCALARS);
50  }
51  catch (itk::ExceptionObject & err)
52  {
53  std::cerr << "ExceptionObject caught!" << std::endl;
54  std::cerr << err << std::endl;
55  return EXIT_FAILURE;
56  }
57 
58  // Converter
60  ConverterType::Pointer converter = ConverterType::New();
61  converter->SetInputData( reader->GetOutput() );
62  converter->Update();
63 
64  // Write file
65  try
66  {
67  std::cout << "Writing file: " << _OutputFile << std::endl;
68  writer->SetInput( converter->GetOutput() );
69  writer->SetFileName( _OutputFile );
70  writer->Update();
71  }
72  catch ( itk::ExceptionObject & err )
73  {
74  std::cerr << "ExceptionObject caught!" << std::endl;
75  std::cerr << err << std::endl;
76  return EXIT_FAILURE;
77  }
78 
79  return EXIT_SUCCESS;
80 }
81 
Convert VTK image data to an ITK image.
int main(int argc, char *argv[])