7 #include <QtScript/QScriptEngine> 8 #include <QtCore/QRegularExpression> 67 std::string inputFileName_ =
"config_openholo.txt";
69 LOG(
"Reading....%s\n", inputFileName_.c_str());
71 std::ifstream inFile(inputFileName_.c_str());
73 if (!inFile.is_open()){
74 LOG(
"file not found.\n");
80 getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n');
81 getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n');
82 getline(inFile, temp,
'\n');
95 getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n');
102 getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n');
105 inFile >>
WAVELENGTH; getline(inFile, temp,
'\n');
111 QScriptValue result = en.evaluate(QString().fromStdString(temp));
112 if (en.hasUncaughtException()) {
113 LOG(
"Error: SLM_PIXEL_NUMBER_X \n");
118 getline(inFile, temp,
'\n');
121 result = en.evaluate(QString().fromStdString(temp));
122 if (en.hasUncaughtException()) {
123 LOG(
"Error: SLM_PIXEL_NUMBER_Y \n");
128 getline(inFile, temp,
'\n');
131 result = en.evaluate(QString().fromStdString(temp));
132 if (en.hasUncaughtException()) {
133 LOG(
"Error: SLM_PIXEL_PITCH_X \n");
137 getline(inFile, temp,
'\n');
140 result = en.evaluate(QString().fromStdString(temp));
141 if (en.hasUncaughtException()) {
142 LOG(
"Error: SLM_PIXEL_PITCH_Y \n");
146 getline(inFile, temp,
'\n');
152 getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n');
154 double NEAR_OF_DEPTH_MAP, FAR_OF_DEPTH_MAP;
155 inFile >> NEAR_OF_DEPTH_MAP; getline(inFile, temp,
'\n');
156 inFile >> FAR_OF_DEPTH_MAP; getline(inFile, temp,
'\n');
165 if (FLAG_CHANGE_DEPTH_QUANTIZATION == 0)
170 getline(inFile, temp,
'\n');
171 QString src = QString().fromStdString(temp);
172 src = src.left(src.indexOf(
"//")).trimmed();
174 QRegularExpressionMatch match;
175 if (src.contains(
":"))
177 QRegularExpression re1(
"(\\d+):(\\d+)");
178 match = re1.match(src);
179 if (match.hasMatch()) {
180 int start = match.captured(1).toInt();
181 int end = match.captured(2).toInt();
183 for (
int k = start; k <= end; k++)
188 QRegularExpression re2(
"(\\d+)");
189 QRegularExpressionMatchIterator i = re2.globalMatch(src);
191 while (i.hasNext()) {
192 int num = i.next().captured(1).toInt();
197 LOG(
"Error: RENDER_DEPTH \n");
204 getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n');
208 inFile >>
eye_length_; getline(inFile, temp,
'\n');
211 inFile >> eye_center_xy_[1]; getline(inFile, temp,
'\n');
214 getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n');
215 getline(inFile, temp,
'\n'); getline(inFile, temp,
'\n');
217 inFile >>
sim_type_; getline(inFile, temp,
'\n');
218 inFile >>
sim_from_; getline(inFile, temp,
'\n');
219 inFile >>
sim_to_; getline(inFile, temp,
'\n');
269 for (
int ftr = 0; ftr <= num_of_frame - 1; ftr++)
271 LOG(
"Calculating hologram of frame %d.\n", ftr);
274 LOG(
"Error: Reading image of frame %d.\n", ftr);
318 QString sdir =
"./" + src_folder;
322 LOG(
"Error: Source folder does not exist: %s.\n", sdir.toStdString().c_str());
328 dir.setNameFilters(nlist);
329 dir.setFilter(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
330 QStringList names = dir.entryList();
332 LOG(
"Error: Source image does not exist.\n");
336 QString imgfullname = sdir +
"/" + names[0];
338 img.load(imgfullname);
339 img = img.convertToFormat(QImage::Format_Grayscale8);
340 LOG(
"Image Load: %s\n", imgfullname.toStdString().c_str());
345 dir.setNameFilters(nlist);
346 dir.setFilter(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
347 names = dir.entryList();
349 LOG(
"Error: Source depthmap does not exist.\n");
353 QString dimgfullname = sdir +
"/" + names[0];
355 dimg.load(dimgfullname);
356 dimg = dimg.convertToFormat(QImage::Format_Grayscale8);
362 QSize imgsize = img.size();
363 if (imgsize.width() != pnx || imgsize.height() != pny)
364 img = img.scaled(pnx, pny);
366 QSize dimgsize = dimg.size();
367 if (dimgsize.width() != pnx || dimgsize.height() != pny)
368 dimg = dimg.scaled(pnx, pny);
430 for (
int p = 0; p <
dlevel_.size(); p++)
461 std::default_random_engine generator;
462 std::uniform_real_distribution<double> distribution(0.0, 1.0);
464 rand_phase_val.
a = 0.0;
465 rand_phase_val.
b = 2 *
PI * distribution(generator);
469 rand_phase_val.
a = 1.0;
470 rand_phase_val.
b = 0.0;
486 int cropx1, cropx2, cropx, cropy1, cropy2, cropy;
487 if (sig_location[1] == 0)
494 cropy = floor(pny / 2);
495 cropy1 = cropy - floor(cropy / 2);
496 cropy2 = cropy1 + cropy - 1;
499 if (sig_location[0] == 0)
506 cropx = floor(pnx / 2);
507 cropx1 = cropx - floor(cropx / 2);
508 cropx2 = cropx1 + cropx - 1;
517 encoding_CPU(cropx1, cropx2, cropy1, cropy2, sig_location);
519 encoding_GPU(cropx1, cropx2, cropy1, cropy2, sig_location);
534 QString fname =
"./" + QString().fromStdString(
RESULT_FOLDER) +
"/" 535 + QString().fromStdString(
RESULT_PREFIX) + QString().setNum(ftr) +
".bmp";
542 double min_val, max_val;
545 for (
int i = 0; i < pnx*pny; ++i)
553 uchar* data = (uchar*)malloc(
sizeof(uchar)*pnx*pny);
554 memset(data, 0,
sizeof(uchar)*pnx*pny);
557 #pragma omp parallel for private(x) 558 for (x = 0; x < pnx*pny; ++x)
559 data[x] = (uint)((
u255_fringe_[x] - min_val) / (max_val - min_val) * 255);
561 QImage img(data, px, py, QImage::Format::Format_RGB888);
562 img.save(QString(fname));
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.
void Write_Result_image(int ftr)
Write the result image.
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.
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.
void TransformViewingWindow()
Transform target object to reflect the system configuration of holographic display.
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.
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.
void exponent_complex(Complex *val)
Calculate the exponential of the complex number.
double focus_distance_
reconstruction variable for testing
uint START_OF_FRAME_NUMBERING
the start frame number.
HologramGenerator()
Constructor.
void Encoding_Symmetrization(ivec2 sig_location)
Encode the CGH according to a signal location parameter.
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
bool prepare_inputdata_GPU(uchar *img, uchar *dimg)
Copy input image & depth map data into a GPU.
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 Calc_Holo_GPU(int frame)
Main method for generating a hologram on the GPU.
double WAVELENGTH
wave length
std::string Simulation_Result_File_Prefix_
reconstruction variable for testing
~HologramGenerator()
Destructor.
std::vector< int > render_depth
Used when only few specific depth levels are rendered, usually for test purpose.
void GenerateHologram()
Generate a hologram, main funtion.
double field_lens
FIELD_LENS at config file.
void GetDepthValues()
Calculate the physical distances of depth map layers.
void Calc_Holo_by_Depth(int frame)
Generate a hologram.
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.
void initialize()
Initialize variables for CPU and GPU implementation.
int test_pixel_number_scale_
reconstruction variable for testing
int Encoding_Method_
encoding method - currently Symmetrization
void init_GPU()
Initialize variables for the GPU implementation.
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.
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.
void init_CPU()
Initialize variables for the CPU implementation.
bool readConfig()
Read parameters from a config file(config_openholo.txt).
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 ReadImageDepth(int ftr)
Read image and depth map.
bool isCPU_
if true, it is implemented on the CPU, otherwise on the GPU.
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 encoding_GPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location)
Encode the CGH according to a signal location parameter on GPU.
void change_depth_quan_GPU()
Quantize depth map on the GPU, when the number of depth quantization is not the default value (i...
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.
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.
void setMode(bool isCPU)
Set the value of a variable isCPU_(true or false)
uint NUMBER_OF_FRAME
the total number of the frame.