Structural deformable models
Fourier.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <stdio.h>
3 #include <assert.h>
4 #include "Fourier.h"
5 #include "common.h"
6 
7 #define WISDOM "fftw_stats.wis"
8 bool Fourier2D::s_WisdomLoaded = false;
9 bool Fourier2D::s_WisdomModified = false;
10 
11 #define F2D_REAL_TRANSFORM
12 
13 //#define F2D_PLANQUAL FFTW_MEASURE
14 #define F2D_PLANQUAL FFTW_ESTIMATE
15 
16 Fourier2D::Fourier2D() : m_PlansCreated(false) {
17  loadWisdom();
18 }
21  saveWisdom();
22 }
24  assert(m_PlansCreated);
25  fftw_execute(m_Plan2D);
26 }
27 
29  assert(m_PlansCreated);
30  fftw_execute(m_Plan2Dinv);
31 }
32 
34  if(!s_WisdomLoaded) {
35  FILE* wisdom_file = fopen(WISDOM, "a+");
36  rewind(wisdom_file);
37  fftw_import_wisdom_from_file(wisdom_file);
38  fclose(wisdom_file);
39  s_WisdomLoaded = true;
40  }
41 }
42 
45  FILE* wisdom_file = fopen(WISDOM, "w");
46  fftw_export_wisdom_to_file(wisdom_file);
47  fclose(wisdom_file);
48  std::cout << "fftw plan written to file " << WISDOM << "."<<std::endl;
49  s_WisdomModified = false;
50  }
51 }
52 
53 void Fourier2D::initTransform(int xsize, int ysize, double* f, double *F) {
55 #ifdef F2D_REAL_TRANSFORM
56  m_Plan2D = fftw_plan_dft_r2c_2d(ysize, xsize, f, (fftw_complex*)F,
57  F2D_PLANQUAL);
58  m_Plan2Dinv = fftw_plan_dft_c2r_2d(ysize, xsize, (fftw_complex*)F, f,
59  FFTW_ESTIMATE);
60 #else
61  m_Plan2D = fftw_plan_dft_2d(ysize, xsize,
62  (fftw_complex*)f, (fftw_complex*)F,
63  FFTW_FORWARD, FFTW_ESTIMATE);
64  m_Plan2Dinv = fftw_plan_dft_2d(ysize, xsize,
65  (fftw_complex*)f, (fftw_complex*)F,
66  FFTW_BACKWARD, FFTW_ESTIMATE);
67 #endif
68  m_SizeX = xsize; m_SizeY = ysize;
69  m_PlansCreated = true;
70  s_WisdomModified = true;
71 }
72 
74  if(m_PlansCreated) {
75  fftw_destroy_plan(m_Plan2D);
76  fftw_destroy_plan(m_Plan2Dinv);
77  m_SizeX = m_SizeY = 0;
78  m_PlansCreated = false;
79  }
80 }
bool m_PlansCreated
Definition: Fourier.h:26
#define F2D_PLANQUAL
Definition: Fourier.cpp:14
void transform()
Definition: Fourier.cpp:23
Fourier2D()
Definition: Fourier.cpp:16
void transformInv()
Definition: Fourier.cpp:28
~Fourier2D()
Definition: Fourier.cpp:19
void destroyTransform()
Definition: Fourier.cpp:73
fftw_plan m_Plan2D
Definition: Fourier.h:25
void loadWisdom()
Definition: Fourier.cpp:33
void initTransform(int xsize, int ysize, double *f, double *F)
Definition: Fourier.cpp:53
static bool s_WisdomModified
Definition: Fourier.h:28
void saveWisdom()
Definition: Fourier.cpp:43
int m_SizeY
Definition: Fourier.h:27
#define WISDOM
Definition: Fourier.cpp:7
fftw_plan m_Plan2Dinv
Definition: Fourier.h:25
int m_SizeX
Definition: Fourier.h:27
static bool s_WisdomLoaded
Definition: Fourier.h:28