forked from InsightSoftwareConsortium/ITK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
itkSCSLComplexConjugateToRealImageFilter.txx
305 lines (286 loc) · 10.3 KB
/
itkSCSLComplexConjugateToRealImageFilter.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkSCSLComplexConjugateToRealImageFilter.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 _itkSCSLComplexConjugateToRealImageFilter_txx
#define _itkSCSLComplexConjugateToRealImageFilter_txx
#ifdef USE_SCSL
#include "itkSCSLComplexConjugateToRealImageFilter.h"
#include <iostream>
#include "itkIndent.h"
#include "itkMetaDataObject.h"
namespace itk
{
#ifndef SCSL_INT_T
#define SCSL_INT_T int
#endif
template <typename TPixel, unsigned int Dimension>
void
SCSLComplexConjugateToRealImageFilter<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;
}
const typename TInputImageType::SizeType& outputSize
= outputPtr->GetLargestPossibleRegion().GetSize();
unsigned int num_dims = outputPtr->GetImageDimension();
if(num_dims != outputPtr->GetImageDimension())
return;
unsigned int total_size = 1;
unsigned int tmp_size = 1;
unsigned dims[32];
{
int i;
for(i = 0; i < Dimension; i++)
{
dims[i] = outputSize[i];
total_size *= dims[i];
tmp_size *= (i == 0 ? (dims[i]+2) : dims[i]);
}
for(; i < 32; i++)
{
dims[i] = 1;
}
}
// allocate output buffer memory
outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
outputPtr->Allocate();
std::complex<TPixel> *in = const_cast<std::complex<TPixel> *>
(inputPtr->GetBufferPointer());
#define MAX2(a,b) ((a) > (b) ? (a) : (b))
#define MAX3(a,b,c) MAX2(MAX2(a,b),c)
/* return type values are undocumented SCSL_INT_T rval; */
SCSL_INT_T isys[2] = {1,0};
#define NF 256
#define NFR 256
if(typeid(TPixel) == typeid(double))
{
double *out = reinterpret_cast<double *>(outputPtr->GetBufferPointer());
double *tmp_buf = reinterpret_cast<double *>(new TPixel[tmp_size]);
switch(num_dims)
{
case 1:
case 2:
{
double *table = new double[(dims[0]+NFR) + (2 * dims[1] + NF)];
double *work = new double[dims[0] + 4 * dims[1]];
/*return type values are undocumented rval = */zdfft2d(0, // sign
dims[0], // size of input x
dims[1], // "" y
1.0, // scale
const_cast<std::complex<double> *>
(reinterpret_cast // input
<const std::complex<double> *>
(inputPtr->GetBufferPointer())),
dims[0]/2 + 1, // ldx
tmp_buf, // output
dims[0] + 2,
table, work,isys);
/*return type values are undocumented rval = */zdfft2d(-1, // sign
dims[0], // size of input x
dims[1], // "" y
1.0, // scale
const_cast<std::complex<double> *>
(reinterpret_cast // input
<const std::complex<double> *>
(inputPtr->GetBufferPointer())),
dims[0]/2 + 1, // ldx
tmp_buf, // output
dims[0] + 2,
table, work,isys);
delete [] table;
delete [] work;
}
break;
case 3:
{
double *work = new double[dims[1] + 4 * dims[2]];
double *table = new double[(dims[0] + 256) +
(2 * dims[1] + 256) +
(2 * dims[2] + 256)];
/*return type values are undocumented rval = */zdfft3d(0, // sign
dims[0], // size of input
dims[1], // ""
dims[2], // ""
1.0, // scale
const_cast<std::complex<double> *>
(reinterpret_cast // input
<const std::complex<double> *>
(inputPtr->GetBufferPointer())),
(dims[0]/2+1),
dims[1],
tmp_buf,
dims[0]+2,
dims[1],
table,work,isys);
/*return type values are undocumented rval = */zdfft3d(-1, // sign
dims[0], // size of input
dims[1], // ""
dims[2], // ""
1.0, // scale
const_cast<std::complex<double> *>
(reinterpret_cast // input
<const std::complex<double> *>
(inputPtr->GetBufferPointer())),
(dims[0]/2+1),
dims[1],
tmp_buf,
dims[0]+2,
dims[1],
table,work,isys);
delete [] table;
delete [] work;
}
break;
default:
break;
}
for(int k = 0; k < dims[2]; k++)
{
for(int j = 0; j < dims[1]; j++)
{
for(int i = 0; i < dims[0]; i++)
out[i + (dims[0] * j) + ((dims[0] * dims[1]) * k)] =
#if 1
tmp_buf[i + ((dims[0]+2)*j) + (((dims[0]+2) * dims[1]) * k)];
#else
tmp_buf[i + (dims[0]*j) + ((dims[0] * dims[1]) * k)];
#endif
}
}
delete [] tmp_buf;
}
else if(typeid(TPixel) == typeid(float))
{
float *out = reinterpret_cast<float *>(outputPtr->GetBufferPointer());
float *tmp_buf = reinterpret_cast<float *>(new TPixel[tmp_size]);
switch(num_dims)
{
case 1:
case 2:
{
float *table = new float[(dims[0]+NFR) + (2 * dims[1] + NF)];
float *work = new float[dims[0] + 4 * dims[1]];
/*return type values are undocumented rval = */csfft2d(0, // sign
dims[0], // size of input x
dims[1], // "" y
1.0, // scale
const_cast<std::complex<float> *>
(reinterpret_cast // input
<const std::complex<float> *>
(inputPtr->GetBufferPointer())),
dims[0]/2 + 1, // ldx
tmp_buf, // output
dims[0] + 2,
table, work,isys);
/*return type values are undocumented rval = */csfft2d(-1, // sign
dims[0], // size of input x
dims[1], // "" y
1.0, // scale
const_cast<std::complex<float> *>
(reinterpret_cast // input
<const std::complex<float> *>
(inputPtr->GetBufferPointer())),
dims[0]/2 + 1, // ldx
tmp_buf, // output
dims[0] + 2,
table, work,isys);
delete [] table;
delete [] work;
}
break;
case 3:
{
float *work = new float[dims[1] + 4 * dims[2]];
float *table = new float[(dims[0] + 256) +
(2 * dims[1] + 256) +
(2 * dims[2] + 256)];
/*return type values are undocumented rval = */csfft3d(0, // sign
dims[0], // size of input
dims[1], // ""
dims[2], // ""
1.0, // scale
const_cast<std::complex<float> *>
(reinterpret_cast // input
<const std::complex<float> *>
(inputPtr->GetBufferPointer())),
(dims[0]/2+1),
dims[1],
tmp_buf,
dims[0]+2,
dims[1],
table,work,isys);
/*return type values are undocumented rval = */csfft3d(-1, // sign
dims[0], // size of input
dims[1], // ""
dims[2], // ""
1.0, // scale
const_cast<std::complex<float> *>
(reinterpret_cast // input
<const std::complex<float> *>
(inputPtr->GetBufferPointer())),
(dims[0]/2+1),
dims[1],
tmp_buf,
dims[0]+2,
dims[1],
table,work,isys);
delete [] table;
delete [] work;
}
break;
default:
break;
}
for(int k = 0; k < dims[2]; k++)
{
for(int j = 0; j < dims[1]; j++)
{
for(int i = 0; i < dims[0]; i++)
out[i + (dims[0] * j) + ((dims[0] * dims[1]) * k)] =
#if 1
tmp_buf[i + ((dims[0]+2)*j) + (((dims[0]+2) * dims[1]) * k)];
#else
tmp_buf[i + (dims[0]*j) + ((dims[0] * dims[1]) * k)];
#endif
}
}
delete [] tmp_buf;
}
ImageRegionIterator<TOutputImageType> it(outputPtr,
outputPtr->GetLargestPossibleRegion());
while(!it.IsAtEnd())
{
it.Set(it.Value() / total_size);
++it;
}
}
template <class TPixel, unsigned int Dimension>
bool
SCSLComplexConjugateToRealImageFilter<TPixel,Dimension>::
FullMatrix()
{
return false;
}
template <typename TPixel, unsigned int Dimension>
void
SCSLComplexConjugateToRealImageFilter<TPixel,Dimension>::
PrintSelf(std::ostream& os,Indent indent) const
{
}
}
#endif
#endif