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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkFFTWRealToComplexConjugateImageFilter.txx,v $
Language: C++
Date: $Date: 2006-12-31 14:07:10 $
Version: $Revision: 1.11 $
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 __itkFFTWRealToComplexConjugateImageFilter_txx
#define __itkFFTWRealToComplexConjugateImageFilter_txx
#include "itkFFTWRealToComplexConjugateImageFilter.h"
#include "itkFFTRealToComplexConjugateImageFilter.txx"
#include <iostream>
#include "itkIndent.h"
#include "itkMetaDataObject.h"
namespace itk
{
/** TODO: There should be compile time type checks so that
if only USE_FFTWF is defined, then only floats are valid.
and if USE_FFTWD is defined, then only doubles are valid.
*/
template <typename TPixel, unsigned int Dimension>
void
FFTWRealToComplexConjugateImageFilter<TPixel,Dimension>::
GenerateData()
{
// get pointers to the input and output
typename TInputImageType::ConstPointer inputPtr = this->GetInput();
typename TOutputImageType::Pointer outputPtr = this->GetOutput();
if ( !inputPtr || !outputPtr )
{
return;
}
// allocate output buffer memory
outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
outputPtr->Allocate();
const typename TInputImageType::SizeType& inputSize
= inputPtr->GetLargestPossibleRegion().GetSize();
const typename TOutputImageType::SizeType& outputSize
= outputPtr->GetLargestPossibleRegion().GetSize();
// figure out sizes
// size of input and output aren't the same which is handled in the superclass,
// sort of.
// the input size and output size only differ in the fastest moving dimension
unsigned int total_inputSize = 1;
unsigned int total_outputSize = 1;
for(unsigned i = 0; i < Dimension; i++)
{
total_inputSize *= inputSize[i];
total_outputSize *= outputSize[i];
}
if(this->m_PlanComputed) // if we've already computed a plan
{
// if the image sizes aren't the same,
// we have to compute the plan again
if(this->m_LastImageSize != total_inputSize)
{
delete [] this->m_InputBuffer;
delete [] this->m_OutputBuffer;
FFTWProxyType::DestroyPlan(this->m_Plan);
this->m_PlanComputed = false;
}
}
if(!this->m_PlanComputed)
{
this->m_InputBuffer = new TPixel[total_inputSize];
this->m_OutputBuffer =
new typename FFTWProxyType::ComplexType[total_outputSize];
this->m_LastImageSize = total_inputSize;
switch(Dimension)
{
case 1:
this->m_Plan = FFTWProxyType::Plan_dft_r2c_1d(inputSize[0],
this->m_InputBuffer,
this->m_OutputBuffer,
FFTW_ESTIMATE);
break;
case 2:
this->m_Plan = FFTWProxyType::Plan_dft_r2c_2d(inputSize[1],
inputSize[0],
this->m_InputBuffer,
this->m_OutputBuffer,
FFTW_ESTIMATE);
break;
case 3:
this->m_Plan = FFTWProxyType::Plan_dft_r2c_3d(inputSize[2],
inputSize[1],
inputSize[0],
this->m_InputBuffer,
this->m_OutputBuffer,
FFTW_ESTIMATE);
break;
default:
int *sizes = new int[Dimension];
for(unsigned int i = 0; i < Dimension; i++)
{
sizes[(Dimension - 1) - i] = inputSize[i];
}
this->m_Plan = FFTWProxyType::Plan_dft_r2c(Dimension,sizes,
this->m_InputBuffer,
this->m_OutputBuffer,
FFTW_ESTIMATE);
delete [] sizes;
}
this->m_PlanComputed = true;
}
memcpy(this->m_InputBuffer,
inputPtr->GetBufferPointer(),
total_inputSize * sizeof(TPixel));
FFTWProxyType::Execute(this->m_Plan);
memcpy(outputPtr->GetBufferPointer(),
this->m_OutputBuffer,
total_outputSize * sizeof(typename FFTWProxyType::ComplexType));
}
template <typename TPixel,unsigned int Dimension>
bool
FFTWRealToComplexConjugateImageFilter<TPixel,Dimension>::
FullMatrix()
{
return false;
}
} // namespace itk
#endif //_itkFFTWRealToComplexConjugateImageFilter_txx
|