### Eclipse Workspace Patch 1.0 #P ITK_3_4_0 Index: Code/BasicFilters/itkRegionOfInterestImageFilter.txx =================================================================== RCS file: /cvsroot/Insight/Insight/Code/BasicFilters/itkRegionOfInterestImageFilter.txx,v retrieving revision 1.15 diff -u -r1.15 itkRegionOfInterestImageFilter.txx --- Code/BasicFilters/itkRegionOfInterestImageFilter.txx 1 Aug 2006 19:16:18 -0000 1.15 +++ Code/BasicFilters/itkRegionOfInterestImageFilter.txx 16 May 2008 15:16:45 -0000 @@ -3,7 +3,7 @@ Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkRegionOfInterestImageFilter.txx,v $ Language: C++ - Date: $Date: 2006-08-01 19:16:18 $ + Date: $Date: 2006/08/01 19:16:18 $ Version: $Revision: 1.15 $ Copyright (c) Insight Software Consortium. All rights reserved. @@ -63,12 +63,46 @@ // get pointer to the input typename Superclass::InputImagePointer inputPtr = const_cast< TInputImage * >( this->GetInput() ); + OutputImagePointer outputPtr = this->GetOutput(); - if( inputPtr ) + if ( !inputPtr || !outputPtr ) { - // request the region of interest - inputPtr->SetRequestedRegion( m_RegionOfInterest ); + return; + } + + // we need to compute the input requested region (size and start index) + unsigned int i; + const typename TInputImage::IndexType& RegionOfInterestStartIndex + = m_RegionOfInterest.GetIndex(); + const typename TInputImage::SizeType& RegionOfInterestSize + = m_RegionOfInterest.GetSize(); + + const typename TOutputImage::IndexType& RequestedRegionStartIndex + = outputPtr->GetRequestedRegion ().GetIndex(); + const typename TOutputImage::SizeType& RequestedRegionSize + = outputPtr->GetRequestedRegion ().GetSize(); + + typename TInputImage::IndexType inputRequestedRegionStartIndex; + typename TInputImage::SizeType inputRequestedRegionSize; + + for (i = 0; i < TInputImage::ImageDimension; i++) + { + // Take the min for the size + inputRequestedRegionSize[i] = (RegionOfInterestSize[i] < RequestedRegionSize[i]) ? + RegionOfInterestSize[i] : RequestedRegionSize[i]; + // Add the indexes for the start index because RequestedRegion is based on the output + inputRequestedRegionStartIndex[i] + = RegionOfInterestStartIndex[i] + RequestedRegionStartIndex[i]; + } + + typename TInputImage::RegionType inputRequestedRegion; + inputRequestedRegion.SetSize( inputRequestedRegionSize ); + inputRequestedRegion.SetIndex( inputRequestedRegionStartIndex ); + + inputRequestedRegion.Crop( inputPtr->GetLargestPossibleRegion() ); // is that really needed ? + + inputPtr->SetRequestedRegion( inputRequestedRegion ); } template @@ -79,8 +113,12 @@ // call the superclass' implementation of this method Superclass::EnlargeOutputRequestedRegion(output); - // generate everything in the region of interest - output->SetRequestedRegionToLargestPossibleRegion(); + // Why setting requested region to largest possible region?? + // Input requested region is calculated in GenerateInputRequestedRegion () + // according to output requested region. Setting the output to the + // largest possible region will set the input requested region to the + // input largest possible region and it is not what we want!? + // output->SetRequestedRegionToLargestPossibleRegion(); }