Openholo  beta 2.0
Open Source Digital Holographic Library
ophWaveAberration Class Reference

Wave Aberration module. More...

Inheritance diagram for ophWaveAberration:
Inheritance graph

Public Member Functions

 ophWaveAberration ()
 Constructor. More...
 
 ~ophWaveAberration ()
 Destructor. More...
 
bool readConfig (const char *fname)
 read configuration from a configration file More...
 
Real factorial (double x)
 Factorial using recursion. More...
 
void imresize (double **X, int Nx, int Ny, int nx, int ny, double **Y)
 Resizes 2D data using bilinear interpolation. More...
 
double ** calculateZernikePolynomial (double n, double m, vector< double > x, vector< double > y, double d)
 Calculates Zernike polynomial. More...
 
void accumulateZernikePolynomial ()
 Sums up the calculated Zernike polynomials. More...
 
void Free2D (oph::Complex< Real > **doublePtr)
 deletes 2D memory array using double pointer More...
 
void saveAberration (const char *fname)
 saves the 2D data array of a wave aberration into a file More...
 
void readAberration (const char *fname)
 reads the 2D data array of a wave aberration from a file More...
 
void ophFree (void)
 Pure virtual function for override in child classes. More...
 
 ophWaveAberration ()
 Constructor. More...
 
 ~ophWaveAberration ()
 Destructor. More...
 
bool readConfig (const char *fname)
 read configuration from a configration file More...
 
Real factorial (double x)
 Factorial using recursion. More...
 
void imresize (double **X, int Nx, int Ny, int nx, int ny, double **Y)
 Resizes 2D data using bilinear interpolation. More...
 
double ** calculateZernikePolynomial (double n, double m, vector< double > x, vector< double > y, double d)
 Calculates Zernike polynomial. More...
 
void accumulateZernikePolynomial ()
 Sums up the calculated Zernike polynomials. More...
 
void Free2D (oph::Complex< Real > **doublePtr)
 deletes 2D memory array using double pointer More...
 
void saveAberration (const char *fname)
 saves the 2D data array of a wave aberration into a file More...
 
void readAberration (const char *fname)
 reads the 2D data array of a wave aberration from a file More...
 
void ophFree (void)
 Pure virtual function for override in child classes. 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...
 
virtual int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
virtual int loadAsOhc (const char *fname)
 Function to read 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...
 

Public Attributes

oph::uint resolutionX
 
oph::uint resolutionY
 
oph::Complex< Real > ** complex_W
 double pointer of the 2D data array of a wave aberration More...
 

Protected Member Functions

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

Wave Aberration module.

Author
Minsik Park

Definition at line 94 of file ophrec/src/ophWaveAberration.h.

Constructor & Destructor Documentation

◆ ophWaveAberration() [1/2]

ophWaveAberration::ophWaveAberration ( )

Constructor.

Definition at line 59 of file ophWaveAberration.cpp.

59  : nOrder(0), mFrequency(0)
60 {
61 
62  cout << "ophWaveAberration Constructor" << endl;
63  uint wavelength_num = 1;
64 
65  complex_H = new Complex<Real>*[wavelength_num];
66  context_.wave_length = new Real[wavelength_num];
67 }

◆ ~ophWaveAberration() [1/2]

ophWaveAberration::~ophWaveAberration ( )

Destructor.

Definition at line 69 of file ophWaveAberration.cpp.

70 {
71  cout << "ophWaveAberration Destructor" << endl;
72 }

◆ ophWaveAberration() [2/2]

ophWaveAberration::ophWaveAberration ( )

Constructor.

◆ ~ophWaveAberration() [2/2]

ophWaveAberration::~ophWaveAberration ( )

Destructor.

Member Function Documentation

◆ accumulateZernikePolynomial() [1/2]

void ophWaveAberration::accumulateZernikePolynomial ( )

Sums up the calculated Zernike polynomials.

Definition at line 179 of file ophWaveAberration.cpp.

180 {
181  const oph::Complex<Real> j(0,1);
182 
183  double wave_lambda = context_.wave_length[0]; // wavelength
184  int z_max = sizeof(zernikeCoefficent)/sizeof(zernikeCoefficent[0]);
185  double *ZC;
186  ZC = zernikeCoefficent;
187 
188 
189  double n, m;
190  double dxa = context_.pixel_pitch[_X]; // Sampling interval in x axis of exit pupil
191  double dya = context_.pixel_pitch[_Y]; // Sampling interval in y axis of exit pupil
192  unsigned int xr = context_.pixel_number[_X];
193  unsigned int yr = context_.pixel_number[_Y]; // Resolution in x, y axis of exit pupil
194 
195  double DE = max(dxa*xr, dya*yr); // Diameter of exit pupil
196  double scale = 1.3;
197 
198  DE = DE * scale;
199 
200  vector<double> xn;
201  vector<double> yn;
202 
203  double max_xn = floor(DE/dxa+1);
204  double max_yn = floor(DE/dya+1);
205 
206  xn.reserve((int)max_xn);
207  for (int i = 0; i < (int)max_xn; i++)
208  {
209  xn.push_back(-DE / 2 + dxa*i);
210  } // x axis coordinate of exit pupil
211 
212  yn.reserve((int)max_yn);
213  for (int i = 0; i < max_yn; i++)
214  {
215  yn.push_back(-DE / 2 + dya*i);
216  }// y axis coordinate of exit pupil
217 
218  double d = DE;
219 
220  vector<double>::size_type length_xn = xn.size();
221  vector<double>::size_type length_yn = yn.size();
222 
223  double **W = new double*[(int)length_xn];
224  double **Temp_W = new double*[(int)length_xn];
225 
226  for (int i = 0; i < (int)length_xn; i++)
227  {
228  W[i] = new double[length_yn];
229  Temp_W[i] = new double[length_yn];
230  }
231 
232  for (int i = 0; i < (int)length_xn; i++)
233  {
234  memset(W[i], 0, length_yn*sizeof(double));
235  memset(Temp_W[i], 0, length_yn * sizeof(double));
236  }
237 
238 
239  // Start : Wavefront Aberration Generation
240  for (int i = 0; i <z_max; i++)
241  {
242  if (ZC[i] != 0)
243  {
244  n = ceil((-3 + sqrt(9 + 8 * i)) / 2); // order of the radial polynomial term
245  m = 2 * i - n * (n + 2); // frequency of the sinusoidal component
246 
247  Temp_W = calculateZernikePolynomial(n, m, xn, yn, d);
248 
249  for(int ii = 0; ii < length_xn; ii++)
250  {
251  for (int jj = 0; jj < length_yn; jj++)
252  {
253  W[ii][jj] = W[ii][jj] + ZC[i] * Temp_W[ii][jj];
254  }
255  }
256  }
257  }
258  // End : Wavefront Aberration Generation
259 
260 
261  for (int i = 0; i < (int)length_xn; i++)
262  {
263  memset(Temp_W[i], 0, length_yn * sizeof(double));
264  }
265 
266  int min_xnn, max_xnn;
267  int min_ynn, max_ynn;
268 
269  min_xnn = (int)round(length_xn / 2 - xr / 2);
270  max_xnn = (int)round(length_xn / 2 + xr / 2 + 1);
271  min_ynn = (int)round(length_yn / 2 - yr / 2);
272  max_ynn = (int)round(length_yn / 2 + yr / 2 + 1);
273 
274  int length_xnn, length_ynn;
275  length_xnn = max_xnn - min_xnn;
276  length_ynn = max_ynn - min_ynn;
277 
278  double **WT = new double*[length_xnn];
279  for (int i = 0; i < length_xnn; i++)
280  {
281  WT[i] = new double[length_ynn];
282  memset(WT[i], 0, length_ynn * sizeof(double));
283  }
284 
285  for (int i = 0; i < length_xnn; i++)
286  {
287  for (int j = 0; j < length_ynn; j++)
288  {
289  WT[i][j] = W[min_xnn+i][min_ynn+j];
290  }
291  }
292 
293  double **WS = new double*[(int)xr];
294  for (int i = 0; i < (int)xr; i++)
295  {
296  WS[i] = new double[yr];
297  memset(WS[i], 0, yr * sizeof(double));
298  }
299 
300  imresize(WT, length_xnn, length_ynn, xr, yr, WS);
301 
302 
303  oph::Complex<Real> **WD = new oph::Complex<Real>*[xr];
304 
305  for(int i = 0; i < (int)xr; i++)
306  WD[i] = new oph::Complex<Real>[yr];
307 
308  for(int ii = 0; ii < (int)xr; ii ++ )
309  {
310  for (int jj = 0; jj < (int)yr; jj++)
311  {
312 
313  WD[ii][jj]= exp(-j * (oph::Complex<Real>)2 * M_PI*WS[ii][jj] / wave_lambda); // Wave Aberration Complex Field
314  }
315  }
316  //WD[x][y]
317 
318  for (int i = 0; i < (int)length_xn; i++)
319  {
320  delete [] W[i];
321  delete [] Temp_W[i];
322  }
323  delete[] W;
324  delete[] Temp_W;
325 
326  for (int i = 0; i < (int)xr; i++)
327  {
328  delete[] WS[i];
329  }
330  delete[] WS;
331 
332  for (int i = 0; i < (int)length_xnn; i++)
333  {
334  delete[] WT[i];
335  }
336  delete[] WT;
337 
338  complex_W = WD;
339 
340  for (int x = 0; x < xr; x++) {
341  for (int y = 0; y < yr; y++) {
342  complex_H[0][x + y * xr] = complex_W[x][y];
343  }
344  }
345 
346 // return WD;
347 }
double ** calculateZernikePolynomial(double n, double m, vector< double > x, vector< double > y, double d)
Calculates Zernike polynomial.
oph::Complex< Real > ** complex_W
double pointer of the 2D data array of a wave aberration
void imresize(double **X, int Nx, int Ny, int nx, int ny, double **Y)
Resizes 2D data using bilinear interpolation.

◆ accumulateZernikePolynomial() [2/2]

void ophWaveAberration::accumulateZernikePolynomial ( )

Sums up the calculated Zernike polynomials.

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

◆ calculateZernikePolynomial() [1/2]

double ** ophWaveAberration::calculateZernikePolynomial ( double  n,
double  m,
vector< double >  x,
vector< double >  y,
double  d 
)

Calculates Zernike polynomial.

Parameters
norder of the radial term of Zernike polynomial
mfrequency of the sinusoidal component of Zernike polynomial
xresolution in y axis of the exit pupil
yresolution in y axis of the exit pupil
ddiameter of aperture of the exit pupil

Definition at line 75 of file ophWaveAberration.cpp.

76 {
77  vector<double>::size_type x_max = x.size();
78  vector<double>::size_type y_max = y.size();
79  double radius = d / 2;
80  double N;
81  double r;
82  double theta;
83  double co ;
84  double si ;
85 
86  double **Z = new double*[x_max];
87  double **A = new double*[x_max];
88  for(int i = 0; i < (int)x_max; i++)
89  {
90  A[i] = new double[y_max];
91  Z[i] = new double[y_max];
92 
93  // memset(A[i], 0, y_max*sizeof(double));
94  }
95 
96  for(int ix = 0; ix < (int)x_max; ix++)
97  {
98  for(int iy = 0; iy < (int)y_max; iy++)
99  {
100  A[ix][iy] = (sqrt(pow(x[ix],2) + pow(y[iy],2)) <= radius);
101  };
102  }
103  // Start : Calculate Zernike polynomial
104 
105  N = sqrt(2 * (n + 1) / (1 + (m == 0))); // Calculate Normalization term
106 
107  if (n == 0)
108  {
109  for(int i=0; i<(int)x_max; i++)
110  memcpy(Z[i], A[i],y_max*sizeof(double));
111  }
112  else
113  {
114  for(int i = 0; i<(int)x_max; i++)
115  memset(Z[i],0, y_max*sizeof(double));
116 
117  for(int ix = 0; ix < (int)x_max; ix++)
118  {
119  for(int iy = 0; iy < (int)y_max; iy++)
120  {
121  r = sqrt(pow(x[ix], 2) + pow(y[iy],2));
122 
123  if (((x[ix] >= 0) && (y[iy] >= 0)) || ((x[ix] >= 0) & (y[iy] < 0)))
124  theta = atan(y[iy] / (x[ix] + 1e-30));
125  else
126  theta = M_PI + atan(y[iy] / (x[ix] + 1e-30));
127 
128  for(int s = 0; s <= (n - abs(m)) / 2; s++)
129  {
130  Z[ix][iy] = Z[ix][iy] + pow((-1),s)*factorial(n - s)*pow((r/radius),(n - 2 * s)) /
131  (factorial(s)*factorial((n + abs(m))/2 - s)*factorial((n - abs(m)) / 2 - s));
132  }
133  co = cos(m*theta);
134  si = sin(m*theta);
135  Z[ix][iy] = A[ix][iy]*N*Z[ix][iy]*((m >= 0)*co - (m < 0)*si);
136  }
137  }
138  }
139  // End : Calculate Zernike polynomial
140  for (int i=0; i < x_max; i++)
141  {
142  delete[] A[i];
143  }
144  delete[] A;
145 
146  return Z;
147 }
Real factorial(double x)
Factorial using recursion.

◆ calculateZernikePolynomial() [2/2]

double** ophWaveAberration::calculateZernikePolynomial ( double  n,
double  m,
vector< double >  x,
vector< double >  y,
double  d 
)

Calculates Zernike polynomial.

Parameters
norder of the radial term of Zernike polynomial
mfrequency of the sinusoidal component of Zernike polynomial
xresolution in y axis of the exit pupil
yresolution in y axis of the exit pupil
ddiameter of aperture of the exit pupil

◆ 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

◆ factorial() [1/2]

double ophWaveAberration::factorial ( double  x)
inline

Factorial using recursion.

Parameters
xa number of factorial

Definition at line 50 of file ophWaveAberration.cpp.

51 {
52  if (x == 0)
53  return (1);
54  else
55  return (x == 1 ? x : x * factorial(x - 1));
56 }
Real factorial(double x)
Factorial using recursion.

◆ factorial() [2/2]

Real ophWaveAberration::factorial ( double  x)

Factorial using recursion.

Parameters
xa number of factorial

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

◆ Free2D() [1/2]

void ophWaveAberration::Free2D ( oph::Complex< Real > **  doublePtr)

deletes 2D memory array using double pointer

Definition at line 350 of file ophWaveAberration.cpp.

351 {
352  for (int i = 0; i < (int)context_.pixel_number[_X]; i++)
353  {
354  delete[] doublePtr[i];
355  }
356 }

◆ Free2D() [2/2]

void ophWaveAberration::Free2D ( oph::Complex< Real > **  doublePtr)

deletes 2D memory array using double pointer

◆ 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

◆ 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

◆ 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

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 }

◆ imresize() [1/2]

void ophWaveAberration::imresize ( double **  X,
int  Nx,
int  Ny,
int  nx,
int  ny,
double **  Y 
)

Resizes 2D data using bilinear interpolation.

Parameters
X2D source image
Nxresolution in x axis of source image
Nyresolution in y axis of source image
nxresolution in x axis target image
nyresolution in y axis target image
ny2D target image

◆ imresize() [2/2]

void ophWaveAberration::imresize ( double **  X,
int  Nx,
int  Ny,
int  nx,
int  ny,
double **  Y 
)

Resizes 2D data using bilinear interpolation.

Parameters
X2D source image
Nxresolution in x axis of source image
Nyresolution in y axis of source image
nxresolution in x axis target image
nyresolution in y axis target image
ny2D target image

Definition at line 150 of file ophWaveAberration.cpp.

151 {
152  int fx, fy;
153  double x, y, tx, tx1, ty, ty1, scale_x, scale_y;
154 
155  scale_x = (double)Nx / (double)nx;
156  scale_y = (double)Ny / (double)ny;
157 
158  for (int i = 0; i < nx; i++)
159  {
160  x = (double)i * scale_x;
161 
162  fx = (int)floor(x);
163  tx = x - fx;
164  tx1 = double(1.0) - tx;
165  for (int j = 0; j < ny; j++)
166  {
167  y = (double)j * scale_y;
168  fy = (int)floor(y);
169  ty = y - fy;
170  ty1 = double(1.0) - ty;
171 
172  Y[i][j] = X[fx][fy] * (tx1*ty1) + X[fx][fy + 1] * (tx1*ty) + X[fx + 1][fy] * (tx*ty1) + X[fx + 1][fy + 1] * (tx*ty);
173  }
174  }
175 }

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

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

Function to read OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophGen, ophGen, ophSig, and ophSig.

Definition at line 193 of file Openholo.cpp.

194 {
195  std::string fullname = fname;
196  if (checkExtension(fname, ".ohc") == 0) fullname.append(".ohc");
197  OHC_decoder->setFileName(fullname.c_str());
198  if (!OHC_decoder->load()) return -1;
199 
200  context_.pixel_number = OHC_decoder->getNumOfPixel();
201  context_.pixel_pitch = OHC_decoder->getPixelPitch();
202 
203  vector<Real> wavelengthArray;
204  OHC_decoder->getWavelength(wavelengthArray);
205  context_.wave_length = new Real[wavelengthArray.size()];
206  for (int i = 0; i < wavelengthArray.size(); i++)
207  context_.wave_length[i] = wavelengthArray[i];
208 
209  OHC_decoder->getComplexFieldData(&complex_H);
210 
211  context_.k = (2 * M_PI) / context_.wave_length[0];
212  context_.ss[_X] = context_.pixel_number[_X] * context_.pixel_pitch[_X];
213  context_.ss[_Y] = context_.pixel_number[_Y] * context_.pixel_pitch[_Y];
214 
215  return 1;
216 }
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79

◆ loadAsOhc() [2/2]

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

Function to read OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophGen, ophGen, ophSig, and ophSig.

◆ ophFree() [1/2]

void ophWaveAberration::ophFree ( void  )
virtual

Pure virtual function for override in child classes.

Implements ophRec.

Definition at line 358 of file ophWaveAberration.cpp.

359 {
360  this->Free2D(complex_W);
361  std::cout << " ophFree" << std::endl;
362 }
void Free2D(oph::Complex< Real > **doublePtr)
deletes 2D memory array using double pointer
oph::Complex< Real > ** complex_W
double pointer of the 2D data array of a wave aberration

◆ ophFree() [2/2]

void ophWaveAberration::ophFree ( void  )
virtual

Pure virtual function for override in child classes.

Implements ophRec.

◆ readAberration() [1/2]

void ophWaveAberration::readAberration ( const char *  fname)

reads the 2D data array of a wave aberration from a file

Parameters
fnamea path name of a file to save a wave aberration

◆ readAberration() [2/2]

void ophWaveAberration::readAberration ( const char *  fname)

reads the 2D data array of a wave aberration from a file

Parameters
fnamea path name of a file to save a wave aberration

Definition at line 464 of file ophWaveAberration.cpp.

465 {
466 
467  complex_W = new oph::Complex<Real>*[context_.pixel_number[_X]];
468  for (int i = 0; i < (int)context_.pixel_number[_X]; i++)
469  complex_W[i] = new oph::Complex<Real>[context_.pixel_number[_Y]];
470 
471  ifstream fin(fname, ios_base::in | ios_base::binary);
472  fin.read((char *)complex_W, context_.pixel_number[_X]*context_.pixel_number[_Y]);
473  fin.close();
474 }
oph::Complex< Real > ** complex_W
double pointer of the 2D data array of a wave aberration

◆ readConfig() [1/2]

bool ophWaveAberration::readConfig ( const char *  fname)

read configuration from a configration file

Parameters
fnamea path name of a configration file

Definition at line 365 of file ophWaveAberration.cpp.

366 {
367  LOG("Reading....%s...\n", fname);
368 
369 
370  /*XML parsing*/
371  tinyxml2::XMLDocument xml_doc;
372  tinyxml2::XMLNode *xml_node;
373  tinyxml2::XMLElement *xml_element;
374  const tinyxml2::XMLAttribute *xml_attribute;
375 
376 
377  if (checkExtension(fname, ".xml") == 0)
378  {
379  LOG("file's extension is not 'xml'\n");
380  return false;
381  }
382  auto ret = xml_doc.LoadFile(fname);
383  if (ret != tinyxml2::XML_SUCCESS)
384  {
385  LOG("Failed to load file \"%s\"\n", fname);
386  return false;
387  }
388 
389  xml_node = xml_doc.FirstChild();
390  xml_element = xml_node->FirstChildElement("Wavelength");
391  if (!xml_element || tinyxml2::XML_SUCCESS != xml_element->QueryDoubleText(&context_.wave_length[0]))
392  return false;
393 
394 
395  xml_element = xml_node->FirstChildElement("PixelPitchHor");
396  if (!xml_element || tinyxml2::XML_SUCCESS != xml_element->QueryDoubleText(&context_.pixel_pitch[_X]))
397  return false;
398 
399  xml_element = xml_node->FirstChildElement("PixelPitchVer");
400  if (!xml_element || tinyxml2::XML_SUCCESS != xml_element->QueryDoubleText(&context_.pixel_pitch[_Y]))
401  return false;
402 
403  xml_element = xml_node->FirstChildElement("ResolutionHor");
404  if (!xml_element || tinyxml2::XML_SUCCESS != xml_element->QueryIntText(&context_.pixel_number[_X]))
405  return false;
406 
407  xml_element = xml_node->FirstChildElement("ResolutionVer");
408  if (!xml_element || tinyxml2::XML_SUCCESS != xml_element->QueryIntText(&context_.pixel_number[_Y]))
409  return false;
410 
411  xml_element = xml_node->FirstChildElement("ZernikeCoeff");
412  xml_attribute = xml_element->FirstAttribute();
413 
414  for(int i=0; i< 45; i++)
415  {
416  if (!xml_attribute || tinyxml2::XML_SUCCESS != xml_attribute->QueryDoubleValue(&zernikeCoefficent[i]))
417  return false;
418  xml_attribute=xml_attribute->Next();
419 
420  }
421 
422  pixelPitchX = context_.pixel_pitch[_X];
423  pixelPitchY = context_.pixel_pitch[_Y];
424 
425  resolutionX = context_.pixel_number[_X];
426  resolutionY = context_.pixel_number[_Y];
427 
428  waveLength = *context_.wave_length;
429 
430  Openholo::setPixelPitchOHC(vec2(context_.pixel_pitch[_X], context_.pixel_pitch[_Y]));
431  Openholo::setPixelNumberOHC(ivec2(context_.pixel_number[_X], context_.pixel_number[_Y]));
432  Openholo::setWavelengthOHC(context_.wave_length[0], oph::LenUnit::m);
433 
434  cout << "Wavelength: " << context_.wave_length[0] << endl;
435  cout << "PixelPitch(Horizontal): " << context_.pixel_pitch[_X] << endl;
436  cout << "PixelPitch(Vertical): " << context_.pixel_pitch[_Y] << endl;
437  cout << "Resolution(Horizontal): " << context_.pixel_number[_X] << endl;
438  cout << "Resolution(Vertical): " << context_.pixel_number[_Y] << endl;
439  cout << "Zernike Coefficient: " << endl;
440  for(int i=0; i<45; i++)
441  {
442  if (i!=0 && (i+1)%5 == 0)
443  cout << "z["<<i<<"]="<< zernikeCoefficent[i]<<endl;
444  else
445  cout << "z[" << i << "]=" << zernikeCoefficent[i] <<" ";
446  zernikeCoefficent[i] = zernikeCoefficent[i] * context_.wave_length[0];
447  }
448  int xr = context_.pixel_number[_X];
449  int yr = context_.pixel_number[_Y];
450 
451  complex_H[0] = new Complex<Real>[xr * yr];
452 
453  return true;
454 
455 }
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
XMLError QueryIntText(int *ival) const
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
XMLError LoadFile(const char *filename)
XMLError QueryDoubleText(double *dval) const
See QueryIntText()
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79
const XMLAttribute * Next() const
The next attribute in the list.
const XMLElement * FirstChildElement(const char *name=0) const
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.

◆ readConfig() [2/2]

bool ophWaveAberration::readConfig ( const char *  fname)

read configuration from a configration file

Parameters
fnamea path name of a configration file

◆ release() [1/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  }

◆ release() [2/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  }

◆ saveAberration() [1/2]

void ophWaveAberration::saveAberration ( const char *  fname)

saves the 2D data array of a wave aberration into a file

Parameters
fnamea path name of a file to save a wave aberration

◆ saveAberration() [2/2]

void ophWaveAberration::saveAberration ( const char *  fname)

saves the 2D data array of a wave aberration into a file

Parameters
fnamea path name of a file to save a wave aberration

Definition at line 457 of file ophWaveAberration.cpp.

458 {
459  ofstream fout(fname, ios_base::out | ios_base::binary);
460  fout.write((char *)complex_W, context_.pixel_number[_X] * context_.pixel_number[_Y] * sizeof(oph::Complex<Real>));
461  fout.close();
462 }
oph::Complex< Real > ** complex_W
double pointer of the 2D data array of a wave aberration

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

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

Function to write OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophSig, and ophSig.

◆ saveAsOhc() [2/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.

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

Member Data Documentation

◆ complex_W

oph::Complex< Real > ** ophWaveAberration::complex_W

double pointer of the 2D data array of a wave aberration

Definition at line 136 of file ophrec/src/ophWaveAberration.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.

◆ resolutionX

oph::uint ophWaveAberration::resolutionX
Parameters
resolutionin x axis of the exit pupil

Definition at line 128 of file ophrec/src/ophWaveAberration.h.

◆ resolutionY

oph::uint ophWaveAberration::resolutionY
Parameters
resolutionin y axis of the exit pupil

Definition at line 132 of file ophrec/src/ophWaveAberration.h.


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