11 #include "PLYparser.h" 16 , m_pHologram(nullptr)
40 LOG(
"<FAILED> Wrong file ext.\n");
45 LOG(
"<FAILED> Loading file.\n");
51 char szNodeName[32] = { 0, };
52 sprintf(szNodeName,
"ScaleX");
55 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[
_X]))
57 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
60 sprintf(szNodeName,
"ScaleY");
62 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[
_Y]))
64 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
67 sprintf(szNodeName,
"ScaleZ");
69 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config.scale[
_Z]))
71 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
74 sprintf(szNodeName,
"Distance");
76 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config.distance))
78 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
84 LOG(
"**************************************************\n");
85 LOG(
" Read Config (Phase-Added Stereogram) \n");
86 LOG(
"1) Focal Length : %.5lf\n", pc_config.distance);
87 LOG(
"2) Object Scale : %.5lf / %.5lf / %.5lf\n", pc_config.scale[
_X], pc_config.scale[
_Y], pc_config.scale[
_Z]);
88 LOG(
"**************************************************\n");
106 for (
int i = 0; i <
NUMTBL; i++) {
107 float theta = (float)
M2_PI * (
float)(i + i - 1) / (
float)(2 *
NUMTBL);
120 double Max = -1E9, Min = 1E9;
136 for (i = 0; i < cghheight; i++) {
137 for (j = 0; j < cghwidth; j++) {
144 for (i = 0; i < cghheight; i++) {
145 for (j = 0; j < cghwidth; j++) {
146 myBuffer = 1.0*(((
m_pHologram[i*cghwidth + j] - Min) / (Max - Min))*255. + 0.5);
147 if (myBuffer >= 255.0) cghfringe[i*cghwidth + j] = 255;
148 else cghfringe[i*cghwidth + j] = (
unsigned char)(myBuffer);
229 float cghScale = conf.
scale[
_X];
242 for (no = 0; no < voxelnum*3; no+=3)
270 , xiInterval, etaInterval, conf);
311 float cghScale = conf.
scale[
_X];
324 clock_t start, finish;
328 cout << sf_base << endl;
330 for (no = 0; no < voxelnum * 3; no += 3)
338 std::cout <<
"X: " << X <<
", Y: " << Y <<
", Z: " << Z <<
", Amp: " <<
Amplitude << endl;
357 , xiInterval, etaInterval, conf);
393 duration = (double)(finish - start) / CLOCKS_PER_SEC;
396 cout << duration << endl;
400 void ophPAS::DataInit(
int segsize,
int cghwidth,
int cghheight,
float xiinter,
float etainter)
462 fftw_destroy_plan(
m_plan);
493 m_elapsedTime = ((std::chrono::duration<Real>)(end - begin)).count();
500 void ophPAS::CalcSpatialFrequency(
float cx,
float cy,
float cz,
float amp,
int segnumx,
int segnumy,
int segsize,
int hsegsize,
float sf_base,
float * xc,
float * yc,
float * sf_cx,
float * sf_cy,
int * pp_cx,
int * pp_cy,
int * cf_cx,
int * cf_cy,
float xiint,
float etaint,
OphPointCloudConfig& conf)
503 float theta_cx, theta_cy;
509 for (segx = 0; segx < segnumx; segx++)
511 theta_cx = (xc[segx] - cx) / cz;
512 sf_cx[segx] = (float)((theta_cx + thetaX) / rWaveLength);
513 (sf_cx[segx] >= 0) ? pp_cx[segx] = (
int)(sf_cx[segx] / sf_base + 0.5)
514 : pp_cx[segx] = (int)(sf_cx[segx] / sf_base - 0.5);
515 (
abs(pp_cx[segx]) < hsegsize) ? cf_cx[segx] = ((segsize - pp_cx[segx]) % segsize)
519 for (segy = 0; segy < segnumy; segy++)
521 theta_cy = (yc[segy] - cy) / cz;
522 sf_cy[segy] = (float)((theta_cy + thetaY) / rWaveLength);
523 (sf_cy[segy] >= 0) ? pp_cy[segy] = (
int)(sf_cy[segy] / sf_base + 0.5)
524 : pp_cy[segy] = (int)(sf_cy[segy] / sf_base - 0.5);
525 (
abs(pp_cy[segy]) < hsegsize) ? cf_cy[segy] = ((segsize - pp_cy[segy]) % segsize)
533 ,
int segNumx,
int segNumy
534 ,
int segsize,
int hsegsize,
float sf_base
535 ,
float *xc,
float *yc
536 ,
int *cf_cx,
int *cf_cy
537 ,
float *COStbl,
float *SINtbl
542 float theta_s, theta_c;
543 int dtheta_s, dtheta_c;
547 float rWaveNum = 9926043.13930423f;
552 for (segy = 0; segy < segNumy; segy++) {
553 for (segx = 0; segx < segNumx; segx++) {
554 segyy = segy * segNumx + segx;
555 segxx = cf_cy[segy] * segsize + cf_cx[segx];
557 R = (float)(sqrt((xc[segx] - cx)*(xc[segx] - cx) + (yc[segy] - cy)*(yc[segy] - cy) + cz * cz));
559 theta = rWaveNum * R;
561 theta_s = theta +
PI;
564 idx_c = (dtheta_c) & (
NUMTBL2);
565 idx_s = (dtheta_s) & (
NUMTBL2);
567 inRe[segyy][segxx] += (float)(amp * COStbl[idx_c]);
568 inIm[segyy][segxx] += (float)(amp * SINtbl[idx_s]);
573 auto during = ((chrono::duration<Real>)(end - start)).count();
580 void ophPAS::RunFFTW(
int segnumx,
int segnumy,
int segsize,
int hsegsize,
float ** inRe,
float ** inIm, fftw_complex * in, fftw_complex * out, fftw_plan * plan,
double * pHologram,
OphPointCloudConfig& conf)
588 for (segy = 0; segy < segnumy; segy++) {
589 for (segx = 0; segx < segnumx; segx++) {
590 segyy = segy * segnumx + segx;
591 memset(in, 0x00,
sizeof(fftw_complex) * segsize * segsize);
592 for (i = 0; i < segsize; i++) {
593 for (j = 0; j < segsize; j++) {
594 segxx = i * segsize + j;
596 in[i*segsize + j][0] = inRe[segyy][segxx];
597 in[i*segsize + j][1] = inIm[segyy][segxx];
602 for (i = 0; i < segsize; i++) {
603 for (j = 0; j < segsize; j++) {
604 pHologram[(segy*segsize + i)*cghWidth + (segx*segsize + j)] = out[i * segsize + j][0];
616 LOG(
"Not found diffracted data.");
626 const long long int pnXY = pnX * pnY;
633 Real cropx = floor(pnX * band_limit[
_X]);
634 Real cropx1 = cropx - floor(cropx / 2);
635 Real cropx2 = cropx1 + cropx - 1;
637 Real cropy = floor(pnY * band_limit[
_Y]);
638 Real cropy1 = cropy - floor(cropy / 2);
639 Real cropy2 = cropy1 + cropy - 1;
644 for (
uint i = 0; i < pnX; i++)
645 x_o[i] = (-ss[
_X] / 2) + (ppX * i) + (ppX / 2);
647 for (
uint i = 0; i < pnY; i++)
648 y_o[i] = (ss[
_Y] - ppY) - (ppY * i);
653 for (
int i = 0; i < pnXY; i++)
654 xx_o[i] = x_o[i % pnX];
657 for (
uint i = 0; i < pnX; i++)
658 for (
uint j = 0; j < pnY; j++)
659 yy_o[i + j * pnX] = y_o[j];
663 for (
uint ch = 0; ch < nChannel; ch++) {
674 for (
int i = 0; i < pnXY; i++) {
679 Real X = (
M_PI * xx_o[i] * spectrum_shift[
_X]) / ppX;
680 Real Y = (
M_PI * yy_o[i] * spectrum_shift[
_Y]) / ppY;
682 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)
OphConfig & getContext(void)
Function for getting the current context.
void encodeHologram(const vec2 band_limit, const vec2 spectrum_shift)
Real distance
Offset value of point cloud.
void PASCalculation(long voxnum, unsigned char *cghfringe, OphPointCloudData *data, OphPointCloudConfig &conf)
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.
void PAS(long voxelnum, OphPointCloudData *data, double *m_pHologram, OphPointCloudConfig &conf)
void CalcCompensatedPhase(float cx, float cy, float cz, float amp, int segnumx, int segnumy, int segsize, int hsegsize, float sf_base, float *xc, float *yc, int *cf_cx, int *cf_cy, float *COStbl, float *SINtbl, float **inRe, float **inIm, OphPointCloudConfig &conf)
vec3 scale
Scaling factor of coordinate of point cloud.
int loadPoint(const char *_filename)
Real m_elapsedTime
Elapsed time of generate hologram.
ivec2 m_vecEncodeSize
Encoded hologram size, varied from encoding type.
Real ** m_lpEncoded
buffer to encoded.
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.
void DataInit(int segsize, int cghwidth, int cghheight, float xiinter, float etainter)
void RunFFTW(int segnumx, int segnumy, int segsize, int hsegsize, float **inRe, float **inIm, fftw_complex *in, fftw_complex *out, fftw_plan *plan, double *pHologram, OphPointCloudConfig &conf)
void Amplitude(Complex< T > *holo, T *encoded, const int size)
void PAS_GPU(long voxelnum, OphPointCloudData *data, double *m_pHologram, OphPointCloudConfig &conf)
bool readConfig(const char *fname)
load to configuration file.
XMLError LoadFile(const char *filename)
Configuration for Point Cloud.
Vertex * vertices
Data of point clouds.
Complex< Real > ** complex_H
unsigned char * cgh_fringe
void CalcSpatialFrequency(float cx, float cy, float cz, float amp, int segnumx, int segnumy, int segsize, int hsegsize, float sf_base, float *xc, float *yc, float *sf_cx, float *sf_cy, int *pp_cx, int *pp_cy, int *cf_cx, int *cf_cy, float xiint, float etaint, OphPointCloudConfig &conf)
int loadPointCloud(const char *pc_file, OphPointCloudData *pc_data_)
load to point cloud data.
const XMLElement * FirstChildElement(const char *name=0) const