Openholo  beta 2.0
Open Source Digital Holographic Library
ophLF Class Reference

Openholo Light Field based CGH generation. More...

Inheritance diagram for ophLF:
Inheritance graph

Public Member Functions

 ophLF (void)
 Constructor. More...
 
int readLFConfig (const char *LF_config)
 Light Field based CGH configuration file load. More...
 
int loadLF (const char *directory, const char *exten)
 Light Field images load. More...
 
void generateHologram ()
 Hologram generation. More...
 
void waveCarry (Real carryingAngleX, Real carryingAngleY)
 Wave carry. More...
 
 ophLF (void)
 Constructor. More...
 
int readLFConfig (const char *LF_config)
 Light Field based CGH configuration file load. More...
 
int loadLF (const char *directory, const char *exten)
 Light Field images load. More...
 
void generateHologram ()
 Hologram generation. More...
 
void waveCarry (Real carryingAngleX, Real carryingAngleY)
 Wave carry. More...
 
void initialize (void)
 Initialize variables for Hologram complex field, encoded data, normalized data. More...
 
void initialize (void)
 Initialize variables for Hologram complex field, encoded data, normalized data. More...
 
int loadPointCloud (const char *pc_file, OphPointCloudData *pc_data_)
 
int loadPointCloud (const char *pc_file, OphPointCloudData *pc_data_)
 
bool readConfig (const char *fname, OphPointCloudConfig &config)
 
bool readConfig (const char *fname, OphDepthMapConfig &config)
 
bool readConfig (const char *fname, OphPointCloudConfig &config)
 
bool readConfig (const char *fname, OphDepthMapConfig &config)
 
void propagationAngularSpectrum (Complex< Real > *input_u, Real propagation_dist)
 Angular spectrum propagation method. More...
 
void normalize (void)
 Normalization function to save as image file after hologram creation. More...
 
void normalize (void)
 Normalization function to save as image file after hologram creation. More...
 
int save (const char *fname, uint8_t bitsperpixel=8, uchar *src=nullptr, uint px=0, uint py=0)
 Function for saving image files. More...
 
int save (const char *fname, uint8_t bitsperpixel=8, uchar *src=nullptr, uint px=0, uint py=0)
 Function for saving image files. More...
 
void * load (const char *fname)
 Function for loading image files. More...
 
void * load (const char *fname)
 Function for loading image files. More...
 
virtual int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
virtual int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
void encoding (unsigned int ENCODE_FLAG)
 Encoding Functions. More...
 
void encoding (unsigned int ENCODE_FLAG)
 Encoding Functions. More...
 
void loadComplex (char *real_file, char *imag_file, int n_x, int n_y)
 Complex field file load. More...
 
void loadComplex (char *real_file, char *imag_file, int n_x, int n_y)
 Complex field file load. More...
 
void normalizeEncoded (void)
 Normalize the encoded hologram. More...
 
void normalizeEncoded (void)
 Normalize the encoded hologram. More...
 
void fresnelPropagation (OphConfig context, Complex< Real > *in, Complex< Real > *out, Real distance)
 Fresnel propagation. More...
 
void fresnelPropagation (OphConfig context, Complex< Real > *in, Complex< Real > *out, Real distance)
 Fresnel propagation. More...
 
virtual int saveAsImg (const char *fname, uint8_t bitsperpixel, uchar *src, int pic_width, int pic_height)
 Function for creating image files. More...
 
virtual int saveAsImg (const char *fname, uint8_t bitsperpixel, uchar *src, int pic_width, int pic_height)
 Function for creating image files. More...
 
virtual uchar * loadAsImg (const char *fname)
 Function for loading image files. More...
 
virtual uchar * loadAsImg (const char *fname)
 Function for loading image files. More...
 
virtual int saveAsOhc (const char *fname)
 Function to write OHC file. More...
 
virtual int saveAsOhc (const char *fname)
 Function to write OHC file. More...
 
unsigned long addRef (void)
 If referenced this(Base's child, not abstract class) instance, must call this method. More...
 
unsigned long addRef (void)
 If referenced this(Base's child, not abstract class) instance, must call this method. More...
 
unsigned long release (void)
 Call release() when reference is finished. More...
 
unsigned long release (void)
 Call release() when reference is finished. More...
 

Protected Member Functions

virtual ~ophLF (void)
 Destructor. More...
 
virtual ~ophLF (void)
 Destructor. More...
 
int save (const char *fname, uint8_t bitsperpixel, uint px, uint py, uint fnum, uchar *args ...)
 Called when saving multiple hologram data at a time. More...
 
int save (const char *fname, uint8_t bitsperpixel, uint px, uint py, uint fnum, uchar *args ...)
 Called when saving multiple hologram data at a time. More...
 
void numericalInterference (oph::Complex< Real > *holo, Real *encoded, const int size)
 Encoding functions. More...
 
void numericalInterference (oph::Complex< Real > *holo, Real *encoded, const int size)
 Encoding functions. More...
 
void freqShift (oph::Complex< Real > *src, Complex< Real > *dst, const ivec2 holosize, int shift_x, int shift_y)
 Frequency shift. More...
 
void freqShift (oph::Complex< Real > *src, Complex< Real > *dst, const ivec2 holosize, int shift_x, int shift_y)
 Frequency shift. More...
 
void encodeSideBand (bool bCPU, ivec2 sig_location)
 Encode the CGH according to a signal location parameter. More...
 
void encodeSideBand (bool bCPU, ivec2 sig_location)
 Encode the CGH according to a signal location parameter. More...
 
void encodeSideBand_CPU (int cropx1, int cropx2, int cropy1, int cropy2, oph::ivec2 sig_location)
 Encode the CGH according to a signal location parameter on the CPU. More...
 
void encodeSideBand_CPU (int cropx1, int cropx2, int cropy1, int cropy2, oph::ivec2 sig_location)
 Encode the CGH according to a signal location parameter on the CPU. More...
 
void getShiftPhaseValue (oph::Complex< Real > &shift_phase_val, int idx, oph::ivec2 sig_location)
 Calculate the shift phase value. More...
 
void getShiftPhaseValue (oph::Complex< Real > &shift_phase_val, int idx, oph::ivec2 sig_location)
 Calculate the shift phase value. More...
 
void getRandPhaseValue (oph::Complex< Real > &rand_phase_val, bool rand_phase)
 Assign random phase value if RANDOM_PHASE == 1. More...
 
void getRandPhaseValue (oph::Complex< Real > &rand_phase_val, bool rand_phase)
 Assign random phase value if RANDOM_PHASE == 1. More...
 
virtual void ophFree (void)
 Pure virtual function for override in child classes. More...
 
virtual void ophFree (void)
 Pure virtual function for override in child classes. More...
 
int checkExtension (const char *fname, const char *ext)
 Functions for extension checking. More...
 
int checkExtension (const char *fname, const char *ext)
 Functions for extension checking. More...
 
int loadAsImgUpSideDown (const char *fname, uchar *dst)
 Function for loading image files | Output image data upside down. More...
 
int loadAsImgUpSideDown (const char *fname, uchar *dst)
 Function for loading image files | Output image data upside down. More...
 
int getImgSize (int &w, int &h, int &bytesperpixel, const char *file_name)
 Function for getting the image size. More...
 
int getImgSize (int &w, int &h, int &bytesperpixel, const char *file_name)
 Function for getting the image size. More...
 
void imgScaleBilnear (unsigned char *src, unsigned char *dst, int w, int h, int neww, int newh)
 Function for change image size. More...
 
void imgScaleBilnear (unsigned char *src, unsigned char *dst, int w, int h, int neww, int newh)
 Function for change image size. More...
 
void convertToFormatGray8 (unsigned char *src, unsigned char *dst, int w, int h, int bytesperpixel)
 Function for convert image format to gray8. More...
 
void convertToFormatGray8 (unsigned char *src, unsigned char *dst, int w, int h, int bytesperpixel)
 Function for convert image format to gray8. More...
 
void fft1 (int n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 1-dimension operations inside Openholo. More...
 
void fft1 (int n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 1-dimension operations inside Openholo. More...
 
void fft2 (oph::ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 2-dimension operations inside Openholo. More...
 
void fft2 (oph::ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 2-dimension operations inside Openholo. More...
 
void fft3 (oph::ivec3 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 3-dimension operations inside Openholo. More...
 
void fft3 (oph::ivec3 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 3-dimension operations inside Openholo. More...
 
void fftExecute (Complex< Real > *out)
 Execution functions to be called after fft1, fft2, and fft3. More...
 
void fftExecute (Complex< Real > *out)
 Execution functions to be called after fft1, fft2, and fft3. More...
 
void fftwShift (Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
 Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. More...
 
void fftwShift (Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
 Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. More...
 
void fftShift (int nx, int ny, Complex< Real > *input, Complex< Real > *output)
 Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom-left. More...
 
void fftShift (int nx, int ny, Complex< Real > *input, Complex< Real > *output)
 Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom-left. More...
 
void setPixelNumberOHC (const ivec2 pixel_number)
 getter/setter for OHC file read and write More...
 
void setPixelNumberOHC (const ivec2 pixel_number)
 getter/setter for OHC file read and write More...
 
void addWaveLengthNComplexFieldDataOHC (const Real wavelength, const OphComplexField &complex_field)
 Function to add ComplexField when adding wavelength data. More...
 
void addWaveLengthNComplexFieldDataOHC (const Real wavelength, const OphComplexField &complex_field)
 Function to add ComplexField when adding wavelength data. More...
 

Protected Attributes

ivec2 encode_size
 
ImgEncoderOhc * OHC_encoder
 OHC file format Variables for read and write. More...
 

Detailed Description

Openholo Light Field based CGH generation.

Author
Yeon-Gyeong Ju, Jae-Hyeung Park

Definition at line 93 of file ophgen/src/ophLightField.h.

Constructor & Destructor Documentation

◆ ophLF() [1/2]

ophLF::ophLF ( void  )
explicit

Constructor.

Definition at line 55 of file ophLightField.cpp.

56  : num_image(ivec2(0, 0))
57  , resolution_image(ivec2(0, 0))
58  , distanceRS2Holo(0.0)
59 {
60 }

◆ ~ophLF() [1/2]

virtual ophLF::~ophLF ( void  )
inlineprotectedvirtual

Destructor.

Definition at line 105 of file ophgen/src/ophLightField.h.

105 {}

◆ ophLF() [2/2]

ophLF::ophLF ( void  )
explicit

Constructor.

◆ ~ophLF() [2/2]

virtual ophLF::~ophLF ( void  )
inlineprotectedvirtual

Destructor.

Definition at line 105 of file Reference/include/ophLightField.h.

105 {}

Member Function Documentation

◆ addRef() [1/2]

unsigned long Base::addRef ( void  )
inlineinherited

If referenced this(Base's child, not abstract class) instance, must call this method.

Definition at line 75 of file openholo/src/Base.h.

75 { return ++refCnt; }

◆ addRef() [2/2]

unsigned long Base::addRef ( void  )
inlineinherited

If referenced this(Base's child, not abstract class) instance, must call this method.

Definition at line 75 of file Reference/include/Base.h.

75 { return ++refCnt; }

◆ addWaveLengthNComplexFieldDataOHC() [1/2]

void Openholo::addWaveLengthNComplexFieldDataOHC ( const Real  wavelength,
const OphComplexField &  complex_field 
)
inlineprotectedinherited

Function to add ComplexField when adding wavelength data.

Definition at line 297 of file Reference/include/Openholo.h.

298  { OHC_encoder->addWavelengthNComplexFieldData(wavelength, complex_field); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ addWaveLengthNComplexFieldDataOHC() [2/2]

void Openholo::addWaveLengthNComplexFieldDataOHC ( const Real  wavelength,
const OphComplexField &  complex_field 
)
inlineprotectedinherited

Function to add ComplexField when adding wavelength data.

Definition at line 297 of file openholo/src/Openholo.h.

298  { OHC_encoder->addWavelengthNComplexFieldData(wavelength, complex_field); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ checkExtension() [1/2]

int Openholo::checkExtension ( const char *  fname,
const char *  ext 
)
protectedinherited

Functions for extension checking.

Parameters
constchar* File name
constchar* File extension
Returns
int return 0 : The extension of "fname" and "ext" is the same return 1 : The extension of "fname" and "ext" is not the same

Definition at line 79 of file Openholo.cpp.

80 {
81  //return 1 : the extension of "fname" and "ext" is the same
82  // 0 : the extension of "fname" and "ext" is not the same
83 
84  std::string filename(fname);
85  size_t pos = filename.find(ext);
86  if (pos == std::string::npos)
87  //when there is no search string
88  return 0;
89  else
90  return 1;
91 }

◆ checkExtension() [2/2]

int Openholo::checkExtension ( const char *  fname,
const char *  ext 
)
protectedinherited

Functions for extension checking.

Parameters
constchar* File name
constchar* File extension
Returns
int return 0 : The extension of "fname" and "ext" is the same return 1 : The extension of "fname" and "ext" is not the same

◆ convertToFormatGray8() [1/2]

void Openholo::convertToFormatGray8 ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  bytesperpixel 
)
protectedinherited

Function for convert image format to gray8.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intImage size, width
intImage size, Height
intBytes per pixel

◆ convertToFormatGray8() [2/2]

void Openholo::convertToFormatGray8 ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  bytesperpixel 
)
protectedinherited

Function for convert image format to gray8.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intImage size, width
intImage size, Height
intBytes per pixel

Definition at line 310 of file Openholo.cpp.

311 {
312  int idx = 0;
313  unsigned int r = 0, g = 0, b = 0;
314  for (int i = 0; i < w*h*bytesperpixel; i++)
315  {
316  unsigned int r = src[i + 0];
317  unsigned int g = src[i + 1];
318  unsigned int b = src[i + 2];
319  dst[idx++] = (r + g + b) / 3;
320  i += bytesperpixel - 1;
321  }
322 }

◆ encodeSideBand() [1/2]

void ophGen::encodeSideBand ( bool  bCPU,
ivec2  sig_location 
)
protectedinherited

Encode the CGH according to a signal location parameter.

Parameters
boolSelect whether to operate with CPU or GPU
oph::ivec2sig_location[0]: upper or lower half, sig_location[1]:left or right half.
See also
encodeSideBand_CPU, encodeSideBand_GPU

Definition at line 1128 of file ophGen.cpp.

1129 {
1130  if ((*complex_H) == nullptr) {
1131  LOG("Not found diffracted data.");
1132  return;
1133  }
1134 
1135  int pnx = context_.pixel_number[_X];
1136  int pny = context_.pixel_number[_Y];
1137 
1138  int cropx1, cropx2, cropx, cropy1, cropy2, cropy;
1139  if (sig_location[1] == 0) { //Left or right half
1140  cropy1 = 1;
1141  cropy2 = pny;
1142  }
1143  else {
1144  cropy = (int)floor(((Real)pny) / 2);
1145  cropy1 = cropy - (int)floor(((Real)cropy) / 2);
1146  cropy2 = cropy1 + cropy - 1;
1147  }
1148 
1149  if (sig_location[0] == 0) { // Upper or lower half
1150  cropx1 = 1;
1151  cropx2 = pnx;
1152  }
1153  else {
1154  cropx = (int)floor(((Real)pnx) / 2);
1155  cropx1 = cropx - (int)floor(((Real)cropx) / 2);
1156  cropx2 = cropx1 + cropx - 1;
1157  }
1158 
1159  cropx1 -= 1;
1160  cropx2 -= 1;
1161  cropy1 -= 1;
1162  cropy2 -= 1;
1163 
1164  if (bCPU)
1165  encodeSideBand_CPU(cropx1, cropx2, cropy1, cropy2, sig_location);
1166  else
1167  encodeSideBand_GPU(cropx1, cropx2, cropy1, cropy2, sig_location);
1168 }
void encodeSideBand_CPU(int cropx1, int cropx2, int cropy1, int cropy2, oph::ivec2 sig_location)
Encode the CGH according to a signal location parameter on the CPU.
Definition: ophGen.cpp:1170

◆ encodeSideBand() [2/2]

void ophGen::encodeSideBand ( bool  bCPU,
ivec2  sig_location 
)
protectedinherited

Encode the CGH according to a signal location parameter.

Parameters
boolSelect whether to operate with CPU or GPU
oph::ivec2sig_location[0]: upper or lower half, sig_location[1]:left or right half.
See also
encodeSideBand_CPU, encodeSideBand_GPU

◆ encodeSideBand_CPU() [1/2]

void ophGen::encodeSideBand_CPU ( int  cropx1,
int  cropx2,
int  cropy1,
int  cropy2,
oph::ivec2  sig_location 
)
protectedinherited

Encode the CGH according to a signal location parameter on the CPU.

The CPU variable, (*complex_H) on CPU has the final result.

Parameters
intthe start x-coordinate to crop
intthe end x-coordinate to crop
intthe start y-coordinate to crop
intthe end y-coordinate to crop
oph::ivec2Signal location sig_location[0]: upper or lower half, sig_location[1]:left or right half.
See also
encodingSymmetrization, fftwShift

Definition at line 1170 of file ophGen.cpp.

1171 {
1172  int pnx = context_.pixel_number[_X];
1173  int pny = context_.pixel_number[_Y];
1174 
1175  oph::Complex<Real>* h_crop = new oph::Complex<Real>[pnx*pny];
1176  memset(h_crop, 0.0, sizeof(oph::Complex<Real>)*pnx*pny);
1177 
1178  int p = 0;
1179 #pragma omp parallel for private(p)
1180  for (p = 0; p < pnx*pny; p++)
1181  {
1182  int x = p % pnx;
1183  int y = p / pnx;
1184  if (x >= cropx1 && x <= cropx2 && y >= cropy1 && y <= cropy2)
1185  h_crop[p] = (*complex_H)[p];
1186  }
1187 
1188  oph::Complex<Real> *in = nullptr;
1189 
1190  fft2(oph::ivec2(pnx, pny), in, OPH_BACKWARD);
1191  fftwShift(h_crop, h_crop, pnx, pny, OPH_BACKWARD, true);
1192 
1193  memset(holo_encoded, 0.0, sizeof(Real)*pnx*pny);
1194  int i = 0;
1195 #pragma omp parallel for private(i)
1196  for (i = 0; i < pnx*pny; i++) {
1197  oph::Complex<Real> shift_phase(1, 0);
1198  getShiftPhaseValue(shift_phase, i, sig_location);
1199 
1200  holo_encoded[i] = (h_crop[i] * shift_phase).real();
1201  }
1202 
1203  delete[] h_crop;
1204 }
void fft2(oph::ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 2-dimension operations inside Openholo.
Definition: Openholo.cpp:357
void getShiftPhaseValue(oph::Complex< Real > &shift_phase_val, int idx, oph::ivec2 sig_location)
Calculate the shift phase value.
Definition: ophGen.cpp:1298
void fftwShift(Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. ...
Definition: Openholo.cpp:466

◆ encodeSideBand_CPU() [2/2]

void ophGen::encodeSideBand_CPU ( int  cropx1,
int  cropx2,
int  cropy1,
int  cropy2,
oph::ivec2  sig_location 
)
protectedinherited

Encode the CGH according to a signal location parameter on the CPU.

The CPU variable, (*complex_H) on CPU has the final result.

Parameters
intthe start x-coordinate to crop
intthe end x-coordinate to crop
intthe start y-coordinate to crop
intthe end y-coordinate to crop
oph::ivec2Signal location sig_location[0]: upper or lower half, sig_location[1]:left or right half.
See also
encodingSymmetrization, fftwShift

◆ encoding() [1/2]

void ophGen::encoding ( unsigned int  ENCODE_FLAG)
inherited

Encoding Functions.

ENCODE_PHASE : Phase ENCODE_AMPLITUDE : Amplitude ENCODE_REAL : Real Part ENCODE_SIMPLENI : Simple numerical interference ENCODE_BURCKHARDT : Burckhardt encoding

See also
C.B. Burckhardt, A simplification of Lees method of generating holograms by computer, Applied Optics, vol. 9, no. 8, pp. 1949-1949, 1970. ENCODE_TWOPHASE : Two Phase Encoding
Returns
holo_encoded ENCODE_BURCKHARDT - (holosizeX*3, holosizeY) ENCODE_TWOPHASE - (holosizeX*2, holosizeY) else - (holosizeX, holosizeY) This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ encoding() [2/2]

void ophGen::encoding ( unsigned int  ENCODE_FLAG)
inherited

Encoding Functions.

ENCODE_PHASE : Phase ENCODE_AMPLITUDE : Amplitude ENCODE_REAL : Real Part ENCODE_SIMPLENI : Simple numerical interference ENCODE_BURCKHARDT : Burckhardt encoding

See also
C.B. Burckhardt, A simplification of Lees method of generating holograms by computer, Applied Optics, vol. 9, no. 8, pp. 1949-1949, 1970. ENCODE_TWOPHASE : Two Phase Encoding
Returns
holo_encoded ENCODE_BURCKHARDT - (holosizeX*3, holosizeY) ENCODE_TWOPHASE - (holosizeX*2, holosizeY) else - (holosizeX, holosizeY) This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 627 of file ophGen.cpp.

627  {
628 
629  const int size = context_.pixel_number.v[_X] * context_.pixel_number.v[_Y];
630 
631  if (ENCODE_FLAG == ENCODE_BURCKHARDT) {
632  encode_size[_X] = context_.pixel_number[_X] * 3;
633  encode_size[_Y] = context_.pixel_number[_Y];
634  }
635  else if (ENCODE_FLAG == ENCODE_TWOPHASE) {
636  encode_size[_X] = context_.pixel_number[_X] * 2;
637  encode_size[_Y] = context_.pixel_number[_Y];
638  }
639  else {
640  encode_size[_X] = context_.pixel_number[_X];
641  encode_size[_Y] = context_.pixel_number[_Y];
642  }
643 
644  /* initialize */
645  if (holo_encoded != nullptr) delete[] holo_encoded;
646  holo_encoded = new Real[encode_size[_X] * encode_size[_Y]];
647  memset(holo_encoded, 0, sizeof(Real) * encode_size[_X] * encode_size[_Y]);
648 
649  if (holo_normalized != nullptr) delete[] holo_normalized;
650  holo_normalized = new uchar[encode_size[_X] * encode_size[_Y]];
651  memset(holo_normalized, 0, sizeof(uchar) * encode_size[_X] * encode_size[_Y]);
652 
653 
654  switch (ENCODE_FLAG)
655  {
656  case ENCODE_SIMPLENI:
657  LOG("Simple Numerical Interference Encoding..");
658  numericalInterference((*complex_H), holo_encoded, size);
659  LOG("Done.\n.");
660  break;
661  case ENCODE_REAL:
662  LOG("Real Part Encoding..");
663  realPart<Real>((*complex_H), holo_encoded, size);
664  LOG("Done.\n.");
665  break;
666  case ENCODE_BURCKHARDT:
667  LOG("Burckhardt Encoding..");
668  burckhardt((*complex_H), holo_encoded, size);
669  LOG("Done.\n.");
670  break;
671  case ENCODE_TWOPHASE:
672  LOG("Two Phase Encoding..");
673  twoPhaseEncoding((*complex_H), holo_encoded, size);
674  LOG("Done.\n.");
675  break;
676  case ENCODE_PHASE:
677  LOG("Phase Encoding..");
678  getPhase((*complex_H), holo_encoded, size);
679  LOG("Done.\n.");
680  break;
681  case ENCODE_AMPLITUDE:
682  LOG("Amplitude Encoding..");
683  getAmplitude((*complex_H), holo_encoded, size);
684  LOG("Done.\n.");
685  break;
686  case ENCODE_SSB:
687  case ENCODE_OFFSSB:
688  LOG("error: PUT PASSBAND\n");
689  cin.get();
690  return;
691  default:
692  LOG("error: WRONG ENCODE_FLAG\n");
693  cin.get();
694  return;
695  }
696 }
ivec2 encode_size
void numericalInterference(oph::Complex< Real > *holo, Real *encoded, const int size)
Encoding functions.
Definition: ophGen.cpp:804

◆ fft1() [1/2]

void Openholo::fft1 ( int  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 1-dimension operations inside Openholo.

Parameters
intNumber of data
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 324 of file Openholo.cpp.

325 {
326  pnx = n;
327  bool bIn = true;
328 
329  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * n);
330  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * n);
331 
332  if (!in){
333  in = new Complex<Real>[pnx];
334  bIn = false;
335  }
336 
337  for (int i = 0; i < n; i++) {
338  fft_in[i][_RE] = in[i].real();
339  fft_in[i][_IM] = in[i].imag();
340  }
341 
342  fft_sign = sign;
343 
344  if (!bIn) delete[] in;
345 
346  if (sign == OPH_FORWARD)
347  plan_fwd = fftw_plan_dft_1d(n, fft_in, fft_out, sign, flag);
348  else if (sign == OPH_BACKWARD)
349  plan_bwd = fftw_plan_dft_1d(n, fft_in, fft_out, sign, flag);
350  else {
351  LOG("failed fftw : wrong sign");
352  fftFree();
353  return;
354  }
355 }

◆ fft1() [2/2]

void Openholo::fft1 ( int  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 1-dimension operations inside Openholo.

Parameters
intNumber of data
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

◆ fft2() [1/2]

void Openholo::fft2 ( oph::ivec2  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 2-dimension operations inside Openholo.

Parameters
oph::ivec2Number of data(int x, int y)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 357 of file Openholo.cpp.

358 {
359  pnx = n[_X], pny = n[_Y];
360  bool bIn = true;
361 
362  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny);
363  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny);
364 
365  if (!in) {
366  in = new Complex<Real>[pnx * pny];
367  bIn = false;
368  }
369 
370  for (int i = 0; i < pnx * pny; i++) {
371  fft_in[i][_RE] = in[i].real();
372  fft_in[i][_IM] = in[i].imag();
373  }
374 
375  fft_sign = sign;
376 
377  if (!bIn) delete[] in;
378 
379  if (sign == OPH_FORWARD)
380  plan_fwd = fftw_plan_dft_2d(pny, pnx, fft_in, fft_out, sign, flag);
381  else if (sign == OPH_BACKWARD)
382  plan_bwd = fftw_plan_dft_2d(pny, pnx, fft_in, fft_out, sign, flag);
383  else {
384  LOG("failed fftw : wrong sign");
385  fftFree();
386  return;
387  }
388 }

◆ fft2() [2/2]

void Openholo::fft2 ( oph::ivec2  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 2-dimension operations inside Openholo.

Parameters
oph::ivec2Number of data(int x, int y)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

◆ fft3() [1/2]

void Openholo::fft3 ( oph::ivec3  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 3-dimension operations inside Openholo.

Parameters
oph::ivec3Number of data(int x, int y, int z)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 390 of file Openholo.cpp.

391 {
392  pnx = n[_X], pny = n[_Y], pnz = n[_Z];
393  bool bIn = true;
394 
395  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny * pnz);
396  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny * pnz);
397 
398  if (!in) {
399  in = new Complex<Real>[pnx * pny * pnz];
400  bIn = false;
401  }
402 
403  for (int i = 0; i < pnx * pny * pnz; i++) {
404  fft_in[i][_RE] = in[i].real();
405  fft_in[i][_IM] = in[i].imag();
406  }
407 
408  fft_sign = sign;
409 
410  if (!bIn) delete[] in;
411 
412  if (sign == OPH_FORWARD)
413  plan_fwd = fftw_plan_dft_3d(pnz, pny, pnx, fft_in, fft_out, sign, flag);
414  else if (sign == OPH_BACKWARD)
415  plan_bwd = fftw_plan_dft_3d(pnz, pny, pnx, fft_in, fft_out, sign, flag);
416  else {
417  LOG("failed fftw : wrong sign");
418  fftFree();
419  return;
420  }
421 }

◆ fft3() [2/2]

void Openholo::fft3 ( oph::ivec3  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 3-dimension operations inside Openholo.

Parameters
oph::ivec3Number of data(int x, int y, int z)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

◆ fftExecute() [1/2]

void Openholo::fftExecute ( Complex< Real > *  out)
protectedinherited

Execution functions to be called after fft1, fft2, and fft3.

Parameters
Complex<Real>*Dest of data

Definition at line 423 of file Openholo.cpp.

424 {
425  if (fft_sign == OPH_FORWARD)
426  fftw_execute(plan_fwd);
427  else if (fft_sign == OPH_BACKWARD)
428  fftw_execute(plan_bwd);
429  else {
430  LOG("failed fftw : wrong sign");
431  out = nullptr;
432  fftFree();
433  return;
434  }
435 
436  for (int i = 0; i < pnx * pny * pnz; i++) {
437  out[i][_RE] = fft_out[i][_RE];
438  out[i][_IM] = fft_out[i][_IM];
439  }
440 
441  fftFree();
442 }

◆ fftExecute() [2/2]

void Openholo::fftExecute ( Complex< Real > *  out)
protectedinherited

Execution functions to be called after fft1, fft2, and fft3.

Parameters
Complex<Real>*Dest of data

◆ fftShift() [1/2]

void Openholo::fftShift ( int  nx,
int  ny,
Complex< Real > *  input,
Complex< Real > *  output 
)
protectedinherited

Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom-left.

Parameters
intthe number of column of the input data
intthe number of row of the input data
Complex<Real>*input data variable
Complex<Real>*output data variable

Definition at line 511 of file Openholo.cpp.

512 {
513  for (int i = 0; i < nx; i++)
514  {
515  for (int j = 0; j < ny; j++)
516  {
517  int ti = i - nx / 2; if (ti < 0) ti += nx;
518  int tj = j - ny / 2; if (tj < 0) tj += ny;
519 
520  output[ti + tj * nx] = input[i + j * nx];
521  }
522  }
523 }

◆ fftShift() [2/2]

void Openholo::fftShift ( int  nx,
int  ny,
Complex< Real > *  input,
Complex< Real > *  output 
)
protectedinherited

Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom-left.

Parameters
intthe number of column of the input data
intthe number of row of the input data
Complex<Real>*input data variable
Complex<Real>*output data variable

◆ fftwShift() [1/2]

void Openholo::fftwShift ( Complex< Real > *  src,
Complex< Real > *  dst,
int  nx,
int  ny,
int  type,
bool  bNormalized = false 
)
protectedinherited

Convert data from the spatial domain to the frequency domain using 2D FFT on CPU.

Parameters
Complex<Real>*Input data variable
Complex<Real>*Output data variable
intthe number of column of the input data
intthe number of row of the input data
intIf type == 1, forward FFT, if type == -1, backward FFT.
boolIf bNomarlized == true, normalize the result after FFT.

Definition at line 466 of file Openholo.cpp.

467 {
468  Complex<Real>* tmp = new Complex<Real>[nx*ny];
469  memset(tmp, 0, sizeof(Complex<Real>)*nx*ny);
470  fftShift(nx, ny, src, tmp);
471 
472  fftw_complex *in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
473  fftw_complex *out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
474 
475  for (int i = 0; i < nx*ny; i++) {
476  in[i][_RE] = tmp[i][_RE];
477  in[i][_IM] = tmp[i][_IM];
478  }
479 
480  fftw_plan plan = nullptr;
481  if (!plan_fwd && !plan_bwd) {
482  plan = fftw_plan_dft_2d(ny, nx, in, out, type, OPH_ESTIMATE);
483  fftw_execute(plan);
484  }
485  else {
486  if (type == OPH_FORWARD)
487  fftw_execute_dft(plan_fwd, in, out);
488  else if (type == OPH_BACKWARD)
489  fftw_execute_dft(plan_bwd, in, out);
490  }
491 
492  int normalF = 1;
493  if (bNormalized) normalF = nx * ny;
494  memset(tmp, 0, sizeof(Complex<Real>)*nx*ny);
495 
496  for (int k = 0; k < nx*ny; k++) {
497  tmp[k][_RE] = out[k][_RE] / normalF;
498  tmp[k][_IM] = out[k][_IM] / normalF;
499  }
500 
501  fftw_free(in);
502  fftw_free(out);
503  if (plan)
504  fftw_destroy_plan(plan);
505 
506  memset(dst, 0, sizeof(Complex<Real>)*nx*ny);
507  fftShift(nx, ny, tmp, dst);
508  delete[] tmp;
509 }
void fftShift(int nx, int ny, Complex< Real > *input, Complex< Real > *output)
Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom...
Definition: Openholo.cpp:511

◆ fftwShift() [2/2]

void Openholo::fftwShift ( Complex< Real > *  src,
Complex< Real > *  dst,
int  nx,
int  ny,
int  type,
bool  bNormalized = false 
)
protectedinherited

Convert data from the spatial domain to the frequency domain using 2D FFT on CPU.

Parameters
Complex<Real>*Input data variable
Complex<Real>*Output data variable
intthe number of column of the input data
intthe number of row of the input data
intIf type == 1, forward FFT, if type == -1, backward FFT.
boolIf bNomarlized == true, normalize the result after FFT.

◆ freqShift() [1/2]

void ophGen::freqShift ( oph::Complex< Real > *  src,
Complex< Real > *  dst,
const ivec2  holosize,
int  shift_x,
int  shift_y 
)
protectedinherited

Frequency shift.

Definition at line 961 of file ophGen.cpp.

962 {
963  int size = holosize[_X] * holosize[_Y];
964 
965  oph::Complex<Real>* AS = new oph::Complex<Real>[size];
966  fft2(holosize, src, OPH_FORWARD, OPH_ESTIMATE);
967  fftwShift(src, AS, holosize[_X], holosize[_Y], OPH_FORWARD);
968  //fftExecute(AS);
969 
970  oph::Complex<Real>* shifted = new oph::Complex<Real>[size];
971  oph::circShift<Complex<Real>>(AS, shifted, shift_x, shift_y, holosize.v[_X], holosize.v[_Y]);
972 
973  fft2(holosize, shifted, OPH_BACKWARD, OPH_ESTIMATE);
974  fftwShift(shifted, dst, holosize[_X], holosize[_Y], OPH_BACKWARD);
975  //fftExecute(dst);
976 }
void fft2(oph::ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 2-dimension operations inside Openholo.
Definition: Openholo.cpp:357
void fftwShift(Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. ...
Definition: Openholo.cpp:466

◆ freqShift() [2/2]

void ophGen::freqShift ( oph::Complex< Real > *  src,
Complex< Real > *  dst,
const ivec2  holosize,
int  shift_x,
int  shift_y 
)
protectedinherited

Frequency shift.

◆ fresnelPropagation() [1/2]

void ophGen::fresnelPropagation ( OphConfig  context,
Complex< Real > *  in,
Complex< Real > *  out,
Real  distance 
)
inherited

Fresnel propagation.

Parameters
OphContextcontext OphContext structure
Complex<Real>*in Input complex field
Complex<Real>*out Output complex field
Realdistance Propagation distance
Returns
out

Definition at line 979 of file ophGen.cpp.

979  {
980 
981  int Nx = context.pixel_number[_X];
982  int Ny = context.pixel_number[_Y];
983 
984  Complex<Real>* in2x = new Complex<Real>[Nx*Ny * 4];
985  Complex<Real> zero(0, 0);
986  oph::memsetArr<Complex<Real>>(in2x, zero, 0, Nx*Ny * 4 - 1);
987 
988  uint idxIn = 0;
989 
990  for (int idxNy = Ny / 2; idxNy < Ny + (Ny / 2); idxNy++) {
991  for (int idxNx = Nx / 2; idxNx < Nx + (Nx / 2); idxNx++) {
992 
993  in2x[idxNy*Nx * 2 + idxNx] = in[idxIn];
994  idxIn++;
995  }
996  }
997 
998  Complex<Real>* temp1 = new Complex<Real>[Nx*Ny * 4];
999 
1000  fft2({ Nx * 2, Ny * 2 }, in2x, OPH_FORWARD, OPH_ESTIMATE);
1001  fftwShift(in2x, temp1, Nx, Ny, OPH_FORWARD);
1002  //fftExecute(temp1);
1003 
1004  Real* fx = new Real[Nx*Ny * 4];
1005  Real* fy = new Real[Nx*Ny * 4];
1006 
1007  uint i = 0;
1008  for (int idxFy = -Ny; idxFy < Ny; idxFy++) {
1009  for (int idxFx = -Nx; idxFx < Nx; idxFx++) {
1010  fx[i] = idxFx / (2 * Nx*context.pixel_pitch[_X]);
1011  fy[i] = idxFy / (2 * Ny*context.pixel_pitch[_Y]);
1012  i++;
1013  }
1014  }
1015 
1016  Complex<Real>* prop = new Complex<Real>[Nx*Ny * 4];
1017  oph::memsetArr<Complex<Real>>(prop, zero, 0, Nx*Ny * 4 - 1);
1018 
1019  Real sqrtPart;
1020 
1021  Complex<Real>* temp2 = new Complex<Real>[Nx*Ny * 4];
1022 
1023  for (int i = 0; i < Nx*Ny * 4; i++) {
1024  sqrtPart = sqrt(1 / (context.wave_length[0]*context.wave_length[0]) - fx[i] * fx[i] - fy[i] * fy[i]);
1025  prop[i][_IM] = 2 * M_PI * distance;
1026  prop[i][_IM] *= sqrtPart;
1027  temp2[i] = temp1[i] * exp(prop[i]);
1028  }
1029 
1030  Complex<Real>* temp3 = new Complex<Real>[Nx*Ny * 4];
1031  fft2({ Nx * 2, Ny * 2 }, temp2, OPH_BACKWARD, OPH_ESTIMATE);
1032  fftwShift(temp2, temp3, Nx*2, Ny*2, OPH_BACKWARD);
1033  //fftExecute(temp3);
1034 
1035  uint idxOut = 0;
1036 
1037  for (int idxNy = Ny / 2; idxNy < Ny + (Ny / 2); idxNy++) {
1038  for (int idxNx = Nx / 2; idxNx < Nx + (Nx / 2); idxNx++) {
1039 
1040  out[idxOut] = temp3[idxNy*Nx * 2 + idxNx];
1041  idxOut++;
1042  }
1043  }
1044 
1045  delete[] in2x;
1046  delete[] temp1;
1047  delete[] fx;
1048  delete[] fy;
1049  delete[] prop;
1050  delete[] temp2;
1051  delete[] temp3;
1052 }
void fft2(oph::ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 2-dimension operations inside Openholo.
Definition: Openholo.cpp:357
void fftwShift(Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. ...
Definition: Openholo.cpp:466

◆ fresnelPropagation() [2/2]

void ophGen::fresnelPropagation ( OphConfig  context,
Complex< Real > *  in,
Complex< Real > *  out,
Real  distance 
)
inherited

Fresnel propagation.

Parameters
OphContextcontext OphContext structure
Complex<Real>*in Input complex field
Complex<Real>*out Output complex field
Realdistance Propagation distance
Returns
out

◆ generateHologram() [1/2]

void ophLF::generateHologram ( void  )

Hologram generation.

Returns
(*complex_H)

Definition at line 276 of file ophLightField.cpp.

276  {
277 
278  auto start = CUR_TIME;
279 
280  LOG("Converting....");
281  convertLF2ComplexField();
282  LOG("finished.\n");
283 
284  LOG("Propagating ...");
285  fresnelPropagation(RSplane_complex_field, (*complex_H), distanceRS2Holo);
286  LOG("finished.\n");
287 
288  auto end = CUR_TIME;
289  auto during = ((std::chrono::duration<Real>)(end - start)).count();
290 
291  LOG("%.5lfsec...hologram generated..\n", during);
292 }
void fresnelPropagation(OphConfig context, Complex< Real > *in, Complex< Real > *out, Real distance)
Fresnel propagation.
Definition: ophGen.cpp:979

◆ generateHologram() [2/2]

void ophLF::generateHologram ( )

Hologram generation.

Returns
(*complex_H)

◆ getImgSize() [1/2]

int Openholo::getImgSize ( int &  w,
int &  h,
int &  bytesperpixel,
const char *  file_name 
)
protectedinherited

Function for getting the image size.

Parameters
int&Image size - width
int&Image size - Height
int&Bytes per pixel
constchar* Input file name

Definition at line 259 of file Openholo.cpp.

260 {
261  char bmpFile[256];
262  sprintf_s(bmpFile, "%s", file_name);
263  FILE *infile;
264  fopen_s(&infile, bmpFile, "rb");
265  if (infile == NULL) { LOG("No Image File"); return 0; }
266 
267  // BMP Header Information
268  fileheader hf;
269  bitmapinfoheader hInfo;
270  fread(&hf, sizeof(fileheader), 1, infile);
271  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0;
272  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
273  //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; }
274 
275  w = hInfo.width;
276  h = hInfo.height;
277  bytesperpixel = hInfo.bitsperpixel / 8;
278 
279  fclose(infile);
280 
281  return 1;
282 }

◆ getImgSize() [2/2]

int Openholo::getImgSize ( int &  w,
int &  h,
int &  bytesperpixel,
const char *  file_name 
)
protectedinherited

Function for getting the image size.

Parameters
int&Image size - width
int&Image size - Height
int&Bytes per pixel
constchar* Input file name

◆ getRandPhaseValue() [1/2]

void ophGen::getRandPhaseValue ( oph::Complex< Real > &  rand_phase_val,
bool  rand_phase 
)
protectedinherited

Assign random phase value if RANDOM_PHASE == 1.

If RANDOM_PHASE == 1, calculate a random phase value using random generator; otherwise, random phase value is 1.

Parameters
rand_phase_val: Input & Ouput value.

Definition at line 1340 of file ophGen.cpp.

1341 {
1342  if (rand_phase)
1343  {
1344  rand_phase_val[_RE] = 0.0;
1345  Real min, max;
1346 #if REAL_IS_DOUBLE & true
1347  min = 0.0;
1348  max = 1.0;
1349 #else
1350  min = 0.f;
1351  max = 1.f;
1352 #endif
1353  rand_phase_val[_IM] = 2 * M_PI * oph::rand(min, max);
1354  rand_phase_val.exp();
1355 
1356  }
1357  else {
1358  rand_phase_val[_RE] = 1.0;
1359  rand_phase_val[_IM] = 0.0;
1360  }
1361 }

◆ getRandPhaseValue() [2/2]

void ophGen::getRandPhaseValue ( oph::Complex< Real > &  rand_phase_val,
bool  rand_phase 
)
protectedinherited

Assign random phase value if RANDOM_PHASE == 1.

If RANDOM_PHASE == 1, calculate a random phase value using random generator; otherwise, random phase value is 1.

Parameters
rand_phase_val: Input & Ouput value.

◆ getShiftPhaseValue() [1/2]

void ophGen::getShiftPhaseValue ( oph::Complex< Real > &  shift_phase_val,
int  idx,
oph::ivec2  sig_location 
)
protectedinherited

Calculate the shift phase value.

Parameters
shift_phase_val: output variable.
idx: the current pixel position.
sig_location: signal location.
See also
encodingSideBand_CPU

Definition at line 1298 of file ophGen.cpp.

1299 {
1300  int pnx = context_.pixel_number[0];
1301  int pny = context_.pixel_number[1];
1302  Real ppx = context_.pixel_pitch[0];
1303  Real ppy = context_.pixel_pitch[1];
1304  Real ssx = context_.ss[0];
1305  Real ssy = context_.ss[1];
1306 
1307  if (sig_location[1] != 0)
1308  {
1309  int r = idx / pnx;
1310  int c = idx % pnx;
1311  Real yy = (ssy / 2.0) - (ppy)*r - ppy;
1312 
1313  oph::Complex<Real> val;
1314  if (sig_location[1] == 1)
1315  val[_IM] = 2 * M_PI * (yy / (4 * ppy));
1316  else
1317  val[_IM] = 2 * M_PI * (-yy / (4 * ppy));
1318 
1319  val.exp();
1320  shift_phase_val *= val;
1321  }
1322 
1323  if (sig_location[0] != 0)
1324  {
1325  int r = idx / pnx;
1326  int c = idx % pnx;
1327  Real xx = (-ssx / 2.0) - (ppx)*c - ppx;
1328 
1329  oph::Complex<Real> val;
1330  if (sig_location[0] == -1)
1331  val[_IM] = 2 * M_PI * (-xx / (4 * ppx));
1332  else
1333  val[_IM] = 2 * M_PI * (xx / (4 * ppx));
1334 
1335  val.exp();
1336  shift_phase_val *= val;
1337  }
1338 }

◆ getShiftPhaseValue() [2/2]

void ophGen::getShiftPhaseValue ( oph::Complex< Real > &  shift_phase_val,
int  idx,
oph::ivec2  sig_location 
)
protectedinherited

Calculate the shift phase value.

Parameters
shift_phase_val: output variable.
idx: the current pixel position.
sig_location: signal location.
See also
encodingSideBand_CPU

◆ imgScaleBilnear() [1/2]

void Openholo::imgScaleBilnear ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  neww,
int  newh 
)
protectedinherited

Function for change image size.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intOriginal width
intOriginal height
intWidth to replace
intHeight to replace

Definition at line 284 of file Openholo.cpp.

285 {
286  for (int y = 0; y < newh; y++)
287  {
288  for (int x = 0; x < neww; x++)
289  {
290  float gx = (x / (float)neww) * (w - 1);
291  float gy = (y / (float)newh) * (h - 1);
292 
293  int gxi = (int)gx;
294  int gyi = (int)gy;
295 
296  uint32_t a00 = src[gxi + 0 + gyi * w];
297  uint32_t a01 = src[gxi + 1 + gyi * w];
298  uint32_t a10 = src[gxi + 0 + (gyi + 1)*w];
299  uint32_t a11 = src[gxi + 1 + (gyi + 1)*w];
300 
301  float dx = gx - gxi;
302  float dy = gy - gyi;
303 
304  dst[x + y * neww] = int(a00 * (1 - dx)*(1 - dy) + a01 * dx*(1 - dy) + a10 * (1 - dx)*dy + a11 * dx*dy);
305 
306  }
307  }
308 }

◆ imgScaleBilnear() [2/2]

void Openholo::imgScaleBilnear ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  neww,
int  newh 
)
protectedinherited

Function for change image size.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intOriginal width
intOriginal height
intWidth to replace
intHeight to replace

◆ initialize() [1/2]

void ophGen::initialize ( void  )
inherited

Initialize variables for Hologram complex field, encoded data, normalized data.

Definition at line 71 of file ophGen.cpp.

72 {
73  // Output Image Size
74  int n_x = context_.pixel_number[_X];
75  int n_y = context_.pixel_number[_Y];
76 
77  // Memory Location for Result Image
78  complex_H[0] = new oph::Complex<Real>[n_x * n_y];
79  memset((*complex_H), 0, sizeof(Complex<Real>) * n_x * n_y);
80 
81  if (holo_encoded != nullptr) delete[] holo_encoded;
82  holo_encoded = new Real[n_x * n_y];
83  memset(holo_encoded, 0, sizeof(Real) * n_x * n_y);
84 
85  if (holo_normalized != nullptr) delete[] holo_normalized;
86  holo_normalized = new uchar[n_x * n_y];
87  memset(holo_normalized, 0, sizeof(uchar) * n_x * n_y);
88 }

◆ initialize() [2/2]

void ophGen::initialize ( void  )
inherited

Initialize variables for Hologram complex field, encoded data, normalized data.

◆ load() [1/2]

void * ophGen::load ( const char *  fname)
inherited

Function for loading image files.

Definition at line 557 of file ophGen.cpp.

558 {
559  if (checkExtension(fname, ".bmp")) {
560  return Openholo::loadAsImg(fname);
561  }
562  else { // when extension is not .bmp
563  return nullptr;
564  }
565 
566  return nullptr;
567 }
virtual uchar * loadAsImg(const char *fname)
Function for loading image files.
Definition: Openholo.cpp:146
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79

◆ load() [2/2]

void* ophGen::load ( const char *  fname)
inherited

Function for loading image files.

◆ loadAsImg() [1/2]

uchar * Openholo::loadAsImg ( const char *  fname)
virtualinherited

Function for loading image files.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

Definition at line 146 of file Openholo.cpp.

147 {
148  FILE *infile;
149  fopen_s(&infile, fname, "rb");
150  if (infile == nullptr) { LOG("No such file"); return 0; }
151 
152  // BMP Header Information
153  fileheader hf;
154  bitmapinfoheader hInfo;
155  fread(&hf, sizeof(fileheader), 1, infile);
156  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File"); return 0; }
157 
158  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
159  fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
160 
161  oph::uchar *img_tmp;
162  if (hInfo.imagesize == 0) {
163  img_tmp = new uchar[hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)];
164  fread(img_tmp, sizeof(oph::uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
165  }
166  else {
167  img_tmp = new uchar[hInfo.imagesize];
168  fread(img_tmp, sizeof(oph::uchar), hInfo.imagesize, infile);
169  }
170  fclose(infile);
171 
172  return img_tmp;
173 }

◆ loadAsImg() [2/2]

virtual uchar* Openholo::loadAsImg ( const char *  fname)
virtualinherited

Function for loading image files.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

◆ loadAsImgUpSideDown() [1/2]

int Openholo::loadAsImgUpSideDown ( const char *  fname,
uchar *  dst 
)
protectedinherited

Function for loading image files | Output image data upside down.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

Definition at line 218 of file Openholo.cpp.

219 {
220  FILE *infile;
221  fopen_s(&infile, fname, "rb");
222  if (infile == nullptr) { LOG("No such file"); return 0; }
223 
224  // BMP Header Information
225  fileheader hf;
226  bitmapinfoheader hInfo;
227  fread(&hf, sizeof(fileheader), 1, infile);
228  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File"); return 0; }
229 
230  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
231  fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
232 
233  oph::uchar* img_tmp;
234  if (hInfo.imagesize == 0) {
235  img_tmp = new oph::uchar[hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)];
236  fread(img_tmp, sizeof(oph::uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
237  }
238  else {
239  img_tmp = new oph::uchar[hInfo.imagesize];
240  fread(img_tmp, sizeof(oph::uchar), hInfo.imagesize, infile);
241  }
242  fclose(infile);
243 
244  // data upside down
245  int bytesperpixel = hInfo.bitsperpixel / 8;
246  int rowsz = bytesperpixel * hInfo.width;
247 
248  for (oph::uint k = 0; k < hInfo.height*rowsz; k++) {
249  int r = k / rowsz;
250  int c = k % rowsz;
251  ((oph::uchar*)dst)[(hInfo.height - r - 1)*rowsz + c] = img_tmp[r*rowsz + c];
252  }
253 
254  delete[] img_tmp;
255 
256  return 1;
257 }

◆ loadAsImgUpSideDown() [2/2]

int Openholo::loadAsImgUpSideDown ( const char *  fname,
uchar *  dst 
)
protectedinherited

Function for loading image files | Output image data upside down.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

◆ loadAsOhc() [1/2]

virtual int ophGen::loadAsOhc ( const char *  fname)
virtualinherited

Function to read OHC file.

Reimplemented from Openholo.

◆ loadAsOhc() [2/2]

int ophGen::loadAsOhc ( const char *  fname)
virtualinherited

Function to read OHC file.

Reimplemented from Openholo.

Definition at line 569 of file ophGen.cpp.

570 {
571  if (Openholo::loadAsOhc(fname) == -1) return -1;
572 
573  if (holo_encoded != nullptr) delete[] holo_encoded;
574  holo_encoded = new Real[context_.pixel_number[_X] * context_.pixel_number[_Y]];
575 
576  if (holo_normalized != nullptr) delete[] holo_normalized;
577  holo_normalized = new uchar[context_.pixel_number[_X] * context_.pixel_number[_Y]];
578 
579  return 0;
580 }
virtual int loadAsOhc(const char *fname)
Function to read OHC file.
Definition: Openholo.cpp:193

◆ loadComplex() [1/2]

void ophGen::loadComplex ( char *  real_file,
char *  imag_file,
int  n_x,
int  n_y 
)
inherited

Complex field file load.

Just used for the reference

Definition at line 584 of file ophGen.cpp.

584  {
585  context_.pixel_number[_X] = n_x;
586  context_.pixel_number[_Y] = n_y;
587 
588  ifstream freal, fimag;
589  freal.open(real_file);
590  fimag.open(imag_file);
591  if (!freal) {
592  cout << "open failed - real" << endl;
593  cin.get();
594  return;
595  }
596  if (!fimag) {
597  cout << "open failed - imag" << endl;
598  cin.get();
599  return;
600  }
601 
602  if ((*complex_H) != nullptr) delete[] (*complex_H);
603  (*complex_H) = new oph::Complex<Real>[n_x * n_y];
604  memset((*complex_H), 0, sizeof(Complex<Real>) * n_x * n_y);
605 
606  Real realVal, imagVal;
607 
608  int i;
609  i = 0;
610  for (int i = 0; i < n_x * n_y; i++) {
611  freal >> realVal;
612  fimag >> imagVal;
613 
614  Complex<Real> compVal;
615  compVal(realVal, imagVal);
616 
617  (*complex_H)[i] = compVal;
618  if (realVal == EOF || imagVal == EOF)
619  break;
620  }
621 }

◆ loadComplex() [2/2]

void ophGen::loadComplex ( char *  real_file,
char *  imag_file,
int  n_x,
int  n_y 
)
inherited

Complex field file load.

Just used for the reference

◆ loadLF() [1/2]

int ophLF::loadLF ( const char *  directory,
const char *  exten 
)

Light Field images load.

Parameters
directoryDirectory which has the Light Field source image files
extenLight Field images extension
Returns
LF This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 169 of file ophLightField.cpp.

170 {
171  LF_directory = directory;
172  ext = exten;
173 
174  initializeLF();
175 
176  _finddata_t data;
177 
178  string sdir = std::string(LF_directory).append("\\").append("*.").append(ext);
179  intptr_t ff = _findfirst(sdir.c_str(), &data);
180  if (ff != -1)
181  {
182  int num = 0;
183  uchar* rgbOut;
184  ivec2 sizeOut;
185  int bytesperpixel;
186 
187  while (1)
188  {
189  string imgfullname = std::string(LF_directory).append("\\").append(data.name);
190 
191  getImgSize(sizeOut[_X], sizeOut[_Y], bytesperpixel, imgfullname.c_str());
192 
193  rgbOut = loadAsImg(imgfullname.c_str());
194 
195  if (rgbOut == 0) {
196  cout << "LF load was failed." << endl;
197  return -1;
198  }
199 
200  convertToFormatGray8(rgbOut, *(LF + num), sizeOut[_X], sizeOut[_Y], bytesperpixel);
201 
202  num++;
203 
204  int out = _findnext(ff, &data);
205  if (out == -1)
206  break;
207  }
208  _findclose(ff);
209  cout << "LF load was successed." << endl;
210 
211  if (num_image[_X] * num_image[_Y] != num) {
212  cout << "num_image is not matched." << endl;
213  }
214  return 1;
215  }
216  else
217  {
218  cout << "LF load was failed." << endl;
219  return -1;
220  }
221 }
int getImgSize(int &w, int &h, int &bytesperpixel, const char *file_name)
Function for getting the image size.
Definition: Openholo.cpp:259
virtual uchar * loadAsImg(const char *fname)
Function for loading image files.
Definition: Openholo.cpp:146
void convertToFormatGray8(unsigned char *src, unsigned char *dst, int w, int h, int bytesperpixel)
Function for convert image format to gray8.
Definition: Openholo.cpp:310

◆ loadLF() [2/2]

int ophLF::loadLF ( const char *  directory,
const char *  exten 
)

Light Field images load.

Parameters
directoryDirectory which has the Light Field source image files
extenLight Field images extension
Returns
LF This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ loadPointCloud() [1/2]

int ophGen::loadPointCloud ( const char *  pc_file,
OphPointCloudData pc_data_ 
)
inherited
Parameters
constchar* Point cloud data file name
OphPointCloudData*Point cloud data - number of points, number of color, geometry of point cloud, color data, phase data
Returns
Positive integer is points number of point cloud, return a negative integer if the load fails

◆ loadPointCloud() [2/2]

int ophGen::loadPointCloud ( const char *  pc_file,
OphPointCloudData pc_data_ 
)
inherited
Parameters
constchar* Point cloud data file name
OphPointCloudData*Point cloud data - number of points, number of color, geometry of point cloud, color data, phase data
Returns
Positive integer is points number of point cloud, return a negative integer if the load fails

Definition at line 90 of file ophGen.cpp.

91 {
92  LOG("Reading....%s...\n", pc_file);
93 
94  auto start = CUR_TIME;
95 
96  PLYparser plyIO;
97  if (!plyIO.loadPLY(pc_file, pc_data_->n_points, pc_data_->n_colors, &pc_data_->vertex, &pc_data_->color, &pc_data_->phase, pc_data_->isPhaseParse))
98  return -1;
99 
100  auto end = CUR_TIME;
101 
102  auto during = ((std::chrono::duration<Real>)(end - start)).count();
103 
104  LOG("%.5lfsec...done\n", during);
105  return pc_data_->n_points;
106 }

◆ normalize() [1/2]

void ophGen::normalize ( void  )
inherited

Normalization function to save as image file after hologram creation.

◆ normalize() [2/2]

void ophGen::normalize ( void  )
inherited

Normalization function to save as image file after hologram creation.

Definition at line 499 of file ophGen.cpp.

500 {
501  oph::normalize((Real*)holo_encoded, holo_normalized, context_.pixel_number[_X], context_.pixel_number[_Y]);
502 }

◆ normalizeEncoded() [1/2]

void ophGen::normalizeEncoded ( void  )
inherited

Normalize the encoded hologram.

Considering the encoded hologram size

Definition at line 623 of file ophGen.cpp.

623  {
624  oph::normalize(holo_encoded, holo_normalized, encode_size.v[_X], encode_size.v[_Y]);
625 }
ivec2 encode_size

◆ normalizeEncoded() [2/2]

void ophGen::normalizeEncoded ( void  )
inherited

Normalize the encoded hologram.

Considering the encoded hologram size

◆ numericalInterference() [1/2]

void ophGen::numericalInterference ( oph::Complex< Real > *  holo,
Real *  encoded,
const int  size 
)
protectedinherited

Encoding functions.

Definition at line 804 of file ophGen.cpp.

805 {
806  Real* temp1 = new Real[size];
807  oph::absCplxArr<Real>(holo, temp1, size);
808 
809  Real* ref = new Real;
810  *ref = oph::maxOfArr(temp1, size);
811 
812  oph::Complex<Real>* temp2 = new oph::Complex<Real>[size];
813  for_i(size,
814  temp2[i] = holo[i] + *ref;
815  );
816 
817  Real* temp3 = new Real[size];
818  oph::absCplxArr<Real>(temp2, temp3, size);
819 
820  for_i(size,
821  encoded[i] = temp3[i] * temp3[i];
822  );
823 
824  delete[] temp1;
825  delete[] temp2;
826  delete[] temp3;
827  delete ref;
828 }

◆ numericalInterference() [2/2]

void ophGen::numericalInterference ( oph::Complex< Real > *  holo,
Real *  encoded,
const int  size 
)
protectedinherited

Encoding functions.

◆ ophFree() [1/2]

void ophGen::ophFree ( void  )
protectedvirtualinherited

Pure virtual function for override in child classes.

Reimplemented from Openholo.

Reimplemented in ophDepthMap, and ophDepthMap.

Definition at line 1363 of file ophGen.cpp.

1364 {
1365  if (holo_encoded) delete[] holo_encoded;
1366  if (holo_normalized) delete[] holo_normalized;
1367 
1368 }

◆ ophFree() [2/2]

virtual void ophGen::ophFree ( void  )
protectedvirtualinherited

Pure virtual function for override in child classes.

Reimplemented from Openholo.

Reimplemented in ophDepthMap, and ophDepthMap.

◆ propagationAngularSpectrum()

void ophGen::propagationAngularSpectrum ( Complex< Real > *  input_u,
Real  propagation_dist 
)
inherited

Angular spectrum propagation method.

The propagation results of all depth levels are accumulated in the variable 'U_complex_'.

Parameters
input_u: each depth plane data.
propagation_dist: the distance from the object to the hologram plane.
See also
Calc_Holo_by_Depth, Calc_Holo_CPU, fftwShift

Definition at line 466 of file ophGen.cpp.

467 {
468  int pnx = context_.pixel_number[0];
469  int pny = context_.pixel_number[1];
470  Real ppx = context_.pixel_pitch[0];
471  Real ppy = context_.pixel_pitch[1];
472  Real ssx = context_.ss[0];
473  Real ssy = context_.ss[1];
474  Real lambda = context_.wave_length[0];
475 
476  for (int i = 0; i < pnx * pny; i++)
477  {
478  Real x = i % pnx;
479  Real y = i / pnx;
480 
481  Real fxx = (-1.0 / (2.0*ppx)) + (1.0 / ssx) * x;
482  Real fyy = (1.0 / (2.0*ppy)) - (1.0 / ssy) - (1.0 / ssy) * y;
483 
484  Real sval = sqrt(1 - (lambda*fxx)*(lambda*fxx) - (lambda*fyy)*(lambda*fyy));
485  sval *= context_.k * propagation_dist;
486  Complex<Real> kernel(0, sval);
487  kernel.exp();
488 
489  int prop_mask = ((fxx * fxx + fyy * fyy) < (context_.k *context_.k)) ? 1 : 0;
490 
491  Complex<Real> u_frequency;
492  if (prop_mask == 1)
493  u_frequency = kernel * input_u[i];
494 
495  (*complex_H)[i] = (*complex_H)[i] + u_frequency;
496  }
497 }

◆ readConfig() [1/4]

bool ophGen::readConfig ( const char *  fname,
OphPointCloudConfig config 
)
inherited
Parameters
constchar* Input file name
OphPointCloudConfig&Config structures variable can get configuration data

Definition at line 108 of file ophGen.cpp.

109 {
110  LOG("Reading....%s...", fname);
111 
112  auto start = CUR_TIME;
113 
114  /*XML parsing*/
115  tinyxml2::XMLDocument xml_doc;
116  tinyxml2::XMLNode *xml_node;
117 
118  if (checkExtension(fname, ".xml") == 0)
119  {
120  LOG("file's extension is not 'xml'\n");
121  return false;
122  }
123  auto ret = xml_doc.LoadFile(fname);
124  if (ret != tinyxml2::XML_SUCCESS )
125  {
126  LOG("Failed to load file \"%s\"\n", fname);
127  return false;
128  }
129 
130  xml_node = xml_doc.FirstChild();
131 
132 #if REAL_IS_DOUBLE & true
133  auto next = xml_node->FirstChildElement("ScalingXofPointCloud");
134  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&configdata.scale[_X]))
135  return false;
136  next = xml_node->FirstChildElement("ScalingYofPointCloud");
137  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&configdata.scale[_Y]))
138  return false;
139  next = xml_node->FirstChildElement("ScalingZofPointCloud");
140  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&configdata.scale[_Z]))
141  return false;
142  next = xml_node->FirstChildElement("OffsetInDepth");
143  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&configdata.offset_depth))
144  return false;
145  next = xml_node->FirstChildElement("SLMpixelPitchX");
146  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.pixel_pitch[_X]))
147  return false;
148  next = xml_node->FirstChildElement("SLMpixelPitchY");
149  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.pixel_pitch[_Y]))
150  return false;
151  next = xml_node->FirstChildElement("WavelengthofLaser");
152  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.wave_length[0]))
153  return false;
154  //(xml_node->FirstChildElement("ScalingXofPointCloud"))->QueryDoubleText(&configdata.scale[_X]);
155  //(xml_node->FirstChildElement("ScalingYofPointCloud"))->QueryDoubleText(&configdata.scale[_Y]);
156  //(xml_node->FirstChildElement("ScalingZofPointCloud"))->QueryDoubleText(&configdata.scale[_Z]);
157  //(xml_node->FirstChildElement("OffsetInDepth"))->QueryDoubleText(&configdata.offset_depth);
158  //(xml_node->FirstChildElement("SLMpixelPitchX"))->QueryDoubleText(&context_.pixel_pitch[_X]);
159  //(xml_node->FirstChildElement("SLMpixelPitchY"))->QueryDoubleText(&context_.pixel_pitch[_Y]);
160  //(xml_node->FirstChildElement("WavelengthofLaser"))->QueryDoubleText(&context_.wave_length[0]);
161  //(xml_node->FirstChildElement("BandpassFilterWidthX"))->QueryDoubleText(&configdata.filter_width[_X]);
162  //(xml_node->FirstChildElement("BandpassFilterWidthY"))->QueryDoubleText(&configdata.filter_width[_Y]);
163  //(xml_node->FirstChildElement("FocalLengthofInputLens"))->QueryDoubleText(&configdata.focal_length_lens_in);
164  //(xml_node->FirstChildElement("FocalLengthofOutputLens"))->QueryDoubleText(&configdata.focal_length_lens_out);
165  //(xml_node->FirstChildElement("FocalLengthofEyepieceLens"))->QueryDoubleText(&configdata.focal_length_lens_eye_piece);
166  //(xml_node->FirstChildElement("TiltAngleX"))->QueryDoubleText(&configdata.tilt_angle[_X]);
167  //(xml_node->FirstChildElement("TiltAngleY"))->QueryDoubleText(&configdata.tilt_angle[_Y]);
168 #else
169  auto next = xml_node->FirstChildElement("ScalingXofPointCloud");
170  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&configdata.scale[_X]))
171  return false;
172  next = xml_node->FirstChildElement("ScalingYofPointCloud");
173  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&configdata.scale[_Y]))
174  return false;
175  next = xml_node->FirstChildElement("ScalingZofPointCloud");
176  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&configdata.scale[_Z]))
177  return false;
178  next = xml_node->FirstChildElement("OffsetInDepth");
179  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&configdata.offset_depth))
180  return false;
181  next = xml_node->FirstChildElement("SLMpixelPitchX");
182  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.pixel_pitch[_X]))
183  return false;
184  next = xml_node->FirstChildElement("SLMpixelPitchY");
185  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.pixel_pitch[_Y]))
186  return false;
187  next = xml_node->FirstChildElement("WavelengthofLaser");
188  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.wave_length[0]))
189  return false;
190  //(xml_node->FirstChildElement("ScalingXofPointCloud"))->QueryFloatText(&configdata.scale[_X]);
191  //(xml_node->FirstChildElement("ScalingYofPointCloud"))->QueryFloatText(&configdata.scale[_Y]);
192  //(xml_node->FirstChildElement("ScalingZofPointCloud"))->QueryFloatText(&configdata.scale[_Z]);
193  //(xml_node->FirstChildElement("OffsetInDepth"))->QueryFloatText(&configdata.offset_depth);
194  //(xml_node->FirstChildElement("SLMpixelPitchX"))->QueryFloatText(&context_.pixel_pitch[_X]);
195  //(xml_node->FirstChildElement("SLMpixelPitchY"))->QueryFloatText(&context_.pixel_pitch[_Y]);
196  //(xml_node->FirstChildElement("WavelengthofLaser"))->QueryFloatText(&context_.wave_length[0]);
197  //(xml_node->FirstChildElement("BandpassFilterWidthX"))->QueryFloatText(&configdata.filter_width[_X]);
198  //(xml_node->FirstChildElement("BandpassFilterWidthY"))->QueryFloatText(&configdata.filter_width[_Y]);
199  //(xml_node->FirstChildElement("FocalLengthofInputLens"))->QueryFloatText(&configdata.focal_length_lens_in);
200  //(xml_node->FirstChildElement("FocalLengthofOutputLens"))->QueryFloatText(&configdata.focal_length_lens_out);
201  //(xml_node->FirstChildElement("FocalLengthofEyepieceLens"))->QueryFloatText(&configdata.focal_length_lens_eye_piece);
202  //(xml_node->FirstChildElement("TiltAngleX"))->QueryFloatText(&configdata.tilt_angle[_X]);
203  //(xml_node->FirstChildElement("TiltAngleY"))->QueryFloatText(&configdata.tilt_angle[_Y]);
204 #endif
205  next = xml_node->FirstChildElement("SLMpixelNumX");
206  if (!next || tinyxml2::XML_SUCCESS != next->QueryIntText(&context_.pixel_number[_X]))
207  return false;
208  next = xml_node->FirstChildElement("SLMpixelNumY");
209  if (!next || tinyxml2::XML_SUCCESS != next->QueryIntText(&context_.pixel_number[_Y]))
210  return false;
211  //(xml_node->FirstChildElement("SLMpixelNumX"))->QueryIntText(&context_.pixel_number[_X]);
212  //(xml_node->FirstChildElement("SLMpixelNumY"))->QueryIntText(&context_.pixel_number[_Y]);
213  //configdata.filter_shape_flag = (int8_t*)(xml_node->FirstChildElement("BandpassFilterShape"))->GetText();
214 
215  context_.k = (2 * M_PI) / context_.wave_length[0];
216  context_.ss[_X] = context_.pixel_number[_X] * context_.pixel_pitch[_X];
217  context_.ss[_Y] = context_.pixel_number[_Y] * context_.pixel_pitch[_Y];
218 
219  Openholo::setPixelNumberOHC(context_.pixel_number);
220  Openholo::setPixelPitchOHC(context_.pixel_pitch);
221  Openholo::setWavelengthOHC(context_.wave_length[0], LenUnit::m);
222 
223  auto end = CUR_TIME;
224 
225  auto during = ((std::chrono::duration<Real>)(end - start)).count();
226 
227  LOG("%.5lfsec...done\n", during);
228  return true;
229 }
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
XMLError LoadFile(const char *filename)
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79
const XMLElement * FirstChildElement(const char *name=0) const

◆ readConfig() [2/4]

bool ophGen::readConfig ( const char *  fname,
OphPointCloudConfig config 
)
inherited
Parameters
constchar* Input file name
OphPointCloudConfig&Config structures variable can get configuration data

◆ readConfig() [3/4]

bool ophGen::readConfig ( const char *  fname,
OphDepthMapConfig config 
)
inherited
Parameters
constchar* Input file name
OphDepthMapConfig&Config structures variable can get configuration data

Definition at line 231 of file ophGen.cpp.

232 {
233  LOG("Reading....%s...", fname);
234 
235  auto start = CUR_TIME;
236  /*XML parsing*/
237 
238  tinyxml2::XMLDocument xml_doc;
239  tinyxml2::XMLNode *xml_node;
240 
241  if (checkExtension(fname, ".xml") == 0)
242  {
243  LOG("file's extension is not 'xml'\n");
244  return false;
245  }
246  auto ret = xml_doc.LoadFile(fname);
247  if (ret != tinyxml2::XML_SUCCESS)
248  {
249  LOG("Failed to load file \"%s\"\n", fname);
250  return false;
251  }
252 
253  xml_node = xml_doc.FirstChild();
254 
255  auto next = xml_node->FirstChildElement("SLMpixelNumX");
256  if (!next || tinyxml2::XML_SUCCESS != next->QueryIntText(&context_.pixel_number[_X]))
257  return false;
258  next = xml_node->FirstChildElement("SLMpixelNumY");
259  if (!next || tinyxml2::XML_SUCCESS != next->QueryIntText(&context_.pixel_number[_Y]))
260  return false;
261 
262  next = xml_node->FirstChildElement("FlagChangeDepthQuantization");
263  if (!next || tinyxml2::XML_SUCCESS != next->QueryBoolText(&config.FLAG_CHANGE_DEPTH_QUANTIZATION))
264  return false;
265  next = xml_node->FirstChildElement("DefaultDepthQuantization");
266  if (!next || tinyxml2::XML_SUCCESS != next->QueryUnsignedText(&config.DEFAULT_DEPTH_QUANTIZATION))
267  return false;
268  next = xml_node->FirstChildElement("NumberOfDepthQuantization");
269  if (!next || tinyxml2::XML_SUCCESS != next->QueryUnsignedText(&config.NUMBER_OF_DEPTH_QUANTIZATION))
270  return false;
271  //(xml_node->FirstChildElement("SLMpixelNumX"))->QueryIntText(&context_.pixel_number[_X]);
272  //(xml_node->FirstChildElement("SLMpixelNumY"))->QueryIntText(&context_.pixel_number[_Y]);
273 
274  //(xml_node->FirstChildElement("FlagChangeDepthQuantization"))->QueryBoolText(&config.FLAG_CHANGE_DEPTH_QUANTIZATION);
275  //(xml_node->FirstChildElement("DefaultDepthQuantization"))->QueryUnsignedText(&config.DEFAULT_DEPTH_QUANTIZATION);
276  //(xml_node->FirstChildElement("NumberOfDepthQuantization"))->QueryUnsignedText(&config.DEFAULT_DEPTH_QUANTIZATION);
277 
278  if (config.FLAG_CHANGE_DEPTH_QUANTIZATION == 0)
279  config.num_of_depth = config.DEFAULT_DEPTH_QUANTIZATION;
280  else
281  config.num_of_depth = config.NUMBER_OF_DEPTH_QUANTIZATION;
282 
283  std::string render_depth;
284  next = xml_node->FirstChildElement("RenderDepth");
285  if (!next || tinyxml2::XML_SUCCESS != next->QueryBoolText(&config.FLAG_CHANGE_DEPTH_QUANTIZATION))
286  return false;
287  else render_depth = (xml_node->FirstChildElement("RenderDepth"))->GetText();
288 
289  std::size_t found = render_depth.find(':');
290  if (found != std::string::npos)
291  {
292  std::string s = render_depth.substr(0, found);
293  std::string e = render_depth.substr(found + 1);
294  int start = std::stoi(s);
295  int end = std::stoi(e);
296  config.render_depth.clear();
297  for (int k = start; k <= end; k++)
298  config.render_depth.push_back(k);
299  }
300  else
301  {
302  std::stringstream ss(render_depth);
303  int render;
304 
305  while (ss >> render)
306  config.render_depth.push_back(render);
307  }
308 
309  if (config.render_depth.empty()) {
310  LOG("not found Render Depth Parameter\n");
311  return false;
312  }
313 
314  next = xml_node->FirstChildElement("RandomPahse");
315  if (!next || tinyxml2::XML_SUCCESS != next->QueryBoolText(&config.RANDOM_PHASE))
316  return false;
317  //(xml_node->FirstChildElement("RandomPahse"))->QueryBoolText(&config.RANDOM_PHASE);
318 
319 #if REAL_IS_DOUBLE & true
320  next = xml_node->FirstChildElement("FieldLens");
321  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&config.field_lens))
322  return false;
323  next = xml_node->FirstChildElement("WaveLength");
324  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.wave_length[0]))
325  return false;
326  next = xml_node->FirstChildElement("SLMpixelPitchX");
327  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.pixel_pitch[_X]))
328  return false;
329  next = xml_node->FirstChildElement("SLMpixelPitchY");
330  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.pixel_pitch[_Y]))
331  return false;
332  next = xml_node->FirstChildElement("NearOfDepth");
333  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&config.near_depthmap))
334  return false;
335  next = xml_node->FirstChildElement("FarOfDepth");
336  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&config.far_depthmap))
337  return false;
338  //(xml_node->FirstChildElement("FieldLens"))->QueryDoubleText(&config.field_lens);
339  //(xml_node->FirstChildElement("WaveLength"))->QueryDoubleText(&context_.wave_length[0]);
340  //(xml_node->FirstChildElement("SLMpixelPitchX"))->QueryDoubleText(&context_.pixel_pitch[_X]);
341  //(xml_node->FirstChildElement("SLMpixelPitchY"))->QueryDoubleText(&context_.pixel_pitch[_Y]);
342  //(xml_node->FirstChildElement("NearOfDepth"))->QueryDoubleText(&config.near_depthmap);
343  //(xml_node->FirstChildElement("FarOfDepth"))->QueryDoubleText(&config.far_depthmap);
344 #else
345  next = xml_node->FirstChildElement("FieldLens");
346  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&config.field_lens))
347  return false;
348  next = xml_node->FirstChildElement("WaveLength");
349  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.wave_length[0]))
350  return false;
351  next = xml_node->FirstChildElement("SLMpixelPitchX");
352  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.pixel_pitch[_X]))
353  return false;
354  next = xml_node->FirstChildElement("SLMpixelPitchY");
355  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.pixel_pitch[_Y]))
356  return false;
357  next = xml_node->FirstChildElement("NearOfDepth");
358  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&config.near_depthmap))
359  return false;
360  next = xml_node->FirstChildElement("FarOfDepth");
361  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&config.far_depthmap))
362  return false;
363  //(xml_node->FirstChildElement("FieldLens"))->QueryFloatText(&config.field_lens);
364  //(xml_node->FirstChildElement("WaveLength"))->QueryFloatText(&context_.wave_length[0]);
365  //(xml_node->FirstChildElement("SLMpixelPitchX"))->QueryFloatText(&context_.pixel_pitch[_X]);
366  //(xml_node->FirstChildElement("SLMpixelPitchY"))->QueryFloatText(&context_.pixel_pitch[_Y]);
367  //(xml_node->FirstChildElement("NearOfDepth"))->QueryFloatText(&config.near_depthmap);
368  //(xml_node->FirstChildElement("FarOfDepth"))->QueryFloatText(&config.far_depthmap);
369 #endif
370 
371  context_.k = (2 * M_PI) / context_.wave_length[0];
372  context_.ss[_X] = context_.pixel_number[_X] * context_.pixel_pitch[_X];
373  context_.ss[_Y] = context_.pixel_number[_Y] * context_.pixel_pitch[_Y];
374 
375  Openholo::setPixelNumberOHC(context_.pixel_number);
376  Openholo::setPixelPitchOHC(context_.pixel_pitch);
377  Openholo::setWavelengthOHC(context_.wave_length[0], LenUnit::m);
378 
379  auto end = CUR_TIME;
380 
381  auto during = ((std::chrono::duration<Real>)(end - start)).count();
382 
383  LOG("%.5lfsec...done\n", during);
384 
385  return true;
386 }
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
XMLError LoadFile(const char *filename)
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79
const XMLElement * FirstChildElement(const char *name=0) const

◆ readConfig() [4/4]

bool ophGen::readConfig ( const char *  fname,
OphDepthMapConfig config 
)
inherited
Parameters
constchar* Input file name
OphDepthMapConfig&Config structures variable can get configuration data

◆ readLFConfig() [1/2]

int ophLF::readLFConfig ( const char *  LF_config)

Light Field based CGH configuration file load.

xml configuration file load

Returns
distanceRS2Holo
num_image
resolution_image
context_.pixel_pitch
context_.pixel_number
context_.lambda

Definition at line 62 of file ophLightField.cpp.

62  {
63  LOG("Reading....%s...\n", LF_config);
64 
65  auto start = CUR_TIME;
66 
67  /*XML parsing*/
68  tinyxml2::XMLDocument xml_doc;
69  tinyxml2::XMLNode *xml_node;
70 
71  if (checkExtension(LF_config, ".xml") == 0)
72  {
73  LOG("file's extension is not 'xml'\n");
74  return false;
75  }
76  auto ret = xml_doc.LoadFile(LF_config);
77  if (ret != tinyxml2::XML_SUCCESS)
78  {
79  LOG("Failed to load file \"%s\"\n", LF_config);
80  return false;
81  }
82 
83  xml_node = xml_doc.FirstChild();
84 
85  //LF_directory = (xml_node->FirstChildElement("LightFieldImageDirectory"))->GetText();
86  //ext = (xml_node->FirstChildElement("LightFieldImageExtention"))->GetText();
87 #if REAL_IS_DOUBLE & true
88  auto next = xml_node->FirstChildElement("DistanceRS2Holo");
89  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&distanceRS2Holo))
90  return false;
91  next = xml_node->FirstChildElement("SLMPixelPitchX");
92  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.pixel_pitch[_X]))
93  return false;
94  next = xml_node->FirstChildElement("SLMPixelPitchY");
95  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.pixel_pitch[_Y]))
96  return false;
97  next = xml_node->FirstChildElement("WavelengthofLaser");
98  if (!next || tinyxml2::XML_SUCCESS != next->QueryDoubleText(&context_.wave_length[0]))
99  return false;
100  //(xml_node->FirstChildElement("DistanceRS2Holo"))->QueryDoubleText(&distanceRS2Holo);
101  //(xml_node->FirstChildElement("SLMPixelPitchX"))->QueryDoubleText(&context_.pixel_pitch[_X]);
102  //(xml_node->FirstChildElement("SLMPixelPitchY"))->QueryDoubleText(&context_.pixel_pitch[_Y]);
103  //(xml_node->FirstChildElement("WavelengthofLaser"))->QueryDoubleText(&context_.wave_length[0]);
104 #else
105  auto next = xml_node->FirstChildElement("DistanceRS2Holo");
106  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&distanceRS2Holo))
107  return false;
108  next = xml_node->FirstChildElement("SLMPixelPitchX");
109  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.pixel_pitch[_X]))
110  return false;
111  next = xml_node->FirstChildElement("SLMPixelPitchY");
112  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.pixel_pitch[_Y]))
113  return false;
114  next = xml_node->FirstChildElement("WavelengthofLaser");
115  if (!next || tinyxml2::XML_SUCCESS != next->QueryFloatText(&context_.wave_length[0]))
116  return false;
117  //(xml_node->FirstChildElement("DistanceRS2Holo"))->QueryFloatText(&distanceRS2Holo);
118  //(xml_node->FirstChildElement("SLMPixelPitchX"))->QueryFloatText(&context_.pixel_pitch[_X]);
119  //(xml_node->FirstChildElement("SLMPixelPitchY"))->QueryFloatText(&context_.pixel_pitch[_Y]);
120  //(xml_node->FirstChildElement("WavelengthofLaser"))->QueryFloatText(&context_.wave_length[0]);
121 #endif
122  next = xml_node->FirstChildElement("NumberofImagesXofLF");
123  if (!next || tinyxml2::XML_SUCCESS != next->QueryIntText(&num_image[_X]))
124  return false;
125  next = xml_node->FirstChildElement("NumberofImagesYofLF");
126  if (!next || tinyxml2::XML_SUCCESS != next->QueryIntText(&num_image[_Y]))
127  return false;
128  next = xml_node->FirstChildElement("NumberofPixelXofLF");
129  if (!next || tinyxml2::XML_SUCCESS != next->QueryIntText(&resolution_image[_X]))
130  return false;
131  next = xml_node->FirstChildElement("NumberofPixelYofLF");
132  if (!next || tinyxml2::XML_SUCCESS != next->QueryIntText(&resolution_image[_Y]))
133  return false;
134  //(xml_node->FirstChildElement("NumberofImagesXofLF"))->QueryIntText(&num_image[_X]);
135  //(xml_node->FirstChildElement("NumberofImagesYofLF"))->QueryIntText(&num_image[_Y]);
136  //(xml_node->FirstChildElement("NumberofPixelXofLF"))->QueryIntText(&resolution_image[_X]);
137  //(xml_node->FirstChildElement("NumberofPixelYofLF"))->QueryIntText(&resolution_image[_Y]);
138  //(xml_node->FirstChildElement("EncodingMethod"))->QueryIntText(&ENCODE_METHOD);
139  //(xml_node->FirstChildElement("SingleSideBandPassBand"))->QueryIntText(&SSB_PASSBAND);
140 
141  context_.pixel_number[_X] = num_image[_X] * resolution_image[_X];
142  context_.pixel_number[_Y] = num_image[_Y] * resolution_image[_Y];
143 
144  context_.k = (2 * M_PI) / context_.wave_length[0];
145  context_.ss[_X] = context_.pixel_number[_X] * context_.pixel_pitch[_X];
146  context_.ss[_Y] = context_.pixel_number[_Y] * context_.pixel_pitch[_Y];
147 
148  cout << endl;
149  cout << "SLM pixel pitch: " << context_.pixel_pitch[_X] << ", " << context_.pixel_pitch[_Y] << endl;
150  cout << "Wavelength of LASER: " << context_.wave_length[0] << endl;
151  cout << "Distance RS plane to Hologram plane: " << distanceRS2Holo << endl;
152  cout << "# of images: " << num_image[_X] << ", " << num_image[_Y] << endl;
153  cout << "Resolution of the images: " << resolution_image[_X] << ", " << resolution_image[_Y] << endl;
154  cout << "Resolution of hologram: " << context_.pixel_number[_X] << ", " << context_.pixel_number[_Y] << endl;
155  cout << endl;
156 
157  setPixelNumberOHC(context_.pixel_number);
158  setPixelPitchOHC(context_.pixel_pitch);
159  addWaveLengthOHC(context_.wave_length[0]);
160 
161  auto end = CUR_TIME;
162 
163  auto during = ((std::chrono::duration<Real>)(end - start)).count();
164 
165  LOG("%.5lfsec...done\n", during);
166  return true;
167 }
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
XMLError LoadFile(const char *filename)
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79
const XMLElement * FirstChildElement(const char *name=0) const

◆ readLFConfig() [2/2]

int ophLF::readLFConfig ( const char *  LF_config)

Light Field based CGH configuration file load.

xml configuration file load

Returns
distanceRS2Holo
num_image
resolution_image
context_.pixel_pitch
context_.pixel_number
context_.lambda

◆ release() [1/2]

unsigned long Base::release ( void  )
inlineinherited

Call release() when reference is finished.

Definition at line 80 of file openholo/src/Base.h.

80  {
81  if (!refCnt) {
82  ophFree();
83  delete this;
84  return 0;
85  }
86  return refCnt--;
87  }

◆ release() [2/2]

unsigned long Base::release ( void  )
inlineinherited

Call release() when reference is finished.

Definition at line 80 of file Reference/include/Base.h.

80  {
81  if (!refCnt) {
82  ophFree();
83  delete this;
84  return 0;
85  }
86  return refCnt--;
87  }

◆ save() [1/4]

int ophGen::save ( const char *  fname,
uint8_t  bitsperpixel = 8,
uchar *  src = nullptr,
uint  px = 0,
uint  py = 0 
)
inherited

Function for saving image files.

Definition at line 504 of file ophGen.cpp.

505 {
506  if (fname == nullptr) return -1;
507 
508  uchar* source = src;
509  ivec2 p(px, py);
510 
511  if (src == nullptr)
512  source = holo_normalized;
513  if (px == 0 && py == 0)
514  p = ivec2(context_.pixel_number[_X], context_.pixel_number[_Y]);
515 
516  if (checkExtension(fname, ".bmp")) // when the extension is bmp
517  return Openholo::saveAsImg(fname, bitsperpixel, source, p[_X], p[_Y]);
518  else { // when extension is not .ohf, .bmp - force bmp
519  char buf[256];
520  memset(buf, 0x00, sizeof(char) * 256);
521  sprintf_s(buf, "%s.bmp", fname);
522 
523  return Openholo::saveAsImg(buf, bitsperpixel, source, p[_X], p[_Y]);
524  }
525 }
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79
virtual int saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int pic_width, int pic_height)
Function for creating image files.
Definition: Openholo.cpp:93

◆ save() [2/4]

int ophGen::save ( const char *  fname,
uint8_t  bitsperpixel = 8,
uchar *  src = nullptr,
uint  px = 0,
uint  py = 0 
)
inherited

Function for saving image files.

◆ save() [3/4]

int ophGen::save ( const char *  fname,
uint8_t  bitsperpixel,
uint  px,
uint  py,
uint  fnum,
uchar *  args ... 
)
protectedinherited

Called when saving multiple hologram data at a time.

Definition at line 527 of file ophGen.cpp.

528 {
529  std::string file = fname;
530  std::string name;
531  std::string ext;
532 
533  size_t ex = file.rfind(".");
534  if (ex == -1) ex = file.length();
535 
536  name = file.substr(0, ex);
537  ext = file.substr(ex, file.length() - 1);
538 
539  va_list ap;
540  __crt_va_start(ap, args);
541 
542  for (uint i = 0; i < fnum; i++) {
543  name.append(std::to_string(i)).append(ext);
544  if (i == 0) {
545  save(name.c_str(), bitsperpixel, args, px, py);
546  continue;
547  }
548  uchar* data = __crt_va_arg(ap, uchar*);
549  save(name.c_str(), bitsperpixel, data, px, py);
550  }
551 
552  __crt_va_end(ap);
553 
554  return 0;
555 }
int save(const char *fname, uint8_t bitsperpixel=8, uchar *src=nullptr, uint px=0, uint py=0)
Function for saving image files.
Definition: ophGen.cpp:504

◆ save() [4/4]

int ophGen::save ( const char *  fname,
uint8_t  bitsperpixel,
uint  px,
uint  py,
uint  fnum,
uchar *  args ... 
)
protectedinherited

Called when saving multiple hologram data at a time.

◆ saveAsImg() [1/2]

int Openholo::saveAsImg ( const char *  fname,
uint8_t  bitsperpixel,
uchar *  src,
int  pic_width,
int  pic_height 
)
virtualinherited

Function for creating image files.

Parameters
constchar* Output file name
uint8_tBit per pixel
unsignedchar* Source of Image file's data
intNumber of pixel - width
intNumber of pixel - height
Returns
int return -1 : Failed to save image file return 1 : Success to save image file

Definition at line 93 of file Openholo.cpp.

94 {
95  LOG("Saving...%s...", fname);
96  auto start = CUR_TIME;
97 
98  int _width = pic_width, _height = pic_height;
99 
100  int _pixelbytesize = _height * _width * bitsperpixel / 8;
101  int _filesize = _pixelbytesize + sizeof(bitmap);
102 
103  FILE *fp;
104  fopen_s(&fp, fname, "wb");
105  if (fp == nullptr) return -1;
106 
107  bitmap *pbitmap = (bitmap*)calloc(1, sizeof(bitmap));
108  memset(pbitmap, 0x00, sizeof(bitmap));
109 
110  pbitmap->fileheader.signature[0] = 'B';
111  pbitmap->fileheader.signature[1] = 'M';
112  pbitmap->fileheader.filesize = _filesize;
113  pbitmap->fileheader.fileoffset_to_pixelarray = sizeof(bitmap);
114 
115  for (int i = 0; i < 256; i++) {
116  pbitmap->rgbquad[i].rgbBlue = i;
117  pbitmap->rgbquad[i].rgbGreen = i;
118  pbitmap->rgbquad[i].rgbRed = i;
119  }
120 
121  pbitmap->bitmapinfoheader.dibheadersize = sizeof(bitmapinfoheader);
122  pbitmap->bitmapinfoheader.width = _width;
123  pbitmap->bitmapinfoheader.height = _height;
124  pbitmap->bitmapinfoheader.planes = OPH_PLANES;
125  pbitmap->bitmapinfoheader.bitsperpixel = bitsperpixel;
126  pbitmap->bitmapinfoheader.compression = OPH_COMPRESSION;
127  pbitmap->bitmapinfoheader.imagesize = _pixelbytesize;
128  pbitmap->bitmapinfoheader.ypixelpermeter = Y_PIXEL_PER_METER;
129  pbitmap->bitmapinfoheader.xpixelpermeter = X_PIXEL_PER_METER;
130  pbitmap->bitmapinfoheader.numcolorspallette = 256;
131  fwrite(pbitmap, 1, sizeof(bitmap), fp);
132 
133  fwrite(src, 1, _pixelbytesize, fp);
134  fclose(fp);
135  free(pbitmap);
136 
137  auto end = CUR_TIME;
138 
139  auto during = ((std::chrono::duration<Real>)(end - start)).count();
140 
141  LOG("%.5lfsec...done\n", during);
142 
143  return 1;
144 }

◆ saveAsImg() [2/2]

virtual int Openholo::saveAsImg ( const char *  fname,
uint8_t  bitsperpixel,
uchar *  src,
int  pic_width,
int  pic_height 
)
virtualinherited

Function for creating image files.

Parameters
constchar* Output file name
uint8_tBit per pixel
unsignedchar* Source of Image file's data
intNumber of pixel - width
intNumber of pixel - height
Returns
int return -1 : Failed to save image file return 1 : Success to save image file

◆ saveAsOhc() [1/2]

int Openholo::saveAsOhc ( const char *  fname)
virtualinherited

Function to write OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophSig, and ophSig.

Definition at line 175 of file Openholo.cpp.

176 {
177  std::string fullname = fname;
178  if (checkExtension(fname, ".ohc") == 0) fullname.append(".ohc");
179  OHC_encoder->setFileName(fullname.c_str());
180 
181  ohcHeader header;
182  OHC_encoder->getOHCheader(header);
183  auto wavelength_num = header.fieldInfo.wavlenNum;
184 
185  for (int i = 0; i < wavelength_num; i++)
186  OHC_encoder->addComplexFieldData(complex_H[i]);
187 
188  if (!OHC_encoder->save()) return -1;
189 
190  return 1;
191 }
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ saveAsOhc() [2/2]

virtual int Openholo::saveAsOhc ( const char *  fname)
virtualinherited

Function to write OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophSig, and ophSig.

◆ setPixelNumberOHC() [1/2]

void Openholo::setPixelNumberOHC ( const ivec2  pixel_number)
inlineprotectedinherited

getter/setter for OHC file read and write

Definition at line 264 of file openholo/src/Openholo.h.

265  { OHC_encoder->setNumOfPixel(pixel_number); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ setPixelNumberOHC() [2/2]

void Openholo::setPixelNumberOHC ( const ivec2  pixel_number)
inlineprotectedinherited

getter/setter for OHC file read and write

Definition at line 264 of file Reference/include/Openholo.h.

265  { OHC_encoder->setNumOfPixel(pixel_number); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ waveCarry() [1/2]

void ophLF::waveCarry ( Real  carryingAngleX,
Real  carryingAngleY 
)

Wave carry.

Parameters
RealcarryingAngleX Wave carrying angle in horizontal direction
RealcarryingAngleY Wave carrying angle in vertical direction

◆ waveCarry() [2/2]

void ophLF::waveCarry ( Real  carryingAngleX,
Real  carryingAngleY 
)

Wave carry.

Parameters
RealcarryingAngleX Wave carrying angle in horizontal direction
RealcarryingAngleY Wave carrying angle in vertical direction

Definition at line 360 of file ophLightField.cpp.

360  {
361 
362  int Nx = context_.pixel_number[_X];
363  int Ny = context_.pixel_number[_Y];
364 
365  Real dfx = 1 / context_.pixel_pitch[_X] / Nx;
366  Real dfy = 1 / context_.pixel_pitch[_Y] / Ny;
367  Real* fx = new Real[Nx*Ny];
368  Real* fy = new Real[Nx*Ny];
369  Real* fz = new Real[Nx*Ny];
370  uint i = 0;
371  for (int idxFy = Ny / 2; idxFy > -Ny / 2; idxFy--) {
372  for (int idxFx = -Nx / 2; idxFx < Nx / 2; idxFx++) {
373  fx[i] = idxFx*dfx;
374  fy[i] = idxFy*dfy;
375  fz[i] = sqrt((1 / context_.wave_length[0])*(1 / context_.wave_length[0]) - fx[i] * fx[i] - fy[i] * fy[i]);
376 
377  i++;
378  }
379  }
380 
381  Complex<Real>* carrier = new Complex<Real>[context_.pixel_number[_X] * context_.pixel_number[_Y]];
382 
383  for (int i = 0; i < context_.pixel_number[_X] * context_.pixel_number[_Y]; i++) {
384  carrier[i][_RE] = 0;
385  carrier[i][_IM] = 0.01 * tan(carryingAngleX)*fx[i] + 0.01 * tan(carryingAngleY)*fy[i];
386  (*complex_H)[i] = (*complex_H)[i] * exp(carrier[i]);
387  }
388 
389  delete[] fx;
390  delete[] fy;
391  delete[] fz;
392  delete[] carrier;
393 }

Member Data Documentation

◆ encode_size

ivec2 ophGen::encode_size
protectedinherited
Parameters
encode_sizeEncoded hologram size, varied from encoding type
ENCODE_METHODEncodinng method flag
SSB_PASSBANDPassband in single side band encoding

Definition at line 208 of file ophgen/src/ophGen.h.

◆ OHC_encoder

ImgEncoderOhc * Openholo::OHC_encoder
protectedinherited

OHC file format Variables for read and write.

Definition at line 257 of file openholo/src/Openholo.h.


The documentation for this class was generated from the following files: