Openholo  v4.2
Open Source Digital Holographic Library
ophPAS.cpp
Go to the documentation of this file.
1 
2 #include "ophPAS.h"
3 #include <fstream>
4 #include <iostream>
5 #include <string>
6 #include <iomanip>
7 
8 #include "sys.h"
9 
10 #include "tinyxml2.h"
11 #include "PLYparser.h"
12 
14  : ophGen()
15  , n_points(-1)
16  , m_pHologram(nullptr)
17 {
18 }
19 
21 {
22  if (m_pHologram != nullptr)
23  delete[] m_pHologram;
24 }
25 
26 bool ophPAS::readConfig(const char* fname)
27 {
28  if (!ophGen::readConfig(fname))
29  return false;
30 
31  bool bRet = true;
32 
33  using namespace tinyxml2;
34  /*XML parsing*/
35  tinyxml2::XMLDocument xml_doc;
36  XMLNode *xml_node;
37 
38  if (!checkExtension(fname, ".xml"))
39  {
40  LOG("<FAILED> Wrong file ext.\n");
41  return false;
42  }
43  if (xml_doc.LoadFile(fname) != XML_SUCCESS)
44  {
45  LOG("<FAILED> Loading file.\n");
46  return false;
47  }
48  xml_node = xml_doc.FirstChild();
49 
50 
51  char szNodeName[32] = { 0, };
52  sprintf(szNodeName, "ScaleX");
53  // about point
54  auto next = xml_node->FirstChildElement(szNodeName);
55  if (!next || XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[_X]))
56  {
57  LOG("<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
58  bRet = false;
59  }
60  sprintf(szNodeName, "ScaleY");
61  next = xml_node->FirstChildElement(szNodeName);
62  if (!next || XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[_Y]))
63  {
64  LOG("<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
65  bRet = false;
66  }
67  sprintf(szNodeName, "ScaleZ");
68  next = xml_node->FirstChildElement(szNodeName);
69  if (!next || XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[_Z]))
70  {
71  LOG("<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
72  bRet = false;
73  }
74  sprintf(szNodeName, "Distance");
75  next = xml_node->FirstChildElement(szNodeName);
76  if (!next || XML_SUCCESS != next->QueryDoubleText(&pc_config.distance))
77  {
78  LOG("<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
79  bRet = false;
80  }
81 
82  initialize();
83 
84  LOG("**************************************************\n");
85  LOG(" Read Config (Phase-Added Stereogram) \n");
86  LOG("1) Focal Length : %.5lf\n", pc_config.distance);
87  LOG("2) Object Scale : %.5lf / %.5lf / %.5lf\n", pc_config.scale[_X], pc_config.scale[_Y], pc_config.scale[_Z]);
88  LOG("**************************************************\n");
89 
90  return bRet;
91 }
92 
93 int ophPAS::loadPoint(const char* _filename)
94 {
95  n_points = ophGen::loadPointCloud(_filename, &pc_data);
96  return n_points;
97 }
98 
100 {
101  if (m_pHologram == nullptr)
103  memset(m_pHologram, 0x00, sizeof(double)*getContext().pixel_number[_X] * getContext().pixel_number[_Y]);
104 
105 
106  for (int i = 0; i < NUMTBL; i++) {
107  float theta = (float)M2_PI * (float)(i + i - 1) / (float)(2 * NUMTBL);
108  m_COStbl[i] = (float)cos(theta);
109  m_SINtbl[i] = (float)sin(theta);
110 
111  }// -> gpu
112 
113 }
114 
115 
116 
117 void ophPAS::PASCalculation(long voxnum, unsigned char * cghfringe, OphPointCloudData *data, OphPointCloudConfig& conf) {
118  long i, j;
119 
120  double Max = -1E9, Min = 1E9;
121  double myBuffer;
122  int cghwidth = getContext().pixel_number[_X];
123  int cghheight = getContext().pixel_number[_Y];
124 
125 
126 
127  //DataInit(_CGHE);
128  init();
129 
130  //PAS
131  //
132  //PAS(voxnum, h_vox, m_pHologram, _CGHE);
133  PAS(voxnum, data, m_pHologram, conf);
134  //
135 
136  for (i = 0; i < cghheight; i++) {
137  for (j = 0; j < cghwidth; j++) {
138  if (Max < m_pHologram[i*cghwidth + j]) Max = m_pHologram[i*cghwidth + j];
139  if (Min > m_pHologram[i*cghwidth + j]) Min = m_pHologram[i*cghwidth + j];
140 
141  }
142  }
143 
144  for (i = 0; i < cghheight; i++) {
145  for (j = 0; j < cghwidth; j++) {
146  myBuffer = 1.0*(((m_pHologram[i*cghwidth + j] - Min) / (Max - Min))*255. + 0.5);
147  if (myBuffer >= 255.0) cghfringe[i*cghwidth + j] = 255;
148  else cghfringe[i*cghwidth + j] = (unsigned char)(myBuffer);
149 
150  }
151  }
152 
153 
154  delete[] m_pHologram;
155 
156 }
157 
158 /*
159 void ophPAS::PAS(long voxelnum, VoxelStruct * voxel, double * m_pHologram, CGHEnvironmentData* _CGHE)
160 {
161  float xiInterval = _CGHE->xiInterval;
162  float etaInterval = _CGHE->etaInterval;
163  float cghScale = _CGHE->CGHScale;
164  float defaultDepth = _CGHE->DefaultDepth;
165 
166  DataInit(_CGHE->fftSegmentationSize, _CGHE->CghWidth, _CGHE->CghHeight, xiInterval, etaInterval);
167 
168  int no; // voxel Number
169 
170 
171  float X, Y, Z; ; // x, y, real distance
172  float Amplitude;
173  float sf_base = 1.0 / (xiInterval*_CGHE->fftSegmentationSize);
174 
175 
176  //CString mm;
177  clock_t start, finish;
178  double duration;
179  start = clock();
180 
181  // Iteration according to the point number
182  for (no = 0; no<voxelnum; no++)
183  {
184  // point coordinate
185  X = (voxel[no].x) * cghScale;
186  Y = (voxel[no].y) * cghScale;
187  Z = voxel[no].z * cghScale - defaultDepth;
188  Amplitude = voxel[no].r;
189 
190  CalcSpatialFrequency(X, Y, Z, Amplitude
191  , m_segNumx, m_segNumy
192  , m_segSize, m_hsegSize, m_sf_base
193  , m_xc, m_yc
194  , m_SFrequency_cx, m_SFrequency_cy
195  , m_PickPoint_cx, m_PickPoint_cy
196  , m_Coefficient_cx, m_Coefficient_cy
197  , xiInterval, etaInterval,_CGHE);
198 
199  CalcCompensatedPhase(X, Y, Z, Amplitude
200  , m_segNumx, m_segNumy
201  , m_segSize, m_hsegSize, m_sf_base
202  , m_xc, m_yc
203  , m_Coefficient_cx, m_Coefficient_cy
204  , m_COStbl, m_SINtbl
205  , m_inRe, m_inIm,_CGHE);
206 
207  }
208 
209  RunFFTW(m_segNumx, m_segNumy
210  , m_segSize, m_hsegSize
211  , m_inRe, m_inIm
212  , m_in, m_out
213  , &m_plan, m_pHologram,_CGHE);
214 
215  finish = clock();
216 
217  duration = (double)(finish - start) / CLOCKS_PER_SEC;
218  //mm.Format("%f", duration);
219  //AfxMessageBox(mm);
220  cout << duration << endl;
221  MemoryRelease();
222 }
223 */
224 
225 void ophPAS::PAS(long voxelnum, OphPointCloudData *data, double * m_pHologram, OphPointCloudConfig& conf)
226 {
227  float xiInterval = getContext().pixel_pitch[_X];//_CGHE->xiInterval;
228  float etaInterval = getContext().pixel_pitch[_Y];//_CGHE->etaInterval;
229  float cghScale = conf.scale[_X];// _CGHE->CGHScale;
230  float defaultDepth = conf.distance;//_CGHE->DefaultDepth;
231 
232  DataInit(FFT_SEGMENT_SIZE, getContext().pixel_number[_X], getContext().pixel_number[_Y], xiInterval, etaInterval);
233 
234  long no; // voxel Number
235 
236 
237  float X, Y, Z; ; // x, y, real distance
238  float Amplitude;
239  float sf_base = 1.0 / (xiInterval* FFT_SEGMENT_SIZE);
240 
241  // Iteration according to the point number
242  for (no = 0; no < voxelnum*3; no+=3)
243  {
244  // point coordinate
245  X = ((float)data->vertices[no].point.pos[_X]) * cghScale;
246  Y = ((float)data->vertices[no].point.pos[_Y]) * cghScale;
247  Z = ((float)data->vertices[no].point.pos[_Z]) * cghScale - defaultDepth;
248  Amplitude = (float)data->vertices[no].phase;
249 
250 
251  //std::cout << "X: " << X << ", Y: " << Y << ", Z: " << Z << ", Amp: " << Amplitude << endl;
252 
253  /*
254  CalcSpatialFrequency(X, Y, Z, Amplitude
255  , m_segNumx, m_segNumy
256  , m_segSize, m_hsegSize, m_sf_base
257  , m_xc, m_yc
258  , m_SFrequency_cx, m_SFrequency_cy
259  , m_PickPoint_cx, m_PickPoint_cy
260  , m_Coefficient_cx, m_Coefficient_cy
261  , xiInterval, etaInterval, _CGHE);
262  */
266  , m_xc, m_yc
270  , xiInterval, etaInterval, conf);
271 
272  /*
273  CalcCompensatedPhase(X, Y, Z, Amplitude
274  , m_segNumx, m_segNumy
275  , m_segSize, m_hsegSize, m_sf_base
276  , m_xc, m_yc
277  , m_Coefficient_cx, m_Coefficient_cy
278  , m_COStbl, m_SINtbl
279  , m_inRe, m_inIm, _CGHE);
280  */
284  , m_xc, m_yc
286  , m_COStbl, m_SINtbl
287  , m_inRe, m_inIm, conf);
288 
289  }
290 
291  /*
292  RunFFTW(m_segNumx, m_segNumy
293  , m_segSize, m_hsegSize
294  , m_inRe, m_inIm
295  , m_in, m_out
296  , &m_plan, m_pHologram, _CGHE);
297  */
300  , m_inRe, m_inIm
301  , m_in, m_out
302  , &m_plan, m_pHologram, conf);
303 
304  MemoryRelease();
305 }
306 
307 void ophPAS::PAS_GPU(long voxelnum, OphPointCloudData * data, double * m_pHologram, OphPointCloudConfig & conf)
308 {
309  float xiInterval = getContext().pixel_pitch[_X];//_CGHE->xiInterval;
310  float etaInterval = getContext().pixel_pitch[_Y];//_CGHE->etaInterval;
311  float cghScale = conf.scale[_X];// _CGHE->CGHScale;
312  float defaultDepth = conf.distance;//_CGHE->DefaultDepth;
313 
314  DataInit(FFT_SEGMENT_SIZE, getContext().pixel_number[_X], getContext().pixel_number[_Y], xiInterval, etaInterval);
315 
316  long no; // voxel Number
317 
318 
319  float X, Y, Z; ; // x, y, real distance
320  float Amplitude;
321  float sf_base = 1.0 / (xiInterval* FFT_SEGMENT_SIZE);
322 
323  //CString mm;
324  clock_t start, finish;
325  double duration;
326  start = clock();
327 
328  cout << sf_base << endl;
329  // Iteration according to the point number
330  for (no = 0; no < voxelnum * 3; no += 3)
331  {
332  // point coordinate
333  X = ((float)data->vertices[no].point.pos[_X]) * cghScale;
334  Y = ((float)data->vertices[no].point.pos[_Y]) * cghScale;
335  Z = ((float)data->vertices[no].point.pos[_Z]) * cghScale - defaultDepth;
336  Amplitude = (float)data->vertices[no].phase;
337 
338  std::cout << "X: " << X << ", Y: " << Y << ", Z: " << Z << ", Amp: " << Amplitude << endl;
339 
340  /*
341  CalcSpatialFrequency(X, Y, Z, Amplitude
342  , m_segNumx, m_segNumy
343  , m_segSize, m_hsegSize, m_sf_base
344  , m_xc, m_yc
345  , m_SFrequency_cx, m_SFrequency_cy
346  , m_PickPoint_cx, m_PickPoint_cy
347  , m_Coefficient_cx, m_Coefficient_cy
348  , xiInterval, etaInterval, _CGHE);
349  */
353  , m_xc, m_yc
357  , xiInterval, etaInterval, conf);
358 
359  /*
360  CalcCompensatedPhase(X, Y, Z, Amplitude
361  , m_segNumx, m_segNumy
362  , m_segSize, m_hsegSize, m_sf_base
363  , m_xc, m_yc
364  , m_Coefficient_cx, m_Coefficient_cy
365  , m_COStbl, m_SINtbl
366  , m_inRe, m_inIm, _CGHE);
367  */
371  , m_xc, m_yc
373  , m_COStbl, m_SINtbl
374  , m_inRe, m_inIm, conf);
375 
376  }
377 
378  /*
379  RunFFTW(m_segNumx, m_segNumy
380  , m_segSize, m_hsegSize
381  , m_inRe, m_inIm
382  , m_in, m_out
383  , &m_plan, m_pHologram, _CGHE);
384  */
387  , m_inRe, m_inIm
388  , m_in, m_out
389  , &m_plan, m_pHologram, conf);
390 
391  finish = clock();
392 
393  duration = (double)(finish - start) / CLOCKS_PER_SEC;
394  //mm.Format("%f", duration);
395  //AfxMessageBox(mm);
396  cout << duration << endl;
397  MemoryRelease();
398 }
399 
400 void ophPAS::DataInit(int segsize, int cghwidth, int cghheight, float xiinter, float etainter)
401 {
402  int i, j;
403  /*
404  for (i = 0; i<NUMTBL; i++) {
405  float theta = (float)M2_PI * (float)(i + i - 1) / (float)(2 * NUMTBL);
406  m_COStbl[i] = (float)cos(theta);
407  m_SINtbl[i] = (float)sin(theta);
408  }
409  */
410 
411 
412  // size
413  this->m_segSize = segsize;
414  this->m_hsegSize = (int)(m_segSize / 2);
416  this->m_segNumx = (int)(cghwidth / m_segSize);
417  this->m_segNumy = (int)(cghheight / m_segSize);
418  this->m_hsegNumx = (int)(m_segNumx / 2);
419  this->m_hsegNumy = (int)(m_segNumy / 2);
420 
421  // calculation components
422  this->m_SFrequency_cx = new float[m_segNumx];
423  this->m_SFrequency_cy = new float[m_segNumy];
424  this->m_PickPoint_cx = new int[m_segNumx];
425  this->m_PickPoint_cy = new int[m_segNumy];
426  this->m_Coefficient_cx = new int[m_segNumx];
427  this->m_Coefficient_cy = new int[m_segNumy];
428  this->m_xc = new float[m_segNumx];
429  this->m_yc = new float[m_segNumy];
430 
431  // base spatial frequency
432  this->m_sf_base = (float)(1.0 / (xiinter*m_segSize));
433 
434  this->m_inRe = new float *[m_segNumy * m_segNumx];
435  this->m_inIm = new float *[m_segNumy * m_segNumx];
436  for (i = 0; i<m_segNumy; i++) {
437  for (j = 0; j<m_segNumx; j++) {
438  m_inRe[i*m_segNumx + j] = new float[m_segSize * m_segSize];
439  m_inIm[i*m_segNumx + j] = new float[m_segSize * m_segSize];
440  memset(m_inRe[i*m_segNumx + j], 0x00, sizeof(float) * m_segSize * m_segSize);
441  memset(m_inIm[i*m_segNumx + j], 0x00, sizeof(float) * m_segSize * m_segSize);
442  }
443  }
444 
445  m_in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * m_segSize * m_segSize);
446  m_out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * m_segSize * m_segSize);
447  memset(m_in, 0x00, sizeof(fftw_complex) * m_segSize * m_segSize);
448 
449  // segmentation center point calculation
450  for (i = 0; i<m_segNumy; i++)
451  m_yc[i] = ((i - m_hsegNumy) * m_segSize + m_hsegSize) * etainter;
452  for (i = 0; i<m_segNumx; i++)
453  m_xc[i] = ((i - m_hsegNumx) * m_segSize + m_hsegSize) * xiinter;
454 
456 }
457 
459 {
460  int i, j;
461 
462  fftw_destroy_plan(m_plan);
463  fftw_free(m_in);
464  fftw_free(m_out);
465 
466  delete[] m_SFrequency_cx;
467  delete[] m_SFrequency_cy;
468  delete[] m_PickPoint_cx;
469  delete[] m_PickPoint_cy;
470  delete[] m_Coefficient_cx;
471  delete[] m_Coefficient_cy;
472  delete[] m_xc;
473  delete[] m_yc;
474 
475  for (i = 0; i<m_segNumy; i++) {
476  for (j = 0; j<m_segNumx; j++) {
477  delete[] m_inRe[i*m_segNumx + j];
478  delete[] m_inIm[i*m_segNumx + j];
479  }
480  }
481  delete[] m_inRe;
482  delete[] m_inIm;
483 
484 }
485 
487 {
488 
489  auto begin = CUR_TIME;
490  cgh_fringe = new unsigned char[context_.pixel_number[_X] * context_.pixel_number[_Y]];
491  PASCalculation(n_points, cgh_fringe, &pc_data, pc_config);
492  auto end = CUR_TIME;
493  m_elapsedTime = ((std::chrono::duration<Real>)(end - begin)).count();
494  LOG("Total Elapsed Time: %lf (s)\n", m_elapsedTime);
495 }
496 
497 
498 
499 
500 void ophPAS::CalcSpatialFrequency(float cx, float cy, float cz, float amp, int segnumx, int segnumy, int segsize, int hsegsize, float sf_base, float * xc, float * yc, float * sf_cx, float * sf_cy, int * pp_cx, int * pp_cy, int * cf_cx, int * cf_cy, float xiint, float etaint, OphPointCloudConfig& conf)
501 {
502  int segx, segy; // coordinate in a Segment
503  float theta_cx, theta_cy;
504 
505  float rWaveLength = context_.wave_length[0];//_CGHE->rWaveLength;
506  float thetaX = 0.0;// _CGHE->ThetaX;
507  float thetaY = 0.0;// _CGHE->ThetaY;
508 
509  for (segx = 0; segx < segnumx; segx++)
510  {
511  theta_cx = (xc[segx] - cx) / cz;
512  sf_cx[segx] = (float)((theta_cx + thetaX) / rWaveLength);
513  (sf_cx[segx] >= 0) ? pp_cx[segx] = (int)(sf_cx[segx] / sf_base + 0.5)
514  : pp_cx[segx] = (int)(sf_cx[segx] / sf_base - 0.5);
515  (abs(pp_cx[segx]) < hsegsize) ? cf_cx[segx] = ((segsize - pp_cx[segx]) % segsize)
516  : cf_cx[segx] = 0;
517  }
518 
519  for (segy = 0; segy < segnumy; segy++)
520  {
521  theta_cy = (yc[segy] - cy) / cz;
522  sf_cy[segy] = (float)((theta_cy + thetaY) / rWaveLength);
523  (sf_cy[segy] >= 0) ? pp_cy[segy] = (int)(sf_cy[segy] / sf_base + 0.5)
524  : pp_cy[segy] = (int)(sf_cy[segy] / sf_base - 0.5);
525  (abs(pp_cy[segy]) < hsegsize) ? cf_cy[segy] = ((segsize - pp_cy[segy]) % segsize)
526  : cf_cy[segy] = 0;
527  }
528 }
529 
530 
531 
532 void ophPAS::CalcCompensatedPhase(float cx, float cy, float cz, float amp
533  , int segNumx, int segNumy
534  , int segsize, int hsegsize, float sf_base
535  , float *xc, float *yc
536  , int *cf_cx, int *cf_cy
537  , float *COStbl, float *SINtbl
538  , float **inRe, float **inIm, OphPointCloudConfig& conf)
539 {
540  int segx, segy; // coordinate in a Segment
541  int segxx, segyy;
542  float theta_s, theta_c;
543  int dtheta_s, dtheta_c;
544  int idx_c, idx_s;
545  float theta;
546 
547  float rWaveNum = 9926043.13930423f;// _CGHE->rWaveNumber;
548 
549  float R;
550  auto start = CUR_TIME;
551 
552  for (segy = 0; segy < segNumy; segy++) {
553  for (segx = 0; segx < segNumx; segx++) {
554  segyy = segy * segNumx + segx;
555  segxx = cf_cy[segy] * segsize + cf_cx[segx];
556 
557  R = (float)(sqrt((xc[segx] - cx)*(xc[segx] - cx) + (yc[segy] - cy)*(yc[segy] - cy) + cz * cz));
558  //°°À½
559  theta = rWaveNum * R;
560  theta_c = theta;
561  theta_s = theta + PI;
562  dtheta_c = ((int)(theta_c*NUMTBL / M2_PI));
563  dtheta_s = ((int)(theta_s*NUMTBL / M2_PI));
564  idx_c = (dtheta_c) & (NUMTBL2);
565  idx_s = (dtheta_s) & (NUMTBL2);
566 
567  inRe[segyy][segxx] += (float)(amp * COStbl[idx_c]);
568  inIm[segyy][segxx] += (float)(amp * SINtbl[idx_s]);
569  }
570  }
571 
572  auto end = CUR_TIME;
573  auto during = ((chrono::duration<Real>)(end - start)).count();
574  //LOG("%lf (s)..done\n", during);
575 
576 }
577 
578 
579 
580 void ophPAS::RunFFTW(int segnumx, int segnumy, int segsize, int hsegsize, float ** inRe, float ** inIm, fftw_complex * in, fftw_complex * out, fftw_plan * plan, double * pHologram, OphPointCloudConfig& conf)
581 {
582  int i, j;
583  int segx, segy; // coordinate in a Segment
584  int segxx, segyy;
585 
586  int cghWidth = getContext().pixel_number[_X];
587 
588  for (segy = 0; segy < segnumy; segy++) {
589  for (segx = 0; segx < segnumx; segx++) {
590  segyy = segy * segnumx + segx;
591  memset(in, 0x00, sizeof(fftw_complex) * segsize * segsize);
592  for (i = 0; i < segsize; i++) {
593  for (j = 0; j < segsize; j++) {
594  segxx = i * segsize + j;
595 
596  in[i*segsize + j][0] = inRe[segyy][segxx];
597  in[i*segsize + j][1] = inIm[segyy][segxx];
598 
599  }
600  }
601  fftw_execute(*plan);
602  for (i = 0; i < segsize; i++) {
603  for (j = 0; j < segsize; j++) {
604  pHologram[(segy*segsize + i)*cghWidth + (segx*segsize + j)] = out[i * segsize + j][0];// - out[l * SEGSIZE + m][1];
605 
606  }
607  }
608  }
609  }
610 
611 }
612 
613 void ophPAS::encodeHologram(const vec2 band_limit, const vec2 spectrum_shift)
614 {
615  if (complex_H == nullptr) {
616  LOG("Not found diffracted data.");
617  return;
618  }
619 
620 
621  const uint nChannel = context_.waveNum;
622  const uint pnX = context_.pixel_number[_X];
623  const uint pnY = context_.pixel_number[_Y];
624  const Real ppX = context_.pixel_pitch[_X];
625  const Real ppY = context_.pixel_pitch[_Y];
626  const long long int pnXY = pnX * pnY;
627 
628  m_vecEncodeSize = ivec2(pnX, pnY);
629  context_.ss[_X] = pnX * ppX;
630  context_.ss[_Y] = pnY * ppY;
631  vec2 ss = context_.ss;
632 
633  Real cropx = floor(pnX * band_limit[_X]);
634  Real cropx1 = cropx - floor(cropx / 2);
635  Real cropx2 = cropx1 + cropx - 1;
636 
637  Real cropy = floor(pnY * band_limit[_Y]);
638  Real cropy1 = cropy - floor(cropy / 2);
639  Real cropy2 = cropy1 + cropy - 1;
640 
641  Real* x_o = new Real[pnX];
642  Real* y_o = new Real[pnY];
643 
644  for (uint i = 0; i < pnX; i++)
645  x_o[i] = (-ss[_X] / 2) + (ppX * i) + (ppX / 2);
646 
647  for (uint i = 0; i < pnY; i++)
648  y_o[i] = (ss[_Y] - ppY) - (ppY * i);
649 
650  Real* xx_o = new Real[pnXY];
651  Real* yy_o = new Real[pnXY];
652 
653  for (int i = 0; i < pnXY; i++)
654  xx_o[i] = x_o[i % pnX];
655 
656 
657  for (uint i = 0; i < pnX; i++)
658  for (uint j = 0; j < pnY; j++)
659  yy_o[i + j * pnX] = y_o[j];
660 
661  Complex<Real>* h = new Complex<Real>[pnXY];
662 
663  for (uint ch = 0; ch < nChannel; ch++) {
664  fft2(complex_H[ch], h, pnX, pnY, OPH_FORWARD);
665  fft2(ivec2(pnX, pnY), h, OPH_FORWARD);
666  fftExecute(h);
667  fft2(h, h, pnX, pnY, OPH_BACKWARD);
668 
669  fft2(h, h, pnX, pnY, OPH_FORWARD);
670  fft2(ivec2(pnX, pnY), h, OPH_BACKWARD);
671  fftExecute(h);
672  fft2(h, h, pnX, pnY, OPH_BACKWARD);
673 
674  for (int i = 0; i < pnXY; i++) {
675  Complex<Real> shift_phase(1.0, 0.0);
676  int r = i / pnX;
677  int c = i % pnX;
678 
679  Real X = (M_PI * xx_o[i] * spectrum_shift[_X]) / ppX;
680  Real Y = (M_PI * yy_o[i] * spectrum_shift[_Y]) / ppY;
681 
682  shift_phase[_RE] = shift_phase[_RE] * (cos(X) * cos(Y) - sin(X) * sin(Y));
683 
684  m_lpEncoded[ch][i] = (h[i] * shift_phase).real();
685  }
686  }
687  delete[] h;
688  delete[] x_o;
689  delete[] xx_o;
690  delete[] y_o;
691  delete[] yy_o;
692 
693 }
694 
695 void ophPAS::encoding(unsigned int ENCODE_FLAG)
696 {
698 }
ENCODE_FLAG
Definition: ophGen.h:84
void abs(const oph::Complex< T > &src, oph::Complex< T > &dst)
Definition: function.h:113
OphConfig & getContext(void)
Function for getting the current context.
Definition: Openholo.h:229
#define M_PI
Definition: define.h:52
void encodeHologram(const vec2 band_limit, const vec2 spectrum_shift)
Definition: ophPAS.cpp:613
fftw_complex * m_out
Definition: ophPAS.h:91
Point point
Definition: struct.h:103
#define OPH_FORWARD
Definition: define.h:66
#define NUMTBL2
Definition: ophACPAS.h:16
int m_hsegNumx
Definition: ophPAS.h:73
float * m_yc
Definition: ophPAS.h:86
int m_segSize
Definition: ophPAS.h:68
Real distance
Offset value of point cloud.
Definition: ophGen.h:559
void PASCalculation(long voxnum, unsigned char *cghfringe, OphPointCloudData *data, OphPointCloudConfig &conf)
Definition: ophPAS.cpp:117
#define NUMTBL
Definition: ophACPAS.h:15
int * m_PickPoint_cx
Definition: ophPAS.h:81
float * m_SFrequency_cx
Definition: ophPAS.h:79
bool readConfig(const char *fname)
Definition: ophPAS.cpp:26
void init()
Definition: ophPAS.cpp:99
void initialize(void)
Initialize variables for Hologram complex field, encoded data, normalized data.
Definition: ophGen.cpp:145
float m_COStbl[NUMTBL]
Definition: ophPAS.h:65
int * m_Coefficient_cx
Definition: ophPAS.h:83
vec2 ss
Definition: Openholo.h:104
float Real
Definition: typedef.h:55
bool checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:86
#define M2_PI
Definition: ophACPAS.h:10
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
float ** m_inIm
Definition: ophPAS.h:95
h
Definition: Openholo.cpp:430
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:761
virtual ~ophPAS()
Definition: ophPAS.cpp:20
int m_segNumx
Definition: ophPAS.h:71
#define FFTW_BACKWARD
Definition: fftw3.h:380
void PAS(long voxelnum, OphPointCloudData *data, double *m_pHologram, OphPointCloudConfig &conf)
Definition: ophPAS.cpp:225
Real phase
Definition: struct.h:105
vec2 pixel_pitch
Definition: Openholo.h:101
ophPAS()
Definition: ophPAS.cpp:13
void MemoryRelease(void)
Definition: ophPAS.cpp:458
void CalcCompensatedPhase(float cx, float cy, float cz, float amp, int segnumx, int segnumy, int segsize, int hsegsize, float sf_base, float *xc, float *yc, int *cf_cx, int *cf_cy, float *COStbl, float *SINtbl, float **inRe, float **inIm, OphPointCloudConfig &conf)
Definition: ophPAS.cpp:532
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:557
int loadPoint(const char *_filename)
Definition: ophPAS.cpp:93
Real m_elapsedTime
Elapsed time of generate hologram.
Definition: ophGen.h:336
ivec2 m_vecEncodeSize
Encoded hologram size, varied from encoding type.
Definition: ophGen.h:330
#define _X
Definition: define.h:92
double * m_pHologram
Definition: ophPAS.h:63
float m_sf_base
Definition: ophPAS.h:89
#define FFT_SEGMENT_SIZE
Definition: ophPAS.h:19
int m_segNumy
Definition: ophPAS.h:72
Real ** m_lpEncoded
buffer to encoded.
Definition: ophGen.h:338
float * m_SFrequency_cy
Definition: ophPAS.h:80
int m_dsegSize
Definition: ophPAS.h:70
#define _RE
Definition: complex.h:55
void fftExecute(Complex< Real > *out, bool bReverse=false)
Execution functions to be called after fft1, fft2, and fft3.
Definition: Openholo.cpp:623
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:559
structure for 2-dimensional Real type vector and its arithmetic.
Definition: vec.h:66
void DataInit(int segsize, int cghwidth, int cghheight, float xiinter, float etainter)
Definition: ophPAS.cpp:400
int * m_Coefficient_cy
Definition: ophPAS.h:84
void RunFFTW(int segnumx, int segnumy, int segsize, int hsegsize, float **inRe, float **inIm, fftw_complex *in, fftw_complex *out, fftw_plan *plan, double *pHologram, OphPointCloudConfig &conf)
Definition: ophPAS.cpp:580
uint waveNum
Definition: Openholo.h:105
void Amplitude(Complex< T > *holo, T *encoded, const int size)
float ** m_inRe
Definition: ophPAS.h:94
ivec2 pixel_number
Definition: Openholo.h:99
void PAS_GPU(long voxelnum, OphPointCloudData *data, double *m_pHologram, OphPointCloudConfig &conf)
Definition: ophPAS.cpp:307
int m_hsegNumy
Definition: ophPAS.h:74
bool readConfig(const char *fname)
load to configuration file.
Definition: ophGen.cpp:220
#define _Y
Definition: define.h:96
XMLError LoadFile(const char *filename)
Definition: tinyxml2.cpp:2150
Configuration for Point Cloud.
Definition: ophGen.h:555
Vertex * vertices
Data of point clouds.
Definition: ophGen.h:588
#define PI
Definition: ophACPAS.h:9
Complex< Real > ** complex_H
Definition: Openholo.h:489
Data for Point Cloud.
Definition: ophGen.h:582
int * m_PickPoint_cy
Definition: ophPAS.h:82
float m_SINtbl[NUMTBL]
Definition: ophPAS.h:66
fftw_plan m_plan
Definition: ophPAS.h:92
void encoding()
Definition: ophGen.cpp:985
#define _Z
Definition: define.h:100
float * m_xc
Definition: ophPAS.h:85
OphConfig context_
Definition: Openholo.h:485
unsigned char * cgh_fringe
Definition: ophPAS.h:87
#define OPH_BACKWARD
Definition: define.h:67
void generateHologram()
Definition: ophPAS.cpp:486
void CalcSpatialFrequency(float cx, float cy, float cz, float amp, int segnumx, int segnumy, int segsize, int hsegsize, float sf_base, float *xc, float *yc, float *sf_cx, float *sf_cy, int *pp_cx, int *pp_cy, int *cf_cx, int *cf_cy, float xiint, float etaint, OphPointCloudConfig &conf)
Definition: ophPAS.cpp:500
int m_hsegSize
Definition: ophPAS.h:69
Real * wave_length
Definition: Openholo.h:106
int loadPointCloud(const char *pc_file, OphPointCloudData *pc_data_)
load to point cloud data.
Definition: ophGen.cpp:206
const XMLElement * FirstChildElement(const char *name=0) const
Definition: tinyxml2.cpp:940
unsigned int uint
Definition: typedef.h:62
#define CUR_TIME
Definition: function.h:58
fftw_complex * m_in
Definition: ophPAS.h:91
Definition: ophGen.h:76
#define FFTW_ESTIMATE
Definition: fftw3.h:392
Real pos[3]
Definition: struct.h:87