]> Creatis software - clitk.git/blob - tools/clitkCatImageGenericFilter.txx
GateAsciiImageIO is now cross-platform using itksys::RegularExpression
[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_VEC_IMAGE_TYPE(2,2,float);
47   ADD_VEC_IMAGE_TYPE(2,3,float);
48   ADD_VEC_IMAGE_TYPE(3,3,float);
49 }
50 //--------------------------------------------------------------------
51
52
53 //--------------------------------------------------------------------
54 template<class args_info_type>
55 void CatImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
56 {
57   mArgsInfo=a;
58   SetIOVerbose(mArgsInfo.verbose_flag);
59   if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
60
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);
67 }
68 //--------------------------------------------------------------------
69
70 //--------------------------------------------------------------------
71 // Update with the number of dimensions and the pixeltype
72 //--------------------------------------------------------------------
73 template<class args_info_type>
74 template<class InputImageType>
75 void
76 CatImageGenericFilter<args_info_type>::UpdateWithInputImageType()
77 {
78
79   // Reading input 1
80   typename InputImageType::Pointer input1 = this->template GetInput<InputImageType>(0);
81   typename InputImageType::Pointer input2 = this->template GetInput<InputImageType>(1);
82
83   // Main filter
84   typedef typename InputImageType::PixelType PixelType;
85   typedef itk::Image<char, InputImageType::ImageDimension> OutputImageType;
86
87   typename InputImageType::RegionType region;
88   region = input2->GetLargestPossibleRegion();
89
90   // Filter
91   typename InputImageType::SizeType upperBound;
92   upperBound.Fill(0);
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);
98
99   typename InputImageType::IndexType index;
100   index.Fill(0);
101   index[mArgsInfo.dimension_arg] = input1->GetLargestPossibleRegion().GetSize(mArgsInfo.dimension_arg);
102
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();
111
112   typename InputImageType::Pointer output = pasteFilter->GetOutput();
113
114   this->template SetNextOutput<InputImageType>(output);
115 }
116 //--------------------------------------------------------------------
117
118
119 }//end clitk
120
121 #endif //#define clitkCatImageGenericFilter_txx