-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFresnel_propagate.c
204 lines (180 loc) · 5.19 KB
/
Fresnel_propagate.c
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
/**
* @file Fresnel_propagate.c
*
*/
#include "CommandLineInterface/CLIcore.h"
#include "COREMOD_memory/COREMOD_memory.h"
#include "fft/dofft.h"
#include "fft/permut.h"
#include <math.h>
// variables local to this translation unit
static char *inimname;
static char *outimname;
static double *pupscale;
static double *propz;
static double *proplambda;
// CLI function arguments and parameters
static CLICMDARGDEF farg[] = {{
CLIARG_IMG,
".in_name",
"input image",
"imin",
CLICMDARG_FLAG_DEFAULT,
FPTYPE_AUTO,
FPFLAG_DEFAULT_INPUT,
(void **) &inimname,
NULL
},
{
CLIARG_STR_NOT_IMG,
".out_name",
"output image",
"imout",
CLICMDARG_FLAG_DEFAULT,
FPTYPE_AUTO,
FPFLAG_DEFAULT_INPUT,
(void **) &inimname,
NULL
},
{
CLIARG_FLOAT64,
".pupscale",
"pupil scale [m/pix]",
"1.0",
CLICMDARG_FLAG_DEFAULT,
FPTYPE_AUTO,
FPFLAG_DEFAULT_INPUT,
(void **) &pupscale,
NULL
},
{
CLIARG_FLOAT64,
".propz",
"propagation distance [m]",
"1.0",
CLICMDARG_FLAG_DEFAULT,
FPTYPE_AUTO,
FPFLAG_DEFAULT_INPUT,
(void **) &propz,
NULL
},
{
CLIARG_FLOAT64,
".proplambda",
"wavelength [m]",
"0.000001",
CLICMDARG_FLAG_DEFAULT,
FPTYPE_AUTO,
FPFLAG_DEFAULT_INPUT,
(void **) &proplambda,
NULL
}
};
// CLI function initialization data
static CLICMDDATA CLIcmddata =
{
"fresnelpw", "Fresnel propagate WF", CLICMD_FIELDS_DEFAULTS
};
// detailed help
static errno_t help_function()
{
return RETURN_SUCCESS;
}
// Computation code
errno_t Fresnel_propagate_wavefront(const char *__restrict in,
const char *__restrict out,
double PUPIL_SCALE,
double z,
double lambda)
{
DEBUG_TRACE_FSTART();
DEBUG_TRACEPOINT("FARG %s %s %lf %lf %lf", in, out, PUPIL_SCALE, z, lambda);
/* all units are in m */
double coeff;
uint32_t naxes[2];
imageID ID;
double co1;
long n0h;
uint8_t datatype;
do2dfft(in, "tmp");
permut("tmp");
ID = image_ID("tmp");
datatype = data.image[ID].md[0].datatype;
naxes[0] = data.image[ID].md[0].size[0];
naxes[1] = data.image[ID].md[0].size[1];
coeff =
PI * z * lambda / (PUPIL_SCALE * naxes[0]) / (PUPIL_SCALE * naxes[0]);
co1 = 1.0 * naxes[0] * naxes[1];
n0h = naxes[0] / 2;
if(datatype == _DATATYPE_COMPLEX_FLOAT)
{
for(uint32_t jj = 0; jj < naxes[1]; jj++)
{
uint32_t jj1 = naxes[0] * jj;
uint32_t jj2 = (jj - naxes[1] / 2) * (jj - naxes[1] / 2);
for(uint32_t ii = 0; ii < naxes[0]; ii++)
{
uint32_t ii1 = jj1 + ii;
uint32_t ii2 = ii - n0h;
double sqdist = ii2 * ii2 + jj2;
double angle = -coeff * sqdist;
double re = data.image[ID].array.CF[ii1].re / co1;
double im = data.image[ID].array.CF[ii1].im / co1;
data.image[ID].array.CF[ii1].re =
re * cos(angle) - im * sin(angle);
data.image[ID].array.CF[ii1].im =
re * sin(angle) + im * cos(angle);
}
}
}
else
{
for(uint32_t jj = 0; jj < naxes[1]; jj++)
{
uint32_t jj1 = naxes[0] * jj;
uint32_t jj2 = (jj - naxes[1] / 2) * (jj - naxes[1] / 2);
for(uint32_t ii = 0; ii < naxes[0]; ii++)
{
uint32_t ii1 = jj1 + ii;
uint32_t ii2 = ii - n0h;
double sqdist = ii2 * ii2 + jj2;
double angle = -coeff * sqdist;
double re = data.image[ID].array.CD[ii1].re / co1;
double im = data.image[ID].array.CD[ii1].im / co1;
data.image[ID].array.CD[ii1].re =
re * cos(angle) - im * sin(angle);
data.image[ID].array.CD[ii1].im =
re * sin(angle) + im * cos(angle);
}
}
}
permut("tmp");
do2dffti("tmp", out);
FUNC_CHECK_RETURN(delete_image_ID("tmp", DELETE_IMAGE_ERRMODE_WARNING));
DEBUG_TRACE_FEXIT();
return RETURN_SUCCESS;
}
// Wrapper function, used by all CLI calls
// Defines how local variables are fed to computation code
// Always local to this translation unit
static errno_t compute_function()
{
DEBUG_TRACE_FSTART();
INSERT_STD_PROCINFO_COMPUTEFUNC_START
Fresnel_propagate_wavefront(inimname,
outimname,
*pupscale,
*propz,
*proplambda);
INSERT_STD_PROCINFO_COMPUTEFUNC_END
DEBUG_TRACE_FEXIT();
return RETURN_SUCCESS;
}
INSERT_STD_FPSCLIfunctions
// Register function in CLI
errno_t
CLIADDCMD_Fresnel_propagate_wavefront()
{
INSERT_STD_CLIREGISTERFUNC
return RETURN_SUCCESS;
}