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;
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>();
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>();
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>();
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>();
52 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
53 UpdateWithDimAndPixelType<Dimension, float>();
57 else if (Components==3)
59 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl;
60 UpdateWithDimAndPixelType<Dimension, itk::Vector<float, 3> >();
63 else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
68 template<unsigned int Dimension, class PixelType >
69 void MergeSequenceGenericFilter::UpdateWithDimAndPixelType()
72 //Define the input and output image type
73 typedef itk::Image<PixelType, Dimension> InputImageType;
74 typedef itk::Image<PixelType, Dimension+1> OutputImageType;
76 //Read the input image series
77 typedef itk::ImageSeriesReader<OutputImageType> ImageReaderType;
78 typename ImageReaderType::Pointer reader= ImageReaderType::New();
79 reader->SetFileNames(m_InputNames);
81 typename OutputImageType::Pointer image =reader->GetOutput();
84 typename OutputImageType::SpacingType spacing=image->GetSpacing();
85 spacing[Dimension]=m_Spacing;
86 image->SetSpacing(spacing);
89 typedef itk::ImageFileWriter<OutputImageType> WriterType;
90 typename WriterType::Pointer writer = WriterType::New();
91 writer->SetFileName(m_OutputName);
92 writer->SetInput(reader->GetOutput());