X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkInvertVFGenericFilter.txx;h=a18a6417c6b0ad26c3efc14225fba5d1c7444153;hb=01a0dd7b79c5e5d5b82878d9e64dcba12891b53d;hp=c2bcc274e0377d37f5bd4a6d6d4067d870211580;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git diff --git a/tools/clitkInvertVFGenericFilter.txx b/tools/clitkInvertVFGenericFilter.txx index c2bcc27..a18a641 100644 --- a/tools/clitkInvertVFGenericFilter.txx +++ b/tools/clitkInvertVFGenericFilter.txx @@ -1,166 +1,236 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +===========================================================================**/ #ifndef clitkInvertVFGenericFilter_txx #define clitkInvertVFGenericFilter_txx +#include "itkVectorResampleImageFilter.h" +#include "clitkConvertBLUTCoeffsToVFFilter.h" + /* ================================================= * @file clitkInvertVFGenericFilter.txx - * @author - * @date - * - * @brief - * + * @author + * @date + * + * @brief + * ===================================================*/ namespace clitk { - //----------------------------------------------------------- - // Constructor - //----------------------------------------------------------- - template - InvertVFGenericFilter::InvertVFGenericFilter() - { - m_Verbose=false; - m_InputFileName=""; +//----------------------------------------------------------- +// Constructor +//----------------------------------------------------------- +template +InvertVFGenericFilter::InvertVFGenericFilter() +{ + m_Verbose=false; + m_InputFileName=""; +} + + +//----------------------------------------------------------- +// Update +//----------------------------------------------------------- +template +void InvertVFGenericFilter::Update() +{ + // Read the Dimension and PixelType + int Dimension; + std::string PixelType; + ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + + + // Call UpdateWithDim + if(Dimension==2) UpdateWithDim<2>(PixelType); + else if(Dimension==3) UpdateWithDim<3>(PixelType); + // else if (Dimension==4)UpdateWithDim<4>(PixelType); + else { + std::cout<<"Error, Only for 2 or 3 Dimensions!!!"< +template +void +InvertVFGenericFilter::UpdateWithDim(std::string PixelType) +{ + if (m_Verbose) std::cout << "Image was detected to be "< - void InvertVFGenericFilter::Update() - { - // Read the Dimension and PixelType - int Dimension; - std::string PixelType; - ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); + // if(PixelType == "short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } - - // Call UpdateWithDim - if(Dimension==2) UpdateWithDim<2>(PixelType); - else if(Dimension==3) UpdateWithDim<3>(PixelType); - // else if (Dimension==4)UpdateWithDim<4>(PixelType); - else - { - std::cout<<"Error, Only for 2 or 3 Dimensions!!!"<(); + // } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + // else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType >(); + // } +} + + +//------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//------------------------------------------------------------------- +template +template +void +InvertVFGenericFilter::UpdateWithDimAndPixelType() +{ + + // ImageTypes + typedef itk::Image InputImageType; + typedef itk::Image OutputImageType; + + // Read the input + typedef itk::ImageFileReader InputReaderType; + typename InputReaderType::Pointer reader = InputReaderType::New(); + reader->SetFileName( m_InputFileName); + reader->Update(); + typename InputImageType::Pointer input = reader->GetOutput(); + + // Filter + typename OutputImageType::Pointer output; + switch (m_ArgsInfo.type_arg) { + + // clitk filter + case 0: { + // Create the InvertVFFilter + typedef clitk::InvertVFFilter FilterType; + typename FilterType::Pointer filter =FilterType::New(); + if (m_ArgsInfo.like_given) { + typename FilterType::SpacingType spacing; + typename FilterType::SizeType size; + itk::ImageIOBase::Pointer header = readImageHeader(m_ArgsInfo.like_arg); + for(unsigned int i=0; iGetDimensions(i); + spacing[i] = header->GetSpacing(i); } + + typedef itk::VectorResampleImageFilter ResampleFilterType; + typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); + resampler->SetInput(input); + resampler->SetOutputOrigin(input->GetOrigin()); + resampler->SetOutputDirection(input->GetDirection()); + resampler->SetOutputSpacing(spacing); + resampler->SetSize(size); + resampler->Update(); + spacing = resampler->GetOutput()->GetSpacing(); + size = resampler->GetOutput()->GetLargestPossibleRegion().GetSize(); + filter->SetInput(resampler->GetOutput()); + } + else + filter->SetInput(input); + + filter->SetVerbose(m_Verbose); + if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg); + if (m_ArgsInfo.pad_given) { + PixelType pad; + if (m_ArgsInfo.pad_given != (pad.GetNumberOfComponents()) ) + pad.Fill(m_ArgsInfo.pad_arg[0]); + else + for(unsigned int i=0; iSetThreadSafe(m_ArgsInfo.threadSafe_flag); + filter->Update(); + output=filter->GetOutput(); + + break; } - //------------------------------------------------------------------- - // Update with the number of dimensions - //------------------------------------------------------------------- - template - template - void - InvertVFGenericFilter::UpdateWithDim(std::string PixelType) - { - if (m_Verbose) std::cout << "Image was detected to be "<(); - // } - // else if(PixelType == "unsigned_short"){ - // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; - // UpdateWithDimAndPixelType(); - // } - - // else if (PixelType == "unsigned_char"){ - // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; - // UpdateWithDimAndPixelType(); - // } - - // else if (PixelType == "char"){ - // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; - // UpdateWithDimAndPixelType(); - // } - // else { - if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; - UpdateWithDimAndPixelType >(); - // } + case 1: { + // Create the InvertVFFilter + typedef clitk::InvertVFFilter FilterType; + typename FilterType::Pointer filter =FilterType::New(); + if (m_ArgsInfo.like_given) { + typedef ConvertBLUTCoeffsToVFFilter VFFilterType; + typename VFFilterType::Pointer vf_filter = VFFilterType::New(); + vf_filter->SetInputFileName(m_InputFileName); + vf_filter->SetLikeFileName(m_ArgsInfo.like_arg); + vf_filter->SetVerbose(m_Verbose); + vf_filter->Update(); + filter->SetInput(vf_filter->GetOutput()); + } + + filter->SetVerbose(m_Verbose); + if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg); + if (m_ArgsInfo.pad_given) { + PixelType pad; + if (m_ArgsInfo.pad_given != (pad.GetNumberOfComponents()) ) + pad.Fill(m_ArgsInfo.pad_arg[0]); + else + for(unsigned int i=0; iSetThreadSafe(m_ArgsInfo.threadSafe_flag); + filter->Update(); + output=filter->GetOutput(); + + break; } + case 2: { + // Create the InverseDeformationFieldFilter + typedef itk::InverseDisplacementFieldImageFilter FilterType; + typename FilterType::Pointer filter =FilterType::New(); + filter->SetInput(input); + filter->SetOutputOrigin(input->GetOrigin()); + filter->SetOutputSpacing(input->GetSpacing()); + filter->SetSize(input->GetLargestPossibleRegion().GetSize()); + filter->SetSubsamplingFactor(m_ArgsInfo.sampling_arg); + filter->Update(); + output=filter->GetOutput(); - //------------------------------------------------------------------- - // Update with the number of dimensions and the pixeltype - //------------------------------------------------------------------- - template - template - void - InvertVFGenericFilter::UpdateWithDimAndPixelType() - { + break; + } - // ImageTypes - typedef itk::Image InputImageType; - typedef itk::Image OutputImageType; - - // Read the input - typedef itk::ImageFileReader InputReaderType; - typename InputReaderType::Pointer reader = InputReaderType::New(); - reader->SetFileName( m_InputFileName); - reader->Update(); - typename InputImageType::Pointer input= reader->GetOutput(); - - // Filter - typename OutputImageType::Pointer output; - switch (m_ArgsInfo.type_arg) - { - - // clitk filter - case 0: - { - // Create the InvertVFFilter - typedef clitk::InvertVFFilter FilterType; - typename FilterType::Pointer filter =FilterType::New(); - filter->SetInput(input); - filter->SetVerbose(m_Verbose); - if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg); - if (m_ArgsInfo.pad_given) - { - PixelType pad; - if (m_ArgsInfo.pad_given != (pad.GetNumberOfComponents()) ) - pad.Fill(m_ArgsInfo.pad_arg[0]); - else - for(unsigned int i=0; iSetThreadSafe(m_ArgsInfo.threadSafe_flag); - filter->Update(); - output=filter->GetOutput(); - - break; - } - - case 1: - { - // Create the InverseDeformationFieldFilter - typedef itk::InverseDeformationFieldImageFilter FilterType; - typename FilterType::Pointer filter =FilterType::New(); - filter->SetInput(input); - filter->SetOutputOrigin(input->GetOrigin()); - filter->SetOutputSpacing(input->GetSpacing()); - filter->SetSize(input->GetLargestPossibleRegion().GetSize()); - filter->SetSubsamplingFactor(m_ArgsInfo.sampling_arg); - filter->Update(); - output=filter->GetOutput(); - - break; - } - - } - - // Output - typedef itk::ImageFileWriter WriterType; - typename WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(m_ArgsInfo.output_arg); - writer->SetInput(output); - writer->Update(); } - - + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + +} + + }//end clitk - + #endif //#define clitkInvertVFGenericFilter_txx