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 clitkFillImageRegionGenericFilter_txx
19 #define clitkFillImageRegionGenericFilter_txx
21 /* =================================================
22 * @file clitkFillImageRegionGenericFilter.txx
28 ===================================================*/
34 //-------------------------------------------------------------------
35 // Update with the number of dimensions
36 //-------------------------------------------------------------------
37 template<unsigned int Dimension>
39 FillImageRegionGenericFilter::UpdateWithDim(std::string PixelType)
41 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
43 if(PixelType == "short"){
44 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
45 UpdateWithDimAndPixelType<Dimension, signed short>();
47 // else if(PixelType == "unsigned_short"){
48 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
49 // UpdateWithDimAndPixelType<Dimension, unsigned short>();
52 else if (PixelType == "unsigned_char"){
53 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
54 UpdateWithDimAndPixelType<Dimension, unsigned char>();
57 // else if (PixelType == "char"){
58 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
59 // UpdateWithDimAndPixelType<Dimension, signed char>();
62 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
63 UpdateWithDimAndPixelType<Dimension, float>();
68 //-------------------------------------------------------------------
69 // Update with the number of dimensions and the pixeltype
70 //-------------------------------------------------------------------
71 template <unsigned int Dimension, class PixelType>
73 FillImageRegionGenericFilter::UpdateWithDimAndPixelType()
77 typedef itk::Image<PixelType, Dimension> InputImageType;
78 typedef itk::Image<PixelType, Dimension> OutputImageType;
81 typedef itk::ImageFileReader<InputImageType> InputReaderType;
82 typename InputReaderType::Pointer reader = InputReaderType::New();
83 reader->SetFileName( m_InputFileName);
85 typename InputImageType::Pointer input= reader->GetOutput();
88 switch(m_ArgsInfo.shape_arg)
93 // Get Size and index of the region
94 typename InputImageType::SizeType size;
95 if (m_ArgsInfo.size_given)
96 for(unsigned int i=0; i<Dimension; i++)
97 size[i]=m_ArgsInfo.size_arg[i];
99 size.Fill(m_ArgsInfo.size_arg[0]);
101 // Get Index of the region
102 typename InputImageType::IndexType index;
103 if (m_ArgsInfo.index_given)
104 for(unsigned int i=0; i<Dimension; i++)
105 index[i]=m_ArgsInfo.index_arg[i];
107 index.Fill(m_ArgsInfo.index_arg[0]);
110 typename InputImageType::RegionType region;
111 region.SetIndex(index);
112 region.SetSize(size);
115 typedef itk::ImageRegionIterator<InputImageType> IteratorType;
116 IteratorType it(input, region);
118 while (!it.IsAtEnd()) {
119 it.Set(m_ArgsInfo.value_arg);
131 typename InputImageType::PointType center;
132 if (m_ArgsInfo.center_given)
133 for(unsigned int i=0; i<Dimension; i++)
134 center[i]=m_ArgsInfo.center_arg[i];
137 typename InputImageType::SizeType size= input->GetLargestPossibleRegion().GetSize();
138 typename InputImageType::SpacingType spacing= input->GetSpacing();
139 typename InputImageType::PointType origin= input->GetOrigin();
140 for (unsigned int i=0; i<Dimension; i++)
141 center[i]=origin[i]+(double)size[i]/2*spacing[i];
143 if (m_ArgsInfo.offset_given)
145 typename itk::Vector<double, Dimension> offset;
146 for (unsigned int i=0; i<Dimension; i++)
147 center[i]+=m_ArgsInfo.offset_arg[i];
151 // Get the half axes size
152 typename itk::Vector<double, Dimension> axes;
153 if (m_ArgsInfo.axes_given)
154 for(unsigned int i=0; i<Dimension; i++)
155 axes[i]=m_ArgsInfo.axes_arg[i];
157 axes.Fill(m_ArgsInfo.axes_arg[0]);
161 typedef itk::ImageRegionIteratorWithIndex<InputImageType> IteratorType;
162 IteratorType it(input, input->GetLargestPossibleRegion());
165 typename InputImageType::PointType point;
166 typename InputImageType::IndexType index;
169 while (!it.IsAtEnd())
172 input->TransformIndexToPhysicalPoint(index, point);
174 for(unsigned int i=0; i<Dimension; i++)
175 distance+=powf( ( (center[i]-point[i])/axes[i] ), 2);
178 it.Set(m_ArgsInfo.value_arg);
186 typedef itk::ImageFileWriter<OutputImageType> WriterType;
187 typename WriterType::Pointer writer = WriterType::New();
188 writer->SetFileName(m_ArgsInfo.output_arg);
189 writer->SetInput(input);
197 #endif //#define clitkFillImageRegionGenericFilter_txx