Openholo  beta 2.0
Open Source Digital Holographic Library
ophCascadedPropagation Class Reference

Cascaded propagation module. More...

Inheritance diagram for ophCascadedPropagation:
Inheritance graph

Public Member Functions

 ophCascadedPropagation (const wchar_t *configfilepath)
 Constructor. More...
 
 ~ophCascadedPropagation ()
 Destructor. More...
 
bool propagate ()
 Do cascaded propagation. More...
 
bool save (const wchar_t *pathname, uint8_t bitsperpixel)
 Save wavefield at retina plane as Windows Bitmap file. More...
 
virtual int saveAsOhc (const char *fname)
 Function to write OHC file. More...
 
virtual int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
bool isReadyToPropagate ()
 Returns if all data are prepared. More...
 
oph::uint getNumColors ()
 Returns number of colors. More...
 
oph::vec3 getWavelengths ()
 Returns wavelengths in meter. More...
 
Real getPixelPitchX ()
 Returns horizontal pixel pitch in meter. More...
 
Real getPixelPitchY ()
 Returns vertical pixel pitch in meter. More...
 
oph::uint getResX ()
 Returns horizontal resolution. More...
 
oph::uint getResY ()
 Returns vertical resolution. More...
 
Real getFieldLensFocalLength ()
 Returns focal length of field lens in meter. More...
 
Real getDistObjectToPupil ()
 Returns distance from reconstruction plane to pupil plane in meter. More...
 
Real getDistPupilToRetina ()
 Returns distance from pupil plane to retina plane in meter. More...
 
Real getPupilDiameter ()
 Returns diameter of pupil in meter. More...
 
Real getNor ()
 Returns Nor, which affects the range of output intensity. More...
 
oph::Complex< Real > * getSlmWavefield (oph::uint id)
 Return monochromatic wavefield at SLM plane. More...
 
oph::Complex< Real > * getPupilWavefield (oph::uint id)
 Return monochromatic wavefield at pupil plane. More...
 
oph::Complex< Real > * getRetinaWavefield (oph::uint id)
 Return monochromatic wavefield at retina plane. More...
 
vector< oph::Complex< Real > * > getRetinaWavefieldAll ()
 Return all wavefields at retina plane. More...
 
bool propagateSlmToPupil ()
 Calculates 1st propagation (from SLM plane to pupil plane) More...
 
bool propagatePupilToRetina ()
 Calculates 2nd propagation (from pupil plane to retina plane) More...
 
 ophCascadedPropagation (const wchar_t *configfilepath)
 Constructor. More...
 
 ~ophCascadedPropagation ()
 Destructor. More...
 
bool propagate ()
 Do cascaded propagation. More...
 
bool save (const wchar_t *pathname, uint8_t bitsperpixel)
 Save wavefield at retina plane as Windows Bitmap file. More...
 
virtual int saveAsOhc (const char *fname)
 Function to write OHC file. More...
 
virtual int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
bool isReadyToPropagate ()
 Returns if all data are prepared. More...
 
oph::uint getNumColors ()
 Returns number of colors. More...
 
oph::vec3 getWavelengths ()
 Returns wavelengths in meter. More...
 
Real getPixelPitchX ()
 Returns horizontal pixel pitch in meter. More...
 
Real getPixelPitchY ()
 Returns vertical pixel pitch in meter. More...
 
oph::uint getResX ()
 Returns horizontal resolution. More...
 
oph::uint getResY ()
 Returns vertical resolution. More...
 
Real getFieldLensFocalLength ()
 Returns focal length of field lens in meter. More...
 
Real getDistObjectToPupil ()
 Returns distance from reconstruction plane to pupil plane in meter. More...
 
Real getDistPupilToRetina ()
 Returns distance from pupil plane to retina plane in meter. More...
 
Real getPupilDiameter ()
 Returns diameter of pupil in meter. More...
 
Real getNor ()
 Returns Nor, which affects the range of output intensity. More...
 
oph::Complex< Real > * getSlmWavefield (oph::uint id)
 Return monochromatic wavefield at SLM plane. More...
 
oph::Complex< Real > * getPupilWavefield (oph::uint id)
 Return monochromatic wavefield at pupil plane. More...
 
oph::Complex< Real > * getRetinaWavefield (oph::uint id)
 Return monochromatic wavefield at retina plane. More...
 
vector< oph::Complex< Real > * > getRetinaWavefieldAll ()
 Return all wavefields at retina plane. More...
 
bool propagateSlmToPupil ()
 Calculates 1st propagation (from SLM plane to pupil plane) More...
 
bool propagatePupilToRetina ()
 Calculates 2nd propagation (from pupil plane to retina plane) 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...
 
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 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

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

Detailed Description

Cascaded propagation module.

Author
Seunghyup Shin

Definition at line 159 of file ophrec/src/ophCascadedPropagation.h.

Constructor & Destructor Documentation

◆ ophCascadedPropagation() [1/2]

ophCascadedPropagation::ophCascadedPropagation ( const wchar_t *  configfilepath)

Constructor.

Parameters
configfilepathabsolute or relative path of configuration file

Definition at line 59 of file ophCascadedPropagation.cpp.

60  : ready_to_propagate(false),
61  hologram_path(L"")
62 {
63  if (readConfig(configfilepath) && allocateMem())
64  {
65  string hologram_path_str;
66  hologram_path_str.assign(hologram_path.begin(), hologram_path.end());
67  ready_to_propagate = (sourcetype_ == SourceType::IMG && loadInputImg(hologram_path_str)) || (sourcetype_ == SourceType::OHC && loadAsOhc(hologram_path_str.c_str()));
68  }
69 }
virtual int loadAsOhc(const char *fname)
Function to read OHC file.

◆ ~ophCascadedPropagation() [1/2]

ophCascadedPropagation::~ophCascadedPropagation ( )

Destructor.

Definition at line 71 of file ophCascadedPropagation.cpp.

72 {
73 }

◆ ophCascadedPropagation() [2/2]

ophCascadedPropagation::ophCascadedPropagation ( const wchar_t *  configfilepath)

Constructor.

Parameters
configfilepathabsolute or relative path of configuration file

◆ ~ophCascadedPropagation() [2/2]

ophCascadedPropagation::~ophCascadedPropagation ( )

Destructor.

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 Reference/include/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 openholo/src/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 openholo/src/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 Reference/include/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

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 }

◆ 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

◆ 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.

◆ getDistObjectToPupil() [1/2]

Real ophCascadedPropagation::getDistObjectToPupil ( )
inline

Returns distance from reconstruction plane to pupil plane in meter.

Definition at line 321 of file ophrec/src/ophCascadedPropagation.h.

321 { return config_.dist_reconstruction_plane_to_pupil; }

◆ getDistObjectToPupil() [2/2]

Real ophCascadedPropagation::getDistObjectToPupil ( )
inline

Returns distance from reconstruction plane to pupil plane in meter.

Definition at line 321 of file Reference/include/ophCascadedPropagation.h.

321 { return config_.dist_reconstruction_plane_to_pupil; }

◆ getDistPupilToRetina() [1/2]

Real ophCascadedPropagation::getDistPupilToRetina ( )
inline

Returns distance from pupil plane to retina plane in meter.

Definition at line 326 of file Reference/include/ophCascadedPropagation.h.

326 { return config_.dist_pupil_to_retina; }

◆ getDistPupilToRetina() [2/2]

Real ophCascadedPropagation::getDistPupilToRetina ( )
inline

Returns distance from pupil plane to retina plane in meter.

Definition at line 326 of file ophrec/src/ophCascadedPropagation.h.

326 { return config_.dist_pupil_to_retina; }

◆ getFieldLensFocalLength() [1/2]

Real ophCascadedPropagation::getFieldLensFocalLength ( )
inline

Returns focal length of field lens in meter.

Definition at line 316 of file Reference/include/ophCascadedPropagation.h.

316 { return config_.field_lens_focal_length; }

◆ getFieldLensFocalLength() [2/2]

Real ophCascadedPropagation::getFieldLensFocalLength ( )
inline

Returns focal length of field lens in meter.

Definition at line 316 of file ophrec/src/ophCascadedPropagation.h.

316 { return config_.field_lens_focal_length; }

◆ 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

◆ 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

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 }

◆ getNor() [1/2]

Real ophCascadedPropagation::getNor ( )
inline

Returns Nor, which affects the range of output intensity.

Nor is NOT intuitive at all and should be changed sometime

Definition at line 337 of file ophrec/src/ophCascadedPropagation.h.

337 { return config_.nor; }

◆ getNor() [2/2]

Real ophCascadedPropagation::getNor ( )
inline

Returns Nor, which affects the range of output intensity.

Nor is NOT intuitive at all and should be changed sometime

Definition at line 337 of file Reference/include/ophCascadedPropagation.h.

337 { return config_.nor; }

◆ getNumColors() [1/2]

oph::uint ophCascadedPropagation::getNumColors ( )
inline

Returns number of colors.

Definition at line 286 of file ophrec/src/ophCascadedPropagation.h.

286 { return config_.num_colors; }

◆ getNumColors() [2/2]

oph::uint ophCascadedPropagation::getNumColors ( )
inline

Returns number of colors.

Definition at line 286 of file Reference/include/ophCascadedPropagation.h.

286 { return config_.num_colors; }

◆ getPixelPitchX() [1/2]

Real ophCascadedPropagation::getPixelPitchX ( )
inline

Returns horizontal pixel pitch in meter.

Definition at line 296 of file ophrec/src/ophCascadedPropagation.h.

296 { return config_.dx; }

◆ getPixelPitchX() [2/2]

Real ophCascadedPropagation::getPixelPitchX ( )
inline

Returns horizontal pixel pitch in meter.

Definition at line 296 of file Reference/include/ophCascadedPropagation.h.

296 { return config_.dx; }

◆ getPixelPitchY() [1/2]

Real ophCascadedPropagation::getPixelPitchY ( )
inline

Returns vertical pixel pitch in meter.

Definition at line 301 of file Reference/include/ophCascadedPropagation.h.

301 { return config_.dy; }

◆ getPixelPitchY() [2/2]

Real ophCascadedPropagation::getPixelPitchY ( )
inline

Returns vertical pixel pitch in meter.

Definition at line 301 of file ophrec/src/ophCascadedPropagation.h.

301 { return config_.dy; }

◆ getPupilDiameter() [1/2]

Real ophCascadedPropagation::getPupilDiameter ( )
inline

Returns diameter of pupil in meter.

Definition at line 331 of file Reference/include/ophCascadedPropagation.h.

331 { return config_.pupil_diameter; }

◆ getPupilDiameter() [2/2]

Real ophCascadedPropagation::getPupilDiameter ( )
inline

Returns diameter of pupil in meter.

Definition at line 331 of file ophrec/src/ophCascadedPropagation.h.

331 { return config_.pupil_diameter; }

◆ getPupilWavefield() [1/2]

oph::Complex< Real > * ophCascadedPropagation::getPupilWavefield ( oph::uint  id)

Return monochromatic wavefield at pupil plane.

Definition at line 483 of file ophCascadedPropagation.cpp.

484 {
485  if (wavefield_pupil.size() <= (size_t)id)
486  return nullptr;
487  return wavefield_pupil[id];
488 }

◆ getPupilWavefield() [2/2]

oph::Complex<Real>* ophCascadedPropagation::getPupilWavefield ( oph::uint  id)

Return monochromatic wavefield at pupil plane.

◆ getResX() [1/2]

oph::uint ophCascadedPropagation::getResX ( )
inline

Returns horizontal resolution.

Definition at line 306 of file Reference/include/ophCascadedPropagation.h.

306 { return config_.nx; }

◆ getResX() [2/2]

oph::uint ophCascadedPropagation::getResX ( )
inline

Returns horizontal resolution.

Definition at line 306 of file ophrec/src/ophCascadedPropagation.h.

306 { return config_.nx; }

◆ getResY() [1/2]

oph::uint ophCascadedPropagation::getResY ( )
inline

Returns vertical resolution.

Definition at line 311 of file Reference/include/ophCascadedPropagation.h.

311 { return config_.ny; }

◆ getResY() [2/2]

oph::uint ophCascadedPropagation::getResY ( )
inline

Returns vertical resolution.

Definition at line 311 of file ophrec/src/ophCascadedPropagation.h.

311 { return config_.ny; }

◆ getRetinaWavefield() [1/2]

oph::Complex< Real > * ophCascadedPropagation::getRetinaWavefield ( oph::uint  id)

Return monochromatic wavefield at retina plane.

Definition at line 490 of file ophCascadedPropagation.cpp.

491 {
492  if (wavefield_retina.size() <= (size_t)id)
493  return nullptr;
494  return wavefield_retina[id];
495 }

◆ getRetinaWavefield() [2/2]

oph::Complex<Real>* ophCascadedPropagation::getRetinaWavefield ( oph::uint  id)

Return monochromatic wavefield at retina plane.

◆ getRetinaWavefieldAll() [1/2]

vector< oph::Complex< Real > * > ophCascadedPropagation::getRetinaWavefieldAll ( )

Return all wavefields at retina plane.

Definition at line 497 of file ophCascadedPropagation.cpp.

498 {
499  return wavefield_retina;
500 }

◆ getRetinaWavefieldAll() [2/2]

vector<oph::Complex<Real>*> ophCascadedPropagation::getRetinaWavefieldAll ( )

Return all wavefields at retina plane.

◆ getSlmWavefield() [1/2]

oph::Complex< Real > * ophCascadedPropagation::getSlmWavefield ( oph::uint  id)

Return monochromatic wavefield at SLM plane.

Definition at line 476 of file ophCascadedPropagation.cpp.

477 {
478  if (wavefield_SLM.size() <= (size_t)id)
479  return nullptr;
480  return wavefield_SLM[id];
481 }

◆ getSlmWavefield() [2/2]

oph::Complex<Real>* ophCascadedPropagation::getSlmWavefield ( oph::uint  id)

Return monochromatic wavefield at SLM plane.

◆ getWavelengths() [1/2]

oph::vec3 ophCascadedPropagation::getWavelengths ( )
inline

Returns wavelengths in meter.

Definition at line 291 of file ophrec/src/ophCascadedPropagation.h.

291 { return config_.wavelengths; }

◆ getWavelengths() [2/2]

oph::vec3 ophCascadedPropagation::getWavelengths ( )
inline

Returns wavelengths in meter.

Definition at line 291 of file Reference/include/ophCascadedPropagation.h.

291 { return config_.wavelengths; }

◆ 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

◆ isReadyToPropagate() [1/2]

bool ophCascadedPropagation::isReadyToPropagate ( )
inline

Returns if all data are prepared.

Definition at line 281 of file Reference/include/ophCascadedPropagation.h.

281 { return ready_to_propagate; }

◆ isReadyToPropagate() [2/2]

bool ophCascadedPropagation::isReadyToPropagate ( )
inline

Returns if all data are prepared.

Definition at line 281 of file ophrec/src/ophCascadedPropagation.h.

281 { return ready_to_propagate; }

◆ 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

◆ 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

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 }

◆ loadAsOhc() [1/2]

int ophCascadedPropagation::loadAsOhc ( const char *  fname)
virtual

Function to read OHC file.

Reimplemented from Openholo.

Definition at line 131 of file ophCascadedPropagation.cpp.

132 {
133  if (Openholo::loadAsOhc(fname) != 1)
134  return -1;
135 
136  oph::uint nx = getResX();
137  oph::uint ny = getResY();
138  config_.num_colors = OHC_decoder->getNumOfWavlen();
139  for (oph::uint i = 0; i < getNumColors(); i++)
140  memcpy(wavefield_SLM[i], complex_H[i], nx * ny * sizeof(Complex<Real>));
141 
142  return 1;
143 }
oph::uint getResX()
Returns horizontal resolution.
virtual int loadAsOhc(const char *fname)
Function to read OHC file.
Definition: Openholo.cpp:193
oph::uint getResY()
Returns vertical resolution.
oph::uint getNumColors()
Returns number of colors.

◆ loadAsOhc() [2/2]

virtual int ophCascadedPropagation::loadAsOhc ( const char *  fname)
virtual

Function to read OHC file.

Reimplemented from Openholo.

◆ ophFree() [1/2]

virtual void ophCascadedPropagation::ophFree ( void  )
protectedvirtual

Pure virtual function for override in child classes.

Implements ophRec.

◆ ophFree() [2/2]

void ophCascadedPropagation::ophFree ( void  )
protectedvirtual

Pure virtual function for override in child classes.

Implements ophRec.

Definition at line 75 of file ophCascadedPropagation.cpp.

76 {
77  deallocateMem();
78 }

◆ propagate() [1/2]

bool ophCascadedPropagation::propagate ( )

Do cascaded propagation.

Returns
true if successful
false when failed

Definition at line 80 of file ophCascadedPropagation.cpp.

81 {
82  if (!isReadyToPropagate())
83  {
84  PRINT_ERROR("module not initialized");
85  return false;
86  }
87 
88  if (!propagateSlmToPupil())
89  {
90  PRINT_ERROR("failed to propagate to pupil plane");
91  return false;
92  }
93 
95  {
96  PRINT_ERROR("failed to propagate to retina plane");
97  return false;
98  }
99 
100  return true;
101 }
bool propagateSlmToPupil()
Calculates 1st propagation (from SLM plane to pupil plane)
bool propagatePupilToRetina()
Calculates 2nd propagation (from pupil plane to retina plane)
bool isReadyToPropagate()
Returns if all data are prepared.

◆ propagate() [2/2]

bool ophCascadedPropagation::propagate ( )

Do cascaded propagation.

Returns
true if successful
false when failed

◆ propagatePupilToRetina() [1/2]

bool ophCascadedPropagation::propagatePupilToRetina ( )

Calculates 2nd propagation (from pupil plane to retina plane)

Returns
true if successful
false when failed

◆ propagatePupilToRetina() [2/2]

bool ophCascadedPropagation::propagatePupilToRetina ( )

Calculates 2nd propagation (from pupil plane to retina plane)

Returns
true if successful
false when failed

Definition at line 442 of file ophCascadedPropagation.cpp.

443 {
444  oph::uint numColors = getNumColors();
445  oph::uint nx = getResX();
446  oph::uint ny = getResY();
447  oph::Complex<Real>* buf = new oph::Complex<Real>[nx * ny];
448  for (oph::uint color = 0; color < numColors; color++)
449  {
450  memcpy(buf, getPupilWavefield(color), sizeof(oph::Complex<Real>) * nx * ny);
451 
452  Real k = 2 * M_PI / getWavelengths()[color];
453  Real vw = getWavelengths()[color] * getFieldLensFocalLength() / getPixelPitchX();
454  Real dx1 = vw / (Real)nx;
455  Real dy1 = vw / (Real)ny;
456  for (oph::uint row = 0; row < ny; row++)
457  {
458  Real Y1 = ((Real)row - ((Real)ny - 1) * 0.5f) * dy1;
459  for (oph::uint col = 0; col < nx; col++)
460  {
461  Real X1 = ((Real)col - ((Real)nx - 1) * 0.5f) * dx1;
462 
463  // 2nd propagation
464  oph::Complex<Real> t1 = oph::Complex<Real>(0, k / 2 / getDistPupilToRetina() * (X1 * X1 + Y1 * Y1)).exp();
465  buf[row * nx + col] *= t1;
466  }
467  }
468 
469  fftwShift(buf, getRetinaWavefield(color), nx, ny, OPH_FORWARD, false);
470  }
471 
472  delete[] buf;
473  return true;
474 }
oph::uint getResX()
Returns horizontal resolution.
Real getDistPupilToRetina()
Returns distance from pupil plane to retina plane in meter.
oph::Complex< Real > * getRetinaWavefield(oph::uint id)
Return monochromatic wavefield at retina plane.
Real getFieldLensFocalLength()
Returns focal length of field lens in meter.
oph::uint getResY()
Returns vertical resolution.
oph::vec3 getWavelengths()
Returns wavelengths in meter.
oph::Complex< Real > * getPupilWavefield(oph::uint id)
Return monochromatic wavefield at pupil plane.
Real getPixelPitchX()
Returns horizontal pixel pitch in meter.
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
oph::uint getNumColors()
Returns number of colors.

◆ propagateSlmToPupil() [1/2]

bool ophCascadedPropagation::propagateSlmToPupil ( )

Calculates 1st propagation (from SLM plane to pupil plane)

Returns
true if successful
false when failed

◆ propagateSlmToPupil() [2/2]

bool ophCascadedPropagation::propagateSlmToPupil ( )

Calculates 1st propagation (from SLM plane to pupil plane)

Returns
true if successful
false when failed

Definition at line 400 of file ophCascadedPropagation.cpp.

401 {
402  oph::uint numColors = getNumColors();
403  oph::uint nx = getResX();
404  oph::uint ny = getResY();
405  oph::Complex<Real>* buf = new oph::Complex<Real>[nx * ny];
406  for (oph::uint color = 0; color < numColors; color++)
407  {
408  fftwShift(getSlmWavefield(color), buf, nx, ny, OPH_FORWARD, false);
409 
410  Real k = 2 * M_PI / getWavelengths()[color];
411  Real vw = getWavelengths()[color] * getFieldLensFocalLength() / getPixelPitchX();
412  Real dx1 = vw / (Real)nx;
413  Real dy1 = vw / (Real)ny;
414  for (oph::uint row = 0; row < ny; row++)
415  {
416  Real Y1 = ((Real)row - ((Real)ny - 1) * 0.5f) * dy1;
417  for (oph::uint col = 0; col < nx; col++)
418  {
419  Real X1 = ((Real)col - ((Real)nx - 1) * 0.5f) * dx1;
420 
421  // 1st propagation
422  oph::Complex<Real> t1 = oph::Complex<Real>(0, k / 2 / getFieldLensFocalLength() * (X1 * X1 + Y1 * Y1)).exp();
423  oph::Complex<Real> t2(0, getWavelengths()[color] * getFieldLensFocalLength());
424  buf[row * nx + col] = t1 / t2 * buf[row * nx + col];
425 
426  // applying aperture: need some optimization later
427  if ((sqrt(X1 * X1 + Y1 * Y1) >= getPupilDiameter() / 2) || (row >= ny / 2 - 1))
428  buf[row * nx + col] = 0;
429 
431  oph::Complex<Real> t3 = oph::Complex<Real>(0, -k / 2 / f_eye * (X1 * X1 + Y1 * Y1)).exp();
432  buf[row * nx + col] *= t3;
433  }
434  }
435 
436  memcpy(getPupilWavefield(color), buf, sizeof(oph::Complex<Real>) * nx * ny);
437  }
438  delete[] buf;
439  return true;
440 }
oph::uint getResX()
Returns horizontal resolution.
Real getPupilDiameter()
Returns diameter of pupil in meter.
Real getDistPupilToRetina()
Returns distance from pupil plane to retina plane in meter.
Real getFieldLensFocalLength()
Returns focal length of field lens in meter.
oph::uint getResY()
Returns vertical resolution.
oph::vec3 getWavelengths()
Returns wavelengths in meter.
oph::Complex< Real > * getSlmWavefield(oph::uint id)
Return monochromatic wavefield at SLM plane.
oph::Complex< Real > * getPupilWavefield(oph::uint id)
Return monochromatic wavefield at pupil plane.
Real getPixelPitchX()
Returns horizontal pixel pitch in meter.
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
Real getDistObjectToPupil()
Returns distance from reconstruction plane to pupil plane in meter.
oph::uint getNumColors()
Returns number of colors.

◆ 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/2]

bool ophCascadedPropagation::save ( const wchar_t *  pathname,
uint8_t  bitsperpixel 
)

Save wavefield at retina plane as Windows Bitmap file.

Parameters
pathnameabsolute or relative path of output file
bitsperpixelnumber of bits per pixel
Returns
true if successfully saved
false when failed

Definition at line 103 of file ophCascadedPropagation.cpp.

104 {
105  wstring bufw(pathname);
106  string bufs;
107  bufs.assign(bufw.begin(), bufw.end());
108  oph::uchar* src = getIntensityfields(getRetinaWavefieldAll());
109  return (1 == saveAsImg(bufs.c_str(), bitsperpixel, src, getResX(), getResY()));
110 }
oph::uint getResX()
Returns horizontal resolution.
vector< oph::Complex< Real > * > getRetinaWavefieldAll()
Return all wavefields at retina plane.
oph::uint getResY()
Returns vertical resolution.
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/2]

bool ophCascadedPropagation::save ( const wchar_t *  pathname,
uint8_t  bitsperpixel 
)

Save wavefield at retina plane as Windows Bitmap file.

Parameters
pathnameabsolute or relative path of output file
bitsperpixelnumber of bits per pixel
Returns
true if successfully saved
false when failed

◆ 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 ophCascadedPropagation::saveAsOhc ( const char *  fname)
virtual

Function to write OHC file.

Reimplemented from Openholo.

Definition at line 112 of file ophCascadedPropagation.cpp.

113 {
114  oph::uint nx = getResX();
115  oph::uint ny = getResY();
116  for (oph::uint i = 0; i < getNumColors(); i++)
117  memcpy(complex_H[i], wavefield_retina[i], nx * ny * sizeof(Complex<Real>));
118 
119  if (!context_.wave_length)
120  context_.wave_length = new Real[getNumColors()];
121  for (oph::uint i = 0; i < getNumColors(); i++)
122  context_.wave_length[i] = config_.wavelengths[i];
123  context_.pixel_pitch[0] = config_.dx;
124  context_.pixel_pitch[1] = config_.dy;
125  context_.pixel_number[0] = config_.nx;
126  context_.pixel_number[1] = config_.ny;
127 
128  return Openholo::saveAsOhc(fname);
129 }
oph::uint getResX()
Returns horizontal resolution.
oph::uint getResY()
Returns vertical resolution.
virtual int saveAsOhc(const char *fname)
Function to write OHC file.
Definition: Openholo.cpp:175
oph::uint getNumColors()
Returns number of colors.

◆ saveAsOhc() [2/2]

virtual int ophCascadedPropagation::saveAsOhc ( const char *  fname)
virtual

Function to write OHC file.

Reimplemented from Openholo.

◆ 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 Reference/include/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 openholo/src/Openholo.h.

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

Member Data Documentation

◆ 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: