8 #include <cooperative_groups.h> 12 #include <cuda_device_runtime_api.h> 14 #include "PLYparser.h" 15 #include <cuda_runtime_api.h> 16 #include <device_launch_parameters.h> 17 #include <device_functions.h> 18 #include <math_constants.h> 44 LOG(
"Reading....%s...", fname);
55 LOG(
"file's extension is not 'xml'\n");
62 LOG(
"Failed to load file \"%s\"\n", fname);
93 char szNodeName[32] = { 0, };
94 for (
int i = 1; i <= nWave; i++) {
95 sprintf(szNodeName,
"SLM_WaveLength_%d", i);
147 for (
int i = 0; i < nWave; i++)
152 auto during = ((std::chrono::duration<Real>)(end - start)).count();
154 LOG(
"%.5lfsec...done\n", during);
177 if (fname ==
nullptr)
return -1;
184 if (px == 0 && py == 0)
191 memset(buf, 0x00,
sizeof(
char) * 256);
192 sprintf(buf,
"%s.bmp", fname);
272 end = t + strlen(t) - 1;
273 while (end != t && isspace(*end))
287 while (*begin !=
'\0') {
376 double Max = -1E9, Min = 1E9;
399 for (i = 0; i < cghheight; i++) {
400 for (j = 0; j < cghwidth; j++) {
406 for (i = 0; i < cghheight; i++) {
407 for (j = 0; j < cghwidth; j++) {
408 myBuffer = 1.0*(((
m_pHologram[i*cghwidth + j] - Min) / (Max - Min))*255. + 0.5);
409 if (myBuffer >= 255.0) cghfringe[i*cghwidth + j] = 255;
410 else cghfringe[i*cghwidth + j] = (
unsigned char)(myBuffer);
498 float cghScale = conf.
scale[
_X];
511 clock_t start, finish;
516 for (no = 0; no < voxelnum * 3; no += 3)
524 std::cout <<
"X: " << X <<
", Y: " << Y <<
", Z: " << Z <<
", Amp: " <<
Amplitude << endl;
547 , xiInterval, etaInterval, conf);
583 duration = (double)(finish - start) / CLOCKS_PER_SEC;
586 cout << duration << endl;
602 void ophPAS_GPU::DataInit(
int segsize,
int cghwidth,
int cghheight,
float xiinter,
float etainter)
645 for (
int i = 0; i<
NUMTBL; i++) {
646 float theta = (float)
M2_PI * (
float)(i + i - 1) / (
float)(2 *
NUMTBL);
694 fftw_destroy_plan(
m_plan);
741 m_elapsedTime = ((std::chrono::duration<Real>)(end - begin)).count();
756 void ophPAS_GPU::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)
759 float theta_cx, theta_cy;
766 for (segx = 0; segx < segnumx; segx++)
768 theta_cx = (xc[segx] - cx) / cz;
769 sf_cx[segx] = (float)((theta_cx + thetaX) / rWaveLength);
770 (sf_cx[segx] >= 0) ? pp_cx[segx] = (
int)(sf_cx[segx] / sf_base + 0.5)
771 : pp_cx[segx] = (int)(sf_cx[segx] / sf_base - 0.5);
772 (
abs(pp_cx[segx]) < hsegsize) ? cf_cx[segx] = ((segsize - pp_cx[segx]) % segsize)
777 for (segy = 0; segy < segnumy; segy++)
779 theta_cy = (yc[segy] - cy) / cz;
780 sf_cy[segy] = (float)((theta_cy + thetaY) / rWaveLength);
781 (sf_cy[segy] >= 0) ? pp_cy[segy] = (
int)(sf_cy[segy] / sf_base + 0.5)
782 : pp_cy[segy] = (int)(sf_cy[segy] / sf_base - 0.5);
783 (
abs(pp_cy[segy]) < hsegsize) ? cf_cy[segy] = ((segsize - pp_cy[segy]) % segsize)
791 ,
int segNumx,
int segNumy
792 ,
int segsize,
int hsegsize,
float sf_base
793 ,
float *xc,
float *yc
794 ,
int *cf_cx,
int *cf_cy
795 ,
float *COStbl,
float *SINtbl
815 int num_x = segNumx*segNumy;
816 int num_y = segsize*segsize;
835 cudaMalloc((
void**)&inRe_d,
sizeof(
float)*num_x*num_y);
836 cudaMalloc((
void**)&inIm_d,
sizeof(
float)*num_x*num_y);
837 cudaMalloc((
void**)&d_const.
cf_cx,
sizeof(
int)*segNumx);
838 cudaMalloc((
void**)&d_const.
cf_cy,
sizeof(
int)*segNumy);
839 cudaMalloc((
void**)&d_const.
xc,
sizeof(
float)*segNumx);
840 cudaMalloc((
void**)&d_const.
yc,
sizeof(
float)*segNumy);
841 cudaMalloc((
void**)&d_const.
costbl,
sizeof(
float)*
NUMTBL);
842 cudaMalloc((
void**)&d_const.
sintbl,
sizeof(
float)*
NUMTBL);
845 cudaMemcpyAsync(inRe_d,
m_inRe_h,
sizeof(
float)*num_x*num_y, cudaMemcpyHostToDevice);
846 cudaMemcpyAsync(inIm_d,
m_inIm_h,
sizeof(
float)*num_x*num_y, cudaMemcpyHostToDevice);
847 cudaMemcpyAsync(d_const.
cf_cx, cf_cx ,
sizeof(
int)*segNumx, cudaMemcpyHostToDevice);
848 cudaMemcpyAsync(d_const.
cf_cy, cf_cy ,
sizeof(
int)*segNumy, cudaMemcpyHostToDevice);
849 cudaMemcpyAsync(d_const.
xc, xc,
sizeof(
float)*segNumx, cudaMemcpyHostToDevice);
850 cudaMemcpyAsync(d_const.
yc, yc,
sizeof(
float)*segNumy, cudaMemcpyHostToDevice);
851 cudaMemcpyAsync(d_const.
costbl, COStbl,
sizeof(
float)*
NUMTBL, cudaMemcpyHostToDevice);
852 cudaMemcpyAsync(d_const.
sintbl, SINtbl,
sizeof(
float)*
NUMTBL, cudaMemcpyHostToDevice);
855 ivec3 v(segNumx, segNumy, segsize);
862 cudaMemcpyAsync(
m_inRe_h, inRe_d ,
sizeof(
float)*num_x*num_y, cudaMemcpyDeviceToHost);
863 cudaMemcpyAsync(
m_inIm_h, inIm_d,
sizeof(
float)*num_x*num_y, cudaMemcpyDeviceToHost);
892 cudaFree(d_const.
cf_cx);
893 cudaFree(d_const.
cf_cy);
894 cudaFree(d_const.
xc);
895 cudaFree(d_const.
yc);
936 void ophPAS_GPU::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)
947 for (segy = 0; segy < segnumy; segy++) {
948 for (segx = 0; segx < segnumx; segx++) {
949 segyy = segy * segnumx + segx;
950 memset(in, 0x00,
sizeof(fftw_complex) * segsize * segsize);
951 for (i = 0; i < segsize; i++) {
952 for (j = 0; j < segsize; j++) {
953 segxx = i * segsize + j;
954 in[i*segsize + j][0] =
m_inRe_h[segyy*segsize*segsize+segxx];
955 in[i*segsize + j][1] =
m_inIm_h[segyy*segsize*segsize+segxx];
961 for (i = 0; i < segsize; i++) {
962 for (j = 0; j < segsize; j++) {
963 pHologram[(segy*segsize + i)*cghWidth + (segx*segsize + j)] = out[i * segsize + j][0];
977 LOG(
"Not found diffracted data.");
981 LOG(
"Single Side Band Encoding..");
987 const long long int pnXY = pnX * pnY;
994 Real cropx = floor(pnX * band_limit[
_X]);
995 Real cropx1 = cropx - floor(cropx / 2);
996 Real cropx2 = cropx1 + cropx - 1;
998 Real cropy = floor(pnY * band_limit[
_Y]);
999 Real cropy1 = cropy - floor(cropy / 2);
1000 Real cropy2 = cropy1 + cropy - 1;
1005 for (
uint i = 0; i < pnX; i++)
1006 x_o[i] = (-ss[
_X] / 2) + (ppX * i) + (ppX / 2);
1008 for (
uint i = 0; i < pnY; i++)
1009 y_o[i] = (ss[
_Y] - ppY) - (ppY * i);
1014 for (
uint i = 0; i < pnXY; i++)
1015 xx_o[i] = x_o[i % pnX];
1018 for (
uint i = 0; i < pnX; i++)
1019 for (
uint j = 0; j < pnY; j++)
1020 yy_o[i + j * pnX] = y_o[j];
1024 for (
uint ch = 0; ch < nChannel; ch++) {
1035 for (
int i = 0; i < pnXY; i++) {
1040 Real X = (
M_PI * xx_o[i] * spectrum_shift[
_X]) / ppX;
1041 Real Y = (
M_PI * yy_o[i] * spectrum_shift[
_Y]) / ppY;
1043 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.
virtual bool saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int width, int height)
Function for creating image files.
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)
Real distance
Offset value of point cloud.
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.
int save(const char *fname, uint8_t bitsperpixel, uchar *src, uint px, uint py)
void PAS(long voxelnum, OphPointCloudData *data, double *m_pHologram, OphPointCloudConfig &conf)
void setWavelengthOHC(const Real wavelength, const LenUnit wavelength_unit)
vec3 scale
Scaling factor of coordinate of point cloud.
Real m_elapsedTime
Elapsed time of generate hologram.
ivec2 m_vecEncodeSize
Encoded hologram size, varied from encoding type.
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)
Real ** m_lpEncoded
buffer to encoded.
void PASCalculation_GPU(long voxnum, unsigned char *cghfringe, OphPointCloudData *data, OphPointCloudConfig &conf)
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.
int loadPoint(const char *_filename)
structure for 2-dimensional Real type vector and its arithmetic.
void Amplitude(Complex< T > *holo, T *encoded, const int size)
unsigned char * cgh_fringe
void encodeHologram(const vec2 band_limit, const vec2 spectrum_shift)
XMLError LoadFile(const char *filename)
Configuration for Point Cloud.
void PASCalculation(long voxnum, unsigned char *cghfringe, OphPointCloudData *data, OphPointCloudConfig &conf)
Vertex * vertices
Data of point clouds.
structure for 3-dimensional integer vector and its arithmetic.
Complex< Real > ** complex_H
uchar ** m_lpNormalized
buffer to normalized.
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.
void cuda_Wrapper_phaseCalc(float *inRe, float *inIm, constValue val, float &cx, float &cy, float &cz, float &, ivec3 &seg)
void DataInit(int segsize, int cghwidth, int cghheight, float xiinter, float etainter)
int loadPointCloud(const char *pc_file, OphPointCloudData *pc_data_)
load to point cloud data.
const XMLElement * FirstChildElement(const char *name=0) const
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)
bool readConfig(const char *fname)