HologramDepthmap Library
HologramGenerator.h
Go to the documentation of this file.
1 
56 /*
57  @section setup How to Install a sample program
58  After installing, user can execute the sample program without building the sources and installing Qt & Visual Studio.
59  1. Download 'Setup.zip' file from the directory, 'Setup' - setup.exe & Setup.msi
60  2. Upzip the zip file.
61  3. Execute 'setup.exe'.
62  4. Then, the setup process installs a sample program.
63  5. User can specify the position that the program is installed.
64  6. After finishing the installation, user can find an execution file, 'HologramDepthmap.exe' under the installed directory.
65  7. To reinstall the program, first remove the installed program using control panel.
66 */
67 
80 #ifndef __Hologram_Generator_h
81 #define __Hologram_Generator_h
82 
83 #include <graphics/vec.h>
84 #include <graphics/complex.h>
85 #include <QtCore/QDir>
86 #include <QtCore/QFile>
87 #include <QtGui/QImage>
88 #include <QtWidgets/qmessagebox.h>
89 #include <vector>
90 #include <cufft.h>
91 #include "Hologram/fftw3.h"
92 
93 using namespace graphics;
94 
101 
102  double field_lens;
103  double lambda;
104  double k;
108 
109  double near_depthmap;
110  double far_depthmap;
111 
113 
119  std::vector<int> render_depth;
120 };
121 
131 
132 public:
133 
136 
137  void setMode(bool isCPU);
138 
140  bool readConfig();
141 
143  void initialize();
144 
146  void GenerateHologram();
147 
149  void ReconstructImage();
150 
151  //void writeMatFileComplex(const char* fileName, Complex* val);
152  //void writeMatFileDouble(const char* fileName, double * val);
153  //bool readMatFileDouble(const char* fileName, double * val);
154 
155 private:
156 
159  void init_CPU();
160  void init_GPU();
165  bool ReadImageDepth(int ftr);
166  bool prepare_inputdata_CPU(uchar* img, uchar* dimg);
167  bool prepare_inputdata_GPU(uchar* img, uchar* dimg);
172  void GetDepthValues();
173  void change_depth_quan_CPU();
174  void change_depth_quan_GPU();
179  void TransformViewingWindow();
184  void Calc_Holo_by_Depth(int frame);
185  void Calc_Holo_CPU(int frame);
186  void Calc_Holo_GPU(int frame);
187  void Propagation_AngularSpectrum_CPU(Complex* input_u, double propagation_dist);
188  void Propagation_AngularSpectrum_GPU(cufftDoubleComplex* input_u, double propagation_dist);
193  void Encoding_Symmetrization(ivec2 sig_location);
194  void encoding_CPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
195  void encoding_GPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
200  void Write_Result_image(int ftr);
203  void get_rand_phase_value(Complex& rand_phase_val);
204  void get_shift_phase_value(Complex& shift_phase_val, int idx, ivec2 sig_location);
205 
206  void fftwShift(Complex* src, Complex* dst, fftw_complex* in, fftw_complex* out, int nx, int ny, int type, bool bNomalized = false);
207  void exponent_complex(Complex* val);
208  void fftShift(int nx, int ny, Complex* input, Complex* output);
209 
210  //void writeIntensity_gray8_bmp(const char* fileName, int nx, int ny, double* intensity);
211  //void writeIntensity_gray8_bmp(const char* fileName, int nx, int ny, Complex* complexvalue);
212  //void writeIntensity_gray8_real_bmp(const char* fileName, int nx, int ny, Complex* complexvalue);
213  //void writeImage_fromGPU(QString imgname, int pnx, int pny, cufftDoubleComplex* gpu_data);
214 
217  void Reconstruction(fftw_complex* in, fftw_complex* out);
218  void Test_Propagation_to_Eye_Pupil(fftw_complex* in, fftw_complex* out);
219  void Write_Simulation_image(int num, double val);
220  void circshift(Complex* in, Complex* out, int shift_x, int shift_y, int nx, int ny);
223 private:
224 
225  bool isCPU_;
226 
227  unsigned char* img_src_gpu_;
228  unsigned char* dimg_src_gpu_;
230 
231  double* img_src_;
232  double* dmap_src_;
233  double* depth_index_;
234  int* alpha_map_;
235 
236  double* dmap_;
237 
238  double dstep_;
239  std::vector<double> dlevel_;
240  std::vector<double> dlevel_transform_;
241 
243  double* u255_fringe_;
244 
246 
247  std::string SOURCE_FOLDER;
248  std::string IMAGE_PREFIX;
249  std::string DEPTH_PREFIX;
250  std::string RESULT_FOLDER;
251  std::string RESULT_PREFIX;
256 
260 
261  double WAVELENGTH;
262 
267 
268  // for Simulation (reconstruction)
269  //===================================================
274  double f_field_;
275  double eye_length_;
279  int sim_type_;
280  double sim_from_;
281  double sim_to_;
283  double* sim_final_;
285 
286 };
287 
288 
289 #endif
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.
structure for 2-dimensional real type vector and its arithmetic.
Definition: vec.h:22
double dstep_
the physical increment of each depth map layer.
uint num_of_depth
the number of depth level.
unsigned char * dimg_src_gpu_
GPU variable - depth map data, values are from 0 to 255.
double * depth_index_
CPU variable - quantized depth map data.
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 k
2 * PI / lambda
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.
bool FLAG_STATIC_IMAGE
if true, the input image is static.
int * alpha_map_
CPU variable - calculated alpha map data, values are 0 or 1.
std::string DEPTH_PREFIX
the prefix of the deptmap file - config file
double far_depthmap
FAR_OF_DEPTH_MAP at config file.
double focus_distance_
reconstruction variable for testing
uint START_OF_FRAME_NUMBERING
the start frame number.
Structure variable for hologram paramemters.
unsigned char * img_src_gpu_
GPU variable - image source data, values are from 0 to 255.
std::vector< double > dlevel_
the physical value of all depth map layer.
int Propagation_Method_
propagation method - currently AngularSpectrum
double lambda
WAVELENGTH at config file.
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:14
ivec2 pn
SLM_PIXEL_NUMBER_X & SLM_PIXEL_NUMBER_Y.
double WAVELENGTH
wave length
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
double eye_length_
reconstruction variable for testing
std::string SOURCE_FOLDER
input source folder - config file.
uint NUMBER_OF_DIGIT_OF_FRAME_NUMBERING
the number of digit of frame number.
int test_pixel_number_scale_
reconstruction variable for testing
int Encoding_Method_
encoding method - currently Symmetrization
double f_field_
reconstruction variable for testing
class for the complex number and its arithmetic.
Definition: complex.h:22
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.
vec2 Pixel_pitch_xy_
reconstruction variable for testing
double * dmap_src_
CPU variable - depth map data, values are from 0 to 1.
double eye_pupil_diameter_
reconstruction variable for testing
bool RANDOM_PHASE
If true, random phase is imposed on each depth layer.
bool isCPU_
if true, it is implemented on the CPU, otherwise on the GPU.
std::vector< double > dlevel_transform_
transfomed dlevel_ variable
Main class for generating a hologram using depth map data.
std::string RESULT_FOLDER
the name of the result folder - config file
double near_depthmap
NEAR_OF_DEPTH_MAP at config file.
uint NUMBER_OF_DEPTH_QUANTIZATION
depth level of input depthmap.
HologramParams params_
structure variable for hologram parameters
int Transform_Method_
transform method
std::string IMAGE_PREFIX
the prefix of the input image file - config file.
double * depth_index_gpu_
GPU variable - quantized depth map data.
uint NUMBER_OF_FRAME
the total number of the frame.