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