Openholo  v1.0
Open Source Digital Holographic Library
ophDepthMap.cpp
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install, copy or use the software.
7 //
8 //
9 // License Agreement
10 // For Open Source Digital Holographic Library
11 //
12 // Openholo library is free software;
13 // you can redistribute it and/or modify it under the terms of the BSD 2-Clause license.
14 //
15 // Copyright (C) 2017-2024, Korea Electronics Technology Institute. All rights reserved.
16 // E-mail : contact.openholo@gmail.com
17 // Web : http://www.openholo.org
18 //
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 // 1. Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // 2. Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other materials provided with the distribution.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the copyright holder or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 // This software contains opensource software released under GNU Generic Public License,
41 // NVDIA Software License Agreement, or CUDA supplement to Software License Agreement.
42 // Check whether software you use contains licensed software.
43 //
44 //M*/
45 
46 #include "ophDepthMap.h"
47 
48 #include <windows.h>
49 #include <random>
50 #include <iomanip>
51 #include <io.h>
52 #include <direct.h>
53 #include "sys.h"
54 #include "tinyxml2.h"
55 #include "include.h"
56 
62  : ophGen()
63  , n_percent(0)
64 {
65  is_CPU = true;
66 
67  // GPU Variables
68  img_src_gpu = nullptr;
69  dimg_src_gpu = nullptr;
70  depth_index_gpu = nullptr;
71 
72  depth_img = nullptr;
73  rgb_img = nullptr;
74 
75  // CPU Variables
76  img_src = nullptr;
77  dmap_src = nullptr;
78  alpha_map = nullptr;
79  depth_index = nullptr;
80  dmap = 0;
81  dstep = 0;
82  dlevel.clear();
83  setViewingWindow(FALSE);
84 }
85 
90 {
91 }
92 
102 void ophDepthMap::setMode(bool isCPU)
103 {
104  is_CPU = isCPU;
105 }
106 
107 void ophDepthMap::setViewingWindow(bool is_ViewingWindow)
108 {
109  this->is_ViewingWindow = is_ViewingWindow;
110 }
115 bool ophDepthMap::readConfig(const char * fname)
116 {
117  if (!ophGen::readConfig(fname))
118  return false;
119 
120  LOG("Reading....%s...", fname);
121  auto start = CUR_TIME;
122  /*XML parsing*/
123 
124  using namespace tinyxml2;
125  tinyxml2::XMLDocument xml_doc;
126  XMLNode *xml_node = nullptr;
127 
128  if (!checkExtension(fname, ".xml"))
129  {
130  LOG("file's extension is not 'xml'\n");
131  return false;
132  }
133  auto ret = xml_doc.LoadFile(fname);
134  if (ret != XML_SUCCESS)
135  {
136  LOG("Failed to load file \"%s\"\n", fname);
137  return false;
138  }
139 
140  xml_node = xml_doc.FirstChild();
141  auto next = xml_node->FirstChildElement("FlagChangeDepthQuantization");
142  if (!next || XML_SUCCESS != next->QueryBoolText(&dm_config_.FLAG_CHANGE_DEPTH_QUANTIZATION))
143  return false;
144  next = xml_node->FirstChildElement("DefaultDepthQuantization");
145  if (!next || XML_SUCCESS != next->QueryUnsignedText(&dm_config_.DEFAULT_DEPTH_QUANTIZATION))
146  return false;
147  next = xml_node->FirstChildElement("NumberOfDepthQuantization");
148  if (!next || XML_SUCCESS != next->QueryUnsignedText(&dm_config_.NUMBER_OF_DEPTH_QUANTIZATION))
149  return false;
150  if (dm_config_.FLAG_CHANGE_DEPTH_QUANTIZATION == 0)
151  dm_config_.num_of_depth = dm_config_.DEFAULT_DEPTH_QUANTIZATION;
152  else
153  dm_config_.num_of_depth = dm_config_.NUMBER_OF_DEPTH_QUANTIZATION;
154 
155  string render_depth;
156  next = xml_node->FirstChildElement("RenderDepth");
157  if (!next || XML_SUCCESS != next->QueryBoolText(&dm_config_.FLAG_CHANGE_DEPTH_QUANTIZATION))
158  return false;
159  else render_depth = (xml_node->FirstChildElement("RenderDepth"))->GetText();
160 
161  size_t found = render_depth.find(':');
162  if (found != string::npos)
163  {
164  string s = render_depth.substr(0, found);
165  string e = render_depth.substr(found + 1);
166  int start = stoi(s);
167  int end = stoi(e);
168  dm_config_.render_depth.clear();
169  for (int k = start; k <= end; k++)
170  dm_config_.render_depth.push_back(k);
171  }
172  else
173  {
174  stringstream ss(render_depth);
175  int render;
176 
177  while (ss >> render)
178  dm_config_.render_depth.push_back(render);
179  }
180 
181  if (dm_config_.render_depth.empty()) {
182  LOG("not found Render Depth Parameter\n");
183  return false;
184  }
185 
186  next = xml_node->FirstChildElement("RandomPhase");
187  if (!next || XML_SUCCESS != next->QueryBoolText(&dm_config_.RANDOM_PHASE))
188  return false;
189  next = xml_node->FirstChildElement("FieldLength");
190  if (!next || XML_SUCCESS != next->QueryDoubleText(&dm_config_.fieldLength))
191  return false;
192  next = xml_node->FirstChildElement("NearOfDepth");
193  if (!next || XML_SUCCESS != next->QueryDoubleText(&dm_config_.near_depthmap))
194  return false;
195  next = xml_node->FirstChildElement("FarOfDepth");
196  if (!next || XML_SUCCESS != next->QueryDoubleText(&dm_config_.far_depthmap))
197  return false;
198 
199  auto end = CUR_TIME;
200  auto during = ((chrono::duration<Real>)(end - start)).count();
201  LOG("%lf (s)...done\n", during);
202 
203  initialize();
204  return true;
205 }
206 
215 bool ophDepthMap::readImageDepth(const char* source_folder, const char* img_prefix, const char* depth_img_prefix)
216 {
217  std::string sdir = source_folder;
218  sdir = sdir.append("\\").append(img_prefix).append("*.bmp");
219 
220  _finddatai64_t fd;
221  intptr_t handle;
222  handle = _findfirst64(sdir.c_str(), &fd);
223  if (handle == -1)
224  {
225  LOG("Error: Source image does not exist: %s.\n", sdir.c_str());
226  return false;
227  }
228 
229  std::string imgfullname;
230  imgfullname = std::string(source_folder).append("\\").append(fd.name);
231 
232  int w, h, bytesperpixel;
233  bool ret = getImgSize(w, h, bytesperpixel, imgfullname.c_str());
234 
235  oph::uchar* imgload = new uchar[w*h*bytesperpixel];
236  ret = loadAsImgUpSideDown(imgfullname.c_str(), imgload);
237  if (!ret) {
238  LOG("Failed::Image Load: %s\n", imgfullname.c_str());
239  return false;
240  }
241  LOG("Succeed::Image Load: %s\n", imgfullname.c_str());
242 
243  oph::uchar* img = new uchar[w*h];
244  convertToFormatGray8(imgload, img, w, h, bytesperpixel);
245 
246  delete[] imgload;
247 
248 
249  //=================================================================================
250  std::string sddir = std::string(source_folder).append("\\").append(depth_img_prefix).append("*.bmp");
251  handle = _findfirst64(sddir.c_str(), &fd);
252  if (handle == -1)
253  {
254  LOG("Error: Source depthmap does not exist: %s.\n", sddir);
255  return false;
256  }
257 
258  std::string dimgfullname = std::string(source_folder).append("\\").append(fd.name);
259 
260  int dw, dh, dbytesperpixel;
261  ret = getImgSize(dw, dh, dbytesperpixel, dimgfullname.c_str());
262 
263  uchar* dimgload = new uchar[dw*dh*dbytesperpixel];
264  ret = loadAsImgUpSideDown(dimgfullname.c_str(), dimgload);
265  if (!ret) {
266  LOG("Failed::Depth Image Load: %s\n", dimgfullname.c_str());
267  return false;
268  }
269  LOG("Succeed::Depth Image Load: %s\n", dimgfullname.c_str());
270 
271  // 2019-10-14 mwnam
272  m_vecDepthImg[_X] = dw;
273  m_vecDepthImg[_Y] = dh;
274 
275  uchar* dimg = new uchar[dw*dh];
276  convertToFormatGray8(dimgload, dimg, dw, dh, dbytesperpixel);
277 
278  delete[] dimgload;
279 
280  //resize image
281  int pnX = context_.pixel_number[_X];
282  int pnY = context_.pixel_number[_Y];
283 
284  if (rgb_img) delete[] rgb_img;
285 
286  rgb_img = new uchar[pnX*pnY];
287  memset(rgb_img, 0, sizeof(char)*pnX*pnY);
288 
289  if (w != pnX || h != pnY)
290  imgScaleBilnear(img, rgb_img, w, h, pnX, pnY);
291  else
292  memcpy(rgb_img, img, sizeof(char)*pnX*pnY);
293 
294  // 2019-10-14 mwnam
295  m_vecRGBImg[_X] = pnX;
296  m_vecRGBImg[_Y] = pnY;
297 
298  //ret = creatBitmapFile(newimg, pnX, pnY, 8, "stest");
299  if (depth_img) delete[] depth_img;
300 
301  depth_img = new uchar[pnX*pnY];
302  memset(depth_img, 0, sizeof(char)*pnX*pnY);
303 
304  if (dw != pnX || dh != pnY)
305  imgScaleBilnear(dimg, depth_img, dw, dh, pnX, pnY);
306  else
307  memcpy(depth_img, dimg, sizeof(char)*pnX*pnY);
308  // 2019-10-14 mwnam
309  m_vecDepthImg[_X] = pnX;
310  m_vecDepthImg[_Y] = pnY;
311 
312  delete[] img;
313  delete[] dimg;
314 
315  return true;
316 }
317 
319 {
320  resetBuffer();
321 
323  auto start_time = CUR_TIME;
324 
325  LOG("1) Algorithm Method : Depth Map\n");
326  LOG("2) Generate Hologram with %s\n", is_CPU ?
327 #ifdef _OPENMP
328  "Multi Core CPU" :
329 #else
330  "Single Core CPU" :
331 #endif
332  "GPU");
333  LOG("3) Transform Viewing Window : %s\n", is_ViewingWindow ? "ON" : "OFF");
334 
335  if (is_CPU) {
336  prepareInputdataCPU(rgb_img, depth_img);
337  getDepthValues();
338  if (is_ViewingWindow)
339  transVW();
340  calcHoloCPU();
341  }
342  else {
343  prepareInputdataGPU(rgb_img, depth_img);
344  getDepthValues();
345  if (is_ViewingWindow)
346  transVW();
347  calcHoloGPU();
348  }
349 
350  auto end_time = CUR_TIME;
351 
352  elapsedTime = ((std::chrono::duration<Real>)(end_time - start_time)).count();
353 
354  LOG("Total Elapsed Time: %lf (s)\n", elapsedTime);
355  n_percent = 0;
356  return elapsedTime;
357 }
358 
360 {
361  LOG("Single Side Band Encoding..");
362  encodeSideBand(is_CPU, ivec2(0, 1));
363  LOG("Done.\n.");
364 }
365 
367 {
368  ophGen::encoding(ENCODE_FLAG, nullptr, true);
369 }
370 
371 void ophDepthMap::encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND)
372 {
373  const uint pnX = context_.pixel_number[_X];
374  const uint pnY = context_.pixel_number[_Y];
375  const uint nChannel = context_.waveNum;
376  Complex<Real>* dst = new Complex<Real>[pnX * pnY];
377 
378  for (uint ch = 0; ch < nChannel; ch++) {
380  fftwShift(complex_H[ch], dst, pnX, pnY, OPH_BACKWARD);
381 
383  ivec2 location;
384  switch (SSB_PASSBAND) {
385  case SSB_TOP:
386  location = ivec2(0, 1);
387  break;
388  case SSB_BOTTOM:
389  location = ivec2(0, -1);
390  break;
391  case SSB_LEFT:
392  location = ivec2(-1, 0);
393  break;
394  case SSB_RIGHT:
395  location = ivec2(1, 0);
396  break;
397  }
398 
399  encodeSideBand(is_CPU, location);
400  }
402  }
403  delete[] dst;
404 }
405 
406 
411 void ophDepthMap::initialize()
412 {
413  dstep = 0;
414  dlevel.clear();
415 
417 
418  initCPU();
419  initGPU();
420 }
421 
428 void ophDepthMap::getDepthValues()
429 {
430  if (dm_config_.num_of_depth > 1)
431  {
432  dstep = (dm_config_.far_depthmap - dm_config_.near_depthmap) / (dm_config_.num_of_depth - 1);
433  Real val = dm_config_.near_depthmap;
434  while (val <= dm_config_.far_depthmap)
435  {
436  dlevel.push_back(val);
437  val += dstep;
438  }
439 
440  } else {
441 
442  dstep = (dm_config_.far_depthmap + dm_config_.near_depthmap) / 2;
443  dlevel.push_back(dm_config_.far_depthmap - dm_config_.near_depthmap);
444 
445  }
446 
447  if (dm_config_.FLAG_CHANGE_DEPTH_QUANTIZATION == 1)
448  {
449  if (is_CPU)
450  changeDepthQuanCPU();
451  else
452  changeDepthQuanGPU();
453  }
454 }
455 
460 void ophDepthMap::transVW()
461 {
462  Real val;
463  dlevel_transform.clear();
464  for (int p = 0; p < dlevel.size(); p++)
465  {
466  val = -dm_config_.fieldLength * dlevel[p] / (dlevel[p] - dm_config_.fieldLength);
467  dlevel_transform.push_back(val);
468  }
469 }
470 
471 
477 void ophDepthMap::initCPU()
478 {
479  const uint pnX = context_.pixel_number[_X];
480  const uint pnY = context_.pixel_number[_Y];
481  const uint pnXY = pnX * pnY;
482 
483  if (img_src) delete[] img_src;
484  img_src = new Real[pnXY];
485 
486  if (dmap_src) delete[] dmap_src;
487  dmap_src = new Real[pnXY];
488 
489  if (alpha_map) delete[] alpha_map;
490  alpha_map = new int[pnXY];
491 
492  if (depth_index) delete[] depth_index;
493  depth_index = new Real[pnXY];
494 
495  if (dmap) delete[] dmap;
496  dmap = new Real[pnXY];
497 
498  fftw_cleanup();
499 }
500 
509 bool ophDepthMap::prepareInputdataCPU(uchar* imgptr, uchar* dimgptr)
510 {
511 #ifdef CHECK_PROC_TIME
512  auto begin = CUR_TIME;
513 #endif
514  const int pnX = context_.pixel_number[_X];
515  const int pnY = context_.pixel_number[_Y];
516  const uint pnXY = pnX * pnY;
517 
518  memset(img_src, 0, sizeof(Real) * pnXY);
519  memset(dmap_src, 0, sizeof(Real) * pnXY);
520  memset(alpha_map, 0, sizeof(int) * pnXY);
521  memset(depth_index, 0, sizeof(Real) * pnXY);
522  memset(dmap, 0, sizeof(Real) * pnXY);
523 
524  int k = 0;
525 #ifdef _OPENMP
526 #pragma omp parallel
527  {
528  int tid = omp_get_thread_num();
529 #pragma omp for private(k)
530 #endif
531  for (k = 0; k < pnXY; k++) {
532  img_src[k] = Real(imgptr[k]) / 255.0; // RGB IMG
533  dmap_src[k] = Real(dimgptr[k]) / 255.0; // DEPTH IMG
534  alpha_map[k] = (imgptr[k] > 0 ? 1 : 0); // RGB IMG
535 
536  if (dm_config_.FLAG_CHANGE_DEPTH_QUANTIZATION == 0) {
537  depth_index[k] = dm_config_.DEFAULT_DEPTH_QUANTIZATION - Real(dimgptr[k]);
538  }
539  }
540 #ifdef _OPENMP
541  }
542 #endif
543 #ifdef CHECK_PROC_TIME
544  auto end = CUR_TIME;
545  LOG("\n%s : %lf(s)\n\n", __FUNCTION__, ((std::chrono::duration<Real>)(end - begin)).count());
546 #endif
547  return true;
548 }
549 
555 void ophDepthMap::changeDepthQuanCPU()
556 {
557 #ifdef CHECK_PROC_TIME
558  auto begin = CUR_TIME;
559 #endif
560  const uint pnX = context_.pixel_number[_X];
561  const uint pnY = context_.pixel_number[_Y];
562  const uint pnXY = pnX * pnY;
563 
564  Real temp_depth, d1, d2;
565  uint num_depth = dm_config_.num_of_depth;
566  Real near_depth = dm_config_.near_depthmap;
567  Real far_depth = dm_config_.far_depthmap;
568 
569  for (uint dtr = 0; dtr < num_depth; ++dtr) {
570  temp_depth = dlevel[dtr];
571  d1 = temp_depth - dstep / 2.0;
572  d2 = temp_depth + dstep / 2.0;
573 
574  int p;
575 #ifdef _OPENMP
576 #pragma omp parallel
577  {
578  int tid = omp_get_thread_num();
579 #pragma omp for private(p)
580 #endif
581  for (p = 0; p < pnXY; ++p) {
582  Real dmap = (1.0 - dmap_src[p])*(far_depth - near_depth) + near_depth;
583 
584  int tdepth;
585  if (dtr < num_depth - 1)
586  tdepth = (dmap >= d1 ? 1 : 0) * (dmap < d2 ? 1 : 0);
587  else
588  tdepth = (dmap >= d1 ? 1 : 0) * (dmap <= d2 ? 1 : 0);
589  depth_index[p] += tdepth * (dtr + 1);
590  }
591 #ifdef _OPENMP
592  }
593 #endif
594  }
595 #ifdef CHECK_PROC_TIME
596  auto end = CUR_TIME;
597  LOG("\n%s : %lf(s)\n\n", __FUNCTION__, ((std::chrono::duration<Real>)(end - begin)).count());
598 #endif
599  //writeIntensity_gray8_bmp("test.bmp", pnX, pnY, depth_index_);
600 }
601 
614 void ophDepthMap::calcHoloCPU()
615 {
616 #ifdef CHECK_PROC_TIME
617  auto begin = CUR_TIME;
618 #endif
619  const uint pnX = context_.pixel_number[_X];
620  const uint pnY = context_.pixel_number[_Y];
621  const uint pnXY = pnX * pnY;
622  const int nChannel = context_.waveNum;
623 
624  size_t depth_sz = dm_config_.render_depth.size();
625 
626  Complex<Real> *in = nullptr, *out = nullptr;
627  fft2(ivec2(pnX, pnY), in, OPH_FORWARD, OPH_ESTIMATE);
628  int p = 0;
629  int sum = 0;
630 
631  for (int ch = 0; ch < nChannel; ch++) {
632  Real lambda = context_.wave_length[ch];
633  Real k = context_.k = (2 * M_PI / lambda);
634 
635 #ifdef _OPENMP
636 #pragma omp parallel
637  {
638  int tid = omp_get_thread_num();
639 #pragma omp for private(p)
640 #endif
641  for (p = 0; p < depth_sz; ++p) {
642  int dtr = dm_config_.render_depth[p];
643 
644  Real temp_depth = (is_ViewingWindow) ? dlevel_transform[dtr - 1] : dlevel[dtr - 1];
645 
646  Complex<Real> *input = new Complex<Real>[pnXY];
647  memset(input, 0.0, sizeof(Complex<Real>) * pnXY);
648  //Complex<Real> *output = new Complex<Real>[pnXY];
649  //memset(output, 0.0, sizeof(Complex<Real>) * pnXY);
650 
651  Real locsum = 0.0;
652  for (int i = 0; i < pnXY; i++)
653  {
654  input[i][_RE] += img_src[i] * alpha_map[i] * (depth_index[i] == dtr ? 1.0 : 0.0);
655  locsum += input[i][_RE];
656  }
657 
658  if (locsum > 0.0)
659  {
660  //LOG("Depth: %d of %d, z = %f mm\n", dtr, dm_config_.num_of_depth, -temp_depth * 1000);
661  Complex<Real> rand_phase_val;
662  getRandPhaseValue(rand_phase_val, dm_config_.RANDOM_PHASE);
663 
664  Complex<Real> carrier_phase_delay(0, k * temp_depth);
665  carrier_phase_delay.exp();
666 
667  for (int i = 0; i < pnXY; i++)
668  input[i] = input[i] * rand_phase_val * carrier_phase_delay;
669 
670  Openholo::fftwShift(input, input, pnX, pnY, OPH_FORWARD, false);
671  propagationAngularSpectrum(ch, input, -temp_depth, k, lambda);
672  }
673  else {
674  //LOG("Depth: %d of %d : Nothing here\n", dtr, dm_config_.num_of_depth);
675  }
676  delete[] input;
677 
678 #pragma omp atomic
679  sum++;
680 
681  n_percent = (int)((Real)sum * 100 / ((Real)depth_sz * nChannel));
682  }
683 #ifdef _OPENMP
684  }
685 #endif
686 
687  LOG("\n%s (%d/%d) : %lf(s)\n\n", __FUNCTION__, ch+1, nChannel, ((std::chrono::duration<Real>)(CUR_TIME - begin)).count());
688  }
689 #ifdef CHECK_PROC_TIME
690  auto end = CUR_TIME;
691  LOG("\n%s : %lf(s)\n\n", __FUNCTION__, ((std::chrono::duration<Real>)(end - begin)).count());
692 #endif
693 }
694 
696 {
697  if(depth_img) delete[] depth_img;
698  if(rgb_img) delete[] rgb_img;
699 }
700 
701 void ophDepthMap::setResolution(ivec2 resolution)
702 {
703  // 해상도 변경이 있을 시, 버퍼를 재생성 한다.
704  if (context_.pixel_number != resolution) {
705  ophGen::setResolution(resolution);
706  initCPU();
707  initGPU();
708  }
709 }
#define OPH_BACKWARD
Definition: define.h:67
ENCODE_FLAG
Definition: ophGen.h:72
Real k
Definition: Openholo.h:66
void setViewingWindow(bool is_ViewingWindow)
Set the value of a variable is_ViewingWindow(true or false)
uint DEFAULT_DEPTH_QUANTIZATION
default value of the depth quantization - 256
Definition: ophGen.h:481
void setResolution(ivec2 resolution)
Function for setting buffer size.
Definition: ophGen.cpp:1289
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:465
bool RANDOM_PHASE
If true, random phase is imposed on each depth layer.
Definition: ophGen.h:485
Real * wave_length
Definition: Openholo.h:69
uint num_of_depth
Definition: ophGen.h:475
bool readImageDepth(const char *source_folder, const char *img_prefix, const char *depth_img_prefix)
Read image and depth map.
SSB_PASSBAND
Definition: ophGen.h:227
unsigned char uchar
Definition: typedef.h:64
float Real
Definition: typedef.h:55
void initialize(void)
Initialize variables for Hologram complex field, encoded data, normalized data.
Definition: ophGen.cpp:69
#define CUR_TIME
Definition: function.h:58
bool checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:80
#define OPH_ESTIMATE
Definition: define.h:76
bool FLAG_CHANGE_DEPTH_QUANTIZATION
if true, change the depth quantization from the default value.
Definition: ophGen.h:479
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:761
ophDepthMap()
Constructor.
Definition: ophDepthMap.cpp:61
void getRandPhaseValue(Complex< Real > &rand_phase_val, bool rand_phase)
Assign random phase value if RANDOM_PHASE == 1.
Definition: ophGen.cpp:1266
Real elapsedTime
Elapsed time of generate hologram.
Definition: ophGen.h:246
#define _Y
Definition: define.h:84
virtual ~ophDepthMap()
Destructor.
Definition: ophDepthMap.cpp:89
void encodeHologram(void)
void encodeSideBand(bool bCPU, ivec2 sig_location)
Encode the CGH according to a signal location parameter.
Definition: ophGen.cpp:976
#define _X
Definition: define.h:80
ivec2 encode_size
Encoded hologram size, varied from encoding type.
Definition: ophGen.h:240
Real near_depthmap
near value of depth in object
Definition: ophGen.h:467
bool readConfig(const char *fname)
Read parameters from a config file(config_openholo.txt).
bool getImgSize(int &w, int &h, int &bytesperpixel, const char *fname)
Function for getting the image size.
Definition: Openholo.cpp:315
oph::ivec2 pixel_number
Definition: Openholo.h:63
#define _RE
Definition: complex.h:54
void fft2(ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 2-dimension operations inside Openholo.
Definition: Openholo.cpp:416
void convertToFormatGray8(uchar *src, uchar *dst, int w, int h, int bytesperpixel)
Function for convert image format to gray8.
Definition: Openholo.cpp:367
Real far_depthmap
far value of depth in object
Definition: ophGen.h:469
void setResolution(ivec2 resolution)
uint waveNum
Definition: Openholo.h:68
void imgScaleBilnear(uchar *src, uchar *dst, int w, int h, int neww, int newh)
Function for change image size.
Definition: Openholo.cpp:340
bool readConfig(const char *fname)
load to configuration file.
Definition: ophGen.cpp:150
XMLError LoadFile(const char *filename)
Definition: tinyxml2.cpp:2157
void ophFree(void)
Pure virtual function for override in child classes.
Real generateHologram(void)
Generate a hologram, main funtion. When the calculation is finished, the angular spectrum is performe...
void encoding()
Definition: ophGen.cpp:525
void resetBuffer()
reset buffer
Definition: ophGen.cpp:363
void fftwShift(Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. ...
Definition: Openholo.cpp:530
void setMode(bool is_CPU)
Set the value of a variable is_CPU(true or false)
OphConfig context_
Definition: Openholo.h:297
#define OPH_FORWARD
Definition: define.h:66
Complex< Real > ** complex_H
Definition: Openholo.h:298
void propagationAngularSpectrum(int ch, Complex< Real > *input_u, Real propagation_dist, Real k, Real lambda)
Angular spectrum propagation method.
Definition: ophGen.cpp:218
vector< int > render_depth
Used when only few specific depth levels are rendered, usually for test purpose.
Definition: ophGen.h:477
Real sum(const vec2 &a)
Definition: vec.h:401
bool loadAsImgUpSideDown(const char *fname, uchar *dst)
Function for loading image files | Output image data upside down.
Definition: Openholo.cpp:274
const XMLElement * FirstChildElement(const char *name=0) const
Definition: tinyxml2.cpp:940
unsigned int uint
Definition: typedef.h:62
#define M_PI
Definition: define.h:52
Definition: ophGen.h:68