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_DEFAULT_VEC_IMAGE_TYPES;
48 //--------------------------------------------------------------------
51 //--------------------------------------------------------------------
52 template<class args_info_type>
53 void CatImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
56 SetIOVerbose(mArgsInfo.verbose_flag);
57 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
59 if (mArgsInfo.input1_given)
60 AddInputFilename(mArgsInfo.input1_arg);
61 if (mArgsInfo.input2_given)
62 AddInputFilename(mArgsInfo.input2_arg);
63 if (mArgsInfo.output_given)
64 SetOutputFilename(mArgsInfo.output_arg);
66 //--------------------------------------------------------------------
68 //--------------------------------------------------------------------
69 // Update with the number of dimensions and the pixeltype
70 //--------------------------------------------------------------------
71 template<class args_info_type>
72 template<class InputImageType>
74 CatImageGenericFilter<args_info_type>::UpdateWithInputImageType()
78 typename InputImageType::Pointer input1 = this->template GetInput<InputImageType>(0);
79 typename InputImageType::Pointer input2 = this->template GetInput<InputImageType>(1);
82 typedef typename InputImageType::PixelType PixelType;
83 typedef itk::Image<char, InputImageType::ImageDimension> OutputImageType;
85 typename InputImageType::RegionType region;
86 region = input2->GetLargestPossibleRegion();
89 typename InputImageType::SizeType upperBound;
91 upperBound[mArgsInfo.dimension_arg] = region.GetSize()[mArgsInfo.dimension_arg];
92 typedef itk::ConstantPadImageFilter<InputImageType, InputImageType> PadImageFilterType;
93 typename PadImageFilterType::Pointer pad= PadImageFilterType::New();
94 pad->SetInput(input1);
95 pad->SetPadUpperBound(upperBound);
97 typename InputImageType::IndexType index;
99 index[mArgsInfo.dimension_arg] = input1->GetLargestPossibleRegion().GetSize(mArgsInfo.dimension_arg);
101 typedef itk::PasteImageFilter<InputImageType, InputImageType, InputImageType> PasteImageFilterType;
102 typename PasteImageFilterType::Pointer pasteFilter=PasteImageFilterType::New();
103 pasteFilter->SetSourceImage(input2);
104 pasteFilter->SetDestinationImage(pad->GetOutput());
105 pasteFilter->SetDestinationIndex(index);
106 pasteFilter->SetSourceRegion(region);
107 pasteFilter->InPlaceOn();
108 pasteFilter->Update();
110 typename InputImageType::Pointer output = pasteFilter->GetOutput();
112 this->template SetNextOutput<InputImageType>(output);
114 //--------------------------------------------------------------------
119 #endif //#define clitkCatImageGenericFilter_txx