]> Creatis software - clitk.git/blob - tools/clitkZeroVFGenericFilter.txx
added the new headers
[clitk.git] / tools / clitkZeroVFGenericFilter.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef __clitkZeroVFGenericFilter_txx
19 #define __clitkZeroVFGenericFilter_txx
20 #include "clitkZeroVFGenericFilter.h"
21
22
23 namespace clitk
24 {
25
26   template<unsigned int Dimension>
27   void ZeroVFGenericFilter::UpdateWithDim(std::string PixelType)
28   {
29     if (PixelType=="double")
30       {
31         UpdateWithDimAndPixelType<Dimension, double>();
32       }     
33     else
34       {
35         UpdateWithDimAndPixelType<Dimension, float>();
36       }
37   }
38
39
40   template<unsigned int Dimension, class PixelType>
41   void ZeroVFGenericFilter::UpdateWithDimAndPixelType()
42   {
43     //Define the image type
44     typedef itk::Vector<PixelType, Dimension> DisplacementType;
45     typedef itk::Image<DisplacementType, Dimension> ImageType;
46
47     //Read the image
48     typedef itk::ImageFileReader<ImageType> ImageReaderType;
49     typename  ImageReaderType::Pointer reader= ImageReaderType::New();
50     reader->SetFileName(m_InputName);
51     reader->Update(); // not very efficient :-p
52     typename ImageType::Pointer image =reader->GetOutput();
53     DisplacementType zero;
54     zero.Fill(0);
55     image->FillBuffer(zero);
56     
57     //Write the output
58     typedef itk::ImageFileWriter<ImageType> WriterType;
59     typename WriterType::Pointer writer = WriterType::New();
60     writer->SetFileName(m_OutputName);
61     writer->SetInput(image);
62     writer->Update();
63   }
64
65
66 }
67
68 #endif