]> Creatis software - clitk.git/blob - registration/clitkResampleBSplineDeformableTransformGenericFilter.txx
7cf8e8464d124d2801b8b45380fd65140d788db2
[clitk.git] / registration / clitkResampleBSplineDeformableTransformGenericFilter.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 clitkResampleBSplineDeformableTransformGenericFilter_txx
19 #define clitkResampleBSplineDeformableTransformGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkResampleBSplineDeformableTransformGenericFilter.txx
23  * @author 
24  * @date   
25  * 
26  * @brief 
27  * 
28  ===================================================*/
29
30
31 namespace clitk
32 {
33
34   //-------------------------------------------------------------------
35   // Update with the number of dimensions
36   //-------------------------------------------------------------------
37   template<unsigned int Dimension>
38   void 
39   ResampleBSplineDeformableTransformGenericFilter::UpdateWithDim(std::string PixelType, int Components)
40   {
41     if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<<Components<<" component(s) of "<<  PixelType<<"..."<<std::endl;
42
43     if (Components==2)
44       {
45         if(PixelType == "double"){  
46           if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 2D double..." << std::endl;
47           UpdateWithDimAndPixelType<Dimension, itk::Vector<double,2 > >(); 
48         }
49         else {
50           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and 2D float..." << std::endl;
51           UpdateWithDimAndPixelType<Dimension, itk::Vector<float,2 > >();
52         }
53       }
54     else if (Components==3)
55       {
56         if(PixelType == "double"){  
57           if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D double..." << std::endl;
58           UpdateWithDimAndPixelType<Dimension, itk::Vector<double,3 > >(); 
59         }
60         else {
61           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and 3D float..." << std::endl;
62           UpdateWithDimAndPixelType<Dimension, itk::Vector<float,3 > >();
63         }
64       }
65     else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
66   }
67
68
69   //-------------------------------------------------------------------
70   // Update with the number of dimensions and the pixeltype
71   //-------------------------------------------------------------------
72   template <unsigned int Dimension, class  PixelType> 
73   void 
74   ResampleBSplineDeformableTransformGenericFilter::UpdateWithDimAndPixelType()
75   {
76
77     // ImageTypes
78     typedef itk::Image<PixelType, Dimension> InputImageType;
79     typedef itk::Image<PixelType, Dimension> OutputImageType;
80     
81     // Read the input
82     typedef itk::ImageFileReader<InputImageType> InputReaderType;
83     typename InputReaderType::Pointer reader = InputReaderType::New();
84     reader->SetFileName( m_InputFileName);
85     reader->Update();
86     typename InputImageType::Pointer input= reader->GetOutput();
87
88     // Filter
89     typedef clitk::ResampleBSplineDeformableTransformImageFilter<InputImageType,OutputImageType> ResampleFilterType;
90     typename   ResampleFilterType::Pointer filter=ResampleFilterType::New();
91     filter->SetInput(input);
92     
93     // Output image info
94     if (m_ArgsInfo.like_given)
95       {
96         typename InputReaderType::Pointer likeReader=InputReaderType::New();
97         likeReader->SetFileName(m_ArgsInfo.like_arg);
98         likeReader->Update();
99         filter->SetOutputParametersFromImage(likeReader->GetOutput());
100       }
101     else
102       {
103         // Size
104         typename OutputImageType::SizeType outputSize;
105         if (m_ArgsInfo.size_given) 
106           {
107             for(unsigned int i=0; i< Dimension; i++)
108               outputSize[i]=m_ArgsInfo.size_arg[i];
109           }
110         else outputSize=input->GetLargestPossibleRegion().GetSize();
111         if (m_Verbose) std::cout<<"Setting the size to "<<outputSize<<"..."<<std::endl;
112         
113         // Spacing
114         typename OutputImageType::SpacingType outputSpacing;
115         if (m_ArgsInfo.spacing_given) 
116           {
117             for(unsigned int i=0; i< Dimension; i++)
118               outputSpacing[i]=m_ArgsInfo.spacing_arg[i];
119           }
120         else outputSpacing=input->GetSpacing();
121         if (m_Verbose) std::cout<<"Setting the spacing to "<<outputSpacing<<"..."<<std::endl;
122     
123         // Origin
124         typename OutputImageType::PointType outputOrigin;
125         if (m_ArgsInfo.origin_given) 
126           {
127             for(unsigned int i=0; i< Dimension; i++)
128               outputOrigin[i]=m_ArgsInfo.origin_arg[i];
129           }
130         else outputOrigin=input->GetOrigin();
131         if (m_Verbose) std::cout<<"Setting the origin to "<<outputOrigin<<"..."<<std::endl;
132
133         // Set
134         filter->SetSize( outputSize );
135         filter->SetOutputSpacing( outputSpacing );
136         filter->SetOutputOrigin(  outputOrigin );
137         
138       }
139
140     // Go
141     filter->Update();
142     
143     // Get the output
144     typename OutputImageType::Pointer output=filter->GetOutput();
145     
146     // Output
147     typedef itk::ImageFileWriter<OutputImageType> WriterType;
148     typename WriterType::Pointer writer = WriterType::New();
149     writer->SetFileName(m_ArgsInfo.output_arg);
150     writer->SetInput(output);
151     writer->Update();
152
153   }
154
155
156 }//end clitk
157  
158 #endif //#define clitkResampleBSplineDeformableTransformGenericFilter_txx