]> Creatis software - clitk.git/blob - tools/clitkComposeVFGenericFilter.txx
Debug RTStruct conversion with empty struc
[clitk.git] / tools / clitkComposeVFGenericFilter.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 __clitkComposeVFGenericFilter_txx
19 #define __clitkComposeVFGenericFilter_txx
20 #include "clitkComposeVFGenericFilter.h"
21
22 #include "clitkConvertBLUTCoeffsToVFFilter.h"
23
24 namespace clitk
25 {
26
27   template<unsigned int Dimension>
28   void ComposeVFGenericFilter::UpdateWithDim(std::string PixelType)
29   {
30     if (PixelType=="double")
31       {
32         UpdateWithDimAndPixelType<Dimension, double>();
33       }     
34     else
35       {
36         UpdateWithDimAndPixelType<Dimension, float>();
37       }
38   }
39
40   
41   template<unsigned int Dimension, class PixelType>
42   void ComposeVFGenericFilter::UpdateWithDimAndPixelType()
43   {
44     typedef itk::Vector<PixelType, Dimension> DisplacementType;
45     typedef itk::Image<DisplacementType, Dimension> ImageType;
46     typename ImageType::Pointer input1, input2;
47
48     //Define the image type
49     if (m_Type == 1) {
50       typedef ConvertBLUTCoeffsToVFFilter<ImageType> VFFilterType;
51       typename VFFilterType::Pointer vf_filter = VFFilterType::New();
52       vf_filter->SetInputFileName(m_InputName1);
53       vf_filter->SetLikeFileName(m_LikeImage);
54       vf_filter->SetVerbose(m_Verbose);
55       vf_filter->Update();
56       input1 = vf_filter->GetOutput();
57
58       vf_filter->SetInputFileName(m_InputName2);
59       vf_filter->Update();
60       input2 = vf_filter->GetOutput();
61     }
62     else {
63       //Read the input1
64       typedef itk::ImageFileReader<ImageType> ImageReaderType;
65       typename  ImageReaderType::Pointer reader1= ImageReaderType::New();
66       reader1->SetFileName(m_InputName1);
67       reader1->Update();
68       input1 =reader1->GetOutput();
69
70       //Read the input2
71       typename  ImageReaderType::Pointer reader2= ImageReaderType::New();
72       reader2->SetFileName(m_InputName2);
73       reader2->Update();
74       input2=reader2->GetOutput();
75     }
76
77       //Create the ComposeVFFilter
78       typedef clitk::ComposeVFFilter<ImageType,ImageType> FilterType;
79       typename FilterType::Pointer filter =FilterType::New();
80       filter->SetInput1(input1);
81       filter->SetInput2(input2);
82       filter->SetVerbose(m_Verbose);
83       filter->Update();
84
85       //Write the output
86       typedef itk::ImageFileWriter<ImageType> WriterType;
87       typename WriterType::Pointer writer = WriterType::New();
88       writer->SetFileName(m_OutputName);
89       writer->SetInput(filter->GetOutput());
90       writer->Update();
91     
92   }
93 }
94
95 #endif