15 ,coefficient_cx(nullptr)
16 ,coefficient_cy(nullptr)
17 ,compensation_cx(nullptr)
18 ,compensation_cy(nullptr)
23 LOG(
"*** PHASE-ADDED STEREOGRAM: BUILD DATE: %s %s ***\n\n", __DATE__, __TIME__);
28 if (coefficient_cx !=
nullptr)
29 delete[] coefficient_cx;
30 if (coefficient_cy !=
nullptr)
31 delete[] coefficient_cy;
32 if (compensation_cx !=
nullptr)
33 delete[] compensation_cx;
34 if (compensation_cy !=
nullptr)
35 delete[] compensation_cy;
56 LOG(
"<FAILED> Wrong file ext.\n");
61 LOG(
"<FAILED> Loading file.\n");
67 char szNodeName[32] = { 0, };
68 sprintf(szNodeName,
"ScaleX");
71 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[
_X]))
73 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
76 sprintf(szNodeName,
"ScaleY");
78 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[
_Y]))
80 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
83 sprintf(szNodeName,
"ScaleZ");
85 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[
_Z]))
87 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
90 sprintf(szNodeName,
"Distance");
92 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config.distance))
94 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
100 LOG(
"**************************************************\n");
101 LOG(
" Read Config (Phase-Added Stereogram) \n");
102 LOG(
"1) Focal Length : %.5lf\n", pc_config.distance);
103 LOG(
"2) Object Scale : %.5lf / %.5lf / %.5lf\n", pc_config.scale[
_X], pc_config.scale[
_Y], pc_config.scale[
_Z]);
104 LOG(
"**************************************************\n");
132 const int snX = pnX / segSize;
133 const int snY = pnY / segSize;
135 if (coefficient_cx ==
nullptr)
136 coefficient_cx =
new int[snX];
137 if (coefficient_cy ==
nullptr)
138 coefficient_cy =
new int[snY];
139 if (compensation_cx ==
nullptr)
140 compensation_cx =
new Real[snX];
141 if (compensation_cy ==
nullptr)
142 compensation_cy =
new Real[snY];
152 for (
int i = 0; i <
NUMTBL; i++) {
153 Real theta = pi2 * (i + i - 1) / (2 *
NUMTBL);
154 LUTCos[i] = cos(theta);
155 LUTSin[i] = sin(theta);
166 const int hpnX = pnX >> 1;
167 const int hpnY = pnY >> 1;
170 const int N = pnX * pnY;
172 const int hSegSize = segSize >> 1;
173 const int sSegSize = segSize * segSize;
176 const int ffthSegSize = fftSegSize >> 1;
177 const int fftsSegSize = fftSegSize * fftSegSize;
179 const int snX = pnX / segSize;
180 const int snY = pnY / segSize;
181 const int hsnX = snX >> 1;
182 const int hsnY = snY >> 1;
184 const int snXY = snX * snY;
189 const Real sf_base = 1.0 / (ppX * fftSegSize);
192 for (
int i = 0; i < snXY; i++) {
204 for (
int i = 0; i < n_points; i++)
213 pt.
pos[
_Z] -= distance;
220 for (
int y = 0; y < snY; y++) {
222 for (
int x = 0; x < snX; x++) {
224 int segyy = y * snX + x;
225 int segxx = coefficient_cy[y] * fftSegSize + coefficient_cx[x];
229 fft2(input[segyy], result, fftSegSize, fftSegSize,
OPH_BACKWARD,
false,
false);
231 for (
int m = 0;
m < segSize;
m++)
233 int yy = y * segSize +
m;
234 int xx = x * segSize;
235 int mm =
m + ffthSegSize;
236 for (
int n = 0; n < segSize; n++)
238 complex_H[ch][yy * pnX + (xx + n)] += result[(
m + ffthSegSize - hSegSize) * fftSegSize + (n + ffthSegSize - hSegSize)][
_RE];
247 for (
int y = 0; y < snY; y++) {
249 for (
int x = 0; x < snX; x++) {
251 int segyy = y * snX + x;
252 int segxx = coefficient_cy[y] * segSize + coefficient_cx[x];
258 for (
int m = 0;
m < segSize;
m++)
260 for (
int n = 0; n < segSize; n++)
262 int segxx =
m * segSize + n;
264 complex_H[ch][(y * segSize +
m) * pnX + (x * segSize + n)] = result[
m * segSize + n][
_RE];
277 for (
int i = 0; i < snXY; i++) {
287 int hSegSize = segSize >> 1;
297 Real sf_base = 1.0 / (ppX * segSize);
303 Real tempX = sf_base * hSegSize * ppX;
304 Real tempY = sf_base * hSegSize * ppY;
306 for (
int x = 0; x < snX; x++) {
307 xc[x] = ((x - hsnX) * segSize + hSegSize) * ppX;
309 Real sf_cx = (theta_cx + thetaX) / lambda;
310 Real val = sf_cx >= 0 ? 0.5 : -0.5;
311 int pp_cx = (int)(sf_cx / sf_base + val);
312 coefficient_cx[x] = (
abs(pp_cx) < hSegSize) ? ((segSize - pp_cx) % segSize) : 0;
313 compensation_cx[x] = pi2 * ((xc[x] - pt->
pos[
_X]) * sf_cx + pp_cx * tempX);
316 for (
int y = 0; y < snY; y++) {
317 yc[y] = ((y - hsnY) * segSize + hSegSize) * ppY;
319 Real sf_cy = (theta_cy + thetaY) / lambda;
320 Real val = sf_cy >= 0 ? 0.5 : -0.5;
321 int pp_cy = (int)(sf_cy / sf_base + val);
322 coefficient_cy[y] = (
abs(pp_cy) < hSegSize) ? ((segSize - pp_cy) % segSize) : 0;
323 compensation_cy[y] = pi2 * ((yc[y] - pt->
pos[
_Y]) * sf_cy + pp_cy * tempY);
328 for (
int x = 0; x < snX; x++) {
329 xc[x] = ((x - hsnX) * segSize + hSegSize) * ppX;
331 Real sf_cx = (theta_cx + thetaX) / lambda;
332 Real val = sf_cx >= 0 ? 0.5 : -0.5;
333 int pp_cx = (int)(sf_cx / sf_base + val);
334 coefficient_cx[x] = (
abs(pp_cx) < hSegSize) ? ((segSize - pp_cx) % segSize) : 0;
337 for (
int y = 0; y < snY; y++) {
338 yc[y] = ((y - hsnY) * segSize + hSegSize) * ppY;
340 Real sf_cy = (theta_cy + thetaY) / lambda;
341 Real val = sf_cy >= 0 ? 0.5 : -0.5;
342 int pp_cy = (int)(sf_cy / sf_base + val);
343 coefficient_cy[y] = (
abs(pp_cy) < hSegSize) ? ((segSize - pp_cy) % segSize) : 0;
351 int hSegSize = segSize >> 1;
363 for (
int y = 0; y < snY; y++)
366 for (
int x = 0; x < snX; x++)
368 int segyy = y * snX + x;
369 int segxx = coefficient_cy[y] * segSize + coefficient_cx[x];
371 Real r = sqrt(xx + yy + zz);
373 Real theta = lambda * r + phase + compensation_cy[y] + compensation_cx[x];
374 Real theta_c = theta;
379 input[segyy][segxx][
_RE] += amplitude * LUTCos[idx_c];
380 input[segyy][segxx][
_IM] += amplitude * LUTSin[idx_s];
386 for (
int y = 0; y < snY; y++)
389 for (
int x = 0; x < snX; x++)
391 int segyy = y * snX + x;
392 int segxx = coefficient_cy[y] * segSize + coefficient_cx[x];
394 Real r = sqrt(xx + yy + zz);
396 Real theta = lambda * r;
397 Real theta_c = theta;
402 input[segyy][segxx][
_RE] += amplitude * LUTCos[idx_c];
403 input[segyy][segxx][
_IM] += amplitude * LUTSin[idx_s];
412 LOG(
"Not found diffracted data.");
422 const long long int pnXY = pnX * pnY;
429 Real cropx = floor(pnX * band_limit[
_X]);
430 Real cropx1 = cropx - floor(cropx / 2);
431 Real cropx2 = cropx1 + cropx - 1;
433 Real cropy = floor(pnY * band_limit[
_Y]);
434 Real cropy1 = cropy - floor(cropy / 2);
435 Real cropy2 = cropy1 + cropy - 1;
440 for (
uint i = 0; i < pnX; i++)
441 x_o[i] = (-ss[
_X] / 2) + (ppX * i) + (ppX / 2);
443 for (
uint i = 0; i < pnY; i++)
444 y_o[i] = (ss[
_Y] - ppY) - (ppY * i);
449 for (
int i = 0; i < pnXY; i++)
450 xx_o[i] = x_o[i % pnX];
453 for (
uint i = 0; i < pnX; i++)
454 for (
uint j = 0; j < pnY; j++)
455 yy_o[i + j * pnX] = y_o[j];
459 for (
uint ch = 0; ch < nChannel; ch++) {
470 for (
int i = 0; i < pnXY; i++) {
475 Real X = (
M_PI * xx_o[i] * spectrum_shift[
_X]) / ppX;
476 Real Y = (
M_PI * yy_o[i] * spectrum_shift[
_Y]) / ppY;
478 shift_phase[
_RE] = shift_phase[
_RE] * (cos(X) * cos(Y) - sin(X) * sin(Y));
void abs(const oph::Complex< T > &src, oph::Complex< T > &dst)
void encodeHologram(const vec2 band_limit, const vec2 spectrum_shift)
void CreateLookupTables()
Real distance
Offset value of point cloud.
ulonglong n_points
Number of points.
Real ** m_lpEncoded
buffer to encoded.
vec2 tilt_angle
Tilt angle for spatial filtering.
bool readConfig(const char *fname)
void initialize(void)
Initialize variables for Hologram complex field, encoded data, normalized data.
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.
vec3 scale
Scaling factor of coordinate of point cloud.
int loadPoint(const char *_filename)
ivec2 m_vecEncodeSize
Encoded hologram size, varied from encoding type.
void CalcSpatialFrequency(Point *pt, Real lambda, bool accurate=false)
void CalcCompensatedPhase(Point *pt, Real amplitude, Real phase, Real lambda, bool accurate=false)
void fftExecute(Complex< Real > *out, bool bReverse=false)
Execution functions to be called after fft1, fft2, and fft3.
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)
Vertex * vertices
Data of point clouds.
bool readConfig(const char *fname)
load to configuration file.
XMLError LoadFile(const char *filename)
void resetBuffer()
reset buffer
Complex< Real > ** complex_H
int loadPointCloud(const char *pc_file, OphPointCloudData *pc_data_)
load to point cloud data.
const XMLElement * FirstChildElement(const char *name=0) const