]> Creatis software - clitk.git/blob - tools/clitkCatImageGenericFilter.txx
COMP: fix compilation errors for ITKv5
[clitk.git] / tools / clitkCatImageGenericFilter.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
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
20
21 #include <itkConstantPadImageFilter.h>
22 #include <itkPasteImageFilter.h>
23 #include <clitkCommon.h>
24
25 namespace clitk
26 {
27
28 //--------------------------------------------------------------------
29 template<class args_info_type>
30 CatImageGenericFilter<args_info_type>::CatImageGenericFilter():
31   ImageToImageGenericFilter<Self>("CatImage")
32 {
33   InitializeImageType<2>();
34   InitializeImageType<3>();
35   InitializeImageType<4>();
36 }
37 //--------------------------------------------------------------------
38
39
40 //--------------------------------------------------------------------
41 template<class args_info_type>
42 template<unsigned int Dim>
43 void CatImageGenericFilter<args_info_type>::InitializeImageType()
44 {
45   ADD_DEFAULT_IMAGE_TYPES(Dim);
46   ADD_DEFAULT_VEC_IMAGE_TYPES;
47 }
48 //--------------------------------------------------------------------
49
50
51 //--------------------------------------------------------------------
52 template<class args_info_type>
53 void CatImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
54 {
55   mArgsInfo=a;
56   this->SetIOVerbose(mArgsInfo.verbose_flag);
57   if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
58
59   if (mArgsInfo.input1_given)
60     this->AddInputFilename(mArgsInfo.input1_arg);
61   if (mArgsInfo.input2_given)
62     this->AddInputFilename(mArgsInfo.input2_arg);
63   if (mArgsInfo.output_given)
64     this->SetOutputFilename(mArgsInfo.output_arg);
65 }
66 //--------------------------------------------------------------------
67
68 //--------------------------------------------------------------------
69 // Update with the number of dimensions and the pixeltype
70 //--------------------------------------------------------------------
71 template<class args_info_type>
72 template<class InputImageType>
73 void
74 CatImageGenericFilter<args_info_type>::UpdateWithInputImageType()
75 {
76
77   // Reading input 1
78   typename InputImageType::Pointer input1 = this->template GetInput<InputImageType>(0);
79   typename InputImageType::Pointer input2 = this->template GetInput<InputImageType>(1);
80
81   // Main filter
82   typedef typename InputImageType::PixelType PixelType;
83   typedef itk::Image<char, InputImageType::ImageDimension> OutputImageType;
84
85   typename InputImageType::RegionType region;
86   region = input2->GetLargestPossibleRegion();
87
88   // Filter
89   typename InputImageType::SizeType upperBound;
90   upperBound.Fill(0);
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);
96
97   typename InputImageType::IndexType index;
98   index.Fill(0);
99   index[mArgsInfo.dimension_arg] = input1->GetLargestPossibleRegion().GetSize(mArgsInfo.dimension_arg);
100
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();
109
110   typename InputImageType::Pointer output = pasteFilter->GetOutput();
111
112   this->template SetNextOutput<InputImageType>(output);
113 }
114 //--------------------------------------------------------------------
115
116
117 }//end clitk
118
119 #endif //#define clitkCatImageGenericFilter_txx