Skip to content
Snippets Groups Projects
Commit e56e5e77 authored by Guillaume Pasero's avatar Guillaume Pasero Committed by Julien Michel
Browse files

ENH: improve GenericRSResampleFilter architecture

parent 407cd39e
No related branches found
No related tags found
No related merge requests found
......@@ -171,6 +171,9 @@ public:
m_DisplacementFilter->SetNumberOfThreads(nbThread);
}
/** Override itk::ProcessObject method to let the internal filter do the propagation */
virtual void PropagateRequestedRegion(itk::DataObject *output);
protected:
StreamingResampleImageFilter();
......@@ -181,8 +184,6 @@ protected:
virtual void GenerateOutputInformation();
virtual void GenerateInputRequestedRegion();
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
......
......@@ -50,7 +50,7 @@ StreamingResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionTy
progress->RegisterInternalFilter(m_WarpFilter, 1.f);
m_WarpFilter->GraftOutput(this->GetOutput());
m_WarpFilter->Update();
m_WarpFilter->UpdateOutputData(m_WarpFilter->GetOutput());
this->GraftOutput(m_WarpFilter->GetOutput());
}
......@@ -62,41 +62,14 @@ void
StreamingResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>
::GenerateOutputInformation()
{
// call the superclass's implementation of this method
Superclass::GenerateOutputInformation();
typename OutputImageType::Pointer outputPtr = this->GetOutput();
outputPtr->SetSpacing( this->GetOutputSpacing() );
outputPtr->SetOrigin( this->GetOutputOrigin() );
typename OutputImageType::RegionType region;
region.SetSize( this->GetOutputSize() );
region.SetIndex(this->GetOutputStartIndex() );
outputPtr->SetLargestPossibleRegion(region);
// check the output spacing of the displacement field
if(this->GetDisplacementFieldSpacing()== itk::NumericTraits<SpacingType>::ZeroValue())
{
this->SetDisplacementFieldSpacing(2.*this->GetOutputSpacing());
}
}
template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
void
StreamingResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>
::GenerateInputRequestedRegion()
{
// Retrieve output pointer
OutputImageType * outputPtr = this->GetOutput();
// Retrieve input pointer
const InputImageType * inputPtr = this->GetInput();
// Retrieve output requested region
RegionType requestedRegion = outputPtr->GetRequestedRegion();
SizeType largestSize = outputPtr->GetLargestPossibleRegion().GetSize();
// Retrieve output largest region
SizeType largestSize = this->GetOutputSize();
// Set up displacement field filter
SizeType displacementFieldLargestSize;
......@@ -117,10 +90,20 @@ StreamingResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionTy
m_DisplacementFilter->SetOutputSize(displacementFieldLargestSize);
m_DisplacementFilter->SetOutputIndex(this->GetOutputStartIndex());
// Generate input requested region
m_WarpFilter->SetInput(inputPtr);
m_WarpFilter->GetOutput()->UpdateOutputInformation();
m_WarpFilter->GetOutput()->SetRequestedRegion(requestedRegion);
m_WarpFilter->SetInput(this->GetInput());
m_WarpFilter->GraftOutput(this->GetOutput());
m_WarpFilter->UpdateOutputInformation();
this->GraftOutput(m_WarpFilter->GetOutput());
}
template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
void
StreamingResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>
::PropagateRequestedRegion(itk::DataObject *output)
{
if (this->m_Updating) return;
m_WarpFilter->GetOutput()->SetRequestedRegion(output);
m_WarpFilter->GetOutput()->PropagateRequestedRegion();
}
......
......@@ -264,6 +264,9 @@ public:
m_Resampler->SetDisplacementFilterNumberOfThreads(nbThread);
}
/** Override itk::ProcessObject method to let the internal filter do the propagation */
virtual void PropagateRequestedRegion(itk::DataObject *output);
protected:
GenericRSResampleImageFilter();
/** Destructor */
......@@ -273,8 +276,6 @@ protected:
virtual void GenerateOutputInformation();
virtual void GenerateInputRequestedRegion();
virtual void UpdateTransform();
void PrintSelf(std::ostream& os, itk::Indent indent) const;
......
......@@ -67,7 +67,7 @@ GenericRSResampleImageFilter<TInputImage, TOutputImage>
progress->RegisterInternalFilter(m_Resampler, 1.f);
m_Resampler->GraftOutput(this->GetOutput());
m_Resampler->Update();
m_Resampler->UpdateOutputData(m_Resampler->GetOutput());
this->GraftOutput(m_Resampler->GetOutput());
}
......@@ -82,20 +82,8 @@ void
GenericRSResampleImageFilter<TInputImage, TOutputImage>
::GenerateOutputInformation()
{
// call the superclass's implementation of this method
Superclass::GenerateOutputInformation();
typename OutputImageType::Pointer outputPtr = this->GetOutput();
outputPtr->SetSpacing( this->GetOutputSpacing() );
outputPtr->SetOrigin( this->GetOutputOrigin() );
typename OutputImageType::RegionType region;
region.SetSize(this->GetOutputSize());
region.SetIndex(this->GetOutputStartIndex() );
outputPtr->SetLargestPossibleRegion(region);
// Get the Output MetaData Dictionary
itk::MetaDataDictionary& dict = outputPtr->GetMetaDataDictionary();
......@@ -112,6 +100,13 @@ GenericRSResampleImageFilter<TInputImage, TOutputImage>
// Estimate the output rpc Model if needed
if (m_EstimateOutputRpcModel)
this->EstimateOutputRpcModel();
m_Resampler->SetInput(this->GetInput());
m_Resampler->SetTransform(m_Transform);
m_Resampler->SetDisplacementFieldSpacing(this->GetDisplacementFieldSpacing());
m_Resampler->GraftOutput(this->GetOutput());
m_Resampler->UpdateOutputInformation();
this->GraftOutput(m_Resampler->GetOutput());
}
/**
......@@ -128,7 +123,11 @@ GenericRSResampleImageFilter<TInputImage, TOutputImage>
// Temp image : not allocated but with the same metadata than the
// output
typename OutputImageType::Pointer tempPtr = OutputImageType::New();
tempPtr->SetRegions(this->GetOutput()->GetLargestPossibleRegion());
typename OutputImageType::RegionType region;
region.SetSize(this->GetOutputSize());
region.SetIndex(this->GetOutputStartIndex() );
tempPtr->SetRegions(region);
// Encapsulate the output metadata in the temp image
itk::MetaDataDictionary& tempDict = tempPtr->GetMetaDataDictionary();
......@@ -171,41 +170,26 @@ GenericRSResampleImageFilter<TInputImage, TOutputImage>
m_Transform->InstanciateTransform();
}
/**
* Generate Input requested region does only propagate the output
* requested region.
*/
template <class TInputImage, class TOutputImage>
void
GenericRSResampleImageFilter<TInputImage, TOutputImage>
::GenerateInputRequestedRegion()
{
// Retrieve output pointer
OutputImageType * outputPtr = this->GetOutput();
// Retrieve input pointer
const InputImageType * inputPtr = this->GetInput();
// Retrieve output requested region
RegionType requestedRegion = outputPtr->GetRequestedRegion();
// Estimate the input rpc model if it is needed
if (m_EstimateInputRpcModel && !m_RpcEstimationUpdated)
{
this->EstimateInputRpcModel();
}
// Instanciate the RS transform
this->UpdateTransform();
// Generate input requested region
m_Resampler->SetInput(inputPtr);
m_Resampler->SetTransform(m_Transform);
m_Resampler->SetDisplacementFieldSpacing(this->GetDisplacementFieldSpacing());
m_Resampler->GetOutput()->UpdateOutputInformation();
m_Resampler->GetOutput()->SetRequestedRegion(requestedRegion);
m_Resampler->GetOutput()->PropagateRequestedRegion();
}
template <class TInputImage, class TOutputImage>
void
GenericRSResampleImageFilter<TInputImage, TOutputImage>
::PropagateRequestedRegion(itk::DataObject *output)
{
if (this->m_Updating) return;
// Estimate the input rpc model if it is needed
if (m_EstimateInputRpcModel && !m_RpcEstimationUpdated)
{
this->EstimateInputRpcModel();
}
// Instanciate the RS transform
this->UpdateTransform();
// Retrieve output requested region
m_Resampler->GetOutput()->SetRequestedRegion(output);
m_Resampler->GetOutput()->PropagateRequestedRegion();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment