]> Creatis software - clitk.git/blob - tools/clitkZeroVFGenericFilter.txx
Initial revision
[clitk.git] / tools / clitkZeroVFGenericFilter.txx
1 #ifndef __clitkZeroVFGenericFilter_txx
2 #define __clitkZeroVFGenericFilter_txx
3
4 #include "clitkZeroVFGenericFilter.h"
5
6
7 namespace clitk
8 {
9
10   template<unsigned int Dimension>
11   void ZeroVFGenericFilter::UpdateWithDim(std::string PixelType)
12   {
13     if (PixelType=="double")
14       {
15         UpdateWithDimAndPixelType<Dimension, double>();
16       }     
17     else
18       {
19         UpdateWithDimAndPixelType<Dimension, float>();
20       }
21   }
22
23
24   template<unsigned int Dimension, class PixelType>
25   void ZeroVFGenericFilter::UpdateWithDimAndPixelType()
26   {
27     //Define the image type
28     typedef itk::Vector<PixelType, Dimension> DisplacementType;
29     typedef itk::Image<DisplacementType, Dimension> ImageType;
30
31     //Read the image
32     typedef itk::ImageFileReader<ImageType> ImageReaderType;
33     typename  ImageReaderType::Pointer reader= ImageReaderType::New();
34     reader->SetFileName(m_InputName);
35     reader->Update(); // not very efficient :-p
36     typename ImageType::Pointer image =reader->GetOutput();
37     DisplacementType zero;
38     zero.Fill(0);
39     image->FillBuffer(zero);
40     
41     //Write the output
42     typedef itk::ImageFileWriter<ImageType> WriterType;
43     typename WriterType::Pointer writer = WriterType::New();
44     writer->SetFileName(m_OutputName);
45     writer->SetInput(image);
46     writer->Update();
47   }
48
49
50 }
51
52 #endif