From 4d9c387d8ceefcc3d199f3de0d997eb4a7c03002 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@c-s.fr> Date: Tue, 2 Dec 2008 11:53:07 +0100 Subject: [PATCH] ENH: Adding GenerateInputRequestedRegion() to MIRegistrationFilter --- Code/DisparityMap/otbMIRegistrationFilter.h | 3 + Code/DisparityMap/otbMIRegistrationFilter.txx | 70 ++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Code/DisparityMap/otbMIRegistrationFilter.h b/Code/DisparityMap/otbMIRegistrationFilter.h index cdae1331e8..3c05a37b50 100644 --- a/Code/DisparityMap/otbMIRegistrationFilter.h +++ b/Code/DisparityMap/otbMIRegistrationFilter.h @@ -127,6 +127,9 @@ protected: /** Apply update. */ virtual void ApplyUpdate(TimeStepType dt); + /** Update the Input requested region. */ + virtual void GenerateInputRequestedRegion(); + private: MIRegistrationFilter(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented diff --git a/Code/DisparityMap/otbMIRegistrationFilter.txx b/Code/DisparityMap/otbMIRegistrationFilter.txx index c7459469bf..7b031702e9 100644 --- a/Code/DisparityMap/otbMIRegistrationFilter.txx +++ b/Code/DisparityMap/otbMIRegistrationFilter.txx @@ -15,9 +15,9 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ - #ifndef __otbMIRegistrationFilter_txx #define __otbMIRegistrationFilter_txx + #include "otbMIRegistrationFilter.h" namespace otb { @@ -187,7 +187,73 @@ MIRegistrationFilter<TFixedImage,TMovingImage,TDeformationField> } - +template <class TFixedImage, class TMovingImage, class TDeformationField> +void +MIRegistrationFilter<TFixedImage,TMovingImage,TDeformationField> +::GenerateInputRequestedRegion() +{ + // get pointers to the input and output + typename Superclass::FixedImagePointer fixedPtr = + const_cast< TFixedImage * >( this->GetFixedImage() ); + typename Superclass::MovingImagePointer movingPtr = + const_cast< TMovingImage * >( this->GetMovingImage() ); + typename TDeformationField::Pointer outputPtr = this->GetOutput(); + + if ( !fixedPtr || !movingPtr || !outputPtr ) + { + return; + } + + // get a copy of the input requested region (should equal the output + // requested region) + typename TDeformationField::RegionType requestedRegion; + requestedRegion = outputPtr->GetRequestedRegion(); + + // pad the input requested region by the operator radius + requestedRegion.PadByRadius( this->GetMIRadius() ); + + // crop the input requested region at the input's largest possible region + if ( requestedRegion.Crop(fixedPtr->GetLargestPossibleRegion())) + { + if ( requestedRegion.Crop(movingPtr->GetLargestPossibleRegion())) + { + fixedPtr->SetRequestedRegion( requestedRegion ); + movingPtr->SetRequestedRegion( requestedRegion ); + return; + } + else + { + // Couldn't crop the region (requested region is outside the largest + // possible region). Throw an exception. + + // store what we tried to request (prior to trying to crop) + movingPtr->SetRequestedRegion( requestedRegion ); + + // build an exception + itk::InvalidRequestedRegionError e(__FILE__, __LINE__); + e.SetLocation(ITK_LOCATION); + e.SetDescription("Requested region is (at least partially) outside the largest possible region of the moving image."); + e.SetDataObject(movingPtr); + throw e; + + } + } + else + { + // Couldn't crop the region (requested region is outside the largest + // possible region). Throw an exception. + + // store what we tried to request (prior to trying to crop) + fixedPtr->SetRequestedRegion( requestedRegion ); + + // build an exception + itk::InvalidRequestedRegionError e(__FILE__, __LINE__); + e.SetLocation(ITK_LOCATION); + e.SetDescription("Requested region is (at least partially) outside the largest possible region of the fixed image."); + e.SetDataObject(fixedPtr); + throw e; + } +} } // end namespace otb -- GitLab