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 clitkJacobianImageGenericFilter_txx
19 #define clitkJacobianImageGenericFilter_txx
21 /* =================================================
22 * @file clitkJacobianImageGenericFilter.txx
28 ===================================================*/
30 #include "clitkImageCommon.h"
31 #include "itkDisplacementFieldJacobianDeterminantFilter.h"
33 #include "itkImageFileReader.h"
34 #include "itkImageFileWriter.h"
35 #include "itkVector.h"
36 #include "itkNormalizeImageFilter.h"
41 //-----------------------------------------------------------
43 //-----------------------------------------------------------
44 template<class args_info_type>
45 JacobianImageGenericFilter<args_info_type>::JacobianImageGenericFilter()
52 //-----------------------------------------------------------
54 //-----------------------------------------------------------
55 template<class args_info_type>
56 void JacobianImageGenericFilter<args_info_type>::Update()
58 // Read the Dimension and PixelType
60 std::string PixelType;
61 ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType);
65 if(Dimension==2) UpdateWithDim<2>(PixelType);
66 else if(Dimension==3) UpdateWithDim<3>(PixelType);
67 // else if (Dimension==4)UpdateWithDim<4>(PixelType);
69 std::cout<<"Error, Only for 2 or 3 Dimensions!!!"<<std::endl ;
74 //-------------------------------------------------------------------
75 // Update with the number of dimensions
76 //-------------------------------------------------------------------
77 template<class args_info_type>
78 template<unsigned int Dimension>
80 JacobianImageGenericFilter<args_info_type>::UpdateWithDim(std::string PixelType)
82 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
84 // if(PixelType == "short"){
85 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
86 // UpdateWithDimAndPixelType<Dimension, signed short>();
88 // else if(PixelType == "unsigned_short"){
89 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
90 // UpdateWithDimAndPixelType<Dimension, unsigned short>();
93 // else if (PixelType == "unsigned_char"){
94 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
95 // UpdateWithDimAndPixelType<Dimension, unsigned char>();
98 // else if (PixelType == "char"){
99 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
100 // UpdateWithDimAndPixelType<Dimension, signed char>();
103 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
104 UpdateWithDimAndPixelType<Dimension, itk::Vector<float, Dimension> >();
109 //-------------------------------------------------------------------
110 // Update with the number of dimensions and the pixeltype
111 //-------------------------------------------------------------------
112 template<class args_info_type>
113 template <unsigned int Dimension, class PixelType>
115 JacobianImageGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
117 std::string vfield_file = m_ArgsInfo.input_arg;
119 const unsigned int dim = Dimension;
120 typedef itk::Vector<double, dim> VectorType;
121 typedef itk::Image<VectorType, dim> VectorFieldType;
122 typedef itk::ImageFileReader<VectorFieldType> VectorFieldReaderType;
124 typename VectorFieldReaderType::Pointer vfield_reader = VectorFieldReaderType::New();
125 vfield_reader->SetFileName(vfield_file.c_str());
127 typedef double OutputPixelType;
128 typedef itk::Image<OutputPixelType, dim> ImageType;
129 typedef itk::DisplacementFieldJacobianDeterminantFilter<VectorFieldType, OutputPixelType, ImageType> JacobianFilterType;
131 typename VectorFieldType::Pointer vfield = vfield_reader->GetOutput();
132 typename JacobianFilterType::Pointer jac = JacobianFilterType::New();
133 jac->SetInput(vfield);
136 typedef itk::NormalizeImageFilter<ImageType, ImageType> NormalizeFilterType;
137 typename NormalizeFilterType::Pointer normalize = NormalizeFilterType::New();
138 normalize->SetInput(jac->GetOutput());
141 typedef itk::ImageFileWriter<ImageType> ImageFileWriterType;
142 typename ImageFileWriterType::Pointer image_writer = ImageFileWriterType::New();
144 std::string image_file = m_ArgsInfo.output_arg;
145 image_writer->SetFileName(image_file.c_str());
146 image_writer->SetInput(jac->GetOutput());
147 image_writer->Update();
154 #endif //#define clitkJacobianImageGenericFilter_txx