]> Creatis software - clitk.git/blob - tools/clitkVectorImageToImageGenericFilter.txx
Merge branch 'master' into extentSimon
[clitk.git] / tools / clitkVectorImageToImageGenericFilter.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 clitkVectorImageToImageGenericFilter_txx
19 #define clitkVectorImageToImageGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkVectorImageToImageGenericFilter.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   VectorImageToImageGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components)
40   {
41     if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
42
43     if (Components==3)
44       {
45         if (PixelType == "unsigned_char")
46             UpdateWithDimAndPixelType<Dimension, itk::Vector<unsigned char, 3> >();
47         else
48         {
49             if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and 3D float..." << std::endl;
50             UpdateWithDimAndPixelType<Dimension, itk::Vector<float, 3> >();
51         }
52       }
53     else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
54   }
55
56
57   //-------------------------------------------------------------------
58   // Update with the number of dimensions and the pixeltype
59   //-------------------------------------------------------------------
60   template <unsigned int Dimension, class  PixelType> 
61   void 
62   VectorImageToImageGenericFilter::UpdateWithDimAndPixelType()
63   {
64     // ImageTypes
65     typedef itk::Image<PixelType, Dimension> InputImageType;
66     typedef typename PixelType::ComponentType ComponentType;
67     typedef itk::Image<ComponentType, Dimension> OutputImageType;
68     
69     // Read the input
70     typedef itk::ImageFileReader<InputImageType> InputReaderType;
71     typename InputReaderType::Pointer reader = InputReaderType::New();
72     reader->SetFileName( m_InputFileName);
73     reader->Update();
74     typename InputImageType::Pointer input= reader->GetOutput();
75
76     // Filter
77     typedef clitk::VectorImageToImageFilter<InputImageType, OutputImageType> FilterType;
78     typename FilterType::Pointer filter=FilterType::New();
79     filter->SetInput(input);
80     filter->SetComponentIndex(m_ArgsInfo.componentIndex_arg);
81     filter->Update();
82     typename OutputImageType::Pointer output=filter->GetOutput();
83     
84     // Output
85     typedef itk::ImageFileWriter<OutputImageType> WriterType;
86     typename WriterType::Pointer writer = WriterType::New();
87     writer->SetFileName(m_ArgsInfo.output_arg);
88     writer->SetInput(output);
89     writer->Update();
90
91   }
92
93
94 }//end clitk
95  
96 #endif //#define clitkVectorImageToImageGenericFilter_txx