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 clitkExtrudeGenericFilter_txx
19 #define clitkExtrudeGenericFilter_txx
22 #include <clitkCommon.h>
27 //--------------------------------------------------------------------
28 template<class args_info_type>
29 ExtrudeGenericFilter<args_info_type>::ExtrudeGenericFilter():
30 ImageToImageGenericFilter<Self>("Extrude")
32 InitializeImageType<2>();
33 InitializeImageType<3>();
35 //--------------------------------------------------------------------
38 //--------------------------------------------------------------------
39 template<class args_info_type>
40 template<unsigned int Dim>
41 void ExtrudeGenericFilter<args_info_type>::InitializeImageType()
43 ADD_DEFAULT_IMAGE_TYPES(Dim);
45 //--------------------------------------------------------------------
48 //--------------------------------------------------------------------
49 template<class args_info_type>
50 void ExtrudeGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
53 this->SetIOVerbose(mArgsInfo.verbose_flag);
55 if (mArgsInfo.input_given) {
56 this->SetInputFilename(mArgsInfo.input_arg);
58 if (mArgsInfo.output_given) {
59 this->SetOutputFilename(mArgsInfo.output_arg);
62 //--------------------------------------------------------------------
64 //--------------------------------------------------------------------
65 // Update with the number of dimensions and the pixeltype
66 //--------------------------------------------------------------------
67 template<class args_info_type>
68 template<class InputImageType>
70 ExtrudeGenericFilter<args_info_type>::UpdateWithInputImageType()
74 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
77 typedef typename InputImageType::PixelType PixelType;
78 const int Dim = InputImageType::ImageDimension;
79 typedef itk::Image<PixelType,Dim> ImageType;
80 typedef itk::Image<PixelType,Dim+1> OutputImageType;
83 typename OutputImageType::IndexType start;
84 typename OutputImageType::SizeType size;
85 typename OutputImageType::PointType origin;
86 typename OutputImageType::SpacingType spacing;
87 typename OutputImageType::DirectionType direction;
88 typename OutputImageType::Pointer output = OutputImageType::New();
93 if (mArgsInfo.size_given) {
94 if (mArgsInfo.size_arg > 0)
95 extrusionSize = mArgsInfo.size_arg;
97 std::cerr << "The size has to be > 0" << std::endl;
102 for (unsigned int i=0; i<Dim; ++i)
103 size[i] = input->GetLargestPossibleRegion().GetSize()[i];
104 size[Dim] = extrusionSize;
106 for (unsigned int i=0; i<Dim; ++i)
107 origin[i] = input->GetOrigin()[i];
108 if (mArgsInfo.origin_given)
109 origin[Dim] = mArgsInfo.origin_arg;
113 for (unsigned int i=0; i<Dim; ++i)
114 spacing[i] = input->GetSpacing()[i];
115 if (mArgsInfo.spacing_given)
116 spacing[Dim] = mArgsInfo.spacing_arg;
120 for (unsigned int i=0; i<Dim; ++i) {
121 for (unsigned int j=0; j<Dim; ++j)
122 direction[i][j] = input->GetDirection()[i][j];
123 direction[i][Dim] = 0;
125 for (unsigned int i=0; i<Dim; ++i)
126 direction[Dim][i] = 0;
127 direction[Dim][Dim] = 1;
129 typename OutputImageType::RegionType region(start, size);
130 output->SetRegions(region);
132 output->FillBuffer(0);
133 output->SetOrigin(origin);
134 output->SetSpacing(spacing);
135 output->SetDirection(direction);
137 itk::ImageRegionIteratorWithIndex<InputImageType> inputIterator(input, input->GetLargestPossibleRegion());
138 while(!inputIterator.IsAtEnd()) {
139 typename OutputImageType::IndexType pixelIndex;
140 for (unsigned int i=0; i<Dim; ++i)
141 pixelIndex[i] = inputIterator.GetIndex()[i];
142 for (unsigned int i=0; i<extrusionSize; ++i) {
144 output->SetPixel(pixelIndex, inputIterator.Get());
149 this->template SetNextOutput<OutputImageType>(output);
152 //--------------------------------------------------------------------
157 #endif //#define clitkExtrudeGenericFilter_txx