1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
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"
25 template<unsigned int Dimension>
26 void MergeSequenceGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components)
29 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<<Components<<" component(s) of "<< PixelType<<"..."<<std::endl;
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>();
48 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
49 UpdateWithDimAndPixelType<Dimension, float>();
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;
58 template<unsigned int Dimension, class PixelType >
59 void MergeSequenceGenericFilter::UpdateWithDimAndPixelType()
62 //Define the input and output image type
63 typedef itk::Image<PixelType, Dimension> InputImageType;
64 typedef itk::Image<PixelType, Dimension+1> OutputImageType;
66 //Read the input image series
67 typedef itk::ImageSeriesReader<OutputImageType> ImageReaderType;
68 typename ImageReaderType::Pointer reader= ImageReaderType::New();
69 reader->SetFileNames(m_InputNames);
71 typename OutputImageType::Pointer image =reader->GetOutput();
74 typename OutputImageType::SpacingType spacing=image->GetSpacing();
75 spacing[Dimension]=m_Spacing;
76 image->SetSpacing(spacing);
79 typedef itk::ImageFileWriter<OutputImageType> WriterType;
80 typename WriterType::Pointer writer = WriterType::New();
81 writer->SetFileName(m_OutputName);
82 writer->SetInput(reader->GetOutput());