diff --git a/Code/Common/otbExtractROIBase.h b/Code/Common/otbExtractROIBase.h index a4f5a775d7c08d5455a0ae961126332e0807d18b..0e4067e64332134a951c90f3d1b3082bfdbca929 100755 --- a/Code/Common/otbExtractROIBase.h +++ b/Code/Common/otbExtractROIBase.h @@ -105,6 +105,10 @@ protected: ~ExtractROIBase() {}; void PrintSelf(std::ostream& os, itk::Indent indent) const; + + virtual void GenerateInputRequestedRegion(); + + /** ExtractROIBase can produce an image which is a different * resolution than its input image. As such, ExtractROIBase * needs to provide an implementation for diff --git a/Code/Common/otbExtractROIBase.txx b/Code/Common/otbExtractROIBase.txx index 3a59bf08ff28ffa707cd8f2a6773a4e87a5c9811..8e0ffe690b6ae3a36107d7e61d6210d544d989a6 100755 --- a/Code/Common/otbExtractROIBase.txx +++ b/Code/Common/otbExtractROIBase.txx @@ -64,8 +64,18 @@ ExtractROIBase<TInputImage,TOutputImage> ::CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion, const OutputImageRegionType &srcRegion) { - ExtractROIBaseRegionCopierType extractImageRegionCopier; - extractImageRegionCopier(destRegion, srcRegion, m_ExtractionRegion); + // ExtractROIBaseRegionCopierType extractImageRegionCopier; +// extractImageRegionCopier(destRegion, srcRegion, m_ExtractionRegion); + + destRegion = srcRegion; + + OutputImageIndexType index = destRegion.GetIndex(); + + for (unsigned int i = 0; i < InputImageDimension; ++i) + { + index[i]+=m_ExtractionRegion.GetIndex()[i]; + } + destRegion.SetIndex(index); } @@ -90,7 +100,7 @@ ExtractROIBase<TInputImage,TOutputImage> if (inputSize[i]) { outputSize[nonzeroSizeCount] = inputSize[i]; - outputIndex[nonzeroSizeCount] = extractRegion.GetIndex()[i]; + outputIndex[nonzeroSizeCount] =0; nonzeroSizeCount++; } } @@ -105,6 +115,32 @@ ExtractROIBase<TInputImage,TOutputImage> this->Modified(); } +template <class TInputImage, class TOutputImage> +void +ExtractROIBase<TInputImage,TOutputImage> +::GenerateInputRequestedRegion() +{ + Superclass::GenerateInputRequestedRegion(); + + typename Superclass::InputImagePointer inputPtr = const_cast<InputImageType*>(this->GetInput()); + typename Superclass::OutputImagePointer outputPtr = this->GetOutput(); + + if ( !outputPtr || !inputPtr) + { + return; + } + InputImageRegionType requestedRegion = outputPtr->GetRequestedRegion(); + InputImageIndexType index = requestedRegion.GetIndex(); + InputImageIndexType offset = m_ExtractionRegion.GetIndex(); + + for (unsigned int i=0; i < InputImageDimension; ++i) + { + index[i]+=offset[i]; + } + requestedRegion.SetIndex(index); + inputPtr->SetRequestedRegion(requestedRegion); +} + /** @@ -166,7 +202,7 @@ ExtractROIBase<TInputImage,TOutputImage> } // Set the output image size to the same value as the extraction region. - outputPtr->SetLargestPossibleRegion( m_OutputImageRegion ); + outputPtr->SetRegions( m_OutputImageRegion ); // Set the output spacing and origin const itk::ImageBase<InputImageDimension> *phyData; diff --git a/Code/Common/otbMultiChannelExtractROI.txx b/Code/Common/otbMultiChannelExtractROI.txx index c7d43a07361b55b2d43f4da856b455eccd22c2d8..44ee07e47a4fd2fc75767e363b2e257ab5f5c545 100755 --- a/Code/Common/otbMultiChannelExtractROI.txx +++ b/Code/Common/otbMultiChannelExtractROI.txx @@ -96,6 +96,8 @@ void MultiChannelExtractROI<TInputPixelType,TOutputPixelType> ::GenerateOutputInformation() { + // Call to the superclass implementation + Superclass::GenerateOutputInformation(); // Analyse of channels to process ChannelsType Channels; if( m_Channels.empty() == false ) @@ -177,12 +179,7 @@ MultiChannelExtractROI<TInputPixelType,TOutputPixelType> itkExceptionMacro(<< oss.str().c_str()); } } - outputPtr->SetNumberOfComponentsPerPixel( outputPtr->GetVectorLength() ); - - // Call to the superclass implementation - Superclass::GenerateOutputInformation(); - } @@ -212,6 +209,9 @@ MultiChannelExtractROI<TInputPixelType,TOutputPixelType> OutputIterator outIt(outputPtr, outputRegionForThread); InputIterator inIt(inputPtr, inputRegionForThread); + outIt.GoToBegin(); + inIt.GoToBegin(); + // if default behaviour if ( m_ChannelsWorksBool == false ) { @@ -245,7 +245,7 @@ MultiChannelExtractROI<TInputPixelType,TOutputPixelType> pixelOutput[channelOut] = static_cast<OutputValueType>(pixelInput[channelIn]); channelOut++; } - outIt.Set( pixelOutput ); + outIt.Set( pixelOutput ); ++outIt; ++inIt; progress.CompletedPixel();