From 25f2ec51914dc5a55443c223bc52ca8c234fe100 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Wed, 19 May 2010 06:06:59 +0000 Subject: [PATCH] - add "SetRegions" before GenerateData --- filters/clitkResampleImageGenericFilter.txx | 26 +++---- itk/clitkResampleImageWithOptionsFilter.h | 1 + itk/clitkResampleImageWithOptionsFilter.txx | 79 ++++++++++----------- 3 files changed, 49 insertions(+), 57 deletions(-) diff --git a/filters/clitkResampleImageGenericFilter.txx b/filters/clitkResampleImageGenericFilter.txx index 5cee0d9..b19f5c9 100644 --- a/filters/clitkResampleImageGenericFilter.txx +++ b/filters/clitkResampleImageGenericFilter.txx @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ + ======================================================================-====*/ #ifndef CLITKRESAMPLEIMAGEGENERICFILTER_TXX #define CLITKRESAMPLEIMAGEGENERICFILTER_TXX @@ -22,15 +22,12 @@ // clitk #include "clitkResampleImageWithOptionsFilter.h" -namespace clitk -{ - //-------------------------------------------------------------------- template -ResampleImageGenericFilter::ResampleImageGenericFilter(): - ImageToImageGenericFilter("Resample") +clitk::ResampleImageGenericFilter::ResampleImageGenericFilter(): + ImageToImageGenericFilter("Resample") { - InitializeImageType<2>(); + // InitializeImageType<2>(); InitializeImageType<3>(); InitializeImageType<4>(); } @@ -40,17 +37,17 @@ ResampleImageGenericFilter::ResampleImageGenericFilter(): //-------------------------------------------------------------------- template template -void ResampleImageGenericFilter::InitializeImageType() -{ - ADD_DEFAULT_IMAGE_TYPES(Dim); - //ADD_IMAGE_TYPE(Dim, short); +void clitk::ResampleImageGenericFilter::InitializeImageType() +{ + //ADD_DEFAULT_IMAGE_TYPES(Dim); + ADD_IMAGE_TYPE(Dim, short); } //-------------------------------------------------------------------- - + //-------------------------------------------------------------------- template -void ResampleImageGenericFilter::SetArgsInfo(const args_info_type & a) +void clitk::ResampleImageGenericFilter::SetArgsInfo(const args_info_type & a) { mArgsInfo=a; if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); @@ -71,7 +68,7 @@ void ResampleImageGenericFilter::SetArgsInfo(const args_info_typ template template void -ResampleImageGenericFilter::UpdateWithInputImageType() +clitk::ResampleImageGenericFilter::UpdateWithInputImageType() { // Reading input @@ -172,7 +169,6 @@ ResampleImageGenericFilter::UpdateWithInputImageType() } //-------------------------------------------------------------------- -} #endif /* end #define CLITKRESAMPLEIMAGEGENERICFILTER_TXX */ diff --git a/itk/clitkResampleImageWithOptionsFilter.h b/itk/clitkResampleImageWithOptionsFilter.h index 9a8f5e2..d997a3d 100644 --- a/itk/clitkResampleImageWithOptionsFilter.h +++ b/itk/clitkResampleImageWithOptionsFilter.h @@ -131,6 +131,7 @@ namespace clitk { GaussianSigmaType m_GaussianSigma; OutputImagePixelType m_DefaultPixelValue; bool m_VerboseOptions; + OutputImageRegionType m_OutputRegion; virtual void GenerateInputRequestedRegion(); virtual void GenerateOutputInformation(); diff --git a/itk/clitkResampleImageWithOptionsFilter.txx b/itk/clitkResampleImageWithOptionsFilter.txx index dd5a821..993b7ec 100644 --- a/itk/clitkResampleImageWithOptionsFilter.txx +++ b/itk/clitkResampleImageWithOptionsFilter.txx @@ -33,13 +33,10 @@ #include "itkBSplineInterpolateImageFunctionWithLUT.h" #include "itkCommand.h" -namespace clitk -{ - //-------------------------------------------------------------------- template -ResampleImageWithOptionsFilter:: -ResampleImageWithOptionsFilter():itk::ImageToImageFilter() +clitk::ResampleImageWithOptionsFilter:: +ResampleImageWithOptionsFilter():itk::ImageToImageFilter() { static const unsigned int dim = InputImageType::ImageDimension; this->SetNumberOfRequiredInputs(1); @@ -64,8 +61,8 @@ ResampleImageWithOptionsFilter():itk::ImageToImageFilter void -ResampleImageWithOptionsFilter:: -SetInput(const InputImageType * image) +clitk::ResampleImageWithOptionsFilter:: +SetInput(const InputImageType * image) { // Process object is not const-correct so the const casting is required. this->SetNthInput(0, const_cast(image)); @@ -76,8 +73,8 @@ SetInput(const InputImageType * image) //-------------------------------------------------------------------- template void -ResampleImageWithOptionsFilter:: -GenerateInputRequestedRegion() +clitk::ResampleImageWithOptionsFilter:: +GenerateInputRequestedRegion() { // call the superclass's implementation of this method Superclass::GenerateInputRequestedRegion(); @@ -97,8 +94,8 @@ GenerateInputRequestedRegion() //-------------------------------------------------------------------- template void -ResampleImageWithOptionsFilter:: -GenerateOutputInformation() +clitk::ResampleImageWithOptionsFilter:: +GenerateOutputInformation() { static const unsigned int dim = InputImageType::ImageDimension; @@ -148,25 +145,27 @@ GenerateOutputInformation() m_OutputSize[l] = inputSize[l]; m_OutputSpacing[l] = inputSpacing[l]; } - + // Set Size/Spacing OutputImagePointer outputImage = this->GetOutput(0); - OutputImageRegionType region; - region.SetSize(m_OutputSize); - region.SetIndex(input->GetLargestPossibleRegion().GetIndex()); - DD(input->GetLargestPossibleRegion().GetIndex()); - outputImage->SetLargestPossibleRegion(region); + // OutputImageRegionType region; + m_OutputRegion.SetSize(m_OutputSize); + m_OutputRegion.SetIndex(input->GetLargestPossibleRegion().GetIndex()); + outputImage->CopyInformation(input); + outputImage->SetLargestPossibleRegion(m_OutputRegion); outputImage->SetSpacing(m_OutputSpacing); // Init Gaussian sigma if (m_GaussianSigma[0] != -1) { // Gaussian filter set by user m_GaussianFilteringEnabled = true; - } else { + } + else { if (m_GaussianFilteringEnabled) { // Automated sigma when downsample for(unsigned int i=0; i inputSpacing[i]) { // downsample m_GaussianSigma[i] = 0.5*m_OutputSpacing[i];// / inputSpacing[i]); - } else m_GaussianSigma[i] = 0; // will be ignore after + } + else m_GaussianSigma[i] = 0; // will be ignore after } } } @@ -179,22 +178,27 @@ GenerateOutputInformation() //-------------------------------------------------------------------- template -void -ResampleImageWithOptionsFilter:: -GenerateData() +void +clitk::ResampleImageWithOptionsFilter:: +GenerateData() { - + // Get input pointer InputImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); static const unsigned int dim = InputImageType::ImageDimension; + // Set regions and allocate + this->GetOutput()->SetRegions(m_OutputRegion); + this->GetOutput()->Allocate(); + // this->GetOutput()->FillBuffer(m_DefaultPixelValue); + // Create main Resample Image Filter typedef itk::ResampleImageFilter FilterType; typename FilterType::Pointer filter = FilterType::New(); filter->GraftOutput(this->GetOutput()); -// this->GetOutput()->Print(std::cout); -// this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetLargestPossibleRegion()); -// this->GetOutput()->Print(std::cout); + // this->GetOutput()->Print(std::cout); + // this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetLargestPossibleRegion()); + // this->GetOutput()->Print(std::cout); // Print options if needed if (m_VerboseOptions) { @@ -205,18 +209,10 @@ GenerateData() std::cout << "Sigma = " << m_GaussianSigma << std::endl; std::cout << "Interpol = "; switch (m_InterpolationType) { - case NearestNeighbor: - std::cout << "NearestNeighbor" << std::endl; - break; - case Linear: - std::cout << "Linear" << std::endl; - break; - case BSpline: - std::cout << "BSpline " << m_BSplineOrder << std::endl; - break; - case B_LUT: - std::cout << "B-LUT " << m_BSplineOrder << " " << m_BLUTSamplingFactor << std::endl; - break; + case NearestNeighbor: std::cout << "NearestNeighbor" << std::endl; break; + case Linear: std::cout << "Linear" << std::endl; break; + case BSpline: std::cout << "BSpline " << m_BSplineOrder << std::endl; break; + case B_LUT: std::cout << "B-LUT " << m_BSplineOrder << " " << m_BLUTSamplingFactor << std::endl; break; } std::cout << "Threads = " << this->GetNumberOfThreads() << std::endl; std::cout << "LastDimIsTime = " << m_LastDimensionIsTime << std::endl; @@ -229,7 +225,8 @@ GenerateData() filter->SetOutputSpacing(m_OutputSpacing); filter->SetOutputOrigin(input->GetOrigin()); filter->SetDefaultPixelValue(m_DefaultPixelValue); - filter->SetNumberOfThreads(this->GetNumberOfThreads()); + filter->SetNumberOfThreads(this->GetNumberOfThreads()); + filter->SetOutputDirection(input->GetDirection()); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example) // Select interpolator switch (m_InterpolationType) { @@ -263,6 +260,7 @@ GenerateData() } // Initial Gaussian blurring if needed + // TODO : replace by itk::DiscreteGaussianImageFilter for small sigma typedef itk::RecursiveGaussianImageFilter GaussianFilterType; std::vector gaussianFilters; if (m_GaussianFilteringEnabled) { @@ -294,6 +292,3 @@ GenerateData() // DD("after Graft"); } //-------------------------------------------------------------------- - -}//end clitk - -- 2.47.1