61 : num_image(
ivec2(0, 0))
62 , resolution_image(
ivec2(0, 0))
63 , distanceRS2Holo(0.0)
65 , is_ViewingWindow(false)
68 LOG(
"*** LIGHT FIELD : BUILD DATE: %s %s ***\n\n", __DATE__, __TIME__);
73 this->is_ViewingWindow = is_ViewingWindow;
90 LOG(
"<FAILED> Wrong file ext.\n");
95 LOG(
"<FAILED> Loading file.\n");
101 char szNodeName[32] = { 0, };
102 sprintf(szNodeName,
"FieldLength");
105 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&fieldLens))
107 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
112 sprintf(szNodeName,
"Image_NumOfX");
114 if (!next ||
XML_SUCCESS != next->QueryIntText(&num_image[
_X]))
116 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
119 sprintf(szNodeName,
"Image_NumOfY");
121 if (!next ||
XML_SUCCESS != next->QueryIntText(&num_image[
_Y]))
123 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
126 sprintf(szNodeName,
"Image_Width");
128 if (!next ||
XML_SUCCESS != next->QueryIntText(&resolution_image[
_X]))
130 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
133 sprintf(szNodeName,
"Image_Height");
135 if (!next ||
XML_SUCCESS != next->QueryIntText(&resolution_image[
_Y]))
137 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
140 sprintf(szNodeName,
"Distance");
142 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&distanceRS2Holo))
144 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
150 LOG(
"**************************************************\n");
151 LOG(
" Read Config (Light Field) \n");
152 LOG(
"1) Focal Length : %.5lf\n", distanceRS2Holo);
153 LOG(
"2) Number of Images : %d x %d\n", num_image[
_X], num_image[
_Y]);
154 LOG(
"3) Resolution of Each Image : %d x %d\n", resolution_image[
_X], resolution_image[
_Y]);
155 LOG(
"4) Field Length (Unused) : %.5lf\n", fieldLens);
156 LOG(
"**************************************************\n");
170 string sdir = std::string(directory).append(
"\\").append(
"*.").append(exten);
171 intptr_t ff = _findfirst(sdir.c_str(), &data);
181 string imgfullname = std::string(directory).append(
"/").append(data.name);
188 size = ((sizeOut[
_X] + 3) & ~3) * sizeOut[
_Y];
190 m_vecImages[num] =
new uchar[size];
192 m_vecImgSize[num] = size;
193 if (img ==
nullptr) {
194 LOG(
"<FAILED> Load image.\n");
200 m_vecImages[num] =
loadAsImg(imgfullname.c_str());
201 m_vecImgSize[num] = size;
202 if (m_vecImages[num] ==
nullptr) {
203 LOG(
"<FAILED> Load image.\n");
209 int out = _findnext(ff, &data);
215 if (num_image[
_X] * num_image[
_Y] != num) {
216 LOG(
"<FAILED> Not matching image.\n");
222 LOG(
"<FAILED> Load image.\n");
230 if (directory[0] !=
'/') {
231 char buf[PATH_MAX] = { 0, };
232 if (getcwd(buf,
sizeof(buf)) !=
nullptr) {
233 sdir = sdir.append(buf).append(
"/").append(directory);
237 sdir = string(directory);
238 string ext = string(exten);
240 if ((dir = opendir(sdir.c_str())) !=
nullptr) {
249 vector<string> fileList;
250 while ((ent = readdir(dir)) !=
nullptr) {
252 filePath = filePath.append(sdir.c_str()).append(
"/").append(ent->d_name);
253 if (filePath !=
"." && filePath !=
"..") {
254 struct stat fileInfo;
255 if (stat(filePath.c_str(), &fileInfo) == 0 && S_ISREG(fileInfo.st_mode)) {
256 if (filePath.substr(filePath.find_last_of(
".") + 1) == ext) {
257 fileList.push_back(filePath);
264 std::sort(fileList.begin(), fileList.end());
266 for (
size_t i = 0; i < fileList.size(); i++)
274 size = ((sizeOut[
_X] + 3) & ~3) * sizeOut[
_Y];
276 m_vecImages[i] =
new uchar[size];
278 m_vecImgSize[i] = size;
279 if (img ==
nullptr) {
280 LOG(
"<FAILED> Load image.\n");
286 m_vecImages[i] =
loadAsImg(fileList[i].c_str());
287 m_vecImgSize[i] = size;
288 if (m_vecImages[i] ==
nullptr) {
289 LOG(
"<FAILED> Load image.\n");
294 if (num_image[
_X] * num_image[
_Y] != (
int)fileList.size()) {
295 LOG(
"<FAILED> Not matching image.\n");
302 LOG(
"<FAILED> Load image : %s\n", sdir.c_str());
312 LOG(
"**************************************************\n");
313 LOG(
" Generate Hologram \n");
314 LOG(
"1) Algorithm Method : Light Field\n");
324 LOG(
"**************************************************\n");
348 for (vector<uchar *>::iterator it = m_vecImages.begin(); it != m_vecImages.end(); it++)
delete[](*it);
350 m_vecImgSize.clear();
352 const int nX = num_image[
_X];
353 const int nY = num_image[
_Y];
354 const int N = nX * nY;
356 m_vecImages.resize(N);
357 m_vecImgSize.resize(N);
365 const uint nX = num_image[
_X];
366 const uint nY = num_image[
_Y];
367 const long long int N = nX * nY;
369 const uint rX = resolution_image[
_X];
370 const uint rY = resolution_image[
_Y];
371 const uint R = rX * rY;
376 for (vector<
Complex<Real>*>::iterator it = m_vecRSplane.begin(); it != m_vecRSplane.end(); it++)
delete[](*it);
377 m_vecRSplane.clear();
378 m_vecRSplane.resize(nWave);
380 for (
uint i = 0; i < nWave; i++)
388 for (
uint ch = 0; ch < nWave; ch++)
390 int iColor = nWave - ch - 1;
391 for (
uint r = 0; r < R; r++)
395 int iWidth = r * nWave;
397 for (
uint n = 0; n < N; n++)
399 tmp[n][
_RE] = (
Real)(m_vecImages[n][iWidth + iColor]);
405 int base1 = N * rX *
h;
407 for (
uint n = 0; n < N; n++)
412 Real randVal = bRandomPhase ?
rand(0.0, 1.0) : 1.0;
414 m_vecRSplane[ch][base1 + base2 + ((n - j) * rX) + j] = tmp[n] * phase.
exp();
427 const int n = nx * ny;
429 double* intensity = (
double*)malloc(
sizeof(
double)*n);
430 for (
int i = 0; i < n; i++)
431 intensity[i] = complexvalue[i].real();
434 double min_val, max_val;
435 min_val = intensity[0];
436 max_val = intensity[0];
438 for (
int i = 0; i < n; ++i)
440 if (min_val > intensity[i])
441 min_val = intensity[i];
442 else if (max_val < intensity[i])
443 max_val = intensity[i];
447 strcpy(fname, fileName);
451 sprintf(num,
"_%d", k);
454 strcat(fname,
".bmp");
458 unsigned char* cgh = (
unsigned char*)malloc(
sizeof(
unsigned char)*n);
460 for (
int i = 0; i < n; ++i) {
461 double val = (intensity[i] - min_val) / (max_val - min_val);
464 unsigned char v = (
uchar)val;
479 for (vector<uchar *>::iterator it = m_vecImages.begin(); it != m_vecImages.end(); it++)
delete[](*it);
480 for (vector<
Complex<Real> *>::iterator it = m_vecRSplane.begin(); it != m_vecRSplane.end(); it++)
delete[](*it);
482 m_vecImgSize.clear();
483 m_vecRSplane.clear();
void convertLF2ComplexField()
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 setViewingWindow(bool is_ViewingWindow)
Set the value of a variable is_ViewingWindow(true or false)
bool readConfig(const char *fname)
Light Field based CGH configuration file load.
void initialize(void)
Initialize variables for Hologram complex field, encoded data, normalized data.
void convertLF2ComplexField_GPU()
bool checkExtension(const char *fname, const char *ext)
Functions for extension checking.
structure for 2-dimensional integer vector and its arithmetic.
void ophFree()
Pure virtual function for override in child classes.
bool GetRandomPhase()
Function for getting the random phase.
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
void generateHologram()
Hologram generation.
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 convertToFormatGray8(uchar *src, uchar *dst, int w, int h, int bytesperpixel)
Function for convert image format to gray8.
#define ELAPSED_TIME(x, y)
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 writeIntensity_gray8_bmp(const char *fileName, int nx, int ny, Complex< Real > *complexvalue, int k=-1)
void resetBuffer()
reset buffer
Complex< Real > ** complex_H
int loadLF(const char *directory, const char *exten)
Light Field images load.
const XMLElement * FirstChildElement(const char *name=0) const
virtual void ophFree(void)
Pure virtual function for override in child classes.