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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkSCSLRealToComplexConjugateImageFilter.txx,v $
Language: C++
Date: $Date: 2005-11-04 15:32:53 $
Version: $Revision: 1.3 $
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 _itkSCSLRealToComplexConjugateImageFilter_txx
#define _itkSCSLRealToComplexConjugateImageFilter_txx
#ifdef USE_SCSL
#include "itkSCSLRealToComplexConjugateImageFilter.h"
#include <iostream>
#include "itkIndent.h"
#include "itkMetaDataObject.h"
#include <complex.h>
#include <scsl_fft.h>
namespace itk
{
#ifndef SCSL_INT_T
#define SCSL_INT_T int
#endif
template <class TPixel, unsigned int Dimension>
void
SCSLRealToComplexConjugateImageFilter<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& 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();
#define MAX2(a,b) ((a) > (b) ? (a) : (b))
#define MAX3(a,b,c) MAX2(MAX2(a,b),c)
unsigned dims[32];
{
int i;
for(i = 0; i < Dimension; i++)
{
dims[i] = inputSize[i];
}
for(; i < 32; i++)
{
dims[i] = 1;
}
}
std::complex<TPixel> *out = outputPtr->GetBufferPointer();
/* return type valus are undocumented SCSL_INT_T rval;*/
SCSL_INT_T isys[2]={1,0};
#define NF 256
#define NFR 256
if(typeid(TPixel) == typeid(double))
{
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 = */
dzfft2d(0, // sign
dims[0], // size of input x
dims[1], // size of input in y
1.0, // scale
const_cast<double *>
(reinterpret_cast<const double *>
(inputPtr->GetBufferPointer())),
dims[0], // ldx -- number of rows in x array
reinterpret_cast<std::complex<double> *>(out),
dims[0]/2 + 1,
table,
work,
isys);
/*return type values are undocumented rval = */
dzfft2d(1, // sign
dims[0], // size of input x
dims[1], //
1.0, // scale
const_cast<double *>
(reinterpret_cast<const double *>
(inputPtr->GetBufferPointer())),
dims[0], //
reinterpret_cast<std::complex<double> *>(out),
dims[0]/2 + 1,
table,
work,
isys);
delete [] table;
delete [] work;
}
break;
case 3:
{
double *table = new double[(dims[0] + NFR) + (2 * dims[1] + NF) +
(2 * dims[2] + NF)];
double *work = new double[dims[0] + 3 * dims[2]];
/*return type values are undocumented rval = */
dzfft3d(0, // sign
dims[0], // size of input
dims[1], // ""
dims[2], // ""
1.0, // scale
const_cast<double *>
(reinterpret_cast<const double *>
(inputPtr->GetBufferPointer())), // input
dims[0], // ldx
dims[1], // ldx2
reinterpret_cast<std::complex<double> *>(out), // output
(dims[0]/2 + 1), // ldy
dims[2], // ldy2
table,work,isys);
/*return type values are undocumented rval = */
dzfft3d(1, // sign
dims[0], // size of input
dims[1], // ""
dims[2], // ""
1.0, // scale
const_cast<double *>
(reinterpret_cast<const double *>
(inputPtr->GetBufferPointer())), // input
dims[0], // ldx
dims[1], // ldx2
reinterpret_cast<std::complex<double> *>(out), // output
(dims[0]/2 + 1), // ldy
dims[1], // ldy2
table,work,isys);
delete [] table;
delete [] work;
}
break;
default:
break;
}
}
else if(typeid(TPixel) == typeid(float))
{
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 = */
scfft2d(0, // sign
dims[0], // size of input x
dims[1], // size of input in y
1.0, // scale
const_cast<float *>
(reinterpret_cast<const float *>
(inputPtr->GetBufferPointer())),
dims[0], // ldx -- number of rows in x array
reinterpret_cast<std::complex<float> *>(out),
dims[0]/2 + 1,
table,
work,
isys);
/*return type values are undocumented rval = */
scfft2d(1, // sign
dims[0], // size of input x
dims[1], //
1.0, // scale
const_cast<float *>
(reinterpret_cast<const float *>
(inputPtr->GetBufferPointer())),
dims[0], //
reinterpret_cast<std::complex<float> *>(out),
dims[0]/2 + 1,
table,
work,
isys);
delete [] table;
delete [] work;
}
break;
case 3:
{
float *table = new float[(dims[0] + NFR) + (2 * dims[1] + NF) +
(2 * dims[2] + NF)];
float *work = new float[dims[0] + 3 * dims[2]];
/*return type values are undocumented rval = */
scfft3d(0, // sign
dims[0], // size of input
dims[1], // ""
dims[2], // ""
1.0, // scale
const_cast<float *>
(reinterpret_cast<const float *>
(inputPtr->GetBufferPointer())), // input
dims[0], // ldx
dims[1], // ldx2
reinterpret_cast<std::complex<float> *>(out), // output
(dims[0]/2 + 1), // ldy
dims[1], // ldy2
table,work,isys);
/*return type values are undocumented rval = */
scfft3d(1, // sign
dims[0], // size of input
dims[1], // ""
dims[2], // ""
1.0, // scale
const_cast<float *>
(reinterpret_cast<const float *>
(inputPtr->GetBufferPointer())), // input
dims[0], // ldx
dims[1], // ldx2
reinterpret_cast<std::complex<float> *>(out), // output
(dims[0]/2 + 1), // ldy
dims[1], // ldy2
table,work,isys);
delete [] table;
delete [] work;
}
break;
default:
break;
}
}
}
template <class TPixel, unsigned int Dimension>
bool
SCSLRealToComplexConjugateImageFilter<TPixel,Dimension>::
FullMatrix()
{
return false;
}
template <class TPixel, unsigned int Dimension>
void
SCSLRealToComplexConjugateImageFilter<TPixel,Dimension>::
PrintSelf(std::ostream& os,Indent indent) const
{
}
}
#endif
#endif
|