]> Creatis software - clitk.git/blob - tools/clitkMergeSequenceGenericFilter.txx
300c8216183854bbfb914c834a08431b90866abc
[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       {
33         if(PixelType == "short"){  
34           if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
35           UpdateWithDimAndPixelType<Dimension, signed short>(); 
36         }
37         //    else if(PixelType == "unsigned_short"){  
38         //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
39         //       UpdateWithDimAndPixelType<Dimension, unsigned short>(); 
40         //     }
41         
42         else if (PixelType == "unsigned_char"){ 
43           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
44           UpdateWithDimAndPixelType<Dimension, unsigned char>();
45         }
46         
47         //     else if (PixelType == "char"){ 
48         //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
49         //       UpdateWithDimAndPixelType<Dimension, signed char>();
50         //     }
51         else {
52           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
53           UpdateWithDimAndPixelType<Dimension, float>();
54         }
55       }
56
57     else if (Components==3)
58       {
59         if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl;
60         UpdateWithDimAndPixelType<Dimension, itk::Vector<float, 3> >();
61       }
62
63     else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
64
65   }
66   
67   
68   template<unsigned int Dimension, class PixelType >
69   void MergeSequenceGenericFilter::UpdateWithDimAndPixelType()
70   {
71
72     //Define the input and output image type
73     typedef itk::Image<PixelType, Dimension> InputImageType;
74     typedef itk::Image<PixelType, Dimension+1> OutputImageType;
75
76     //Read the input image series
77     typedef itk::ImageSeriesReader<OutputImageType> ImageReaderType;
78     typename  ImageReaderType::Pointer reader= ImageReaderType::New();
79     reader->SetFileNames(m_InputNames);
80     reader->Update();
81     typename OutputImageType::Pointer image =reader->GetOutput();
82
83     //Set the spacing
84     typename OutputImageType::SpacingType spacing=image->GetSpacing();
85     spacing[Dimension]=m_Spacing;
86     image->SetSpacing(spacing);
87
88     //Write the output
89     typedef itk::ImageFileWriter<OutputImageType> WriterType;
90     typename WriterType::Pointer writer = WriterType::New();
91     writer->SetFileName(m_OutputName);
92     writer->SetInput(reader->GetOutput());
93     writer->Update();
94
95   }
96
97
98 }
99
100 #endif
101