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");
347 for (vector<uchar *>::iterator it = m_vecImages.begin(); it != m_vecImages.end(); it++)
delete[](*it);
349 m_vecImgSize.clear();
351 const int nX = num_image[
_X];
352 const int nY = num_image[
_Y];
353 const int N = nX * nY;
355 m_vecImages.resize(N);
356 m_vecImgSize.resize(N);
364 const uint nX = num_image[
_X];
365 const uint nY = num_image[
_Y];
366 const long long int N = nX * nY;
368 const uint rX = resolution_image[
_X];
369 const uint rY = resolution_image[
_Y];
370 const uint R = rX * rY;
375 for (vector<
Complex<Real>*>::iterator it = m_vecRSplane.begin(); it != m_vecRSplane.end(); it++)
delete[](*it);
376 m_vecRSplane.clear();
377 m_vecRSplane.resize(nWave);
379 for (
uint i = 0; i < nWave; i++)
387 for (
uint ch = 0; ch < nWave; ch++)
389 int iColor = nWave - ch - 1;
390 for (
uint r = 0; r < R; r++)
394 int iWidth = r * nWave;
396 for (
uint n = 0; n < N; n++)
398 tmp[n][
_RE] = (
Real)(m_vecImages[n][iWidth + iColor]);
404 int base1 = N * rX *
h;
406 for (
uint n = 0; n < N; n++)
411 Real randVal = bRandomPhase ?
rand(0.0, 1.0) : 1.0;
413 m_vecRSplane[ch][base1 + base2 + ((n - j) * rX) + j] = tmp[n] * phase.
exp();
426 const int n = nx * ny;
428 double* intensity = (
double*)malloc(
sizeof(
double)*n);
429 for (
int i = 0; i < n; i++)
430 intensity[i] = complexvalue[i].real();
433 double min_val, max_val;
434 min_val = intensity[0];
435 max_val = intensity[0];
437 for (
int i = 0; i < n; ++i)
439 if (min_val > intensity[i])
440 min_val = intensity[i];
441 else if (max_val < intensity[i])
442 max_val = intensity[i];
446 strcpy(fname, fileName);
450 sprintf(num,
"_%d",
k);
453 strcat(fname,
".bmp");
457 unsigned char* cgh = (
unsigned char*)malloc(
sizeof(
unsigned char)*n);
459 for (
int i = 0; i < n; ++i) {
460 double val = (intensity[i] - min_val) / (max_val - min_val);
463 unsigned char v = (
uchar)val;
478 for (vector<uchar *>::iterator it = m_vecImages.begin(); it != m_vecImages.end(); it++)
delete[](*it);
479 for (vector<
Complex<Real> *>::iterator it = m_vecRSplane.begin(); it != m_vecRSplane.end(); it++)
delete[](*it);
481 m_vecImgSize.clear();
482 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 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.
void fresnelPropagation(OphConfig context, Complex< Real > *in, Complex< Real > *out, Real distance)
Fresnel propagation.
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)
Complex< Real > ** complex_H
void resetBuffer()
reset buffer
#define ELAPSED_TIME(x, y)
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.