49 memset(
img_src_, 0,
sizeof(
double)*pnx * pny);
50 memset(
dmap_src_, 0,
sizeof(
double)*pnx * pny);
53 memset(
dmap_, 0,
sizeof(
double)*pnx * pny);
56 #pragma omp parallel for private(k) 57 for (k = 0; k < pnx*pny; k++)
59 img_src_[k] = double(imgptr[k]) / 255.0;
60 dmap_src_[k] = double(dimgptr[k]) / 255.0;
79 double temp_depth, d1, d2;
85 d1 = temp_depth -
dstep_ / 2.0;
86 d2 = temp_depth +
dstep_ / 2.0;
89 #pragma omp parallel for private(p) 90 for (p = 0; p < pnx * pny; p++)
94 tdepth = (
dmap_[p] >= d1 ? 1 : 0) * (
dmap_[p] < d2 ? 1 : 0);
96 tdepth = (
dmap_[p] >= d1 ? 1 : 0) * (
dmap_[p] <= d2 ? 1 : 0);
125 fftw_complex *in, *out;
126 fft_plan_fwd_ = fftw_plan_dft_2d(pny, pnx, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
129 #pragma omp parallel for private(p) 130 for (p = 0; p < depth_sz; ++p)
136 memset(u_o, 0.0,
sizeof(
Complex)*pnx*pny);
139 for (
int i = 0; i < pnx * pny; i++)
147 LOG(
"Frame#: %d, Depth: %d of %d, z = %f mm\n", frame, dtr,
params_.
num_of_depth, -temp_depth * 1000);
155 for (
int i = 0; i < pnx * pny; i++)
156 u_o[i] = u_o[i] * rand_phase_val * carrier_phase_delay;
159 fftwShift(u_o, u_o, in, out, pnx, pny, 1,
false);
196 for (
int i = 0; i < pnx * pny; i++)
201 double fxx = (-1.0 / (2.0*ppx)) + (1.0 / ssx) * x;
202 double fyy = (1.0 / (2.0*ppy)) - (1.0 / ssy) - (1.0 / ssy) * y;
204 double sval = sqrt(1 - (lambda*fxx)*(lambda*fxx) - (lambda*fyy)*(lambda*fyy));
205 sval *=
params_.
k * propagation_dist;
213 u_frequency = kernel * input_u[i];
237 memset(h_crop, 0.0,
sizeof(
Complex)*pnx*pny);
240 #pragma omp parallel for private(p) 241 for (p = 0; p < pnx*pny; p++)
245 if (x >= cropx1 && x <= cropx2 && y >= cropy1 && y <= cropy2)
249 fftw_complex *in, *out;
250 fft_plan_bwd_ = fftw_plan_dft_2d(pny, pnx, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
251 fftwShift(h_crop, h_crop, in, out, pnx, pny, -1,
true);
257 #pragma omp parallel for private(i) 258 for (i = 0; i < pnx*pny; i++) {
288 memset(tmp, 0.0,
sizeof(
Complex)*nx*ny);
291 in = (fftw_complex*)fftw_malloc(
sizeof(fftw_complex) * nx * ny);
292 out = (fftw_complex*)fftw_malloc(
sizeof(fftw_complex) * nx * ny);
294 for (
int i = 0; i < nx*ny; i++)
306 if (bNomarlized) normalF = nx * ny;
307 memset(tmp, 0,
sizeof(
Complex)*nx*ny);
309 for (
int k = 0; k < nx*ny; k++) {
310 tmp[k].
a = out[k][0] / normalF;
311 tmp[k].
b = out[k][1] / normalF;
317 memset(dst, 0.0,
sizeof(
Complex)*nx*ny);
334 for (
int i = 0; i < nx; i++)
336 for (
int j = 0; j < ny; j++)
338 int ti = i - nx / 2;
if (ti < 0) ti += nx;
339 int tj = j - ny / 2;
if (tj < 0) tj += ny;
341 output[ti + tj * nx] = input[i + j * nx];
353 double realv = val->
a;
354 double imgv = val->
b;
355 val->
a = exp(realv)*cos(imgv);
356 val->
b = exp(realv)*sin(imgv);
376 if (sig_location[1] != 0)
380 double yy = (ssy / 2.0) - (ppy)*r - ppy;
383 if (sig_location[1] == 1)
384 val.
b = 2 *
PI * (yy / (4 * ppy));
386 val.
b = 2 *
PI * (-yy / (4 * ppy));
389 shift_phase_val *= val;
392 if (sig_location[0] != 0)
396 double xx = (-ssx / 2.0) - (ppx)*c - ppx;
399 if (sig_location[0] == -1)
400 val.
b = 2 *
PI * (-xx / (4 * ppx));
402 val.
b = 2 *
PI * (xx / (4 * ppx));
405 shift_phase_val *= val;
420 LOG(
"Error: No Hologram Data\n");
436 double vmax, vmin, vstep, vval;
448 fftw_complex *in, *out;
449 fft_plan_fwd_ = fftw_plan_dft_2d(SLM_pixel_number_xy_[1], SLM_pixel_number_xy_[0], in, out, FFTW_FORWARD, FFTW_ESTIMATE);
462 vval = vmin + (vtr - 1)*vstep;
500 double F_size_x = pnx*ppx;
501 double F_size_y = pny*ppy;
506 for (
int k = 0; k < pnx*pny; k++)
512 fftwShift(hh, hh, in, out, pnx, pny, 1,
false);
514 double pp_ex = lambda *
f_field_ / F_size_x;
515 double pp_ey = lambda *
f_field_ / F_size_y;
516 double E_size_x = pp_ex*pnx;
517 double E_size_y = pp_ey*pny;
520 #pragma omp parallel for private(p) 521 for (p = 0; p < pnx * pny; p++)
526 double xe = (-E_size_x / 2.0) + (pp_ex * x);
527 double ye = (E_size_y / 2.0 - pp_ey) - (pp_ey * y);
529 double sval =
PI / lambda /
f_field_ * (xe*xe + ye*ye);
550 double F_size_x = pnx*ppx;
551 double F_size_y = pny*ppy;
553 double pp_ex = lambda *
f_field_ / F_size_x;
554 double pp_ey = lambda *
f_field_ / F_size_y;
555 double E_size_x = pp_ex*pnx;
556 double E_size_y = pp_ey*pny;
569 #pragma omp parallel for private(p) 570 for (p = 0; p < pnx * pny; p++)
575 double xe = (-E_size_x / 2.0) + (pp_ex * x);
576 double ye = (E_size_y / 2.0 - pp_ey) - (pp_ey * y);
578 Complex eye_propagation_kernel(0,
PI / lambda / effective_f * (xe*xe + ye*ye));
580 int eye_lens_anti_aliasing_mask = (sqrt(xe*xe + ye*ye) < abs(lambda*effective_f / (2.0 * max(pp_ex, pp_ey)))) ? 1 : 0;
583 hh_e_[p] = hh_e_shift[p] * eye_propagation_kernel * eye_lens_anti_aliasing_mask * eye_pupil_mask;
587 fftwShift(hh_e_, hh_e_, in, out, pnx, pny, 1,
false);
591 double Ret_size_x = pp_ret_x*pnx;
592 double Ret_size_y = pp_ret_y*pny;
594 #pragma omp parallel for private(p) 595 for (p = 0; p < pnx * pny; p++)
600 double xr = (-Ret_size_x / 2.0) + (pp_ret_x * x);
601 double yr = (Ret_size_y / 2.0 - pp_ret_y) - (pp_ret_y * y);
625 QString fname =
"./" + QString().fromStdString(
RESULT_FOLDER) +
"/" 628 + QString().setNum(num)
629 + QString(
"_") + (
sim_type_ == 0 ?
"FOCUS_" :
"EYE_Y_") + QString().setNum(round(val * 1000))
637 double min_val, max_val;
640 for (
int i = 0; i < pnx*pny; ++i)
648 uchar* data = (uchar*)malloc(
sizeof(uchar)*pnx*pny);
649 memset(data, 0,
sizeof(uchar)*pnx*pny);
650 for (
int k = 0; k < pnx*pny; k++)
651 data[k] = (uint)((
sim_final_[k] - min_val) / (max_val - min_val) * 255);
653 QImage img(data, px, py, QImage::Format::Format_RGB888);
654 img.save(QString(fname));
666 for (
int i = 0; i < nx; i++)
668 for (
int j = 0; j < ny; j++)
670 ti = (i + shift_x) % nx;
673 tj = (j + shift_y) % ny;
677 out[ti + tj * nx] = in[i + j * nx];
double sim_from_
reconstruction variable for testing
int sim_type_
reconstruction variable for testing
double * img_src_
CPU variable - image source data, values are from 0 to 1.
double dstep_
the physical increment of each depth map layer.
void Calc_Holo_CPU(int frame)
Main method for generating a hologram on the CPU.
void get_shift_phase_value(Complex &shift_phase_val, int idx, ivec2 sig_location)
Calculate the shift phase value.
uint num_of_depth
the number of depth level.
double * depth_index_
CPU variable - quantized depth map data.
void ReconstructImage()
It is a testing function used for the reconstruction.
Complex * U_complex_
CPU variable - the generated hologram before encoding.
uint DEFAULT_DEPTH_QUANTIZATION
default value of the depth quantization - 256
std::string RESULT_PREFIX
the prefix of the result file - config file
double * sim_final_
reconstruction variable for testing
Complex * hh_complex_
reconstruction variable for testing
bool FLAG_CHANGE_DEPTH_QUANTIZATION
if true, change the depth quantization from the default value.
int * alpha_map_
CPU variable - calculated alpha map data, values are 0 or 1.
double far_depthmap
FAR_OF_DEPTH_MAP at config file.
void exponent_complex(Complex *val)
Calculate the exponential of the complex number.
double focus_distance_
reconstruction variable for testing
std::vector< double > dlevel_
the physical value of all depth map layer.
int Propagation_Method_
propagation method - currently AngularSpectrum
void circshift(Complex *in, Complex *out, int shift_x, int shift_y, int nx, int ny)
It is a testing function used for the reconstruction.
double lambda
WAVELENGTH at config file.
structure for 2-dimensional integer vector and its arithmetic.
ivec2 pn
SLM_PIXEL_NUMBER_X & SLM_PIXEL_NUMBER_Y.
void change_depth_quan_CPU()
Quantize depth map on the CPU, when the number of depth quantization is not the default value (i...
void Write_Simulation_image(int num, double val)
It is a testing function used for the reconstruction.
std::string Simulation_Result_File_Prefix_
reconstruction variable for testing
std::vector< int > render_depth
Used when only few specific depth levels are rendered, usually for test purpose.
double field_lens
FIELD_LENS at config file.
int sim_step_num_
reconstruction variable for testing
void fftwShift(Complex *src, Complex *dst, fftw_complex *in, fftw_complex *out, int nx, int ny, int type, bool bNomalized=false)
Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. ...
double eye_length_
reconstruction variable for testing
void Reconstruction(fftw_complex *in, fftw_complex *out)
It is a testing function used for the reconstruction.
void fftShift(int nx, int ny, Complex *input, Complex *output)
Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom...
int test_pixel_number_scale_
reconstruction variable for testing
double f_field_
reconstruction variable for testing
class for the complex number and its arithmetic.
double sim_to_
reconstruction variable for testing
vec2 eye_center_xy_
reconstruction variable for testing
double * dmap_
CPU variable - physical distances of depth map.
ivec2 SLM_pixel_number_xy_
reconstruction variable for testing
vec2 pp
SLM_PIXEL_PITCH_X & SLM_PIXEL_PITCH_Y.
double * u255_fringe_
the final hologram, used for writing the result image.
bool prepare_inputdata_CPU(uchar *img, uchar *dimg)
Preprocess input image & depth map data for the CPU implementation.
vec2 Pixel_pitch_xy_
reconstruction variable for testing
void init_CPU()
Initialize variables for the CPU implementation.
void Propagation_AngularSpectrum_CPU(Complex *input_u, double propagation_dist)
Angular spectrum propagation method for CPU implementation.
double * dmap_src_
CPU variable - depth map data, values are from 0 to 1.
double eye_pupil_diameter_
reconstruction variable for testing
std::vector< double > dlevel_transform_
transfomed dlevel_ variable
std::string RESULT_FOLDER
the name of the result folder - config file
double near_depthmap
NEAR_OF_DEPTH_MAP at config file.
void get_rand_phase_value(Complex &rand_phase_val)
Assign random phase value if RANDOM_PHASE == 1.
void encoding_CPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location)
Encode the CGH according to a signal location parameter on the CPU.
HologramParams params_
structure variable for hologram parameters
void Test_Propagation_to_Eye_Pupil(fftw_complex *in, fftw_complex *out)
It is a testing function used for the reconstruction.