49 #include <cuda_runtime_api.h> 73 void cudaFFT(CUstream_st* stream,
int nx,
int ny, cufftDoubleComplex* in_filed, cufftDoubleComplex* output_field,
int direction,
bool bNormailized =
false);
89 void cudaCropFringe(CUstream_st* stream,
int nx,
int ny, cufftDoubleComplex* in_field, cufftDoubleComplex* out_field,
int cropx1,
int cropx2,
int cropy1,
int cropy2);
108 void cudaGetFringe(CUstream_st* stream,
int pnx,
int pny, cufftDoubleComplex* in_field, cufftDoubleComplex* out_field,
int sig_locationx,
int sig_locationy,
118 , m_lpEncoded(nullptr)
119 , m_lpNormalized(nullptr)
122 , m_dFieldLength(0.0)
126 , normalized(nullptr)
135 , m_bRandomPhase(false)
154 for (
uint i = 0; i < m_nOldChannel; i++) {
165 for (
uint i = 0; i < nChannel; i++) {
171 for (
uint i = 0; i < m_nOldChannel; i++) {
181 for (
uint i = 0; i < nChannel; i++) {
187 for (
uint i = 0; i < m_nOldChannel; i++) {
197 for (
uint i = 0; i < nChannel; i++) {
202 m_nOldChannel = nChannel;
230 LOG(
"<FAILED> Wrong file ext.\n");
236 LOG(
"<FAILED> Loading file (%d)\n", ret);
242 char szNodeName[32] = { 0, };
244 sprintf(szNodeName,
"SLM_WaveNum");
246 if (!next ||
XML_SUCCESS != next->QueryIntText(&nWave))
248 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
255 for (
int i = 1; i <= nWave; i++) {
256 sprintf(szNodeName,
"SLM_WaveLength_%d", i);
260 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
265 sprintf(szNodeName,
"SLM_PixelNumX");
269 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
273 sprintf(szNodeName,
"SLM_PixelNumY");
277 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
281 sprintf(szNodeName,
"SLM_PixelPitchX");
285 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
289 sprintf(szNodeName,
"SLM_PixelPitchY");
293 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
336 for (
int i = 0; i < nWave; i++)
343 LOG(
"**************************************************\n");
344 LOG(
" Read Config (Common) \n");
350 LOG(
"4) Image Rotate : %s\n",
imgCfg.
rotate ?
"Y" :
"N");
354 LOG(
"6) Image Merge : %s\n",
imgCfg.
merge ?
"Y" :
"N");
355 LOG(
"**************************************************\n");
368 const Real ssX = pConfig->
ss[
_X] = pnX * ppX;
369 const Real ssY = pConfig->
ss[
_Y] = pnY * ppY;
370 const int offsetX = pConfig->
offset[
_X];
371 const int offsetY = pConfig->
offset[
_Y];
373 const Real tx = lambda / (2 * ppX);
374 const Real ty = lambda / (2 * ppY);
375 const Real sqrtX = sqrt(1 - (tx * tx));
376 const Real sqrtY = sqrt(1 - (ty * ty));
377 const Real x = -ssX / 2;
378 const Real y = -ssY / 2;
382 Real ampZ = amplitude * z;
395 floor((_xbound[
_X] - x) / ppX) + 1,
396 floor((_xbound[
_Y] - x) / ppX) + 1
400 pnY - floor((_ybound[
_Y] - y) / ppY),
401 pnY - floor((_ybound[
_X] - y) / ppY)
404 if (Xbound[
_X] > pnX) Xbound[
_X] = pnX;
405 if (Xbound[
_Y] < 0) Xbound[
_Y] = 0;
406 if (Ybound[
_X] > pnY) Ybound[
_X] = pnY;
407 if (Ybound[
_Y] < 0) Ybound[
_Y] = 0;
410 for (
int yytr = Ybound[
_Y]; yytr < Ybound[
_X]; ++yytr)
412 int offset = yytr * pnX;
413 Real yyy = y + ((pnY - yytr + offsetY) * ppY);
420 for (
int xxtr = Xbound[
_Y]; xxtr < Xbound[
_X]; ++xxtr)
422 Real xxx = x + ((xxtr - 1 + offsetX) * ppX);
429 if (((xxx < range_x[
_X]) && (xxx > range_x[
_Y])) && ((yyy < range_y[
_X]) && (yyy > range_y[
_Y]))) {
431 Real operand = lambda * r * r;
432 Real res_real = (ampZ * sin(kr)) / operand;
433 Real res_imag = (-ampZ * cos(kr)) / operand;
436 dst[offset + xxtr][
_RE] += res_real;
440 dst[offset + xxtr][
_IM] += res_imag;
454 const Real ssX = pConfig->
ss[
_X] = pnX * ppX;
455 const Real ssY = pConfig->
ss[
_Y] = pnY * ppY;
456 const int offsetX = pConfig->
offset[
_X];
457 const int offsetY = pConfig->
offset[
_Y];
465 Real operand = lambda * z;
468 src.
pos[
_X] +
abs(operand / (2 * ppX)),
469 src.
pos[
_X] -
abs(operand / (2 * ppX))
473 src.
pos[
_Y] +
abs(operand / (2 * ppY)),
474 src.
pos[
_Y] -
abs(operand / (2 * ppY))
478 floor((_xbound[
_X] - x) / ppX) + 1,
479 floor((_xbound[
_Y] - x) / ppX) + 1
483 pnY - floor((_ybound[
_Y] - y) / ppY),
484 pnY - floor((_ybound[
_X] - y) / ppY)
487 if (Xbound[
_X] > pnX) Xbound[
_X] = pnX;
488 if (Xbound[
_Y] < 0) Xbound[
_Y] = 0;
489 if (Ybound[
_X] > pnY) Ybound[
_X] = pnY;
490 if (Ybound[
_Y] < 0) Ybound[
_Y] = 0;
492 for (
int yytr = Ybound[
_Y]; yytr < Ybound[
_X]; ++yytr)
494 Real yyy = (y + (pnY - yytr + offsetY) * ppY) - src.
pos[
_Y];
495 int offset = yytr * pnX;
496 for (
int xxtr = Xbound[
_Y]; xxtr < Xbound[
_X]; ++xxtr)
498 Real xxx = (x + (xxtr - 1 + offsetX) * ppX) - src.
pos[
_X];
499 Real p = k * (xxx * xxx + yyy * yyy + 2 * zz) / (2 * z);
501 Real res_real = amplitude * sin(p) / operand;
502 Real res_imag = amplitude * (-cos(p)) / operand;
507 dst[offset + xxtr][
_RE] += res_real;
511 dst[offset + xxtr][
_IM] += res_imag;
524 const Real ssX = pConfig->
ss[
_X] = pnX * ppX;
525 const Real ssY = pConfig->
ss[
_Y] = pnY * ppY;
526 const Real ssX2 = ssX * 2;
527 const Real ssY2 = ssY * 2;
534 for (
int i = 0; i < pnY; i++) {
535 for (
int j = 0; j < pnX; j++) {
546 LUT_fx[i] = (i - pnX) / ssX2;
547 LUT_fx[i] *= LUT_fx[i];
551 LUT_fy[i] = (i - pnY) / ssY2;
552 LUT_fy[i] *= LUT_fy[i];
556 Real lambda_square = lambda * lambda;
563 sqrtPart = sqrt(1 / lambda_square - LUT_fx[j] - LUT_fy[k]);
566 temp[i] = temp[i] * exp(prop);
573 for (
int i = 0; i < pnY; i++) {
574 for (
int j = 0; j < pnX; j++) {
587 const int N = pnX * pnY;
598 Real kd = k * distance;
599 Real fx = -1 / (ppX * 2);
600 Real fy = 1 / (ppY * 2);
603 #pragma omp parallel for firstprivate(pnX, dfx, dfy, lambda, kd, kk) 605 for (
int i = 0; i < N; i++)
610 Real fxx = fx + dfx * x;
611 Real fyy = fy - dfy - dfy * y;
613 Real fxxx = lambda * fxx;
614 Real fyyy = lambda * fyy;
616 Real sval = sqrt(1 - (fxxx * fxxx) - (fyyy * fyyy));
621 bool prop_mask = ((fxx * fxx + fyy * fyy) < kk) ?
true :
false;
625 u_frequency = kernel * src[i];
626 dst[i][
_RE] += u_frequency[
_RE];
627 dst[i][
_IM] += u_frequency[
_IM];
634 int N = size[
_X] * size[
_Y];
644 for (
int i = 0; i < N; i++)
645 dstFT[i] = src1FT[i] * src2FT[i];
659 const long long int N = pnX * pnY;
662 for (
uint ch = 0; ch < nWave; ch++)
673 gap = maxVal - minVal;
674 for (
uint ch = 0; ch < nWave; ch++)
677 #pragma omp parallel for firstprivate(minVal, gap, pnX) 679 for (
int j = 0; j < pnY; j++) {
681 for (
int i = 0; i < pnX; i++) {
693 if (fname ==
nullptr)
return bOK;
700 if (px == 0 && py == 0)
704 std::string file = fname;
705 std::replace(file.begin(), file.end(),
'\\',
'/');
708 std::vector<std::string> components;
709 std::stringstream ss(file);
713 while (std::getline(ss, item, token)) {
714 components.push_back(item);
719 for (
size_t i = 0; i < components.size() - 1; i++)
721 dir += components[i];
725 std::string filename = components[components.size() - 1];
729 size_t ext_pos = file.rfind(
".");
730 hasExt = (ext_pos == string::npos) ?
false :
true;
733 filename.append(
".bmp");
735 std::string fullpath = dir + filename;
737 if (src ==
nullptr) {
740 saveAsImg(fullpath.c_str(), bitsperpixel, source, p[
_X], p[
_Y]);
742 else if (nChannel == 3) {
744 uint nSize = (((p[
_X] * bitsperpixel >> 3) + 3) & ~3) * p[
_Y];
745 source =
new uchar[nSize];
747 for (
uint i = 0; i < nChannel; i++) {
751 saveAsImg(fullpath.c_str(), bitsperpixel, source, p[
_X], p[
_Y]);
752 if (bAlloc)
delete[] source;
755 for (
uint i = 0; i < nChannel; i++) {
756 char path[FILENAME_MAX] = { 0, };
757 sprintf(path,
"%s%d_%s", dir.c_str(), i, filename.c_str());
759 saveAsImg(path, bitsperpixel / nChannel, source, p[
_X], p[
_Y]);
766 saveAsImg(fullpath.c_str(), bitsperpixel, source, p[
_X], p[
_Y]);
792 for (
uint ch = 0; ch < nChannel; ch++) {
824 Real *encoded =
nullptr;
838 LOG(
"<FAILED> WRONG PARAMETERS.\n");
871 default: LOG(
"<FAILED> WRONG PARAMETERS.\n");
return;
874 if (holo ==
nullptr) holo =
complex_H[0];
884 holo ==
nullptr ? holo = *
complex_H : holo;
885 encoded ==
nullptr ? encoded = *
m_lpEncoded : encoded;
891 for (
uint ch = 0; ch < nChannel; ch++) {
910 LOG(
"ENCODE_OFFSSB");
919 LOG(
"<FAILED> WRONG PARAMETERS.\n");
931 switch (BIN_ENCODE_FLAG) {
933 LOG(
"ENCODE_SIMPLEBINARY\n");
934 if (holo ==
nullptr || encoded ==
nullptr)
935 for (
uint ch = 0; ch < nChannel; ch++) {
942 LOG(
"ENCODE_EDBINARY\n");
944 LOG(
"<FAILED> WRONG PARAMETERS : %d\n",
ENCODE_FLAG);
947 if (holo ==
nullptr || encoded ==
nullptr)
948 for (
uint ch = 0; ch < nChannel; ch++) {
955 LOG(
"<FAILED> WRONG PARAMETERS.\n");
970 for (
uint ch = 0; ch < nChannel; ch++) {
984 LOG(
"ENCODE_SIMPLENI\n");
988 LOG(
"ENCODE_REAL\n");
992 LOG(
"ENCODE_BURCKHARDT\n");
996 LOG(
"ENCODE_TWOPHASE\n");
1000 LOG(
"ENCODE_PHASE\n");
1004 LOG(
"ENCODE_AMPLITUDE\n");
1008 LOG(
"ENCODE_SSB\n");
1012 LOG(
"ENCODE_OFFSSB\n");
1017 LOG(
"<FAILED> WRONG PARAMETERS.\n");
1025 const int nX = holosize[
_X];
1026 const int nY = holosize[
_Y];
1027 const int half_nX = nX >> 1;
1028 const int half_nY = nY >> 1;
1030 const long long int N = nX * nY;
1031 const long long int half_N = N >> 1;
1042 for (
int i = 0; i < nY; i++)
1044 std::memset(&
AS[i * nX + half_nX], 0.0,
sizeof(
Complex<Real>) * half_nX);
1048 for (
int i = 0; i < nY; i++)
1070 oph::realPart<Real>(filtered, realFiltered, N);
1076 delete[] realFiltered;
1081 int N = holosize[
_X] * holosize[
_Y];
1089 circShift<Complex<Real>>(
AS, shifted, shift_x, shift_y, holosize.v[
_X], holosize.v[
_Y]);
1100 bool ophGen::saveRefImages(
char* fnameW,
char* fnameWC,
char* fnameAS,
char* fnameSSB,
char* fnameHP,
char* fnameFreq,
char* fnameReal,
char* fnameBin,
char* fnameReconBin,
char* fnameReconErr,
char* fnameReconNo)
1103 int nx = holosize[
_X], ny = holosize[
_Y];
1111 cout <<
"W saved" << endl;
1113 oph::absCplxArr<Real>(
weightC, temp1, ss);
1116 cout <<
"WC saved" << endl;
1118 oph::absCplxArr<Real>(
AS, temp1, ss);
1121 cout <<
"AS saved" << endl;
1125 cout <<
"SSB saved" << endl;
1129 cout <<
"HP saved" << endl;
1131 oph::absCplxArr<Real>(
freqW, temp1, ss);
1134 cout <<
"Freq saved" << endl;
1138 cout <<
"Real saved" << endl;
1142 cout <<
"Bin saved" << endl;
1146 for (
int i = 0; i < ss; i++) {
1152 for (
int i = 0; i < ss; i++) {
1164 oph::absCplxArr<Real>(reconBin, temp1, ss);
1165 for (
int i = 0; i < ss; i++) {
1166 temp1[i] = temp1[i] * temp1[i];
1169 saveAsImg(fnameReconBin, 8, temp2, nx, ny);
1170 cout <<
"recon bin saved" << endl;
1174 for (
int i = 0; i < ss; i++) {
1180 for (
int i = 0; i < ss; i++) {
1191 oph::absCplxArr<Real>(reconBin, temp1, ss);
1192 for (
int i = 0; i < ss; i++) {
1193 temp1[i] = temp1[i] * temp1[i];
1196 saveAsImg(fnameReconErr, 8, temp2, nx, ny);
1197 cout <<
"recon error saved" << endl;
1203 for (
int i = 0; i < ss; i++) {
1209 for (
int i = 0; i < ss; i++) {
1220 oph::absCplxArr<Real>(reconBin, temp1, ss);
1221 for (
int i = 0; i < ss; i++) {
1222 temp1[i] = temp1[i] * temp1[i];
1225 saveAsImg(fnameReconNo, 8, temp2, nx, ny);
1235 int ss = holosize[
_X] * holosize[
_Y];
1241 memsetArr<Real>(
weight, 0.0, 0, ss - 1);
1252 for (
int i = 0; i < ss; i++) {
1267 LOG(
"normalize finishied..\n");
1268 if (encoded ==
nullptr)
1269 encoded =
new Real[ss];
1272 LOG(
"shiftW finishied..\n");
1277 for (
int i = 0; i < ss; i++) {
1278 oph::absCplx<Real>(
freqW[i], absFW);
1279 if (((
Real)i / (
Real)holosize[
_X]) < ((
Real)holosize[
_Y] / 2.0) && absFW < 0.6)
1289 for (
int i = 0; i < ss; i++) {
1298 for (
int i = 0; i < ss; i++) {
1302 int cx = (holosize[
_X] + 1) / 2, cy = (holosize[
_Y] + 1) / 2;
1304 for (
int iy = 0; iy < holosize[
_Y] - Nw[
_Y]; iy++) {
1305 for (
int ix = Nw[
_X]; ix < holosize[
_X] - Nw[
_X]; ix++) {
1307 ii = ix + iy*holosize[
_X];
1308 if (ix >= Nw[
_X] && ix < (holosize[
_X] - Nw[
_X]) && iy < (holosize[
_Y] - Nw[
_Y])) {
1310 if (toBeBin[ii][
_RE] > threshold)
1315 error = toBeBin[ii][
_RE] - encoded[ii];
1317 for (
int iwy = 0; iwy < Nw[
_Y] + 1; iwy++) {
1318 for (
int iwx = -Nw[
_X]; iwx < Nw[
_X] + 1; iwx++) {
1319 iii = (ix + iwx) + (iy + iwy)*holosize[
_X];
1320 jjj = (cx + iwx) + (cy + iwy)*holosize[
_X];
1322 toBeBin[iii] +=
weightC[jjj] * error;
1331 LOG(
"binary finishied..\n");
1340 int cx = (holosize[
_X] + 1) / 2;
1341 int cy = (holosize[
_Y] + 1) / 2;
1347 LOG(
"ERROR DIFFUSION : FLOYD_STEINBERG\n");
1348 weight[(cx + 1) + cy*holosize[
_X]] = 7.0 / 16.0;
1349 weight[(cx - 1) + (cy + 1)*holosize[
_X]] = 3.0 / 16.0;
1350 weight[(cx)+(cy + 1)*holosize[
_X]] = 5.0 / 16.0;
1351 weight[(cx + 1) + (cy + 1)*holosize[
_X]] = 1.0 / 16.0;
1352 Nw[
_X] = 1; Nw[
_Y] = 1;
1355 LOG(
"ERROR DIFFUSION : SINGLE_RIGHT\n");
1356 weight[(cx + 1) + cy*holosize[
_X]] = 1.0;
1357 Nw[
_X] = 1; Nw[
_Y] = 0;
1360 LOG(
"ERROR DIFFUSION : SINGLE_DOWN\n");
1361 weight[cx + (cy + 1)*holosize[
_X]] = 1.0;
1362 Nw[
_X] = 0; Nw[
_Y] = 1;
1365 LOG(
"<FAILED> WRONG PARAMETERS.\n");
1376 int ss = holosize[
_X] * holosize[
_Y];
1381 for (
int i = 0; i < ss; i++) {
1383 x = i % holosize[
_X] - holosize[
_X] / 2; y = i / holosize[
_X] - holosize[
_Y];
1393 for (
int i = 0; i < ss; i++) {
1406 #pragma omp parallel for firstprivate(threshold) 1408 for (
int i = 0; i < size; i++) {
1409 if (src[i][
_RE] > threshold)
1422 const int pnXY = pnX * pnY;
1424 const Real ssX = pnX * ppX * 2;
1425 const Real ssY = pnY * ppY * 2;
1426 const Real z = 2 *
M_PI * distance;
1427 const Real v = 1 / (lambda * lambda);
1428 const int hpnX = pnX / 2;
1429 const int hpnY = pnY / 2;
1430 const int pnX2 = pnX * 2;
1431 const int pnY2 = pnY * 2;
1437 #pragma omp parallel for firstprivate(pnX, pnX2, hpnX, hpnY) 1439 for (
int i = 0; i < pnY; i++)
1442 int dst = pnX2 * (i + hpnY) + hpnX;
1449 #pragma omp parallel for firstprivate(ssX, ssY, z, v) 1451 for (
int j = 0; j < pnY2; j++)
1453 Real fy = (-pnY + j) / ssY;
1455 int iWidth = j * pnX2;
1456 for (
int i = 0; i < pnX2; i++)
1458 Real fx = (-pnX + i) / ssX;
1461 Real sqrtPart = sqrt(v - fxx - fyy);
1463 temp[iWidth + i] *= prop.
exp();
1470 #pragma omp parallel for firstprivate(pnX, pnX2, hpnX, hpnY) 1472 for (
int i = 0; i < pnY; i++)
1474 int src = pnX2 * (i + hpnY) + hpnX;
1484 if (x == 0.0 && y == 0.0)
return false;
1486 bool bAxisX = (x == 0.0) ? false :
true;
1487 bool bAxisY = (y == 0.0) ? false :
true;
1494 Real ppY2 = ppY * 2;
1495 Real ppX2 = ppX * 2;
1499 Real *waveRatio =
new Real[nChannel];
1503 for (
uint i = 0; i < nChannel; i++) {
1506 Real ratioX = x * waveRatio[i];
1507 Real ratioY = y * waveRatio[i];
1510 #pragma omp parallel for firstprivate(ppX, ppY, ppX2, ppY2, ssX, ssY, pi2) 1512 for (
int y = 0; y < pnY; y++) {
1515 Real startY = ssY + (ppY * y);
1516 Real shiftY = startY / ppY2 * ratioY;
1517 yy = (pi2 * shiftY).exp();
1519 int offset = y * pnX;
1521 for (
int x = 0; x < pnX; x++) {
1526 Real startX = ssX + (ppX * x);
1527 Real shiftX = startX / ppX2 * ratioX;
1543 const long long int pnXY = pnX * pnY;
1545 Real dfx = 1 / ppX / pnX;
1546 Real dfy = 1 / ppY / pnY;
1548 int beginX = -pnX >> 1;
1549 int endX = pnX >> 1;
1550 int beginY = pnY >> 1;
1551 int endY = -pnY >> 1;
1553 Real carryX = distance * tan(carryingAngleX);
1554 Real carryY = distance * tan(carryingAngleY);
1556 for (
uint ch = 0; ch < nChannel; ch++) {
1558 for (
int i = beginY; i > endY; i--)
1560 Real _carryY = carryY * i * dfy;
1562 for (
int j = beginX; j < endX; j++)
1580 const long long int pnXY = pnX * pnY;
1581 Real dfx = 1 / ppX / pnX;
1582 Real dfy = 1 / ppY / pnY;
1584 int beginX = -pnX >> 1;
1585 int endX = pnX >> 1;
1586 int beginY = pnY >> 1;
1587 int endY = -pnY >> 1;
1591 for (
int i = beginY; i > endY; i--)
1593 Real y = i * dfy * ppY * carryIdxY;
1595 for (
int j = beginX; j < endX; j++)
1597 Real x = j * dfx * ppX * carryIdxX;
1600 dst[k] = src[k] * exp(carrier);
1610 LOG(
"Not found diffracted data.");
1618 int cropx1, cropx2, cropy1, cropy2;
1622 sig_location[0] = 0;
1623 sig_location[1] = passband ==
SSB_TOP ? 1 : -1;
1627 int cropy = (int)floor(((
Real)pnY) / 2);
1628 cropy1 = cropy - (int)floor(((
Real)cropy) / 2);
1629 cropy2 = cropy1 + cropy - 1;
1632 sig_location[0] = passband ==
SSB_LEFT ? -1 : 1;
1633 sig_location[1] = 0;
1637 int cropx = (int)floor(((
Real)pnX) / 2);
1638 cropx1 = cropx - (int)floor(((
Real)cropx) / 2);
1639 cropx2 = cropx1 + cropx - 1;
1659 const long long int pnXY = pnX * pnY;
1664 for (
uint ch = 0; ch < nChannel; ch++) {
1668 #pragma omp parallel for firstprivate(cropx1, cropx2, cropy1, cropy2, pnX) 1670 for (
int p = 0; p < pnXY; p++)
1674 if (x >= cropx1 && x <= cropx2 && y >= cropy1 && y <= cropy2)
1685 #pragma omp parallel for firstprivate(sig_location) 1687 for (
int i = 0; i < pnXY; i++) {
1691 m_lpEncoded[ch][i] = (h_crop[i] * shift_phase).real();
1701 const long long int pnXY = pnX * pnY;
1708 cufftDoubleComplex *k_temp_d_, *u_complex_gpu_;
1709 cudaStream_t stream_;
1710 cudaStreamCreate(&stream_);
1712 cudaMalloc((
void**)&u_complex_gpu_,
sizeof(cufftDoubleComplex) * pnXY);
1713 cudaMalloc((
void**)&k_temp_d_,
sizeof(cufftDoubleComplex) * pnXY);
1715 for (
uint ch = 0; ch < nChannel; ch++) {
1716 cudaMemcpy(u_complex_gpu_,
complex_H[ch],
sizeof(cufftDoubleComplex) * pnXY, cudaMemcpyHostToDevice);
1718 cudaMemsetAsync(k_temp_d_, 0,
sizeof(cufftDoubleComplex) * pnXY, stream_);
1719 cudaCropFringe(stream_, pnX, pnY, u_complex_gpu_, k_temp_d_, cropx1, cropx2, cropy1, cropy2);
1721 cudaMemsetAsync(u_complex_gpu_, 0,
sizeof(cufftDoubleComplex) * pnXY, stream_);
1722 cudaFFT(stream_, pnX, pnY, k_temp_d_, u_complex_gpu_, 1,
true);
1724 cudaMemsetAsync(k_temp_d_, 0,
sizeof(cufftDoubleComplex) * pnXY, stream_);
1725 cudaGetFringe(stream_, pnX, pnY, u_complex_gpu_, k_temp_d_, sig_location[0], sig_location[1], ssX, ssY, ppX, ppY,
M_PI);
1727 cufftDoubleComplex* sample_fd = (cufftDoubleComplex*)malloc(
sizeof(cufftDoubleComplex) * pnXY);
1728 memset(sample_fd, 0.0,
sizeof(cufftDoubleComplex) * pnXY);
1730 cudaMemcpyAsync(sample_fd, k_temp_d_,
sizeof(cufftDoubleComplex) * pnXY, cudaMemcpyDeviceToHost, stream_);
1733 for (
int i = 0; i < pnX * pnY; i++)
1736 cudaFree(sample_fd);
1738 cudaStreamDestroy(stream_);
1750 if (sig_location[1] != 0)
1754 Real yy = (ssY / 2.0) - (ppY)*r - ppY;
1757 if (sig_location[1] == 1)
1758 val[
_IM] = 2 *
M_PI * (yy / (4 * ppY));
1760 val[
_IM] = 2 *
M_PI * (-yy / (4 * ppY));
1763 shift_phase_val *= val;
1766 if (sig_location[0] != 0)
1770 Real xx = (-ssX / 2.0) - (ppX)*c - ppX;
1773 if (sig_location[0] == -1)
1774 val[
_IM] = 2 *
M_PI * (-xx / (4 * ppX));
1776 val[
_IM] = 2 *
M_PI * (xx / (4 * ppX));
1779 shift_phase_val *= val;
1787 rand_phase_val[
_RE] = 0.0;
1789 #if REAL_IS_DOUBLE & true 1797 rand_phase_val.
exp();
1801 rand_phase_val[
_RE] = 1.0;
1802 rand_phase_val[
_IM] = 0.0;
1820 template <
typename T>
1824 #pragma omp parallel for 1826 for (
int i = 0; i < size; i++) {
1827 encoded[i] = real(holo[i]);
1831 template <
typename T>
1835 #pragma omp parallel for 1837 for (
int i = 0; i < size; i++) {
1838 encoded[i] = imag(holo[i]);
1842 template <
typename T>
1845 double pi2 =
M_PI * 2;
1847 #pragma omp parallel for firstprivate(pi2) 1849 for (
int i = 0; i < size; i++) {
1850 encoded[i] = (holo[i].
angle() +
M_PI) / pi2;
1854 template <
typename T>
1858 #pragma omp parallel for 1860 for (
int i = 0; i < size; i++) {
1861 encoded[i] = holo[i].
mag();
1865 template <
typename T>
1868 int resize = size >> 1;
1872 #pragma omp parallel for 1874 for (
int i = 0; i < resize; i++) {
1875 normCplx[i] = holo[i * 2];
1878 oph::normalize<T>(normCplx, normCplx, resize);
1880 T* ampl =
new T[resize];
1883 T* phase =
new T[resize];
1884 Phase(normCplx, phase, resize);
1887 #pragma omp parallel for 1889 for (
int i = 0; i < resize; i++) {
1890 T delPhase = acos(ampl[i]);
1891 encoded[i * 2] = (phase[i] +
M_PI) + delPhase;
1892 encoded[i * 2 + 1] = (phase[i] +
M_PI) - delPhase;
1900 template <
typename T>
1903 int resize = size / 3;
1906 #pragma omp parallel for 1908 for (
int i = 0; i < resize; i++) {
1909 norm[i] = holo[i * 3];
1914 T* phase =
new T[resize];
1917 T* ampl =
new T[resize];
1925 #pragma omp parallel for firstprivate(pi2, pi4, sqrt3) 1927 for (
int i = 0; i < resize; i++) {
1929 if (phase[i] >= 0 && phase[i] < (pi2 / 3))
1931 encoded[idx] = ampl[i] * (cos(phase[i]) + sin(phase[i]) / sqrt3);
1932 encoded[idx + 1] = 2 * sin(phase[i]) / sqrt3;
1934 else if (phase[i] >= (pi2 / 3) && phase[i] < (pi4 / 3))
1936 encoded[idx + 1] = ampl[i] * (cos(phase[i] - (pi2 / 3)) + sin(phase[i] - (pi2 / 3)) / sqrt3);
1937 encoded[idx + 2] = 2 * sin(phase[i] - (pi2 / 3)) / sqrt3;
1939 else if (phase[i] >= (pi4 / 3) && phase[i] < (pi2))
1941 encoded[idx + 2] = ampl[i] * (cos(phase[i] - (pi4 / 3)) + sin(phase[i] - (pi4 / 3)) / sqrt3);
1942 encoded[idx] = 2 * sin(phase[i] - (pi4 / 3)) / sqrt3;
1952 template <
typename T>
1955 T* tmp1 =
new T[size];
1957 #pragma omp parallel for 1959 for (
int i = 0; i < size; i++) {
1960 tmp1[i] = holo[i].
mag();
1967 #pragma omp parallel for firstprivate(max) 1969 for (
int i = 0; i < size; i++) {
1970 T tmp = (holo[i] + max).mag();
1971 encoded[i] = tmp * tmp;
1978 for (
int i = 0; i < nVertex; i++)
1989 for (
int i = 0; i < nVertex; i++) {
1990 dst[i] = -fieldLens * src[i] / (src[i] - fieldLens);
2001 #pragma omp parallel for firstprivate(x, y, z) 2003 for (
int i = 0; i < nSize; i++) {
2004 dst[i + 0] = src[i + 0] * x;
2005 dst[i + 1] = src[i + 1] * y;
2006 dst[i + 2] = src[i + 2] * z;
2015 for (
int i = 0; i < len; i++) {
2016 if (src[i] > maxTmp)
2018 if (src[i] < minTmp)
2029 if (nWave <= 1)
return;
2033 for (
int i = 0; i < nWave - 1; i++)
2036 int scale_x = round(width * wavelengthRatio * scaleFactor);
2037 int scale_y = round(height * wavelengthRatio * scaleFactor);
2039 int ww = width * scaleFactor;
2040 int hh = height * scaleFactor;
2042 int M = scale_x * scale_y;
2047 memset(img_tmp, 0,
sizeof(
uchar) * N);
2051 int offset_x = round((ww - scale_x) / 2);
2052 int offset_y = round((hh - scale_y) / 2);
2055 #pragma omp parallel for firstprivate(offset_x, offset_y, scale_x, ww) 2057 for (
int i = 0; i < M; i++) {
2058 int x = i % scale_x;
2059 int y = i / scale_x;
2061 img_tmp[(y + offset_y) * ww + x + offset_x] = img_scaled[y * scale_x + x];
2067 delete[] img_scaled;
2079 for (
uint i = 0; i < nChannel; i++) {
2090 for (
uint i = 0; i < nChannel; i++) {
bool loadPLY(const std::string &fileName, ulonglong &n_points, Vertex **vertices)
void abs(const oph::Complex< T > &src, oph::Complex< T > &dst)
void Phase(Complex< T > *holo, T *encoded, const int size)
void fresnelPropagation(Complex< Real > *in, Complex< Real > *out, Real distance, uint channel)
Fresnel propagation.
void RS_Diffraction(Point src, Complex< Real > *dst, Real lambda, Real distance, Real amplitude)
RS-diffraction method.
virtual bool saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int width, int height)
Function for creating image files.
void encodeSideBand(unsigned int passband)
Encode the CGH according to a passband parameter.
void cudaCropFringe(CUstream_st *stream, int nx, int ny, cufftDoubleComplex *in_field, cufftDoubleComplex *out_field, int cropx1, int cropx2, int cropy1, int cropy2)
Crop input data according to x, y coordinates on GPU.
void setResolution(ivec2 resolution)
Function for setting buffer size.
void conv_fft2(Complex< Real > *src1, Complex< Real > *src2, Complex< Real > *dst, ivec2 size)
Convolution between Complex arrays which have same size.
void GetMaxMin(Real *src, int len, Real &max, Real &min)
bool getWeightED(const ivec2 holosize, const int type, ivec2 *pNw)
void AngularSpectrumMethod(Complex< Real > *src, Complex< Real > *dst, Real lambda, Real distance)
Angular spectrum propagation method.
void encodeSideBand_CPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location)
Encode the CGH according to a signal location parameter on the CPU.
void binarization(Complex< Real > *src, Real *dst, const int size, int ENCODE_FLAG, Real threshold)
void GetRandomPhaseValue(Complex< Real > &rand_phase_val, bool rand_phase)
Assign random phase value if random_phase == 1.
ulonglong n_points
Number of points.
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
Complex< Real > * weightC
long long int double_size
Real ** m_lpEncoded
buffer to encoded.
void initialize(void)
Initialize variables for Hologram complex field, encoded data, normalized data.
void RealPart(Complex< T > *holo, T *encoded, const int size)
Encoding method.
void setPixelPitchOHC(const vec2 pixel_pitch)
bool shiftW(ivec2 holosize)
void cudaFFT(CUstream_st *stream, int nx, int ny, cufftDoubleComplex *in_filed, cufftDoubleComplex *output_field, int direction, bool bNormailized=false)
Convert data from the spatial domain to the frequency domain using 2D FFT on GPU. ...
void TwoPhase(Complex< T > *holo, T *encoded, const int size)
bool checkExtension(const char *fname, const char *ext)
Functions for extension checking.
structure for 2-dimensional integer vector and its arithmetic.
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
void normalize(const Complex< T > *src, Complex< T > *dst, const int &size)
Normalize all elements of Complex<T>* src from 0 to 1.
void Burckhardt(Complex< T > *holo, T *encoded, const int size)
void setWavelengthOHC(const Real wavelength, const LenUnit wavelength_unit)
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.
void ImaginaryPart(Complex< T > *holo, T *encoded, const int size)
bool Shift(Real x, Real y)
void normalize(void)
Normalization function to save as image file after hologram creation.
bool binaryErrorDiffusion(Complex< Real > *holo, Real *encoded, const ivec2 holosize, const int type, Real threshold)
bool save(const char *fname, uint8_t bitsperpixel=8, uchar *src=nullptr, uint px=0, uint py=0)
Function for saving image files.
ivec2 m_vecEncodeSize
Encoded hologram size, varied from encoding type.
void singleSideBand(Complex< Real > *holo, Real *encoded, const ivec2 holosize, int passband)
Encoding method.
void encodeSideBand_GPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location)
Encode the CGH according to a signal location parameter on the GPU.
void getShiftPhaseValue(Complex< Real > &shift_phase_val, int idx, ivec2 sig_location)
Calculate the shift phase value.
void imgScaleBilinear(uchar *src, uchar *dst, int w, int h, int neww, int newh, int channels=1)
Function for change image size.
void * load(const char *fname)
Function for loading image files.
void SimpleNI(Complex< T > *holo, T *encoded, const int size)
void Fresnel_FFT(Complex< Real > *src, Complex< Real > *dst, Real lambda, Real distance)
Fresnel-fft method.
void waveCarry(Real carryingAngleX, Real carryingAngleY, Real distance)
Wave carry.
void fft2(ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 2-dimension operations inside Openholo.
structure for 2-dimensional Real type vector and its arithmetic.
#define ELAPSED_TIME(x, y)
void cudaGetFringe(CUstream_st *stream, int pnx, int pny, cufftDoubleComplex *in_field, cufftDoubleComplex *out_field, int sig_locationx, int sig_locationy, Real ssx, Real ssy, Real ppx, Real ppy, Real PI)
Encode the CGH according to a signal location parameter on the GPU.
void Amplitude(Complex< T > *holo, T *encoded, const int size)
bool saveRefImages(char *fnameW, char *fnameWC, char *fnameAS, char *fnameSSB, char *fnameHP, char *fnameFreq, char *fnameReal, char *fnameBin, char *fnameReconBin, char *fnameReconErr, char *fnameReconNo)
Vertex * vertices
Data of point clouds.
virtual bool loadAsOhc(const char *fname)
Function to read OHC file.
bool readConfig(const char *fname)
load to configuration file.
XMLError LoadFile(const char *filename)
virtual uchar * loadAsImg(const char *fname)
Function for loading image files.
Real rand(const Real min, const Real max, oph::ulong _SEED_VALUE=0)
Get random Real value from min to max.
void getAmplitude(oph::Complex< Real > *src, Real *dst, const int &size)
void ScaleChange(Real *src, Real *dst, int nSize, Real scaleX, Real scaleY, Real scaleZ)
void CorrectionChromaticAberration(uchar *src, uchar *dst, int width, int height, int scaleFactor=2)
uchar ** m_lpNormalized
buffer to normalized.
Complex< Real > * AS
Binary Encoding - Error diffusion.
Real minOfArr(const std::vector< Real > &arr)
Real maxOfArr(const std::vector< Real > &arr)
void resetBuffer()
reset buffer
void setPixelNumber(ivec2 n)
Function for setting the output resolution.
Complex< Real > * normalized
void Fresnel_Diffraction(Point src, Complex< Real > *dst, Real lambda, Real distance, Real amplitude)
Fresnel-diffraction method.
Complex< Real > ** complex_H
virtual bool loadAsOhc(const char *fname)
Function to read OHC file.
void transVW(int nVertex, Vertex *dst, Vertex *src)
int ENCODE_METHOD
Encoding method flag.
void freqShift(Complex< Real > *holo, Complex< Real > *encoded, const ivec2 holosize, int shift_x, int shift_y)
Frequency shift.
int loadPointCloud(const char *pc_file, OphPointCloudData *pc_data_)
load to point cloud data.
const XMLElement * FirstChildElement(const char *name=0) const
bool mergeColor(int idx, int width, int height, uchar *src, uchar *dst)
Function for generate RGB image from each grayscale image.
virtual void ophFree(void)
Pure virtual function for override in child classes.
virtual void ophFree(void)
Pure virtual function for override in child classes.
virtual ~ophGen(void)=0
Destructor.