HologramDepthmap Library
HologramGenerator.cpp
Go to the documentation of this file.
1 
3 #include <fstream>
4 #include <sstream>
5 #include <random>
6 #include "graphics/sys.h"
7 #include <QtScript/QScriptEngine>
8 #include <QtCore/QRegularExpression>
9 //#include "matlab/mat.h"
10 
16 {
17  isCPU_ = true;
18 
19  // GPU Variables
20  img_src_gpu_ = 0;
21  dimg_src_gpu_ = 0;
22  depth_index_gpu_ = 0;
23 
24  // CPU Variables
25  img_src_ = 0;
26  dmap_src_ = 0;
27  alpha_map_ = 0;
28  depth_index_ = 0;
29  dmap_ = 0;
30  dstep_ = 0;
31  dlevel_.clear();
32  U_complex_ = 0;
33  u255_fringe_ = 0;
34 
35  sim_final_ = 0;
36  hh_complex_ = 0;
37 
38 }
39 
44 {
45 }
46 
56 void HologramGenerator::setMode(bool isCPU)
57 {
58  isCPU_ = isCPU;
59 }
60 
66 {
67  std::string inputFileName_ = "config_openholo.txt";
68 
69  LOG("Reading....%s\n", inputFileName_.c_str());
70 
71  std::ifstream inFile(inputFileName_.c_str());
72 
73  if (!inFile.is_open()){
74  LOG("file not found.\n");
75  return false;
76  }
77 
78  // skip 7 lines
79  std::string temp;
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');
83 
84  inFile >> SOURCE_FOLDER; getline(inFile, temp, '\n');
85  inFile >> IMAGE_PREFIX; getline(inFile, temp, '\n');
86  inFile >> DEPTH_PREFIX; getline(inFile, temp, '\n');
87  inFile >> RESULT_FOLDER; getline(inFile, temp, '\n');
88  inFile >> RESULT_PREFIX; getline(inFile, temp, '\n');
89  inFile >> FLAG_STATIC_IMAGE; getline(inFile, temp, '\n');
90  inFile >> START_OF_FRAME_NUMBERING; getline(inFile, temp, '\n');
91  inFile >> NUMBER_OF_FRAME; getline(inFile, temp, '\n');
92  inFile >> NUMBER_OF_DIGIT_OF_FRAME_NUMBERING; getline(inFile, temp, '\n');
93 
94  // skip 3 lines
95  getline(inFile, temp, '\n'); getline(inFile, temp, '\n'); getline(inFile, temp, '\n');
96 
97  inFile >> Transform_Method_; getline(inFile, temp, '\n');
98  inFile >> Propagation_Method_; getline(inFile, temp, '\n');
99  inFile >> Encoding_Method_; getline(inFile, temp, '\n');
100 
101  // skip 3 lines
102  getline(inFile, temp, '\n'); getline(inFile, temp, '\n'); getline(inFile, temp, '\n');
103 
104  inFile >> params_.field_lens; getline(inFile, temp, '\n');
105  inFile >> WAVELENGTH; getline(inFile, temp, '\n');
107  params_.k = 2 * PI / WAVELENGTH;
108 
109  inFile >> temp;
110  QScriptEngine en;
111  QScriptValue result = en.evaluate(QString().fromStdString(temp));
112  if (en.hasUncaughtException()) {
113  LOG("Error: SLM_PIXEL_NUMBER_X \n");
114  return false;
115  }
116 
117  params_.pn[0] = result.toNumber();
118  getline(inFile, temp, '\n');
119 
120  inFile >> temp;
121  result = en.evaluate(QString().fromStdString(temp));
122  if (en.hasUncaughtException()) {
123  LOG("Error: SLM_PIXEL_NUMBER_Y \n");
124  return false;
125  }
126 
127  params_.pn[1] = result.toNumber();
128  getline(inFile, temp, '\n');
129 
130  inFile >> temp;
131  result = en.evaluate(QString().fromStdString(temp));
132  if (en.hasUncaughtException()) {
133  LOG("Error: SLM_PIXEL_PITCH_X \n");
134  return false;
135  }
136  params_.pp[0] = result.toNumber();
137  getline(inFile, temp, '\n');
138 
139  inFile >> temp;
140  result = en.evaluate(QString().fromStdString(temp));
141  if (en.hasUncaughtException()) {
142  LOG("Error: SLM_PIXEL_PITCH_Y \n");
143  return false;
144  }
145  params_.pp[1] = result.toNumber();
146  getline(inFile, temp, '\n');
147 
148  params_.ss[0] = params_.pp[0] * params_.pn[0];
149  params_.ss[1] = params_.pp[1] * params_.pn[1];
150 
151  // skip 3 lines
152  getline(inFile, temp, '\n'); getline(inFile, temp, '\n'); getline(inFile, temp, '\n');
153 
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');
157 
158  params_.near_depthmap = min(NEAR_OF_DEPTH_MAP, FAR_OF_DEPTH_MAP);
159  params_.far_depthmap = max(NEAR_OF_DEPTH_MAP, FAR_OF_DEPTH_MAP);
160 
161  inFile >> FLAG_CHANGE_DEPTH_QUANTIZATION; getline(inFile, temp, '\n');
162  inFile >> DEFAULT_DEPTH_QUANTIZATION; getline(inFile, temp, '\n');
163  inFile >> NUMBER_OF_DEPTH_QUANTIZATION; getline(inFile, temp, '\n');
164 
165  if (FLAG_CHANGE_DEPTH_QUANTIZATION == 0)
167  else
169 
170  getline(inFile, temp, '\n');
171  QString src = QString().fromStdString(temp);
172  src = src.left(src.indexOf("//")).trimmed();
173 
174  QRegularExpressionMatch match;
175  if (src.contains(":"))
176  {
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();
182  params_.render_depth.clear();
183  for (int k = start; k <= end; k++)
184  params_.render_depth.push_back(k);
185  }
186  }else {
187 
188  QRegularExpression re2("(\\d+)");
189  QRegularExpressionMatchIterator i = re2.globalMatch(src);
190  params_.render_depth.clear();
191  while (i.hasNext()) {
192  int num = i.next().captured(1).toInt();
193  params_.render_depth.push_back(num);
194  }
195  }
196  if (params_.render_depth.empty()){
197  LOG("Error: RENDER_DEPTH \n");
198  return false;
199  }
200 
201  inFile >> RANDOM_PHASE; getline(inFile, temp, '\n');
202 
203  //==Simulation parameters ======================================================================
204  getline(inFile, temp, '\n'); getline(inFile, temp, '\n'); getline(inFile, temp, '\n');
205 
206  inFile >> Simulation_Result_File_Prefix_; getline(inFile, temp, '\n');
207  inFile >> test_pixel_number_scale_; getline(inFile, temp, '\n');
208  inFile >> eye_length_; getline(inFile, temp, '\n');
209  inFile >> eye_pupil_diameter_; getline(inFile, temp, '\n');
210  inFile >> eye_center_xy_[0]; getline(inFile, temp, '\n');
211  inFile >> eye_center_xy_[1]; getline(inFile, temp, '\n');
212  inFile >> focus_distance_; getline(inFile, temp, '\n');
213 
214  getline(inFile, temp, '\n'); getline(inFile, temp, '\n'); getline(inFile, temp, '\n');
215  getline(inFile, temp, '\n'); getline(inFile, temp, '\n');
216 
217  inFile >> sim_type_; getline(inFile, temp, '\n');
218  inFile >> sim_from_; getline(inFile, temp, '\n');
219  inFile >> sim_to_; getline(inFile, temp, '\n');
220  inFile >> sim_step_num_; getline(inFile, temp, '\n');
221 
222  //=====================================================================================
223  inFile.close();
224 
225  LOG("done\n");
226 
227  return true;
228 
229 }
230 
236 {
237  dstep_ = 0;
238  dlevel_.clear();
239 
240  if (u255_fringe_) free(u255_fringe_);
241  u255_fringe_ = (double*)malloc(sizeof(double) * params_.pn[0] * params_.pn[1]);
242 
243  if (isCPU_)
244  init_CPU();
245  else
246  init_GPU();
247 }
248 
262 {
263  int num_of_frame;
264  if (FLAG_STATIC_IMAGE == 0)
265  num_of_frame = NUMBER_OF_FRAME;
266  else
267  num_of_frame = 1;
268 
269  for (int ftr = 0; ftr <= num_of_frame - 1; ftr++)
270  {
271  LOG("Calculating hologram of frame %d.\n", ftr);
272 
273  if (!ReadImageDepth(ftr)) {
274  LOG("Error: Reading image of frame %d.\n", ftr);
275  continue;
276  }
277 
278  GetDepthValues();
279 
280  if (Transform_Method_ == 0)
282 
283  Calc_Holo_by_Depth(ftr);
284 
285  if (Encoding_Method_ == 0)
287 
288  Write_Result_image(ftr);
289 
290  //writeMatFileDouble("u255_fringe", u255_fringe_);
291  //writeMatFileComplex("U_complex", U_complex_);
292  }
293 
294 }
295 
305 {
306  QString src_folder;
307  if (FLAG_STATIC_IMAGE == 0)
308  {
310  src_folder = QString().fromStdString(SOURCE_FOLDER) + "/" + QString("%1").arg((uint)(ftr + START_OF_FRAME_NUMBERING), (int)NUMBER_OF_DIGIT_OF_FRAME_NUMBERING, 10, (QChar)'0');
311  else
312  src_folder = QString().fromStdString(SOURCE_FOLDER) + "/" + QString().setNum(ftr + START_OF_FRAME_NUMBERING);
313 
314  }else
315  src_folder = QString().fromStdString(SOURCE_FOLDER);
316 
317 
318  QString sdir = "./" + src_folder;
319  QDir dir(sdir);
320  if (!dir.exists())
321  {
322  LOG("Error: Source folder does not exist: %s.\n", sdir.toStdString().c_str());
323  return false;
324  }
325 
326  QStringList nlist;
327  nlist << QString().fromStdString(IMAGE_PREFIX) + "*.*";
328  dir.setNameFilters(nlist);
329  dir.setFilter(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
330  QStringList names = dir.entryList();
331  if (names.empty()) {
332  LOG("Error: Source image does not exist.\n");
333  return false;
334  }
335 
336  QString imgfullname = sdir + "/" + names[0];
337  QImage img;
338  img.load(imgfullname);
339  img = img.convertToFormat(QImage::Format_Grayscale8);
340  LOG("Image Load: %s\n", imgfullname.toStdString().c_str());
341 
342  nlist.clear();
343  names.clear();
344  nlist << QString().fromStdString(DEPTH_PREFIX) + "*.*";
345  dir.setNameFilters(nlist);
346  dir.setFilter(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
347  names = dir.entryList();
348  if (names.empty()) {
349  LOG("Error: Source depthmap does not exist.\n");
350  return false;
351  }
352 
353  QString dimgfullname = sdir + "/" + names[0];
354  QImage dimg;
355  dimg.load(dimgfullname);
356  dimg = dimg.convertToFormat(QImage::Format_Grayscale8);
357 
358  //resize image
359  int pnx = params_.pn[0];
360  int pny = params_.pn[1];
361 
362  QSize imgsize = img.size();
363  if (imgsize.width() != pnx || imgsize.height() != pny)
364  img = img.scaled(pnx, pny);
365 
366  QSize dimgsize = dimg.size();
367  if (dimgsize.width() != pnx || dimgsize.height() != pny)
368  dimg = dimg.scaled(pnx, pny);
369 
370  int ret;
371  if (isCPU_)
372  ret = prepare_inputdata_CPU(img.bits(), dimg.bits());
373  else
374  ret = prepare_inputdata_GPU(img.bits(), dimg.bits());
375 
376  //writeIntensity_gray8_bmp("test.bmp", pnx, pny, dmap_src_);
377  //writeIntensity_gray8_bmp("test2.bmp", pnx, pny, dmap_);
378  //dimg.save("test_dmap.bmp");
379  //img.save("test_img.bmp");
380 
381  return ret;
382 
383 }
384 
392 {
393  if (params_.num_of_depth > 1)
394  {
396  double val = params_.near_depthmap;
397  while (val <= params_.far_depthmap)
398  {
399  dlevel_.push_back(val);
400  val += dstep_;
401  }
402 
403  } else {
404 
407 
408  }
409 
411  {
412  if (isCPU_)
414  else
416  }
417 }
418 
424 {
425  int pnx = params_.pn[0];
426  int pny = params_.pn[1];
427 
428  double val;
429  dlevel_transform_.clear();
430  for (int p = 0; p < dlevel_.size(); p++)
431  {
432  val = -params_.field_lens * dlevel_[p] / (dlevel_[p] - params_.field_lens);
433  dlevel_transform_.push_back(val);
434  }
435 }
436 
443 {
444  if (isCPU_)
445  Calc_Holo_CPU(frame);
446  else
447  Calc_Holo_GPU(frame);
448 
449 }
450 
458 {
459  if (RANDOM_PHASE > 0)
460  {
461  std::default_random_engine generator;
462  std::uniform_real_distribution<double> distribution(0.0, 1.0);
463 
464  rand_phase_val.a = 0.0;
465  rand_phase_val.b = 2 * PI * distribution(generator);
466  exponent_complex(&rand_phase_val);
467 
468  } else {
469  rand_phase_val.a = 1.0;
470  rand_phase_val.b = 0.0;
471  }
472 
473 }
474 
482 {
483  int pnx = params_.pn[0];
484  int pny = params_.pn[1];
485 
486  int cropx1, cropx2, cropx, cropy1, cropy2, cropy;
487  if (sig_location[1] == 0) //Left or right half
488  {
489  cropy1 = 1;
490  cropy2 = pny;
491 
492  } else {
493 
494  cropy = floor(pny / 2);
495  cropy1 = cropy - floor(cropy / 2);
496  cropy2 = cropy1 + cropy - 1;
497  }
498 
499  if (sig_location[0] == 0) // Upper or lower half
500  {
501  cropx1 = 1;
502  cropx2 = pnx;
503 
504  } else {
505 
506  cropx = floor(pnx / 2);
507  cropx1 = cropx - floor(cropx / 2);
508  cropx2 = cropx1 + cropx - 1;
509  }
510 
511  cropx1 -= 1;
512  cropx2 -= 1;
513  cropy1 -= 1;
514  cropy2 -= 1;
515 
516  if (isCPU_)
517  encoding_CPU(cropx1, cropx2, cropy1, cropy2, sig_location);
518  else
519  encoding_GPU(cropx1, cropx2, cropy1, cropy2, sig_location);
520 
521 
522 }
523 
529 {
530  QDir dir("./");
531  if (!dir.exists(QString().fromStdString(RESULT_FOLDER)))
532  dir.mkdir(QString().fromStdString(RESULT_FOLDER));
533 
534  QString fname = "./" + QString().fromStdString(RESULT_FOLDER) + "/"
535  + QString().fromStdString(RESULT_PREFIX) + QString().setNum(ftr) + ".bmp";
536 
537  int pnx = params_.pn[0];
538  int pny = params_.pn[1];
539  int px = pnx / 3;
540  int py = pny;
541 
542  double min_val, max_val;
543  min_val = u255_fringe_[0];
544  max_val = u255_fringe_[0];
545  for (int i = 0; i < pnx*pny; ++i)
546  {
547  if (min_val > u255_fringe_[i])
548  min_val = u255_fringe_[i];
549  else if (max_val < u255_fringe_[i])
550  max_val = u255_fringe_[i];
551  }
552 
553  uchar* data = (uchar*)malloc(sizeof(uchar)*pnx*pny);
554  memset(data, 0, sizeof(uchar)*pnx*pny);
555 
556  int x = 0;
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);
560 
561  QImage img(data, px, py, QImage::Format::Format_RGB888);
562  img.save(QString(fname));
563 
564  free(data);
565 }
566 
567 /*
568 void HologramGenerator::writeIntensity_gray8_bmp(const char* fileName, int nx, int ny, double* intensity)
569 {
570  const int n = nx*ny;
571 
572  double min_val, max_val;
573  min_val = intensity[0];
574  max_val = intensity[0];
575 
576  for (int i = 0; i < n; ++i)
577  {
578  if (min_val > intensity[i])
579  min_val = intensity[i];
580  else if (max_val < intensity[i])
581  max_val = intensity[i];
582  }
583 
584  char fname[100];
585  strcpy(fname, fileName);
586  strcat(fname, ".bmp");
587 
588  //LOG("minval %f, max val %f\n", min_val, max_val);
589  unsigned char* cgh = (unsigned char*)malloc(sizeof(unsigned char)*n);
590 
591  for (int i = 0; i < n; ++i){
592  double val = 255 * ((intensity[i] - min_val) / (max_val - min_val));
593  cgh[i] = val;
594  }
595 
596  QImage img(cgh, nx, ny, QImage::Format::Format_Grayscale8);
597  img.save(QString(fname));
598 
599  free(cgh);
600 }
601 
602 void HologramGenerator::writeIntensity_gray8_bmp(const char* fileName, int nx, int ny, Complex* complexvalue)
603 {
604  const int n = nx*ny;
605 
606  double* intensity = (double*)malloc(sizeof(double)*n);
607  for (int i = 0; i < n; i++)
608  intensity[i] = complexvalue[i].a;
609  //intensity[i] = complexvalue[i].mag2();
610 
611  double min_val, max_val;
612  min_val = intensity[0];
613  max_val = intensity[0];
614 
615  for (int i = 0; i < n; ++i)
616  {
617  if (min_val > intensity[i])
618  min_val = intensity[i];
619  else if (max_val < intensity[i])
620  max_val = intensity[i];
621  }
622 
623  char fname[100];
624  strcpy(fname, fileName);
625  strcat(fname, ".bmp");
626 
627  //LOG("minval %e, max val %e\n", min_val, max_val);
628 
629  unsigned char* cgh = (unsigned char*)malloc(sizeof(unsigned char)*n);
630 
631  for (int i = 0; i < n; ++i) {
632  double val = (intensity[i] - min_val) / (max_val - min_val);
633  //val = pow(val, 1.0 / 1.5);
634  val = val * 255.0;
635  unsigned char v = (uchar)val;
636 
637  cgh[i] = v;
638  }
639 
640  QImage img(cgh, nx, ny, QImage::Format::Format_Grayscale8);
641  img.save(QString(fname));
642 
643 
644  free(intensity);
645  free(cgh);
646 }
647 
648 void HologramGenerator::writeIntensity_gray8_real_bmp(const char* fileName, int nx, int ny, Complex* complexvalue)
649 {
650  const int n = nx*ny;
651 
652  double* intensity = (double*)malloc(sizeof(double)*n);
653  for (int i = 0; i < n; i++)
654  intensity[i] = complexvalue[i].a;
655 
656  double min_val, max_val;
657  min_val = intensity[0];
658  max_val = intensity[0];
659 
660  for (int i = 0; i < n; ++i)
661  {
662  if (min_val > intensity[i])
663  min_val = intensity[i];
664  else if (max_val < intensity[i])
665  max_val = intensity[i];
666  }
667 
668  char fname[100];
669  strcpy(fname, fileName);
670  strcat(fname, ".bmp");
671 
672  //LOG("minval %e, max val %e\n", min_val, max_val);
673 
674  unsigned char* cgh = (unsigned char*)malloc(sizeof(new unsigned char)*n);
675 
676  for (int i = 0; i < n; ++i) {
677  double val = (intensity[i] - min_val) / (max_val - min_val);
678  //val = pow(val, 1.0 / 1.5);
679  val = val * 255.0;
680  unsigned char v = (uchar)val;
681 
682  cgh[i] = v;
683  }
684 
685  QImage img(cgh, nx, ny, QImage::Format::Format_Grayscale8);
686  img.save(QString(fname));
687 
688  free(intensity);
689  free(cgh);
690 
691 }
692 */
693 
694 /*
695 bool HologramGenerator::readMatFileDouble(const char* fileName, double * val)
696 {
697  MATFile *pmat;
698  mxArray *parray;
699 
700  char fname[100];
701  strcpy(fname, fileName);
702 
703  pmat = matOpen(fname, "r");
704  if (pmat == NULL) {
705  OG("Error creating file %s\n", fname);
706  return false;
707  }
708 
709  //===============================================================
710  parray = matGetVariableInfo(pmat, "inputmat");
711 
712  if (parray == NULL) {
713  printf("Error reading existing matrix \n");
714  return false;
715  }
716 
717  int m = mxGetM(parray);
718  int n = mxGetN(parray);
719 
720  if (params_.pn[0] * params_.pn[1] != m*n)
721  {
722  printf("Error : different matrix dimension \n");
723  return false;
724  }
725 
726  double* dst_r;
727  parray = matGetVariable(pmat, "inputmat");
728  dst_r = val;
729 
730  double* CompRealPtr = mxGetPr(parray);
731 
732  for (int col = 0; col < n; col++)
733  {
734  for (int row = 0; row < m; row++)
735  {
736  dst_r[n*row + col] = *CompRealPtr++;
737  }
738  }
739 
740  // clean up
741  mxDestroyArray(parray);
742 
743  if (matClose(pmat) != 0) {
744  LOG("Error closing file %s\n", fname);
745  return false;
746  }
747 
748  LOG("Read Mat file %s\n", fname);
749  return true;
750 }
751 
752 void HologramGenerator::writeMatFileComplex(const char* fileName, Complex* val)
753 {
754  MATFile *pmat;
755  mxArray *pData;
756 
757  char fname[100];
758  strcpy(fname, fileName);
759  strcat(fname, ".mat");
760 
761  pmat = matOpen(fname, "w");
762  if (pmat == NULL) {
763  LOG("Error creating file %s\n", fname);
764  return;
765  }
766 
767  ivec2 pn = params_.pn;
768  int w = pn[0];
769  int h = pn[1];
770  const int n = w * h;
771 
772  pData = mxCreateDoubleMatrix(h, w, mxCOMPLEX);
773  if (pData == NULL) {
774  LOG("Unable to create mxArray.\n");
775  return;
776  }
777 
778  double* CompRealPtr = mxGetPr(pData);
779  double* CompImgPtr = mxGetPi(pData);
780 
781  for (int col = 0; col < w; col++)
782  {
783  //for (int row = h-1; row >= 0; row--)
784  for (int row = 0; row < h; row++)
785  {
786  *CompRealPtr++ = val[w*row + col].a;
787  *CompImgPtr++ = val[w*row + col].b;
788  }
789  }
790 
791  int status;
792  status = matPutVariable(pmat, "data", pData);
793 
794  if (status != 0) {
795  LOG("%s : Error using matPutVariable on line %d\n", __FILE__, __LINE__);
796  return;
797  }
798 
800  mxDestroyArray(pData);
801 
802  if (matClose(pmat) != 0) {
803  LOG("Error closing file %s\n", fname);
804  return;
805  }
806 
807  LOG("Write Mat file %s\n", fname);
808 
809 }
810 
811 void HologramGenerator::writeMatFileDouble(const char* fileName, double * val)
812 {
813  MATFile *pmat;
814  mxArray *pData;
815 
816  char fname[100];
817  strcpy(fname, fileName);
818  strcat(fname, ".mat");
819 
820  pmat = matOpen(fname, "w");
821  if (pmat == NULL) {
822  LOG("Error creating file %s\n", fname);
823  return;
824  }
825 
826  ivec2 pn = params_.pn;
827  int w = pn[0];
828  int h = pn[1];
829  const int n = w * h;
830 
831  pData = mxCreateDoubleMatrix(h, w, mxREAL);
832  if (pData == NULL) {
833  LOG("Unable to create mxArray.\n");
834  return;
835  }
836 
837  double* CompRealPtr = mxGetPr(pData);
838  for (int col = 0; col < w; col++)
839  {
840  //for (int row = h-1; row >= 0; row--)
841  for (int row = 0; row < h; row++)
842  *CompRealPtr++ = val[w*row + col];
843  }
844 
845  int status;
846  status = matPutVariable(pmat, "inputmat", pData);
847 
848  if (status != 0) {
849  LOG("%s : Error using matPutVariable on line %d\n", __FILE__, __LINE__);
850  return;
851  }
852 
854  mxDestroyArray(pData);
855 
856  if (matClose(pmat) != 0) {
857  LOG("Error closing file %s\n", fname);
858  return;
859  }
860 
861  LOG("Write Mat file %s\n", fname);
862 }
863 */
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.
double a
Definition: complex.h:145
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.
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.
Definition: ivec.h:14
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.
cudaEvent_t start
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
double b
Definition: complex.h:145
void init_GPU()
Initialize variables for the GPU implementation.
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.
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.
const double PI
Definition: complex.h:16
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.