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 clitkCombineImageGenericFilter_txx
19 #define clitkCombineImageGenericFilter_txx
21 /* =================================================
22 * @file clitkCombineImageGenericFilter.txx
28 ===================================================*/
34 //-------------------------------------------------------------------
35 // Update with the number of dimensions
36 //-------------------------------------------------------------------
37 template<unsigned int Dimension>
39 CombineImageGenericFilter::UpdateWithDim(std::string PixelType, int Components)
41 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<<Components<<" component(s) of "<< PixelType<<"..."<<std::endl;
45 if(PixelType == "short"){
46 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
47 UpdateWithDimAndPixelType<Dimension, signed short>();
49 // else if(PixelType == "unsigned_short"){
50 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
51 // UpdateWithDimAndPixelType<Dimension, unsigned short>();
54 else if (PixelType == "unsigned_char"){
55 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
56 UpdateWithDimAndPixelType<Dimension, unsigned char>();
59 // else if (PixelType == "char"){
60 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
61 // UpdateWithDimAndPixelType<Dimension, signed char>();
64 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
65 UpdateWithDimAndPixelType<Dimension, float>();
69 else if (Components==3)
71 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl;
72 UpdateWithDimAndPixelType<Dimension, itk::Vector<float, Dimension> >();
74 else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
78 //-------------------------------------------------------------------
79 // Update with the number of dimensions and the pixeltype
80 //-------------------------------------------------------------------
81 template <unsigned int Dimension, class PixelType>
83 CombineImageGenericFilter::UpdateWithDimAndPixelType()
87 typedef itk::Image<PixelType, Dimension> InputImageType;
88 typedef itk::Image<int, Dimension> MaskImageType;
89 typedef itk::Image<PixelType, Dimension> OutputImageType;
92 typedef itk::ImageFileReader<InputImageType> InputReaderType;
93 typename InputReaderType::Pointer reader = InputReaderType::New();
94 reader->SetFileName( m_InputFileName);
96 typename InputImageType::Pointer input1= reader->GetOutput();
97 typename InputReaderType::Pointer reader2 = InputReaderType::New();
98 reader2->SetFileName( m_ArgsInfo.input2_arg);
100 typename InputImageType::Pointer input2= reader2->GetOutput();
103 typedef itk::ImageFileReader<MaskImageType> MaskReaderType;
104 typename MaskReaderType::Pointer mReader = MaskReaderType::New();
105 mReader->SetFileName( m_ArgsInfo.mask_arg);
107 typename MaskImageType::Pointer mask= mReader->GetOutput();
110 typedef CombineImageFilter<InputImageType> CombineImageFilterType;
111 typename CombineImageFilterType::Pointer filter=CombineImageFilterType::New();
112 filter->SetInput( input1 );
113 filter->SetInput(1, input2 );
114 filter->SetMask( mask );
116 typename OutputImageType::Pointer output=filter->GetOutput();
119 typedef itk::ImageFileWriter<OutputImageType> WriterType;
120 typename WriterType::Pointer writer = WriterType::New();
121 writer->SetFileName(m_ArgsInfo.output_arg);
122 writer->SetInput(output);
130 #endif //#define clitkCombineImageGenericFilter_txx