forked from InsightSoftwareConsortium/ITK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
itkFFTWRealToComplexConjugateImageFilter.txx
190 lines (169 loc) · 5.9 KB
/
itkFFTWRealToComplexConjugateImageFilter.txx
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkFFTWRealToComplexConjugateImageFilter.txx
Language: C++
Date: $Date$
Version: $Revision$
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
#if defined(USE_FFTWF) || defined(USE_FFTWD)
#include "itkFFTWRealToComplexConjugateImageFilter.h"
#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.
*/
#if defined(USE_FFTWF)
template <unsigned int Dimension>
void
FFTWRealToComplexConjugateImageFilter<float,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;
}
const typename TInputImageType::SizeType& inputSize
= inputPtr->GetLargestPossibleRegion().GetSize();
unsigned int num_dims = inputPtr->GetImageDimension();
if(num_dims != outputPtr->GetImageDimension())
return;
// allocate output buffer memory
outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
outputPtr->Allocate();
std::complex<TPixel> *out = outputPtr->GetBufferPointer();
{
float *in =
const_cast<float *>(reinterpret_cast<const float *>(inputPtr->GetBufferPointer()));
fftwf_complex *dptr = reinterpret_cast<float (*)[2]>(out);
switch(num_dims)
{
case 1:
M_plan = fftwf_plan_dft_r2c_1d(inputSize[0],
in,dptr,
FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
break;
case 2:
M_plan = fftwf_plan_dft_r2c_2d(inputSize[1],inputSize[0],
in,dptr,
FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
break;
case 3:
M_plan = fftwf_plan_dft_r2c_3d(inputSize[2],inputSize[1],inputSize[0],
in,dptr,
FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
break;
default:
int *sizes = new int[num_dims];
for(unsigned int i = 0; i < num_dims; i++)
{
sizes[(num_dims - 1) - i] = inputSize[i];
}
M_plan = fftwf_plan_dft_r2c(num_dims,sizes,
in,dptr,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
delete []sizes;
}
M_PlanComputed = true;
fftwf_execute(M_plan);
}
}
template <unsigned int Dimension>
bool
FFTWRealToComplexConjugateImageFilter<float,Dimension>::
FullMatrix()
{
return false;
}
template <unsigned int Dimension>
void
FFTWRealToComplexConjugateImageFilter<float,Dimension>::
PrintSelf(std::ostream& os,Indent indent) const
{
}
#endif //defined(USE_FFTWF)
#if defined(USE_FFTWD)
template <unsigned int Dimension>
void
FFTWRealToComplexConjugateImageFilter<double,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;
}
const typename TInputImageType::SizeType& inputSize
= inputPtr->GetLargestPossibleRegion().GetSize();
unsigned int num_dims = inputPtr->GetImageDimension();
if(num_dims != outputPtr->GetImageDimension())
return;
// allocate output buffer memory
outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
outputPtr->Allocate();
std::complex<TPixel> *out = outputPtr->GetBufferPointer();
{
double *in = const_cast<double *>(reinterpret_cast<const double *>(inputPtr->GetBufferPointer()));
fftw_complex *dptr = reinterpret_cast<double (*)[2]>(out);
switch(num_dims)
{
case 1:
M_plan = fftw_plan_dft_r2c_1d(inputSize[0],
in,dptr,
FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
break;
case 2:
M_plan = fftw_plan_dft_r2c_2d(inputSize[1],inputSize[0],
in,dptr,
FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
break;
case 3:
M_plan = fftw_plan_dft_r2c_3d(inputSize[2],inputSize[1],inputSize[0],
in,dptr,
FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
break;
default:
int *sizes = new int[num_dims];
for(unsigned int i = 0; i < num_dims; i++)
{
sizes[(num_dims - 1) - i] = inputSize[i];
}
M_plan = fftw_plan_dft_r2c(num_dims,sizes,
in,dptr,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
delete []sizes;
}
M_PlanComputed = true;
fftw_execute(M_plan);
}
}
template <unsigned int Dimension>
bool
FFTWRealToComplexConjugateImageFilter<double,Dimension>::
FullMatrix()
{
return false;
}
template <unsigned int Dimension>
void
FFTWRealToComplexConjugateImageFilter<double,Dimension>::
PrintSelf(std::ostream& os,Indent indent) const
{
}
#endif //defined(USE_FFTWD)
} // namespace itk
#endif // defined(USE_FFTWF) || defined(USE_FFTWD)
#endif //_itkFFTWRealToComplexConjugateImageFilter_txx