10 #include "PLYparser.h" 16 , m_pHologram(nullptr)
42 LOG(
"<FAILED> Wrong file ext.\n");
48 LOG(
"<FAILED> Loading file.\n");
54 char szNodeName[32] = { 0, };
55 sprintf(szNodeName,
"ScaleX");
58 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config_.scale[
_X]))
60 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
63 sprintf(szNodeName,
"ScaleY");
65 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config_.scale[
_Y]))
67 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
70 sprintf(szNodeName,
"ScaleZ");
72 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config_.scale[
_Z]))
74 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
77 sprintf(szNodeName,
"Distance");
79 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&pc_config_.distance))
81 LOG(
"<FAILED> Not found node : \'%s\' (Double) \n", szNodeName);
86 sprintf(szNodeName,
"CGH Width");
88 if (!next ||
XML_SUCCESS != next->QueryIntText(&env.CghWidth))
90 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
93 sprintf(szNodeName,
"CGH Height");
95 if (!next ||
XML_SUCCESS != next->QueryIntText(&env.CghHeight))
97 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
100 sprintf(szNodeName,
"CGH Scale");
102 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.CGHScale))
104 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
107 sprintf(szNodeName,
"Segmentation Size");
109 if (!next ||
XML_SUCCESS != next->QueryIntText(&env.SegmentationSize))
111 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
114 sprintf(szNodeName,
"FFT Segmentation Size");
116 if (!next ||
XML_SUCCESS != next->QueryIntText(&env.fftSegmentationSize))
118 LOG(
"<FAILED> Not found node : \'%s\' (Integer) \n", szNodeName);
121 sprintf(szNodeName,
"Red WaveLength");
123 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.rWaveLength))
125 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
129 sprintf(szNodeName,
"Tilting angle on x axis");
131 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.ThetaX))
133 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
136 sprintf(szNodeName,
"Tilting angle on y axis");
138 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.ThetaY))
140 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
143 sprintf(szNodeName,
"Default depth");
145 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.DefaultDepth))
147 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
151 sprintf(szNodeName,
"3D point interval on x axis");
153 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.xInterval))
155 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
158 sprintf(szNodeName,
"3D point interval on y axis");
160 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.yInterval))
162 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
165 sprintf(szNodeName,
"Hologram interval on xi axis");
167 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.xiInterval))
169 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
172 sprintf(szNodeName,
"Hologram interval on eta axis");
174 if (!next ||
XML_SUCCESS != next->QueryFloatText(&env.etaInterval))
176 LOG(
"<FAILED> Not found node : \'%s\' (Float) \n", szNodeName);
190 LOG(
"**************************************************\n");
191 LOG(
" Read Config (Accurate Phase-Added Stereogram) \n");
192 LOG(
"1) Focal Length : %.5lf\n", pc_config_.distance);
193 LOG(
"2) Object Scale : %.5lf / %.5lf / %.5lf\n", pc_config_.scale[
_X], pc_config_.scale[
_Y], pc_config_.scale[
_Z]);
194 LOG(
"**************************************************\n");
207 if (fname ==
nullptr)
return -1;
215 for (
uint ch = 0; ch < nChannel; ch++) {
218 if (px == 0 && py == 0)
225 memset(buf, 0x00,
sizeof(
char) * 256);
226 sprintf(buf,
"%s.bmp", fname);
241 for (
int i = 0; i <
NUMTBL; i++) {
242 float theta = (float)
M2_PI * (
float)(i + i - 1) / (
float)(2 *
NUMTBL);
250 double Max = -1E9, Min = 1E9;
257 for (
int i = 0; i < cghheight; i++) {
258 for (
int j = 0; j < cghwidth; j++) {
264 for (
int i = 0; i < cghheight; i++) {
265 for (
int j = 0; j < cghwidth; j++) {
266 double temp = 1.0*(((
m_pHologram[i*cghwidth + j] - Min) / (Max - Min))*255. + 0.5);
267 if (temp >= 255.0) cghfringe[i*cghwidth + j] = 255;
268 else cghfringe[i*cghwidth + j] = (
unsigned char)(temp);
281 float thetaX = env.
ThetaX;
282 float thetaY = env.
ThetaY;
288 int hsegNumx = segNumx >> 1;
289 int hsegNumy = segNumy >> 1;
294 float *SFrequency_cx =
new float[segNumx];
295 float *SFrequency_cy =
new float[segNumy];
296 int *PickPoint_cx =
new int[segNumx];
297 int *PickPoint_cy =
new int[segNumy];
298 int *Coefficient_cx =
new int[segNumx];
299 int *Coefficient_cy =
new int[segNumy];
300 float *dPhaseSFy =
new float[segNumx];
301 float *dPhaseSFx =
new float[segNumy];
302 float *xc =
new float[segNumx];
303 float *yc =
new float[segNumy];
306 float theta_s, theta_c;
307 int dtheta_s, dtheta_c;
309 double *Compensation_cx =
new double[segNumx];
310 double *Compensation_cy =
new double[segNumy];
314 fftw_complex *in, *out;
317 double **inRe =
new double *[segNumy * segNumx];
318 double **inIm =
new double *[segNumy * segNumx];
319 for (
int i = 0; i < segNumy; i++) {
320 for (
int j = 0; j < segNumx; j++) {
321 inRe[i * segNumx + j] =
new double[FFTdsegSize];
322 inIm[i * segNumx + j] =
new double[FFTdsegSize];
323 memset(inRe[i*segNumx + j], 0x00,
sizeof(
double) * FFTdsegSize);
324 memset(inIm[i*segNumx + j], 0x00,
sizeof(
double) * FFTdsegSize);
328 in = (fftw_complex *)fftw_malloc(
sizeof(fftw_complex) * FFTdsegSize);
329 out = (fftw_complex *)fftw_malloc(
sizeof(fftw_complex) * FFTdsegSize);
330 memset(in, 0x00,
sizeof(fftw_complex) * FFTdsegSize);
333 for (
int i = 0; i < segNumy; i++)
335 for (
int i = 0; i < segNumx; i++)
338 for (
int i = 0; i < pc_data_.
n_points; i++)
346 for (
int j = 0; j < segNumy; j++)
348 float theta_cy = (yc[j] - y) - z;
349 SFrequency_cy[j] = (theta_cy + thetaY) / env.
rWaveLength;
350 PickPoint_cy[j] = (SFrequency_cy[j] >= 0 ) ? (int)(SFrequency_cy[j] / sf_base + 0.5) : (int)(SFrequency_cy[j] / sf_base - 0.5);
352 Compensation_cy[j] = (float)(2 *
PI * ((yc[j] - y) * SFrequency_cy[j] + PickPoint_cy[j] * sf_base * FFThsegSize * xiInterval));
354 for (
int j = 0; j < segNumx; j++)
356 float theta_cx = (xc[j] - x) / z;
357 SFrequency_cx[j] = (theta_cx + thetaX) / env.
rWaveLength;
358 PickPoint_cx[j] = (SFrequency_cx[j] >= 0) ? (int)(SFrequency_cx[j] / sf_base + 0.5) : (int)(SFrequency_cx[j] / sf_base - 0.5);
360 Compensation_cx[j] = (float)(2 *
PI * ((xc[j] - x) * SFrequency_cx[j] + PickPoint_cx[j] * sf_base * FFThsegSize * etaInterval));
362 for (
int j = 0; j < segNumy; j++) {
363 for (
int k = 0;
k < segNumx;
k++) {
364 int idx = j* segNumx +
k;
366 float R = sqrt((xc[
k] - x) * (xc[
k] - x) + (yc[j] - y) * (yc[j] - y) + z * z);
367 theta = rWaveNum * R + phase + Compensation_cy[j] + Compensation_cx[
k];
370 theta_s = theta +
PI;
373 idx_c = (dtheta_c) & (
NUMTBL2);
374 idx_s = (dtheta_s) & (
NUMTBL2);
375 inRe[idx][idx2] += (double)(amplitude *
m_COStbl[idx_c]);
376 inIm[idx][idx2] += (double)(amplitude *
m_SINtbl[idx_s]);
383 for (
int j = 0; j < segNumy; j++) {
384 for (
int k = 0;
k < segNumx;
k++) {
385 int idx = j * segNumx +
k;
386 memset(in, 0x00,
sizeof(fftw_complex) * FFTdsegSize);
404 fftw_destroy_plan(plan);
409 delete[] SFrequency_cx;
410 delete[] SFrequency_cy;
411 delete[] PickPoint_cx;
412 delete[] PickPoint_cy;
413 delete[] Coefficient_cx;
414 delete[] Coefficient_cy;
417 for (
int i = 0; i < segNumy; i++) {
418 for (
int j = 0; j < segNumx; j++) {
419 delete[] inRe[i * segNumx + j];
420 delete[] inIm[i * segNumx + j];
void abs(const oph::Complex< T > &src, oph::Complex< T > &dst)
OphConfig & getContext(void)
Function for getting the current context.
virtual bool saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int width, int height)
Function for creating image files.
Real distance
Offset value of point cloud.
int ACPASCalcuation(unsigned char *cghfringe)
bool readConfig(const char *fname)
int loadPointCloud(const char *pc_file)
ulonglong n_points
Number of points.
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
void initialize(void)
Initialize variables for Hologram complex field, encoded data, normalized data.
void setPixelPitchOHC(const vec2 pixel_pitch)
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 setWavelengthOHC(const Real wavelength, const LenUnit wavelength_unit)
vec3 scale
Scaling factor of coordinate of point cloud.
int save(const char *fname, uint8_t bitsperpixel, uchar *src, uint px, uint py)
bool readConfig(const char *fname)
load to configuration file.
XMLError LoadFile(const char *filename)
Vertex * vertices
Data of point clouds.
uchar ** m_lpNormalized
buffer to normalized.
int loadPointCloud(const char *pc_file, OphPointCloudData *pc_data_)
load to point cloud data.
const XMLElement * FirstChildElement(const char *name=0) const