]> Creatis software - clitk.git/blob - tools/clitkCoeffsToDVF.cxx
Moved from repository clitk to clitk.private/tests_dav
[clitk.git] / tools / clitkCoeffsToDVF.cxx
1 #include "clitkCoeffsToDVF_ggo.h"
2 #include "clitkCoeffsToDVF.h"
3 #include "itkImage.h"
4 #include "itkImageFileWriter.h"
5 #include "itkImageIOFactory.h"
6 #include <string>
7
8 template <class DisplacementFieldType> 
9 void
10 Write(typename DisplacementFieldType::Pointer dvf, std::string fileName)
11 {
12   typedef itk::ImageFileWriter<DisplacementFieldType> ImageWriterType;
13   typename ImageWriterType::Pointer writer = ImageWriterType::New();
14   writer->SetFileName(fileName);
15   writer->SetInput(dvf);
16   writer->Update();
17 }
18
19 int main(int argc, char** argv) 
20 {
21   GGO(clitkCoeffsToDVF, args_info);
22   CLITK_INIT;
23
24   typename itk::ImageIOBase::Pointer image_io = itk::ImageIOFactory::CreateImageIO(args_info.input_arg, itk::ImageIOFactory::ReadMode);
25   image_io->SetFileName(args_info.input_arg);
26   image_io->ReadImageInformation();
27   
28   unsigned int ndim = image_io->GetNumberOfDimensions();
29   switch (ndim) {
30     case 2:
31     {
32       unsigned const dim = 2;
33       typedef itk::Vector<double, dim>  PixelType;
34       typedef itk::Image<PixelType, dim> DVFType;
35       typename DVFType::Pointer dvf = clitk::BLUTCoeffsToDVF<DVFType>(args_info.input_arg, args_info.like_arg);
36       Write<DVFType>(dvf, args_info.output_arg);
37     }
38     break;
39     
40     case 3:
41     {
42       unsigned const dim = 3;
43       typedef itk::Vector<double, dim>  PixelType;
44       typedef itk::Image<PixelType, dim> DVFType;
45       typename DVFType::Pointer dvf = clitk::BLUTCoeffsToDVF<DVFType>(args_info.input_arg, args_info.like_arg);
46       Write<DVFType>(dvf, args_info.output_arg);
47     }
48     break;
49     
50     default:
51       std::cerr << "Unsupported image dimension (either 2 or 3)" << std::endl;
52       return -1;
53   }
54   
55   return 0;
56 }