]> Creatis software - clitk.git/blob - tools/clitkImageToVectorImageGenericFilter.txx
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[clitk.git] / tools / clitkImageToVectorImageGenericFilter.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 clitkImageToVectorImageGenericFilter_txx
19 #define clitkImageToVectorImageGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkImageToVectorImageGenericFilter.txx
23  * @author 
24  * @date   
25  * 
26  * @brief 
27  * 
28  ===================================================*/
29 #if ITK_VERSION_MAJOR < 4 || (ITK_VERSION_MAJOR == 4 && ITK_VERSION_MINOR <= 2)
30 # include "itkCompose3DVectorImageFilter.h"
31 #else
32 # include "itkComposeImageFilter.h"
33 #endif
34
35 namespace clitk
36 {
37
38   //-------------------------------------------------------------------
39   // Update with the number of dimensions
40   //-------------------------------------------------------------------
41   template<unsigned int Dimension>
42   void 
43   ImageToVectorImageGenericFilter::UpdateWithDim(std::string PixelType)
44   {
45     if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
46
47     if(PixelType == "short"){  
48       if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
49       UpdateWithDimAndPixelType<Dimension, signed short>(); 
50     }
51     //    else if(PixelType == "unsigned_short"){  
52     //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
53     //       UpdateWithDimAndPixelType<Dimension, unsigned short>(); 
54     //     }
55     
56     else if (PixelType == "unsigned_char"){ 
57       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
58       UpdateWithDimAndPixelType<Dimension, unsigned char>();
59     }
60     
61     //     else if (PixelType == "char"){ 
62     //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
63     //       UpdateWithDimAndPixelType<Dimension, signed char>();
64     //     }
65     else {
66       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
67       UpdateWithDimAndPixelType<Dimension, float>();
68     }
69   }
70
71
72   //-------------------------------------------------------------------
73   // Update with the number of dimensions and the pixeltype
74   //-------------------------------------------------------------------
75   template <unsigned int Dimension, class  PixelType> 
76   void 
77   ImageToVectorImageGenericFilter::UpdateWithDimAndPixelType()
78   {
79
80     // ImageTypes
81     typedef itk::Image<PixelType, Dimension> InputImageType;
82     typedef itk::Image<itk::Vector<PixelType,3>, Dimension> OutputImageType;
83     
84     // Filter
85 #if ITK_VERSION_MAJOR < 4 || (ITK_VERSION_MAJOR == 4 && ITK_VERSION_MINOR <= 2)
86     typedef itk::Compose3DVectorImageFilter<InputImageType,OutputImageType> ComposeFilterType;
87 #else
88     typedef itk::ComposeImageFilter<InputImageType,OutputImageType> ComposeFilterType;
89 #endif
90     typename ComposeFilterType::Pointer composeFilter=ComposeFilterType::New();
91
92     // Read the inputs
93     typedef itk::ImageFileReader<InputImageType> InputReaderType;
94     for (unsigned int i=0; i<3;i++)
95       {
96         typename InputReaderType::Pointer reader = InputReaderType::New();
97         reader->SetFileName( m_ArgsInfo.inputs[i]);
98         reader->Update();
99         composeFilter->SetInput(i, reader->GetOutput());
100       }
101     composeFilter->Update();
102     typename OutputImageType::Pointer output = composeFilter->GetOutput();
103
104     // Output
105     typedef itk::ImageFileWriter<OutputImageType> WriterType;
106     typename WriterType::Pointer writer = WriterType::New();
107     writer->SetFileName(m_ArgsInfo.output_arg);
108     writer->SetInput(output);
109     writer->Update();
110
111   }
112
113
114 }//end clitk
115  
116 #endif //#define clitkImageToVectorImageGenericFilter_txx