From 0bbf0c26e4e2b917143315bec9ce1c52a357a500 Mon Sep 17 00:00:00 2001 From: bharath Date: Wed, 21 Jul 2010 09:38:56 +0000 Subject: [PATCH] Inherits from ImageToImageGenericFilter --- .../clitkAffineRegistrationGenericFilter.txx | 128 ++++++++++-------- 1 file changed, 70 insertions(+), 58 deletions(-) diff --git a/registration/clitkAffineRegistrationGenericFilter.txx b/registration/clitkAffineRegistrationGenericFilter.txx index 2ece121..2282585 100644 --- a/registration/clitkAffineRegistrationGenericFilter.txx +++ b/registration/clitkAffineRegistrationGenericFilter.txx @@ -49,7 +49,7 @@ public: } void Execute(const itk::Object * object, const itk::EventObject & event) { - if( !(itk::IterationEvent().CheckEvent( &event )) ) { + if ( !(itk::IterationEvent().CheckEvent( &event )) ) { return; } @@ -58,6 +58,29 @@ public: OptimizerPointer m_Optimizer; }; +//==================================================================================================================================// +//Constructor +//===================================================================================================================================// + +template +AffineRegistrationGenericFilter::AffineRegistrationGenericFilter(): + ImageToImageGenericFilter("Register") + +{ + InitializeImageType<2>(); + InitializeImageType<3>(); + m_Verbose=false; +} +//==========================================================================================================// +//============================================================================================================// +//-------------------------------------------------------------------- +template +template +void AffineRegistrationGenericFilter::InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); +} +//-------------------------------------------------------------------- //============================================================================== @@ -87,7 +110,7 @@ public: // is the pointer to the object which invoked the event and the // second is the event that was invoked. void Execute(itk::Object * object, const itk::EventObject & event) { - if( !(itk::IterationEvent().CheckEvent( &event )) ) { + if ( !(itk::IterationEvent().CheckEvent( &event )) ) { return; } @@ -126,31 +149,21 @@ public: args_info_clitkAffineRegistration m_ArgsInfo; }; - -//============================================================================== -// Update with the number of dimensions -//============================================================================== -template -void AffineRegistrationGenericFilter::UpdateWithDim(std::string PixelType) -{ - if (m_Verbose) std::cout << "Images were detected to be "<< Dimension << "D and " << PixelType << "..." << std::endl; - if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; - UpdateWithDimAndPixelType(); - // } - -} - - //============================================================================== // Update with the number of dimensions and pixeltype //============================================================================== -template -void -AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() +template +template +void AffineRegistrationGenericFilter::UpdateWithInputImageType() { //============================================================================= //Input //============================================================================= + + typedef typename InputImageType::PixelType PixelType; +//typedef typename InputImageType::ImageDimension Dimension; + + bool threadsGiven=m_ArgsInfo.threads_given; int threads=m_ArgsInfo.threads_arg; @@ -158,11 +171,11 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() typedef double TCoordRep; //The pixeltype of the fixed image will be used for output - typedef itk::Image< PixelType, Dimension > FixedImageType; + typedef itk::Image< PixelType, InputImageType::ImageDimension > FixedImageType; //Whatever the pixel type, internally we work with an image represented in float - typedef PixelType InternalPixelType; - typedef itk::Image< InternalPixelType, Dimension > InternalImageType; + typedef typename InputImageType::PixelType InternalPixelType; + typedef itk::Image< InternalPixelType, InputImageType::ImageDimension > InternalImageType; //Read in the reference/fixed image typedef itk::ImageFileReader< InternalImageType > ReaderType; @@ -242,7 +255,7 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() //============================================================================ // Setting up the moving image in a reference system //============================================================================ - const itk::Vector movingResolution = movingImage->GetSpacing(); + const itk::Vector movingResolution = movingImage->GetSpacing(); typename InternalImageType::RegionType movingRegion = movingImage->GetLargestPossibleRegion(); typename InternalImageType::RegionType::SizeType movingSize = movingRegion.GetSize(); @@ -250,11 +263,11 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() if (m_Verbose) { std::cout << "Object or Moving image:"< fixedResolution = fixedImage->GetSpacing(); + const itk::Vector fixedResolution = fixedImage->GetSpacing(); typename InternalImageType::RegionType fixedRegion = fixedImage->GetLargestPossibleRegion(); typename InternalImageType::RegionType::SizeType fixedSize = fixedRegion.GetSize(); @@ -270,11 +283,11 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() if (m_Verbose) { std::cout << "Target or Moving image:"< MaskType; + typedef itk::ImageMaskSpatialObject< InputImageType::ImageDimension > MaskType; typename MaskType::Pointer fixedMask=NULL; if (m_ArgsInfo.referenceMask_given) { fixedMask= MaskType::New(); - typedef itk::Image< unsigned char, Dimension > ImageMaskType; + typedef itk::Image< unsigned char, InputImageType::ImageDimension > ImageMaskType; typedef itk::ImageFileReader< ImageMaskType > MaskReaderType; typename MaskReaderType::Pointer maskReader = MaskReaderType::New(); maskReader->SetFileName(m_ArgsInfo.referenceMask_arg); try { maskReader->Update(); - } catch( itk::ExceptionObject & err ) { + } catch ( itk::ExceptionObject & err ) { std::cerr << "ExceptionObject caught while reading mask !" << std::endl; std::cerr << err << std::endl; return; @@ -304,17 +317,17 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() fixedMask->SetImage( maskReader->GetOutput() ); } - typedef itk::ImageMaskSpatialObject< Dimension > MaskType; + typedef itk::ImageMaskSpatialObject< InputImageType::ImageDimension > MaskType; typename MaskType::Pointer movingMask=NULL; if (m_ArgsInfo.targetMask_given) { movingMask= MaskType::New(); - typedef itk::Image< unsigned char, Dimension > ImageMaskType; + typedef itk::Image< unsigned char, InputImageType::ImageDimension > ImageMaskType; typedef itk::ImageFileReader< ImageMaskType > MaskReaderType; typename MaskReaderType::Pointer maskReader = MaskReaderType::New(); maskReader->SetFileName(m_ArgsInfo.targetMask_arg); try { maskReader->Update(); - } catch( itk::ExceptionObject & err ) { + } catch ( itk::ExceptionObject & err ) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; } @@ -380,8 +393,8 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() fixedCalculator->SetImage(fixedThresh); fixedCalculator->Compute(); - Vector fixedCenter=fixedCalculator->GetCenterOfGravity(); - if(m_Verbose)std::cout<<"The fixed center of gravity is "< fixedCenter=fixedCalculator->GetCenterOfGravity(); + if (m_Verbose)std::cout<<"The fixed center of gravity is "< CalculatorType; typename CalculatorType::Pointer movingCalculator= CalculatorType::New(); @@ -398,24 +411,24 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() movingCalculator->SetImage(movingThresh); movingCalculator->Compute(); - Vector movingCenter=movingCalculator->GetCenterOfGravity(); - if(m_Verbose)std::cout<<"The moving center of gravity is "< movingCenter=movingCalculator->GetCenterOfGravity(); + if (m_Verbose)std::cout<<"The moving center of gravity is "< shift= movingCenter-fixedCenter; - if(m_Verbose)std::cout<<"The initial shift applied is "< shift= movingCenter-fixedCenter; + if (m_Verbose)std::cout<<"The initial shift applied is "< GenericAffineTransformType; + typedef clitk::GenericAffineTransform GenericAffineTransformType; typename GenericAffineTransformType::Pointer genericAffineTransform = GenericAffineTransformType::New(); genericAffineTransform->SetArgsInfo(m_ArgsInfo); - typedef itk::Transform< double, Dimension, Dimension > TransformType; + typedef itk::Transform< double, InputImageType::ImageDimension, InputImageType::ImageDimension > TransformType; typename TransformType::Pointer transform = genericAffineTransform->GetTransform(); @@ -434,7 +447,7 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() //============================================================================ typedef clitk::GenericOptimizer GenericOptimizerType; unsigned int nParam = transform->GetNumberOfParameters(); - GenericOptimizerType::Pointer genericOptimizer=GenericOptimizerType::New(); + typename GenericOptimizerType::Pointer genericOptimizer=GenericOptimizerType::New(); genericOptimizer->SetArgsInfo(m_ArgsInfo); genericOptimizer->SetOutputIteration(m_Verbose); genericOptimizer->SetOutputPosition(m_Verbose); @@ -447,12 +460,11 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() // Scales itk::Optimizer::ScalesType scales( nParam ); - for (unsigned int i=nParam-Dimension; iSetScales(scales); - //============================================================================ // Multiresolution registration //============================================================================ @@ -499,7 +511,7 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() try { registration->StartRegistration(); - } catch( itk::ExceptionObject & err ) { + } catch ( itk::ExceptionObject & err ) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; } @@ -511,30 +523,30 @@ AffineRegistrationGenericFilter::UpdateWithDimAndPixelType() OptimizerType::ParametersType finalParameters = registration->GetLastTransformParameters(); std::cout<< "Result : " <