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 clitkCatImageGenericFilter_txx
19 #define clitkCatImageGenericFilter_txx
21 #include <itkConstantPadImageFilter.h>
22 #include <itkPasteImageFilter.h>
23 #include <clitkCommon.h>
28 //--------------------------------------------------------------------
29 template<class args_info_type>
30 CatImageGenericFilter<args_info_type>::CatImageGenericFilter():
31 ImageToImageGenericFilter<Self>("CatImage")
33 InitializeImageType<2>();
34 InitializeImageType<3>();
35 InitializeImageType<4>();
37 //--------------------------------------------------------------------
40 //--------------------------------------------------------------------
41 template<class args_info_type>
42 template<unsigned int Dim>
43 void CatImageGenericFilter<args_info_type>::InitializeImageType()
45 ADD_DEFAULT_IMAGE_TYPES(Dim);
46 ADD_VEC_IMAGE_TYPE(2,2,float);
47 ADD_VEC_IMAGE_TYPE(2,3,float);
48 ADD_VEC_IMAGE_TYPE(3,3,float);
50 //--------------------------------------------------------------------
53 //--------------------------------------------------------------------
54 template<class args_info_type>
55 void CatImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
58 SetIOVerbose(mArgsInfo.verbose_flag);
59 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
61 if (mArgsInfo.input1_given)
62 AddInputFilename(mArgsInfo.input1_arg);
63 if (mArgsInfo.input2_given)
64 AddInputFilename(mArgsInfo.input2_arg);
65 if (mArgsInfo.output_given)
66 SetOutputFilename(mArgsInfo.output_arg);
68 //--------------------------------------------------------------------
70 //--------------------------------------------------------------------
71 // Update with the number of dimensions and the pixeltype
72 //--------------------------------------------------------------------
73 template<class args_info_type>
74 template<class InputImageType>
76 CatImageGenericFilter<args_info_type>::UpdateWithInputImageType()
80 typename InputImageType::Pointer input1 = this->template GetInput<InputImageType>(0);
81 typename InputImageType::Pointer input2 = this->template GetInput<InputImageType>(1);
84 typedef typename InputImageType::PixelType PixelType;
85 typedef itk::Image<char, InputImageType::ImageDimension> OutputImageType;
87 typename InputImageType::RegionType region;
88 region = input2->GetLargestPossibleRegion();
91 typename InputImageType::SizeType upperBound;
93 upperBound[mArgsInfo.dimension_arg] = region.GetSize()[mArgsInfo.dimension_arg];
94 typedef itk::ConstantPadImageFilter<InputImageType, InputImageType> PadImageFilterType;
95 typename PadImageFilterType::Pointer pad= PadImageFilterType::New();
96 pad->SetInput(input1);
97 pad->SetPadUpperBound(upperBound);
99 typename InputImageType::IndexType index;
101 index[mArgsInfo.dimension_arg] = input1->GetLargestPossibleRegion().GetSize(mArgsInfo.dimension_arg);
103 typedef itk::PasteImageFilter<InputImageType, InputImageType, InputImageType> PasteImageFilterType;
104 typename PasteImageFilterType::Pointer pasteFilter=PasteImageFilterType::New();
105 pasteFilter->SetSourceImage(input2);
106 pasteFilter->SetDestinationImage(pad->GetOutput());
107 pasteFilter->SetDestinationIndex(index);
108 pasteFilter->SetSourceRegion(region);
109 pasteFilter->InPlaceOn();
110 pasteFilter->Update();
112 typename InputImageType::Pointer output = pasteFilter->GetOutput();
114 this->template SetNextOutput<InputImageType>(output);
116 //--------------------------------------------------------------------
121 #endif //#define clitkCatImageGenericFilter_txx