1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkFFTRealToComplexConjugateImageFilter.txx,v $
Language: C++
Date: $Date: 2006-12-30 17:56:24 $
Version: $Revision: 1.5 $
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkFFTRealToComplexConjugateImageFilter_txx
#define __itkFFTRealToComplexConjugateImageFilter_txx
#include "itkFFTRealToComplexConjugateImageFilter.h"
#include "itkMetaDataObject.h"
#include "itkVnlFFTRealToComplexConjugateImageFilter.h"
#if defined(USE_FFTWD) || defined(USE_FFTWF)
#include "itkFFTWRealToComplexConjugateImageFilter.h"
#endif
namespace itk
{
template < class TPixel , unsigned int Dimension >
typename FFTRealToComplexConjugateImageFilter < TPixel , Dimension >::Pointer
FFTRealToComplexConjugateImageFilter < TPixel , Dimension >
::New(void)
{
Pointer smartPtr = ::itk::ObjectFactory<Self>::Create();
#ifdef USE_FFTWD
if(smartPtr.IsNull())
{
if (typeid(TPixel) == typeid(double))
{
smartPtr = dynamic_cast<Self *>(
FFTWRealToComplexConjugateImageFilter< double, Dimension >
::New().GetPointer() );
}
}
#endif
#ifdef USE_FFTWF
if(smartPtr.IsNull())
{
if (typeid(TPixel) == typeid(float))
{
smartPtr = dynamic_cast<Self *>(
FFTWRealToComplexConjugateImageFilter< float, Dimension >
::New().GetPointer());
}
}
#endif
if(smartPtr.IsNull())
{
smartPtr = VnlFFTRealToComplexConjugateImageFilter< TPixel, Dimension >
::New().GetPointer();
}
return smartPtr;
}
template < class TPixel , unsigned int Dimension >
void
FFTRealToComplexConjugateImageFilter < TPixel , Dimension >
::GenerateOutputInformation()
{
// call the superclass' implementation of this method
Superclass::GenerateOutputInformation();
//
// If this implementation returns a full result
// instead of a 'half-complex' matrix, then none of this
// is necessary
if(this->FullMatrix())
return;
// get pointers to the input and output
typename TInputImageType::ConstPointer inputPtr = this->GetInput();
typename TOutputImageType::Pointer outputPtr = this->GetOutput();
if ( !inputPtr || !outputPtr )
{
return;
}
//
// This is all based on the same function in itk::ShrinkImageFilter
// ShrinkImageFilter also modifies the image spacing, but spacing
// has no meaning in the result of an FFT.
unsigned int i;
const typename TInputImageType::SizeType& inputSize
= inputPtr->GetLargestPossibleRegion().GetSize();
const typename TInputImageType::IndexType& inputStartIndex
= inputPtr->GetLargestPossibleRegion().GetIndex();
typename TOutputImageType::SizeType outputSize;
typename TOutputImageType::IndexType outputStartIndex;
//
// in 4.3.4 of the FFTW documentation, they indicate the size of
// of a real-to-complex FFT is N * N ... + (N /2+1)
// 1 2 d
// complex numbers.
// static_cast prob. not necessary but want to make sure integer
// division is used.
outputSize[0] = static_cast<unsigned int>(inputSize[0])/2 + 1;
outputStartIndex[0] = inputStartIndex[0];
for (i = 1; i < TOutputImageType::ImageDimension; i++)
{
outputSize[i] = inputSize[i];
outputStartIndex[i] = inputStartIndex[i];
}
//
// the halving of the input size hides the actual size of the input.
// to get the same size image out of the IFFT, need to send it as
// Metadata.
typedef typename TOutputImageType::SizeType::SizeValueType SizeScalarType;
itk::MetaDataDictionary &OutputDic=outputPtr->GetMetaDataDictionary();
itk::EncapsulateMetaData<SizeScalarType>(OutputDic,
std::string("FFT_Actual_RealImage_Size"),
inputSize[0]);
typename TOutputImageType::RegionType outputLargestPossibleRegion;
outputLargestPossibleRegion.SetSize( outputSize );
outputLargestPossibleRegion.SetIndex( outputStartIndex );
outputPtr->SetLargestPossibleRegion( outputLargestPossibleRegion );
}
template < class TPixel , unsigned int Dimension >
void
FFTRealToComplexConjugateImageFilter < TPixel , Dimension >
::GenerateInputRequestedRegion()
{
// call the superclass' implementation of this method
Superclass::GenerateInputRequestedRegion();
// get pointers to the inputs
typename TInputImageType::Pointer input =
const_cast<TInputImageType *> (this->GetInput());
if ( !input )
{
return;
}
input->SetRequestedRegionToLargestPossibleRegion();
}
template < class TPixel , unsigned int Dimension >
void
FFTRealToComplexConjugateImageFilter < TPixel , Dimension >
::EnlargeOutputRequestedRegion(DataObject *output)
{
Superclass::EnlargeOutputRequestedRegion(output);
output->SetRequestedRegionToLargestPossibleRegion();
}
}
#endif
|