]> Creatis software - clitk.git/blob - tools/clitkZeroVFGenericFilter.txx
GateAsciiImageIO is now cross-platform using itksys::RegularExpression
[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://www.centreleonberard.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     UpdateWithDimAndPixelType<Dimension, double>();
31   } else {
32     UpdateWithDimAndPixelType<Dimension, float>();
33   }
34 }
35
36
37 template<unsigned int Dimension, class PixelType>
38 void ZeroVFGenericFilter::UpdateWithDimAndPixelType()
39 {
40   //Define the image type
41   typedef itk::Vector<PixelType, Dimension> DisplacementType;
42   typedef itk::Image<DisplacementType, Dimension> ImageType;
43
44   //Read the image
45   typedef itk::ImageFileReader<ImageType> ImageReaderType;
46   typename  ImageReaderType::Pointer reader= ImageReaderType::New();
47   reader->SetFileName(m_InputName);
48   reader->Update(); // not very efficient :-p
49   typename ImageType::Pointer image =reader->GetOutput();
50   DisplacementType zero;
51   zero.Fill(0);
52   image->FillBuffer(zero);
53
54   //Write the output
55   typedef itk::ImageFileWriter<ImageType> WriterType;
56   typename WriterType::Pointer writer = WriterType::New();
57   writer->SetFileName(m_OutputName);
58   writer->SetInput(image);
59   writer->Update();
60 }
61
62
63 }
64
65 #endif