OSDN Git Service

first
[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 FFT2 {\r
24         protected:\r
25                 int width_, height_;\r
26                 int left, top, x_zero, y_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                 FFT2();\r
34                 FFT2(int width, int height);\r
35                 FFT2(const Image &source);\r
36                 FFT2(const Matrix &source);\r
37                 FFT2(const Matrix &reali, const Matrix &imagi);\r
38                 ~FFT2();\r
39                 void release();\r
40                 void set(int wid, int hei);\r
41                 void set(const Image &source);\r
42                 void set(const Matrix &source);\r
43                 void set(const Matrix &reali, const Matrix &imagi);\r
44                 void setSpectrum(const Matrix &reali, const Matrix &imagi);\r
45 \r
46                 // Accesser to elements\r
47                 int freqX(int x) const;\r
48                 int freqY(int y) const;\r
49 \r
50                 double pix(int x, int y, double l);\r
51                 double pix(int x, int y, const Color &c);\r
52                 double getPix(int x, int y);\r
53 \r
54                 double getDC();\r
55                 double setDC(double l);\r
56 \r
57                 // Core FFT Execution\r
58                 void fft();\r
59                 void ifft();\r
60                 void normalizeFFT();\r
61                 //Matrix normalizeMichelson(const Matrix &matrix);\r
62                 //Matrix normalizeRMS(const Matrix &matrix);\r
63 \r
64                 // Core Filter\r
65                 void filtering(const Matrix &filter);\r
66                 void filtering(double cutoff_lambda1, double cutoff_lambda2, double half_power_width = 0.0625);\r
67 \r
68                 // Visualizer (read only)\r
69                 void getImage(Image &absolute);\r
70                 void getSpectrum(Image &absolute, double gamma);\r
71                 void getImage(Matrix &absolute);\r
72                 void getSpectrum(Matrix &absolute, double gamma = 1.0);\r
73                 void getImage(Matrix &reali, Matrix &imagi);\r
74                 void getSpectrum(Matrix &reali, Matrix &imagi);\r
75 \r
76                 // Utilities\r
77                 void makeNoise();\r
78         protected:\r
79                 static void getSpectrumExec(FFT2 &tmp, Image &result, double gamma);\r
80                 static void getRawSpectrumExec(FFT2 &tmp, Image &reali, Image &imagi, double gamma);\r
81         public:\r
82                 static void getSpectrum(const Image &source, Image &result, double gamma);\r
83                 static void getSpectrum(const Matrix &source, Image &result, double gamma);\r
84                 static void getSpectrum(const Image &source, Image &reali, Image &imagi, double gamma);\r
85                 static void getSpectrum(const Matrix &source, Image &reali, Image &imagi, double gamma);\r
86         protected:\r
87                 static void filterImageExec(FFT2 &tmp, Image &result, const Matrix &carnel);\r
88         public:\r
89                 static void filterImage(const Image &source, Image &result, const Matrix &carnel);\r
90                 static void filterImage(const Matrix &source, Image &result, const Matrix &carnel);\r
91                 static void filterImage(const Image &source, Image &result, double cutoff_lambda1, double cutoff_lambda2, double half_power_width = 0.0625);\r
92                 static void filterImage(const Matrix &source, Image &result, double cutoff_lambda1, double cutoff_lambda2, double half_power_width = 0.0625);\r
93                 static Matrix makeFilter(int height, int width, double cutoff_lambda1, double cutoff_lambda2, double half_power_width = 0.0625);\r
94                 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
95                 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
96 \r
97         protected:\r
98                 static void copyBoxSpectrum(FFT2 &source, int s_left, int s_top, FFT2 &target, int t_left, int t_top, int width, int height);\r
99         public:\r
100                 static void resizeImage(const Image &source, Image &result, int new_width, int new_height);\r
101 \r
102                 static int originFor(int size);\r
103         };\r
104 \r
105 \r
106         class FFTW3D {\r
107         protected:\r
108                 int width_, height_, depth_, image_size_;\r
109                 int left, top, front, x_zero, y_zero, z_zero;\r
110                 fftw_complex *img_spc;\r
111                 fftw_complex *frq_spc;\r
112 \r
113 \r
114         public:\r
115                 FFTW3D();\r
116                 FFTW3D(int wid, int hei, int dep);\r
117                 FFTW3D(const Image *source, int framsize);\r
118                 FFTW3D(const Matrix *source, int framsize);\r
119                 ~FFTW3D();\r
120                 void set(int wid, int hei, int dep);\r
121                 void set(const Image *source, int framsize);\r
122                 void set(const Matrix *source, int framsize);\r
123 \r
124                 int freqX(int x) const;\r
125                 int freqY(int y) const;\r
126                 int freqT(int t) const;\r
127 \r
128                 double pix(int x, int y, int z, double l);\r
129                 double pix(int x, int y, int z, const Color &c);\r
130                 double getPix(int x, int y, int z);\r
131 \r
132                 double getDC();\r
133                 double setDC(double l);\r
134 \r
135                 void fft();\r
136                 void ifft();\r
137                 //FFT2 filter(const Matrix &filter);\r
138 \r
139                 void normalizeFFT();\r
140                 //Matrix normalizeMichelson(const Matrix &matrix);\r
141                 //Matrix normalizeRMS(const Matrix &matrix);\r
142                 //void getImage(Image &target);\r
143                 //void getSpectrum(Image &target, double gamma);\r
144                 //void getImage(Matrix &real, Matrix &imag);\r
145                 //void getSpectrum(Matrix &real, Matrix &imag);\r
146                 void drawCloudImage(Drawable &target = *Drawable::prime);\r
147                 void drawCloudSpectrum(Point c, double gamma, Drawable &target = *Drawable::prime);\r
148 /*\r
149                 void filtering(const Matrix &filter);\r
150                 void filtering(double cutoff_lambda1, double cutoff_lambda2, double slope);\r
151 \r
152         protected:\r
153                 static void getSpectrumExec(FFT2 &tmp, Image &result, double gamma);\r
154         public:\r
155                 static void getSpectrum(const Image &source, Image &result, double gamma);\r
156                 static void getSpectrum(const Matrix &source, Image &result, double gamma);\r
157         protected:\r
158                 static void filterImageExec(FFT2 &tmp, Image &result, const Matrix &carnel);\r
159         public:\r
160                 static void filterImage(const Image &source, Image &result, const Matrix &carnel);\r
161                 static void filterImage(const Matrix &source, Image &result, const Matrix &carnel);\r
162                 static void filterImage(const Image &source, Image &result, double cutoff_lambda1, double cutoff_lambda2, double slope);\r
163                 static void filterImage(const Matrix &source, Image &result, double cutoff_lambda1, double cutoff_lambda2, double slope);\r
164                 static Matrix makeFilter(int height, int width, double cutoff_lambda1, double cutoff_lambda2, double slope);\r
165 */\r
166         };\r
167 \r
168 }       /*      <- namespace Psycholops         */\r
169 \r
170 \r
171 #endif\r