OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimFftw3Filter.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // OSSIM Open Source Geospatial Data Processing Library
4 // See top level LICENSE.txt file for license information
5 //
6 //**************************************************************************************************
7 
8 
9 #include "ossimFftw3Filter.h"
13 #include <complex.h>
14 #include <fftw3.h>
15 
16 RTTI_DEF1(ossimFftw3Filter, "ossimFftw3Filter", ossimFftFilter);
17 
19  :ossimFftFilter(owner)
20 {
21 }
22 
24  :ossimFftFilter(inputSource)
25 {
26 }
27 
29  ossimImageSource* inputSource)
30  :ossimFftFilter(owner, inputSource)
31 {
32 }
33 
35 {
36 }
37 
40 {
41  ossim_uint32 w = input->getWidth();
42  ossim_uint32 h = input->getHeight();
43  ossim_uint32 n = w*h;
44  double realVal, imagVal;
45  double nullPix = getNullPixelValue();
46  ossim_uint32 numBands = input->getNumberOfBands();
48  numBands /= 2;
49 
50  fftw_complex* indata = fftw_alloc_complex(n);
51  fftw_complex* outdata = fftw_alloc_complex(n);
52  ossim_uint32 flags = 0;
53 
54  int dir = 1; // inverse
56  dir = -1;
57 
58  fftw_plan fp = fftw_plan_dft_2d(w, h, indata, outdata, dir, flags);
59  double* realBuf = 0;
60  double* imagBuf = 0;
61 
62  // Transfer the image data to the FFTW data structure:
63  ossim_uint32 cplx_band_idx = 0;
64  for(ossim_uint32 band = 0; band < numBands; ++band)
65  {
66  cplx_band_idx = 2*band;
67 
68  // Fill the FFTW3 complex buffer with pixel values representing real part and imaginary
69  // part (if doing inverse) of input:
71  {
72  realBuf = (double*) input->getBuf(band);
73  imagBuf = 0;
74  }
75  else
76  {
77  realBuf = (double*) input->getBuf(cplx_band_idx);
78  imagBuf = (double*) input->getBuf(cplx_band_idx+1);
79  }
80 
81  ossim_uint32 i = 0;
82  int sign = 1.0;
83  for(ossim_uint32 y = 0; y < h; ++y)
84  {
85  for(ossim_uint32 x = 0; x < w; ++x)
86  {
88  {
89  indata[i][0] = sign*realBuf[i];
90  indata[i][1] = 0;
91  }
92  else
93  {
94  indata[i][0] = sign*realBuf[i];
95  indata[i][1] = sign*imagBuf[i];
96  }
97  i++;
98 
99  //sign *= -1;
100  }
101  //sign *= -1;
102  }
103 
104  // Compute the FFT (or inverse FFT):
105  fftw_execute(fp);
106 
107  // Pull data out of FFTW3 structure and into OSSIM output tile:
108  if (theDirectionType == FORWARD)
109  {
110  realBuf = (double*) output->getBuf(cplx_band_idx);
111  imagBuf = (double*) output->getBuf(cplx_band_idx+1);
112  }
113  else
114  {
115  realBuf = (double*) output->getBuf(band);
116  imagBuf = 0;
117  }
118 
119  i = 0;
120  for(ossim_uint32 y = 0; y < h; ++y)
121  {
122  for(ossim_uint32 x = 0; x < w; ++x)
123  {
124  if (theDirectionType == FORWARD)
125  {
126  realBuf[i] = outdata[i][0] / (double)n;
127  imagBuf[i] = outdata[i][1] / (double)n;
128  }
129  else
130  {
131  realBuf[i] = outdata[i][0];
132  }
133  i++;
134  }
135  }
136 
137  band++;
138  }
139 
140  fftw_cleanup();
141 }
142 
virtual ossim_uint32 getWidth() const
ossim_uint32 x
virtual ~ossimFftw3Filter()
virtual double getNullPixelValue(ossim_uint32 band=0) const
virtual ossim_uint32 getNumberOfBands() const
Real sign(Real x, Real y)
Definition: newmatrm.h:108
virtual void runFft(ossimRefPtr< ossimImageData > &input, ossimRefPtr< ossimImageData > &output)
ossim_uint32 y
virtual ossim_uint32 getHeight() const
ossimFftw3Filter(ossimObject *owner=NULL)
os2<< "> n<< " > nendobj n
unsigned int ossim_uint32
RTTI_DEF1(ossimFftw3Filter, "ossimFftw3Filter", ossimFftFilter)
virtual const void * getBuf() const
ossimFftFilterDirectionType theDirectionType