16 : num_image(
ivec2(0, 0))
17 , resolution_image(
ivec2(0, 0))
18 , distanceRS2Holo(0.0)
20 , is_ViewingWindow(false)
25 , FToverUV_LF(nullptr)
28 , LF_directory(nullptr)
31 LOG(
"*** LIGHT FIELD : BUILD DATE: %s %s ***\n\n", __DATE__, __TIME__);
36 this->is_ViewingWindow = is_ViewingWindow;
54 LOG(
"<FAILED> Wrong file ext.\n");
59 LOG(
"<FAILED> Loading file.\n");
65 char szNodeName[32] = { 0, };
66 sprintf(szNodeName,
"FieldLength");
69 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&fieldLens))
71 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
76 sprintf(szNodeName,
"Image_NumOfX");
78 if (!next ||
XML_SUCCESS != next->QueryIntText(&num_image[
_X]))
80 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
83 sprintf(szNodeName,
"Image_NumOfY");
85 if (!next ||
XML_SUCCESS != next->QueryIntText(&num_image[
_Y]))
87 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
90 sprintf(szNodeName,
"Image_Width");
92 if (!next ||
XML_SUCCESS != next->QueryIntText(&resolution_image[
_X]))
94 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
97 sprintf(szNodeName,
"Image_Height");
99 if (!next ||
XML_SUCCESS != next->QueryIntText(&resolution_image[
_Y]))
101 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
104 sprintf(szNodeName,
"Distance");
106 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&distanceRS2Holo))
108 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
123 string sdir = std::string(LF_directory).append(
"\\").append(
"*.").append(exten);
124 intptr_t ff = _findfirst(sdir.c_str(), &data);
134 string imgfullname = std::string(LF_directory).append(
"\\").append(data.name);
140 LOG(
"<FAILED> Load image.");
147 int out = _findnext(ff, &data);
155 if (directory[0] !=
'/') {
156 char buf[PATH_MAX] = { 0, };
157 if (getcwd(buf,
sizeof(buf)) !=
nullptr) {
158 sdir = sdir.append(buf).append(
"/").append(directory);
162 sdir = string(directory);
163 string ext = string(exten);
165 if ((dir = opendir(sdir.c_str())) !=
nullptr) {
174 vector<string> fileList;
175 while ((ent = readdir(dir)) !=
nullptr) {
177 filePath = filePath.append(sdir.c_str()).append(
"/").append(ent->d_name);
178 if (filePath !=
"." && filePath !=
"..") {
179 struct stat fileInfo;
180 if (stat(filePath.c_str(), &fileInfo) == 0 && S_ISREG(fileInfo.st_mode)) {
181 if (filePath.substr(filePath.find_last_of(
".") + 1) == ext) {
182 fileList.push_back(filePath);
189 std::sort(fileList.begin(), fileList.end());
192 for (
size_t i = 0; i < fileList.size(); i++)
201 LOG(
"<FAILED> Load image.");
209 if (num_image[
_X] * num_image[
_Y] != num) {
210 LOG(
"<FAILED> Not matching image.");
216 LOG(
"<FAILED> Load image.");
232 LOG(
"1) Algorithm Method : Non-hogel based hologram generation from Light Field\n");
242 LOG(
"4) Number of Images : %d x %d\n", num_image[
_X], num_image[
_Y]);
247 LOG(
"Not implement GPU version");
267 LOG(
"1) Algorithm Method : Non-hogel based hologram generation from Light Field\n");
277 LOG(
"4) Number of Images : %d x %d\n", num_image[
_X], num_image[
_Y]);
282 LOG(
"Not implement GPU version");
309 const uint nU = num_image[
_X];
310 const uint nV = num_image[
_Y];
311 nBufferX = (nU >> 1) + 1;
312 nBufferY = (nV >> 1) + 1;
318 for (
int i = 0; i < nImages; i++) {
328 LF =
new uchar*[num_image[
_X] * num_image[
_Y]];
329 for (
int i = 0; i < num_image[
_X] * num_image[
_Y]; i++) {
330 LF[i] =
new uchar[resolution_image[
_X] * resolution_image[
_Y]];
331 memset(LF[i], 0, resolution_image[
_X] * resolution_image[
_Y]);
333 nImages = num_image[
_X] * num_image[
_Y];
340 const uint nU = num_image[
_X];
341 const uint nV = num_image[
_Y];
342 const uint nUV = nU * nV;
343 const uint nX = resolution_image[
_X];
344 const uint nY = resolution_image[
_Y];
345 const uint nXY = nX * nY;
346 const uint nXwithBuffer = nX + 2 * nBufferX;
347 const uint nYwithBuffer = nY + 2 * nBufferY;
348 const long long int nXYwithBuffer = nXwithBuffer * nYwithBuffer;
360 #pragma omp parallel for 362 for (
int idxnXY = 0; idxnXY < nXYwithBuffer; idxnXY++) {
364 phase(0.0, 2.0 *
M_PI * randVal);
365 WField[idxnXY] = exp(phase);
373 const uint nU = num_image[
_X];
374 const uint nV = num_image[
_Y];
375 const uint nUV = nU * nV;
376 const uint nX = resolution_image[
_X];
377 const uint nY = resolution_image[
_Y];
378 const uint nXY = nX * nY;
379 const long long int nXwithBuffer = nX + 2 * nBufferX;
380 const long long int nYwithBuffer = nY + 2 * nBufferY;
381 const long long int nXYwithBuffer = nXwithBuffer * nYwithBuffer;
396 for (
int idxnX = 0; idxnX < nXwithBuffer; idxnX++) {
397 for (
int idxnY = 0; idxnY < nYwithBuffer; idxnY++) {
398 phase(0.0, 2.0*
M_PI* (carrierFreqX*idxnX*px + carrierFreqY*idxnY*py));
399 WField[idxnX + nXwithBuffer*idxnY] = exp(phase);
408 const int nX = resolution_image[
_X];
409 const int nY = resolution_image[
_Y];
410 const long long int nXY = nX * nY;
411 const int nU = num_image[
_X];
412 const int nV = num_image[
_Y];
413 const int nUV = nU * nV;
414 const long long int nXwithBuffer = nX + 2 * nBufferX;
415 const long long int nYwithBuffer = nY + 2 * nBufferY;
416 const long long int nXYwithBuffer = nXwithBuffer * nYwithBuffer;
421 for (
int idxnUV = 0; idxnUV < nUV; idxnUV++) {
422 if (FToverUV_LF[idxnUV]) {
423 delete[] FToverUV_LF[idxnUV];
424 FToverUV_LF[idxnUV] =
nullptr;
427 delete[] FToverUV_LF;
428 FToverUV_LF =
nullptr;
432 for (
int idxnUV = 0; idxnUV < nUV; idxnUV++) {
434 memset(FToverUV_LF[idxnUV], 0.0, nXY);
440 int progressCheckPoint = 10000;
442 for (
int idxnXY = 0; idxnXY < nXY; idxnXY++) {
446 for (
int idxnUV = 0; idxnUV < nUV; idxnUV++) {
447 LFatXY[idxnUV] = LF[idxnUV][idxnXY];
453 for (
int idxnUV = 0; idxnUV < nUV; idxnUV++) {
454 FToverUV_LF[idxnUV][idxnXY] = FToverUVatXY[idxnUV];
458 if (idxProgress == progressCheckPoint ) {
459 LOG(
"idxnXY : %1d out of nXY= %llu\n", idxnXY, nXY);
467 delete[] FToverUVatXY;
476 const int nX = resolution_image[
_X];
477 const int nY = resolution_image[
_Y];
478 const long long int nXY = nX * nY;
479 const int nU = num_image[
_X];
480 const int nV = num_image[
_Y];
481 const int nUV = nU * nV;
482 const long long int nXwithBuffer = nX + 2 * nBufferX;
483 const long long int nYwithBuffer = nY + 2 * nBufferY;
484 const long long int nXYwithBuffer = nXwithBuffer * nYwithBuffer;
494 memset(HologramWithBuffer, 0.0,
sizeof(
Complex<Real>) * nXYwithBuffer);
505 for (idxnU = 0; idxnU < nU; idxnU++) {
506 startXH = (int)((((
double)idxnU) - 1.) / 2.) + (int)(-(((
double)nU) + 1.) / 4. - ((double)(nX))/2.0 + ((
double)(nXwithBuffer)) / 2.0);
507 startXW = startXH + (int)(((
double)nU) / 2.) - (idxnU - 1);
509 for (idxnV = 0; idxnV < nV; idxnV++) {
510 startYH = (int)((((
double)idxnV) - 1.) / 2.) + (int)(-(((
double)nV) + 1.) / 4. - ((double)(nY)) / 2.0 + ((
double)(nYwithBuffer)) / 2.0);
511 startYW = startYH + (int)(((
double)nV) / 2.) - (idxnV - 1);
513 for (idxnX = 0; idxnX < nX; idxnX++) {
514 for (idxnY = 0; idxnY < nY; idxnY++) {
516 HologramWithBuffer[(startXH + idxnX) + nXwithBuffer*(startYH + idxnY)] += FToverUV_LF[idxnU + nU*idxnV][idxnX+nX*idxnY] * WField[(startXW + idxnX) + nXwithBuffer*(startYW + idxnY)];
523 for (idxnX = 0; idxnX < nX; idxnX++) {
524 for (idxnY = 0; idxnY < nY; idxnY++) {
525 Hologram[idxnX + nX*idxnY] = HologramWithBuffer[(nBufferX + idxnX) + nXwithBuffer*(nBufferY + idxnY)];
528 delete[] HologramWithBuffer;
534 const int n = nx * ny;
536 double* intensity = (
double*)malloc(
sizeof(
double)*n);
537 for (
int i = 0; i < n; i++)
538 intensity[i] = complexvalue[i].real();
541 double min_val, max_val;
542 min_val = intensity[0];
543 max_val = intensity[0];
545 for (
int i = 0; i < n; ++i)
547 if (min_val > intensity[i])
548 min_val = intensity[i];
549 else if (max_val < intensity[i])
550 max_val = intensity[i];
554 strcpy(fname, fileName);
558 sprintf(num,
"_%d", k);
561 strcat(fname,
".bmp");
565 unsigned char* cgh = (
unsigned char*)malloc(
sizeof(
unsigned char)*n);
567 for (
int i = 0; i < n; ++i) {
568 double val = (intensity[i] - min_val) / (max_val - min_val);
571 unsigned char v = (
uchar)val;
virtual bool saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int width, int height)
Function for creating image files.
void fftFree(void)
Resource release method.
void writeIntensity_gray8_bmp(const char *fileName, int nx, int ny, Complex< Real > *complexvalue, int k=-1)
void convertLF2ComplexFieldUsingNonHogelMethod()
int loadLF(const char *directory, const char *exten)
Light Field images load.
void initialize(void)
Initialize variables for Hologram complex field, encoded data, normalized data.
void fourierTransformOverUVLF()
bool checkExtension(const char *fname, const char *ext)
Functions for extension checking.
structure for 2-dimensional integer vector and its arithmetic.
bool GetRandomPhase()
Function for getting the random phase.
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
void setViewingWindow(bool is_ViewingWindow)
Set the value of a variable is_ViewingWindow(true or false)
bool getImgSize(int &w, int &h, int &bytesperpixel, const char *fname)
Function for getting the image size.
void Fresnel_FFT(Complex< Real > *src, Complex< Real > *dst, Real lambda, Real distance)
Fresnel-fft method.
void fft2(ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 2-dimension operations inside Openholo.
void makePlaneWaveWField(double thetaX, double thetaY)
void convertToFormatGray8(uchar *src, uchar *dst, int w, int h, int bytesperpixel)
Function for convert image format to gray8.
bool readConfig(const char *fname)
Light Field based CGH configuration file load.
#define ELAPSED_TIME(x, y)
bool readConfig(const char *fname)
load to configuration file.
ophNonHogelLF(void)
Constructor.
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 resetBuffer()
reset buffer
void preprocessLF()
Hologram generation.
Complex< Real > ** complex_H
const XMLElement * FirstChildElement(const char *name=0) const