OSDN Git Service

test
[psychlops/cpp.git] / psychlops / extension / standard / fft / psychlops_FFTW_bridge.h
1 /*\r
2  *  psychlops_FFTW_bridge.h\r
3  *  Psychlops Standard Library (Universal)\r
4  *\r
5  *  Last Modified 2010/03/05 by Kenchi HOSOKAWA\r
6  *  (C) 2010 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO\r
7  */\r
8 \r
9 \r
10 #ifndef HEADER_PSYCHLOPS_FFTW\r
11 #define HEADER_PSYCHLOPS_FFTW\r
12 \r
13 #include "../../../psychlops_core.h"\r
14 #include "fftw3.h"\r
15 \r
16 \r
17 namespace Psychlops {\r
18 \r
19         double log2NormalDistibution(double log_x, double octave_mu, double octave_sigma);\r
20         double cumulativeLog2NormalDistibution(double log_x, double octave_mu, double octave_sigma);\r
21 \r
22 \r
23         class FFT1 {\r
24         protected:\r
25                 int width_;\r
26                 int left, x_zero;\r
27                 fftw_complex *img_spc;\r
28                 fftw_complex *frq_spc;\r
29                 void construct_default();\r
30         public:\r
31 \r
32                 // Initialize\r
33                 FFT1();\r
34                 FFT1(int width);\r
35                 FFT1(const Matrix &source);\r
36                 ~FFT1();\r
37                 void release();\r
38                 void set(int wid);\r
39                 void set(const Matrix &source);\r
40 \r
41                 // Accesser to elements\r
42                 double getDC();\r
43                 double setDC(double l);\r
44 \r
45                 // Core FFT Execution\r
46                 void fft();\r
47                 void ifft();\r
48                 void normalizeFFT();\r
49 \r
50                 void getImage(Matrix &absolute);\r
51                 void getSpectrum(Matrix &absolute, double gamma = 1.0);\r
52                 //void getImage(Matrix &reali, Matrix &imagi);\r
53                 //void getSpectrum(Matrix &reali, Matrix &imagi);\r
54 \r
55         };\r
56 \r
57         class FFT2 {\r
58         protected:\r
59                 int width_, height_;\r
60                 int left, top, x_zero, y_zero;\r
61                 fftw_complex *img_spc;\r
62                 fftw_complex *frq_spc;\r
63                 void construct_default();\r
64         public:\r
65 \r
66                 // Initialize\r
67                 FFT2();\r
68                 FFT2(int width, int height);\r
69                 FFT2(const Image &source);\r
70                 FFT2(const Matrix &source);\r
71                 FFT2(const Matrix &reali, const Matrix &imagi);\r
72                 ~FFT2();\r
73                 void release();\r
74                 void set(int wid, int hei);\r
75                 void set(const Image &source);\r
76                 void set(const Matrix &source);\r
77                 void set(const Matrix &reali, const Matrix &imagi);\r
78                 void setSpectrum(const Matrix &reali, const Matrix &imagi);\r
79 \r
80                 // Accesser to elements\r
81                 int freqX(int x) const;\r
82                 int freqY(int y) const;\r
83 \r
84                 double pix(int x, int y, double l);\r
85                 double pix(int x, int y, const Color &c);\r
86                 double getPix(int x, int y);\r
87 \r
88                 double getDC();\r
89                 double setDC(double l);\r
90 \r
91                 // Core FFT Execution\r
92                 void fft();\r
93                 void ifft();\r
94                 void normalizeFFT();\r
95                 //Matrix normalizeMichelson(const Matrix &matrix);\r
96                 //Matrix normalizeRMS(const Matrix &matrix);\r
97 \r
98                 // Core Filter\r
99                 void filtering(const Matrix &filter);\r
100                 void filtering(double cutoff_lambda1, double cutoff_lambda2, double half_power_width = 0.0625);\r
101 \r
102                 // Visualizer (read only)\r
103                 void getImage(Image &absolute);\r
104                 void getSpectrum(Image &absolute, double gamma);\r
105                 void getImage(Matrix &absolute);\r
106                 void getSpectrum(Matrix &absolute, double gamma = 1.0);\r
107                 void getImage(Matrix &reali, Matrix &imagi);\r
108                 void getSpectrum(Matrix &reali, Matrix &imagi);\r
109 \r
110                 // Utilities\r
111                 void makeNoise();\r
112         protected:\r
113                 static void getSpectrumExec(FFT2 &tmp, Image &result, double gamma);\r
114                 static void getRawSpectrumExec(FFT2 &tmp, Image &reali, Image &imagi, double gamma);\r
115         public:\r
116                 static void getSpectrum(const Image &source, Image &result, double gamma);\r
117                 static void getSpectrum(const Matrix &source, Image &result, double gamma);\r
118                 static void getSpectrum(const Image &source, Image &reali, Image &imagi, double gamma);\r
119                 static void getSpectrum(const Matrix &source, Image &reali, Image &imagi, double gamma);\r
120         protected:\r
121                 static void filterImageExec(FFT2 &tmp, Image &result, const Matrix &carnel);\r
122         public:\r
123                 static void filterImage(const Image &source, Image &result, const Matrix &carnel);\r
124                 static void filterImage(const Matrix &source, Image &result, const Matrix &carnel);\r
125                 static void filterImage(const Image &source, Image &result, double cutoff_lambda1, double cutoff_lambda2, double half_power_width = 0.0625);\r
126                 static void filterImage(const Matrix &source, Image &result, double cutoff_lambda1, double cutoff_lambda2, double half_power_width = 0.0625);\r
127                 static Matrix makeFilter(int height, int width, double cutoff_lambda1, double cutoff_lambda2, double half_power_width = 0.0625);\r
128                 static Matrix makeFilterSector(int height, int width, double cutoff_lambda1, double cutoff_lambda2, double theta1, double theta2, double half_power_width = 0.0625, double half_power_width_ori = PI/90.0);\r
129                 static Matrix makeFilter(int height, int width, double cutoff_lambda1, double cutoff_lambda2, double cutoff_lambda3, double cutoff_lambda4, double theta1, double theta2, double half_power_width = 0.0625);\r
130 \r
131         protected:\r
132                 static void copyBoxSpectrum(FFT2 &source, int s_left, int s_top, FFT2 &target, int t_left, int t_top, int width, int height);\r
133         public:\r
134                 static void resizeImage(const Image &source, Image &result, int new_width, int new_height);\r
135 \r
136                 static int originFor(int size);\r
137         };\r
138 \r
139 \r
140         class FFTW3D {\r
141         protected:\r
142                 int width_, height_, depth_, image_size_;\r
143                 int left, top, front, x_zero, y_zero, z_zero;\r
144                 fftw_complex *img_spc;\r
145                 fftw_complex *frq_spc;\r
146 \r
147 \r
148         public:\r
149                 FFTW3D();\r
150                 FFTW3D(int wid, int hei, int dep);\r
151                 FFTW3D(const Image *source, int framsize);\r
152                 FFTW3D(const Matrix *source, int framsize);\r
153                 ~FFTW3D();\r
154                 void set(int wid, int hei, int dep);\r
155                 void set(const Image *source, int framsize);\r
156                 void set(const Matrix *source, int framsize);\r
157 \r
158                 int freqX(int x) const;\r
159                 int freqY(int y) const;\r
160                 int freqT(int t) const;\r
161 \r
162                 double pix(int x, int y, int z, double l);\r
163                 double pix(int x, int y, int z, const Color &c);\r
164                 double getPix(int x, int y, int z);\r
165 \r
166                 double getDC();\r
167                 double setDC(double l);\r
168 \r
169                 void fft();\r
170                 void ifft();\r
171                 //FFT2 filter(const Matrix &filter);\r
172 \r
173                 void normalizeFFT();\r
174                 //Matrix normalizeMichelson(const Matrix &matrix);\r
175                 //Matrix normalizeRMS(const Matrix &matrix);\r
176                 //void getImage(Image &target);\r
177                 //void getSpectrum(Image &target, double gamma);\r
178                 //void getImage(Matrix &real, Matrix &imag);\r
179                 //void getSpectrum(Matrix &real, Matrix &imag);\r
180                 void drawCloudImage(Drawable &target = *Drawable::prime);\r
181                 void drawCloudSpectrum(Point c, double gamma, Drawable &target = *Drawable::prime);\r
182 /*\r
183                 void filtering(const Matrix &filter);\r
184                 void filtering(double cutoff_lambda1, double cutoff_lambda2, double slope);\r
185 \r
186         protected:\r
187                 static void getSpectrumExec(FFT2 &tmp, Image &result, double gamma);\r
188         public:\r
189                 static void getSpectrum(const Image &source, Image &result, double gamma);\r
190                 static void getSpectrum(const Matrix &source, Image &result, double gamma);\r
191         protected:\r
192                 static void filterImageExec(FFT2 &tmp, Image &result, const Matrix &carnel);\r
193         public:\r
194                 static void filterImage(const Image &source, Image &result, const Matrix &carnel);\r
195                 static void filterImage(const Matrix &source, Image &result, const Matrix &carnel);\r
196                 static void filterImage(const Image &source, Image &result, double cutoff_lambda1, double cutoff_lambda2, double slope);\r
197                 static void filterImage(const Matrix &source, Image &result, double cutoff_lambda1, double cutoff_lambda2, double slope);\r
198                 static Matrix makeFilter(int height, int width, double cutoff_lambda1, double cutoff_lambda2, double slope);\r
199 */\r
200         };\r
201 \r
202 }       /*      <- namespace Psycholops         */\r
203 \r
204 \r
205 #endif\r