54 ophCascadedPropagation::ophCascadedPropagation()
55 : ready_to_propagate(false),
60 ophCascadedPropagation::ophCascadedPropagation(
const wchar_t* configfilepath)
61 : ready_to_propagate(false),
64 if (readConfig(configfilepath) && allocateMem())
66 string hologram_path_str;
67 hologram_path_str.assign(hologram_path.begin(), hologram_path.end());
106 wstring bufw(pathname);
108 bufs.assign(bufw.begin(), bufw.end());
118 memcpy(
complex_H[i], wavefield_retina[i], nx * ny *
sizeof(Complex<Real>));
141 memcpy(wavefield_SLM[i],
complex_H[i], nx * ny *
sizeof(Complex<Real>));
146 bool ophCascadedPropagation::allocateMem()
165 void ophCascadedPropagation::deallocateMem()
167 for (
auto e : wavefield_SLM)
169 wavefield_SLM.clear();
171 for (
auto e : wavefield_pupil)
173 wavefield_pupil.clear();
175 for (
auto e : wavefield_retina)
177 wavefield_retina.clear();
184 bool ophCascadedPropagation::loadInputImg(
string hologram_path_str)
208 for (
oph::uint color = 0; color < numColors; color++)
211 wavefield_SLM[numColors - 1 - color][(ny - 1 - row) * nx+ col] =
oph::Complex<Real>((
Real)data[(row * nx + col) * numColors + color], 0);
218 PRINT_ERROR(
"failed to generate wavefield from bmp");
230 if (numColors != 1 && numColors != 3)
239 for (
oph::uint color = 0; color < numColors; color++)
241 Real* intensityFieldUnnormalized =
new Real[nx * ny];
244 Real maxIntensity = 0.0;
250 intensityFieldUnnormalized[row * nx + col] = waveFields[color][row * nx + col].mag2();
251 maxIntensity = max(maxIntensity, intensityFieldUnnormalized[row * nx + col]);
252 minIntensity = min(minIntensity, intensityFieldUnnormalized[row * nx + col]);
257 if (maxIntensity <= minIntensity)
263 intensityField[(row * nx + col) * numColors + (numColors - 1 - color)] = 0;
273 Real normalizedVal = (intensityFieldUnnormalized[row * nx + col] - minIntensity) / (maxIntensity - minIntensity);
274 normalizedVal = min(1.0, normalizedVal);
277 intensityField[((ny - 1 - row) * nx + (nx - 1 - col)) * numColors + (numColors - 1 - color)] = (
oph::uchar)(normalizedVal * 255);
281 delete[] intensityFieldUnnormalized;
284 return intensityField;
287 bool ophCascadedPropagation::readConfig(
const wchar_t* fname)
292 wstring fnamew(fname);
294 fnames.assign(fnamew.begin(), fnamew.end());
298 LOG(
"file's extension is not 'xml'\n");
301 auto ret = xml_doc.
LoadFile(fnames.c_str());
304 LOG(
"Failed to load file \"%s\"\n", fnames.c_str());
310 if (!next || !(next->GetText()))
313 if (sourceTypeStr ==
string(
"IMG"))
315 else if (sourceTypeStr ==
string(
"OHC"))
351 PRINT_ERROR(
"current implementation assumes pixel pitches are same for X and Y axes");
393 if (!next || !(next->GetText()))
396 hologram_path.assign(holopaths.begin(), holopaths.end());
408 for (
oph::uint color = 0; color < numColors; color++)
426 buf[row * nx + col] = t1 / t2 * buf[row * nx + col];
429 if ((sqrt(X1 * X1 + Y1 * Y1) >=
getPupilDiameter() / 2) || (row >= ny / 2 - 1))
430 buf[row * nx + col] = 0;
434 buf[row * nx + col] *= t3;
443 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
445 LOG(
"SLM to Pupil propagation - Implement time : %.5lf sec\n", during_time);
458 for (
oph::uint color = 0; color < numColors; color++)
475 buf[row * nx + col] *= t1;
484 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
486 LOG(
"Pupil to Retina propagation - Implement time : %.5lf sec\n", during_time);
494 if (wavefield_SLM.size() <= (size_t)
id)
496 return wavefield_SLM[id];
501 if (wavefield_pupil.size() <= (size_t)
id)
503 return wavefield_pupil[id];
508 if (wavefield_retina.size() <= (size_t)
id)
510 return wavefield_retina[id];
515 return wavefield_retina;
virtual bool saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int width, int height)
Function for creating image files.
oph::uint getResX()
Returns horizontal resolution.
Real field_lens_focal_length
bool save(const wchar_t *pathname, uint8_t bitsperpixel)
Save wavefield at retina plane as Windows Bitmap file.
#define PRINT_ERROR(errorMsg)
Real getPupilDiameter()
Returns diameter of pupil in meter.
Real getDistPupilToRetina()
Returns distance from pupil plane to retina plane in meter.
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
oph::Complex< Real > * getRetinaWavefield(oph::uint id)
Return monochromatic wavefield at retina plane.
Real getFieldLensFocalLength()
Returns focal length of field lens in meter.
bool propagateSlmToPupil()
Calculates 1st propagation (from SLM plane to pupil plane)
void setPixelPitchOHC(const vec2 pixel_pitch)
virtual bool loadAsOhc(const char *fname)
Function to read OHC file.
bool checkExtension(const char *fname, const char *ext)
Functions for extension checking.
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Real dist_pupil_to_retina
vector< oph::Complex< Real > * > getRetinaWavefieldAll()
Return all wavefields at retina plane.
virtual bool saveAsOhc(const char *fname)
Function to write OHC file.
oph::uint getResY()
Returns vertical resolution.
void addWaveLengthOHC(const Real wavelength)
~ophCascadedPropagation()
Destructor.
void fft2(ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 2-dimension operations inside Openholo.
bool propagatePupilToRetina()
Calculates 2nd propagation (from pupil plane to retina plane)
ImgDecoderOhc * OHC_decoder
oph::vec3 getWavelengths()
Returns wavelengths in meter.
bool isReadyToPropagate()
Returns if all data are prepared.
bool propagate()
Do cascaded propagation.
Real getPixelPitchY()
Returns vertical pixel pitch in meter.
oph::Complex< Real > * getSlmWavefield(oph::uint id)
Return monochromatic wavefield at SLM plane.
virtual bool loadAsOhc(const char *fname)
Function to read OHC file.
XMLError LoadFile(const char *filename)
virtual void ophFree(void)
Pure virtual function for override in child classes.
virtual bool saveAsOhc(const char *fname)
Function to write OHC file
Complex< Real > ** complex_H
oph::Complex< Real > * getPupilWavefield(oph::uint id)
Return monochromatic wavefield at pupil plane.
Real getPixelPitchX()
Returns horizontal pixel pitch in meter.
Real getDistObjectToPupil()
Returns distance from reconstruction plane to pupil plane in meter.
oph::uint getNumColors()
Returns number of colors.
bool loadAsImgUpSideDown(const char *fname, uchar *dst)
Function for loading image files | Output image data upside down.
const XMLElement * FirstChildElement(const char *name=0) const
Real dist_reconstruction_plane_to_pupil
Real getNor()
Returns Nor, which affects the range of output intensity.