1 #ifndef clitkInvertVFGenericFilter_txx
2 #define clitkInvertVFGenericFilter_txx
4 /* =================================================
5 * @file clitkInvertVFGenericFilter.txx
11 ===================================================*/
17 //-----------------------------------------------------------
19 //-----------------------------------------------------------
20 template<class args_info_type>
21 InvertVFGenericFilter<args_info_type>::InvertVFGenericFilter()
28 //-----------------------------------------------------------
30 //-----------------------------------------------------------
31 template<class args_info_type>
32 void InvertVFGenericFilter<args_info_type>::Update()
34 // Read the Dimension and PixelType
36 std::string PixelType;
37 ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType);
41 if(Dimension==2) UpdateWithDim<2>(PixelType);
42 else if(Dimension==3) UpdateWithDim<3>(PixelType);
43 // else if (Dimension==4)UpdateWithDim<4>(PixelType);
46 std::cout<<"Error, Only for 2 or 3 Dimensions!!!"<<std::endl ;
51 //-------------------------------------------------------------------
52 // Update with the number of dimensions
53 //-------------------------------------------------------------------
54 template<class args_info_type>
55 template<unsigned int Dimension>
57 InvertVFGenericFilter<args_info_type>::UpdateWithDim(std::string PixelType)
59 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
61 // if(PixelType == "short"){
62 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
63 // UpdateWithDimAndPixelType<Dimension, signed short>();
65 // else if(PixelType == "unsigned_short"){
66 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
67 // UpdateWithDimAndPixelType<Dimension, unsigned short>();
70 // else if (PixelType == "unsigned_char"){
71 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
72 // UpdateWithDimAndPixelType<Dimension, unsigned char>();
75 // else if (PixelType == "char"){
76 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
77 // UpdateWithDimAndPixelType<Dimension, signed char>();
80 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
81 UpdateWithDimAndPixelType<Dimension, itk::Vector<float, Dimension> >();
86 //-------------------------------------------------------------------
87 // Update with the number of dimensions and the pixeltype
88 //-------------------------------------------------------------------
89 template<class args_info_type>
90 template <unsigned int Dimension, class PixelType>
92 InvertVFGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
96 typedef itk::Image<PixelType, Dimension> InputImageType;
97 typedef itk::Image<PixelType, Dimension> OutputImageType;
100 typedef itk::ImageFileReader<InputImageType> InputReaderType;
101 typename InputReaderType::Pointer reader = InputReaderType::New();
102 reader->SetFileName( m_InputFileName);
104 typename InputImageType::Pointer input= reader->GetOutput();
107 typename OutputImageType::Pointer output;
108 switch (m_ArgsInfo.type_arg)
114 // Create the InvertVFFilter
115 typedef clitk::InvertVFFilter<InputImageType,OutputImageType> FilterType;
116 typename FilterType::Pointer filter =FilterType::New();
117 filter->SetInput(input);
118 filter->SetVerbose(m_Verbose);
119 if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg);
120 if (m_ArgsInfo.pad_given)
123 if (m_ArgsInfo.pad_given != (pad.GetNumberOfComponents()) )
124 pad.Fill(m_ArgsInfo.pad_arg[0]);
126 for(unsigned int i=0; i<Dimension; i++)
127 pad[i]=m_ArgsInfo.pad_arg[i];
129 filter->SetThreadSafe(m_ArgsInfo.threadSafe_flag);
131 output=filter->GetOutput();
138 // Create the InverseDeformationFieldFilter
139 typedef itk::InverseDeformationFieldImageFilter<InputImageType,OutputImageType> FilterType;
140 typename FilterType::Pointer filter =FilterType::New();
141 filter->SetInput(input);
142 filter->SetOutputOrigin(input->GetOrigin());
143 filter->SetOutputSpacing(input->GetSpacing());
144 filter->SetSize(input->GetLargestPossibleRegion().GetSize());
145 filter->SetSubsamplingFactor(m_ArgsInfo.sampling_arg);
147 output=filter->GetOutput();
155 typedef itk::ImageFileWriter<OutputImageType> WriterType;
156 typename WriterType::Pointer writer = WriterType::New();
157 writer->SetFileName(m_ArgsInfo.output_arg);
158 writer->SetInput(output);
166 #endif //#define clitkInvertVFGenericFilter_txx