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");
266 LOG(
"1) Algorithm Method : Non-hogel based hologram generation from Light Field\n");
276 LOG(
"4) Number of Images : %d x %d\n", num_image[
_X], num_image[
_Y]);
281 LOG(
"Not implement GPU version");
307 const uint nU = num_image[
_X];
308 const uint nV = num_image[
_Y];
309 nBufferX = (nU >> 1) + 1;
310 nBufferY = (nV >> 1) + 1;
316 for (
int i = 0; i < nImages; i++) {
326 LF =
new uchar*[num_image[
_X] * num_image[
_Y]];
327 for (
int i = 0; i < num_image[
_X] * num_image[
_Y]; i++) {
328 LF[i] =
new uchar[resolution_image[
_X] * resolution_image[
_Y]];
329 memset(LF[i], 0, resolution_image[
_X] * resolution_image[
_Y]);
331 nImages = num_image[
_X] * num_image[
_Y];
338 const uint nU = num_image[
_X];
339 const uint nV = num_image[
_Y];
340 const uint nUV = nU * nV;
341 const uint nX = resolution_image[
_X];
342 const uint nY = resolution_image[
_Y];
343 const uint nXY = nX * nY;
344 const uint nXwithBuffer = nX + 2 * nBufferX;
345 const uint nYwithBuffer = nY + 2 * nBufferY;
346 const long long int nXYwithBuffer = nXwithBuffer * nYwithBuffer;
358 #pragma omp parallel for 360 for (
int idxnXY = 0; idxnXY < nXYwithBuffer; idxnXY++) {
362 phase(0.0, 2.0 *
M_PI * randVal);
363 WField[idxnXY] = exp(phase);
371 const uint nU = num_image[
_X];
372 const uint nV = num_image[
_Y];
373 const uint nUV = nU * nV;
374 const uint nX = resolution_image[
_X];
375 const uint nY = resolution_image[
_Y];
376 const uint nXY = nX * nY;
377 const long long int nXwithBuffer = nX + 2 * nBufferX;
378 const long long int nYwithBuffer = nY + 2 * nBufferY;
379 const long long int nXYwithBuffer = nXwithBuffer * nYwithBuffer;
394 for (
int idxnX = 0; idxnX < nXwithBuffer; idxnX++) {
395 for (
int idxnY = 0; idxnY < nYwithBuffer; idxnY++) {
396 phase(0.0, 2.0*
M_PI* (carrierFreqX*idxnX*px + carrierFreqY*idxnY*py));
397 WField[idxnX + nXwithBuffer*idxnY] = exp(phase);
406 const int nX = resolution_image[
_X];
407 const int nY = resolution_image[
_Y];
408 const long long int nXY = nX * nY;
409 const int nU = num_image[
_X];
410 const int nV = num_image[
_Y];
411 const int nUV = nU * nV;
412 const long long int nXwithBuffer = nX + 2 * nBufferX;
413 const long long int nYwithBuffer = nY + 2 * nBufferY;
414 const long long int nXYwithBuffer = nXwithBuffer * nYwithBuffer;
419 for (
int idxnUV = 0; idxnUV < nUV; idxnUV++) {
420 if (FToverUV_LF[idxnUV]) {
421 delete[] FToverUV_LF[idxnUV];
422 FToverUV_LF[idxnUV] =
nullptr;
425 delete[] FToverUV_LF;
426 FToverUV_LF =
nullptr;
430 for (
int idxnUV = 0; idxnUV < nUV; idxnUV++) {
432 memset(FToverUV_LF[idxnUV], 0.0, nXY);
438 int progressCheckPoint = 10000;
440 for (
int idxnXY = 0; idxnXY < nXY; idxnXY++) {
444 for (
int idxnUV = 0; idxnUV < nUV; idxnUV++) {
445 LFatXY[idxnUV] = LF[idxnUV][idxnXY];
451 for (
int idxnUV = 0; idxnUV < nUV; idxnUV++) {
452 FToverUV_LF[idxnUV][idxnXY] = FToverUVatXY[idxnUV];
456 if (idxProgress == progressCheckPoint ) {
457 LOG(
"idxnXY : %1d out of nXY= %llu\n", idxnXY, nXY);
465 delete[] FToverUVatXY;
474 const int nX = resolution_image[
_X];
475 const int nY = resolution_image[
_Y];
476 const long long int nXY = nX * nY;
477 const int nU = num_image[
_X];
478 const int nV = num_image[
_Y];
479 const int nUV = nU * nV;
480 const long long int nXwithBuffer = nX + 2 * nBufferX;
481 const long long int nYwithBuffer = nY + 2 * nBufferY;
482 const long long int nXYwithBuffer = nXwithBuffer * nYwithBuffer;
492 memset(HologramWithBuffer, 0.0,
sizeof(
Complex<Real>) * nXYwithBuffer);
503 for (idxnU = 0; idxnU < nU; idxnU++) {
504 startXH = (int)((((
double)idxnU) - 1.) / 2.) + (int)(-(((
double)nU) + 1.) / 4. - ((double)(nX))/2.0 + ((
double)(nXwithBuffer)) / 2.0);
505 startXW = startXH + (int)(((
double)nU) / 2.) - (idxnU - 1);
507 for (idxnV = 0; idxnV < nV; idxnV++) {
508 startYH = (int)((((
double)idxnV) - 1.) / 2.) + (int)(-(((
double)nV) + 1.) / 4. - ((double)(nY)) / 2.0 + ((
double)(nYwithBuffer)) / 2.0);
509 startYW = startYH + (int)(((
double)nV) / 2.) - (idxnV - 1);
511 for (idxnX = 0; idxnX < nX; idxnX++) {
512 for (idxnY = 0; idxnY < nY; idxnY++) {
514 HologramWithBuffer[(startXH + idxnX) + nXwithBuffer*(startYH + idxnY)] += FToverUV_LF[idxnU + nU*idxnV][idxnX+nX*idxnY] * WField[(startXW + idxnX) + nXwithBuffer*(startYW + idxnY)];
521 for (idxnX = 0; idxnX < nX; idxnX++) {
522 for (idxnY = 0; idxnY < nY; idxnY++) {
523 Hologram[idxnX + nX*idxnY] = HologramWithBuffer[(nBufferX + idxnX) + nXwithBuffer*(nBufferY + idxnY)];
526 delete[] HologramWithBuffer;
532 const int n = nx * ny;
534 double* intensity = (
double*)malloc(
sizeof(
double)*n);
535 for (
int i = 0; i < n; i++)
536 intensity[i] = complexvalue[i].real();
539 double min_val, max_val;
540 min_val = intensity[0];
541 max_val = intensity[0];
543 for (
int i = 0; i < n; ++i)
545 if (min_val > intensity[i])
546 min_val = intensity[i];
547 else if (max_val < intensity[i])
548 max_val = intensity[i];
552 strcpy(fname, fileName);
556 sprintf(num,
"_%d",
k);
559 strcat(fname,
".bmp");
563 unsigned char* cgh = (
unsigned char*)malloc(
sizeof(
unsigned char)*n);
565 for (
int i = 0; i < n; ++i) {
566 double val = (intensity[i] - min_val) / (max_val - min_val);
569 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 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.
void fresnelPropagation(OphConfig context, Complex< Real > *in, Complex< Real > *out, Real distance)
Fresnel propagation.
bool readConfig(const char *fname)
Light Field based CGH configuration file load.
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.
Complex< Real > ** complex_H
void resetBuffer()
reset buffer
#define ELAPSED_TIME(x, y)
void preprocessLF()
Hologram generation.
const XMLElement * FirstChildElement(const char *name=0) const