diff --git a/Code/DisparityMap/otbNCCRegistrationFilter.h b/Code/DisparityMap/otbNCCRegistrationFilter.h index 1dacb291ff02ba6cdfed827067675496a47311b2..aa871c227125ce0a859420fd33785e9bc81e99ca 100644 --- a/Code/DisparityMap/otbNCCRegistrationFilter.h +++ b/Code/DisparityMap/otbNCCRegistrationFilter.h @@ -127,70 +127,9 @@ protected: /** Apply update. */ virtual void ApplyUpdate(TimeStepType dt); - virtual void 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->GetNCCRadius() ); - - // 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; - } - } + + /** Update the Input requested region. */ + virtual void GenerateInputRequestedRegion(); private: diff --git a/Code/DisparityMap/otbNCCRegistrationFilter.txx b/Code/DisparityMap/otbNCCRegistrationFilter.txx index 14436f59ca0dae3b578d7eb4ec992f7086eabf1a..b3b3f21efd1b3bd4f69859db0fa5739bbc7718f2 100644 --- a/Code/DisparityMap/otbNCCRegistrationFilter.txx +++ b/Code/DisparityMap/otbNCCRegistrationFilter.txx @@ -156,6 +156,74 @@ NCCRegistrationFilter<TFixedImage,TMovingImage,TDeformationField> } +template <class TFixedImage, class TMovingImage, class TDeformationField> +void +NCCRegistrationFilter<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->GetNCCRadius() ); + + // 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; + } +} + /* * Get the metric value from the difference function */