]> Creatis software - clitk.git/blob - tools/clitkVFConvertGenericFilter.txx
Add 2 options to clitkImage2Dicom
[clitk.git] / tools / clitkVFConvertGenericFilter.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 clitkVFConvertGenericFilter_txx
19 #define clitkVFConvertGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkVFConvertGenericFilter.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   VFConvertGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components)
40   {
41     if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D with "<< Components <<" components 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 with "<< Components <<" components of double..." << std::endl;
47           UpdateWithDimAndPixelType<Dimension, itk::Vector<double, 2> >();
48         }
49         else {
50           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of 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 with "<< Components <<" components of double..." << std::endl;
58           UpdateWithDimAndPixelType<Dimension, itk::Vector<double, 3> >();
59         }
60         else {
61           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of float..." << std::endl;
62           UpdateWithDimAndPixelType<Dimension, itk::Vector<float, 3> >();
63         }
64       }
65     else if (Components==4)
66       {
67         if (PixelType == "double"){ 
68           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of double..." << std::endl;
69           UpdateWithDimAndPixelType<Dimension, itk::Vector<double, 4> >();
70         }
71         else {
72           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D with "<< Components <<" components of float..." << std::endl;
73           UpdateWithDimAndPixelType<Dimension, itk::Vector<float, 4> >();
74         }
75       }
76     else std::cerr<<"Only 2,3 and 4 components!"<<std::endl;
77   }
78
79
80   //-------------------------------------------------------------------
81   // Update with the number of dimensions and the pixeltype
82   //-------------------------------------------------------------------
83   template <unsigned int Dimension, class  PixelType> 
84   void 
85   VFConvertGenericFilter::UpdateWithDimAndPixelType()
86   {
87
88     // ImageTypes
89     typedef itk::Image<PixelType, Dimension> InputImageType;
90     typedef itk::Image<PixelType, Dimension> OutputImageType;
91     
92     // Read the input
93     typedef itk::ImageFileReader<InputImageType> InputReaderType;
94     typename InputReaderType::Pointer reader = InputReaderType::New();
95     reader->SetFileName( m_InputFileName);
96     reader->Update();
97     typename InputImageType::Pointer input= reader->GetOutput();
98
99     // Output
100     typedef itk::ImageFileWriter<OutputImageType> WriterType;
101     typename WriterType::Pointer writer = WriterType::New();
102     writer->SetFileName(m_ArgsInfo.output_arg);
103     writer->SetInput(input);
104     writer->Update();
105
106   }
107
108
109 }//end clitk
110  
111 #endif //#define clitkVFConvertGenericFilter_txx