]> Creatis software - clitk.git/blob - tools/clitkValuesToBSplineCoefficientsGenericFilter.txx
782aad88e702058bc95025da3a0feea54ad92bd1
[clitk.git] / tools / clitkValuesToBSplineCoefficientsGenericFilter.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 clitkValuesToBSplineCoefficientsGenericFilter_txx
19 #define clitkValuesToBSplineCoefficientsGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkValuesToBSplineCoefficientsGenericFilter.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   ValuesToBSplineCoefficientsGenericFilter::UpdateWithDim(std::string PixelType, unsigned 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==1)
44       {
45         if(PixelType == "short"){  
46           if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
47           UpdateWithDimAndPixelType<Dimension, signed short>(); 
48         }
49         //    else if(PixelType == "unsigned_short"){  
50         //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
51         //       UpdateWithDimAndPixelType<Dimension, unsigned short>(); 
52         //     }
53         
54         else if (PixelType == "unsigned_char"){ 
55           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
56           UpdateWithDimAndPixelType<Dimension, unsigned char>();
57         }
58         
59         //     else if (PixelType == "char"){ 
60         //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
61         //       UpdateWithDimAndPixelType<Dimension, signed char>();
62         //     }
63         else {
64           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
65           UpdateWithDimAndPixelType<Dimension, float>();
66         }
67       }
68     
69     else if (Components==3)
70       {
71         if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl;
72         UpdateWithDimAndVectorType<Dimension, itk::Vector<float, 3> >();
73       }
74
75     else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
76   }
77
78
79   //-------------------------------------------------------------------
80   // Update with the number of dimensions and the pixeltype
81   //-------------------------------------------------------------------
82   template <unsigned int Dimension, class  PixelType> 
83   void 
84   ValuesToBSplineCoefficientsGenericFilter::UpdateWithDimAndPixelType()
85   {
86
87     // ImageTypes
88     typedef itk::Image<PixelType, Dimension> InputImageType;
89     typedef itk::Image<PixelType, Dimension> OutputImageType;
90     
91     // Read the input
92     typedef itk::ImageFileReader<InputImageType> InputReaderType;
93     typename InputReaderType::Pointer reader = InputReaderType::New();
94     reader->SetFileName( m_InputFileName);
95     reader->Update();
96     typename InputImageType::Pointer input= reader->GetOutput();
97
98     // Filter
99     typedef itk::BSplineDecompositionImageFilter<InputImageType, OutputImageType> FilterType;
100     typename FilterType::Pointer filter=FilterType::New();
101     filter->SetInput(input);
102     filter->SetSplineOrder(m_ArgsInfo.order_arg);
103     filter->Update();
104     typename OutputImageType::Pointer output=filter->GetOutput();
105         
106     // Output
107     typedef itk::ImageFileWriter<OutputImageType> WriterType;
108     typename WriterType::Pointer writer = WriterType::New();
109     writer->SetFileName(m_ArgsInfo.output_arg);
110     writer->SetInput(output);
111     writer->Update();
112
113   }
114
115
116   //-------------------------------------------------------------------
117   // Update with the number of dimensions and the Vectortype
118   //-------------------------------------------------------------------
119   template <unsigned int Dimension, class  PixelType> 
120   void 
121   ValuesToBSplineCoefficientsGenericFilter::UpdateWithDimAndVectorType()
122   {
123
124     // ImageTypes
125     typedef itk::Image<PixelType, Dimension> InputImageType;
126     typedef itk::Image<PixelType, Dimension> OutputImageType;
127     
128     // Read the input
129     typedef itk::ImageFileReader<InputImageType> InputReaderType;
130     typename InputReaderType::Pointer reader = InputReaderType::New();
131     reader->SetFileName( m_InputFileName);
132     reader->Update();
133     typename InputImageType::Pointer input= reader->GetOutput();
134
135     // Filter
136     typedef clitk::VectorBSplineDecompositionImageFilter<InputImageType, OutputImageType> FilterType;
137     typename FilterType::Pointer filter=FilterType::New();
138     filter->SetInput(input);
139     filter->SetSplineOrder(m_ArgsInfo.order_arg);
140     filter->Update();
141     typename OutputImageType::Pointer output=filter->GetOutput();
142         
143     // Output
144     typedef itk::ImageFileWriter<OutputImageType> WriterType;
145     typename WriterType::Pointer writer = WriterType::New();
146     writer->SetFileName(m_ArgsInfo.output_arg);
147     writer->SetInput(output);
148     writer->Update();
149
150   }
151
152
153 }//end clitk
154  
155 #endif //#define clitkValuesToBSplineCoefficientsGenericFilter_txx