]> Creatis software - clitk.git/blob - tools/clitkMergeSequenceGenericFilter.txx
Add pixel type options for clitkMergeSequence (double and unsigned char)
[clitk.git] / tools / clitkMergeSequenceGenericFilter.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 __clitkMergeSequenceGenericFilter_txx
19 #define __clitkMergeSequenceGenericFilter_txx
20 #include "clitkMergeSequenceGenericFilter.h"
21
22
23 namespace clitk
24 {
25   template<unsigned int Dimension>
26   void MergeSequenceGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components)
27   {
28
29     if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<<Components<<" component(s) of "<<  PixelType<<"..."<<std::endl;
30
31     if (Components==1) {
32       if(PixelType == "short") {
33         if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
34         UpdateWithDimAndPixelType<Dimension, signed short>();
35       } else if(PixelType == "unsigned_short") {
36          if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
37          UpdateWithDimAndPixelType<Dimension, unsigned short>();
38       } else if (PixelType == "unsigned_char") {
39         if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
40         UpdateWithDimAndPixelType<Dimension, unsigned char>();
41       } else if (PixelType == "char"){
42         if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
43         UpdateWithDimAndPixelType<Dimension, signed char>();
44       } else if(PixelType == "double"){
45         if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and double..." << std::endl;
46         UpdateWithDimAndPixelType<Dimension, double>();
47       } else {
48         if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
49         UpdateWithDimAndPixelType<Dimension, float>();
50       }
51     } else if (Components==3) {
52       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl;
53       UpdateWithDimAndPixelType<Dimension, itk::Vector<float, 3> >();
54     } else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
55   }
56
57
58   template<unsigned int Dimension, class PixelType >
59   void MergeSequenceGenericFilter::UpdateWithDimAndPixelType()
60   {
61
62     //Define the input and output image type
63     typedef itk::Image<PixelType, Dimension> InputImageType;
64     typedef itk::Image<PixelType, Dimension+1> OutputImageType;
65
66     //Read the input image series
67     typedef itk::ImageSeriesReader<OutputImageType> ImageReaderType;
68     typename  ImageReaderType::Pointer reader= ImageReaderType::New();
69     reader->SetFileNames(m_InputNames);
70     reader->Update();
71     typename OutputImageType::Pointer image =reader->GetOutput();
72
73     //Set the spacing
74     typename OutputImageType::SpacingType spacing=image->GetSpacing();
75     spacing[Dimension]=m_Spacing;
76     image->SetSpacing(spacing);
77
78     //Write the output
79     typedef itk::ImageFileWriter<OutputImageType> WriterType;
80     typename WriterType::Pointer writer = WriterType::New();
81     writer->SetFileName(m_OutputName);
82     writer->SetInput(reader->GetOutput());
83     writer->Update();
84
85   }
86
87
88 }
89
90 #endif
91