Openholo  v1.1
Open Source Digital Holographic Library
Openholo.h
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install, copy or use the software.
7 //
8 //
9 // License Agreement
10 // For Open Source Digital Holographic Library
11 //
12 // Openholo library is free software;
13 // you can redistribute it and/or modify it under the terms of the BSD 2-Clause license.
14 //
15 // Copyright (C) 2017-2024, Korea Electronics Technology Institute. All rights reserved.
16 // E-mail : contact.openholo@gmail.com
17 // Web : http://www.openholo.org
18 //
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 // 1. Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // 2. Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other materials provided with the distribution.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the copyright holder or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 // This software contains opensource software released under GNU Generic Public License,
41 // NVDIA Software License Agreement, or CUDA supplement to Software License Agreement.
42 // Check whether software you use contains licensed software.
43 //
44 //M*/
45 
46 
47 #ifndef __Openholo_h
48 #define __Openholo_h
49 
50 #include "Base.h"
51 #include "include.h"
52 #include "vec.h"
53 #include "ivec.h"
54 #include "fftw3.h"
55 
56 #include "ImgCodecOhc.h"
57 #include <vector>
58 
59 using namespace oph;
60 
62 {
63  bool bUseDP; // use double precision
64  ivec2 pixel_number; //< SLM_PIXEL_NUMBER_X & SLM_PIXEL_NUMBER_Y
65  vec2 pixel_pitch; //< SLM_PIXEL_PITCH_X & SLM_PIXEL_PITCH_Y
66  vec3 shift; // shift
67  Real k; //< 2 * PI / lambda(wavelength)
68  vec2 ss; //< pn * pp
69  uint waveNum; // wave num
70  Real* wave_length; //< wave length
71  bool bRotation;
72  bool bMergeImg;
73 };
74 
75 
76 
77 
84 class OPH_DLL Openholo : public Base{
85 
86 public:
90  explicit Openholo(void);
91 
92 protected:
97  virtual ~Openholo(void) = 0;
98 
99 protected:
108  bool checkExtension(const char* fname, const char* ext);
109 
110 public:
122  virtual bool saveAsImg(const char* fname, uint8_t bitsperpixel, uchar* src, int width, int height);
123 
131  virtual uchar* loadAsImg(const char* fname);
132 
140  virtual bool saveAsOhc(const char *fname);
141 
142 
150  virtual bool loadAsOhc(const char *fname);
151 
152 
159  inline Complex<Real>** getComplexField(void) { return complex_H; }
160 
161 
168  OphConfig& getContext(void) { return context_; }
169 
174  inline void setPixelNumber(ivec2 n) { context_.pixel_number[_X] = n[_X]; context_.pixel_number[_Y] = n[_Y]; }
175  inline void setPixelNumber(int width, int height) { context_.pixel_number[_X] = width; context_.pixel_number[_Y] = height; }
176 
181  inline void setPixelPitch(vec2 p) { context_.pixel_pitch[_X] = p[_X]; context_.pixel_pitch[_Y] = p[_Y]; }
182  inline void setPixelPitch(Real pitchX, Real pitchY) { context_.pixel_pitch[_X] = pitchX; context_.pixel_pitch[_Y] = pitchY; }
183 
189  inline void setWaveLength(Real w, const uint idx = 0) { context_.wave_length[idx] = w; }
190  inline void setMergeImage(bool bMerge) { context_.bMergeImg = bMerge; }
191 
192  void setWaveNum(int nNum);
193 
194 protected:
203  bool loadAsImgUpSideDown(const char* fname, uchar* dst);
204 
215  bool getImgSize(int& w, int& h, int& bytesperpixel, const char* fname);
216 
226  void imgScaleBilinear(uchar* src, uchar* dst, int w, int h, int neww, int newh, int channels = 1);
227  void ImageRotation(double rotate, uchar* src, uchar* dst, int w, int h, int channels);
236  void convertToFormatGray8(uchar* src, uchar* dst, int w, int h, int bytesperpixel);
237 
245  void fft1(int n, Complex<Real>* in, int sign = OPH_FORWARD, uint flag = OPH_ESTIMATE);
246 
254  void fft2(ivec2 n, Complex<Real>* in, int sign = OPH_FORWARD, uint flag = OPH_ESTIMATE);
262  void fft3(ivec3 n, Complex<Real>* in, int sign = OPH_FORWARD, uint flag = OPH_ESTIMATE);
263 
268  void fftExecute(Complex<Real>* out, bool bReverse = false);
269  void fftFree(void);
279  void fftwShift(Complex<Real>* src, Complex<Real>* dst, int nx, int ny, int type, bool bNormalized = false);
280 
288  void fftShift(int nx, int ny, Complex<Real>* input, Complex<Real>* output);
289 
290 protected:
294  virtual void ophFree(void);
295 
296 private:
300  fftw_plan plan_fwd, plan_bwd;
301  fftw_complex *fft_in, *fft_out;
302  int pnx, pny, pnz;
303  int fft_sign;
304 
305 protected:
307  Complex<Real>** complex_H;
308 
309 protected:
315 
316 protected:
320  inline void setPixelNumberOHC(const ivec2 pixel_number)
321  { OHC_encoder->setNumOfPixel(pixel_number); }
322 
323  inline void setPixelPitchOHC(const vec2 pixel_pitch)
324  { OHC_encoder->setPixelPitch(pixel_pitch); }
325 
326  inline void setWavelengthOHC(const Real wavelength, const LenUnit wavelength_unit)
327  { OHC_encoder->setWavelength(wavelength, wavelength_unit); }
328 
329  inline void setWaveLengthNumOHC(const uint wavelength_num)
330  { OHC_encoder->setNumOfWavlen(wavelength_num); }
331 
332  inline void setColorTypeOHC(const ColorType color_type)
333  { OHC_encoder->setColorType(color_type); }
334 
335  inline void setColorArrangeOHC(const ColorArran color_arrange)
336  { OHC_encoder->setColorArrange(color_arrange); }
337 
338  inline void setWaveLengthUnitOHC(const LenUnit length_unit)
339  { OHC_encoder->setUnitOfWavlen(length_unit); }
340 
341  inline void setFieldEncodingOHC(const FldStore field_store, const FldCodeType field_code_type)
342  { OHC_encoder->setFieldEncoding(field_store, field_code_type); }
343 
344  inline void setPhaseEncodingOHC(const BPhaseCode phase_code, const vec2 phase_code_range)
345  { OHC_encoder->setPhaseEncoding(phase_code, phase_code_range); }
346 
347  //inline void setCompressedFormatType(const CompresType compress_type)
348  // { OHC_encoder->setCompressedFormatType(compress_type); }
349 
353  inline void addWaveLengthNComplexFieldDataOHC(const Real wavelength, const OphComplexField& complex_field)
354  { OHC_encoder->addWavelengthNComplexFieldData(wavelength, complex_field); }
355 
356  inline void addWaveLengthOHC(const Real wavelength)
357  { OHC_encoder->addWavelength(wavelength); }
358 
359  inline void addComplexFieldDataOHC(const OphComplexField& complex_field)
360  { OHC_encoder->addComplexFieldData(complex_field); }
361 
365  //inline void addLinkFilePath(const std::string& path)
366  // { OHC_encoder->addLinkFilePath(path); }
367 
371  //inline void getLinkFilePath(std::vector<std::string> &linkFilePath_array)
372  // { OHC_decoder->getLinkFilePath(linkFilePath_array); }
373 
374  inline void getPixelNumberOHC(ivec2& pixel_number)
375  { pixel_number = OHC_decoder->getNumOfPixel(); }
376 
377  inline void getPixelPitchOHC(vec2& pixel_pitch)
378  { pixel_pitch = OHC_decoder->getPixelPitch(); }
379 
380  inline void getWavelengthOHC(vector<Real>& wavelength)
381  { OHC_decoder->getWavelength(wavelength); }
382 
383  inline void getWaveLengthNumOHC(uint& wavelength_num)
384  { wavelength_num = OHC_decoder->getNumOfWavlen(); }
385 
386  inline void getColorTypeOHC(ColorType& color_type)
387  { color_type = OHC_decoder->getColorType(); }
388 
389  inline void getColorArrangeOHC(ColorArran& color_arrange)
390  { color_arrange = OHC_decoder->getColorArrange(); }
391 
392  inline void getWaveLengthUnitOHC(LenUnit& length_unit)
393  { length_unit = OHC_decoder->getUnitOfWavlen(); }
394 
395  inline void getComplexFieldDataOHC(Complex<Real>** cmplx, uint wavelen_idx)
396  { OHC_decoder->getComplexFieldData(cmplx, wavelen_idx); }
397 
398  inline void getComplexFieldDataOHC(OphComplexField& cmplx, uint wavelen_idx)
399  { OHC_decoder->getComplexFieldData(cmplx, wavelen_idx); }
400 
401  //inline void getCompressedFormatType(const CompresType compress_type)
402  // { OHC_encoder->setCompressedFormatType(compress_type); }
403 
404 
405 };
406 
407 #endif // !__Openholo_h
void setWaveLength(Real w, const uint idx=0)
Function for setting the wave length.
Definition: Openholo.h:189
oph::matrix< Complex< Real > > OphComplexField
Definition: mat.h:421
OphConfig & getContext(void)
Function for getting the current context.
Definition: Openholo.h:168
void setColorArrangeOHC(const ColorArran color_arrange)
Definition: Openholo.h:335
void setPhaseEncodingOHC(const BPhaseCode phase_code, const vec2 phase_code_range)
Definition: Openholo.h:344
Abstract class.
Definition: Openholo.h:84
Real k
Definition: Openholo.h:67
Definition: Base.h:55
void getPixelPitchOHC(vec2 &pixel_pitch)
Definition: Openholo.h:377
vec3 shift
Definition: Openholo.h:66
#define OPH_ESTIMATE
Definition: define.h:76
void setMergeImage(bool bMerge)
Definition: Openholo.h:190
void setColorArrange(const ColorArran _clrArrange)
ColorArran getColorArrange()
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
Definition: Openholo.h:320
unsigned char uchar
Definition: typedef.h:64
void getColorArrangeOHC(ColorArran &color_arrange)
Definition: Openholo.h:389
void setPixelPitchOHC(const vec2 pixel_pitch)
Definition: Openholo.h:323
vec2 ss
Definition: Openholo.h:68
#define _Y
Definition: define.h:84
void getComplexFieldDataOHC(Complex< Real > **cmplx, uint wavelen_idx)
Definition: Openholo.h:395
void setColorTypeOHC(const ColorType color_type)
Definition: Openholo.h:332
void getWaveLengthUnitOHC(LenUnit &length_unit)
Definition: Openholo.h:392
void getPixelNumberOHC(ivec2 &pixel_number)
Definition: Openholo.h:374
void setWavelengthOHC(const Real wavelength, const LenUnit wavelength_unit)
Definition: Openholo.h:326
void setPixelNumber(int width, int height)
Definition: Openholo.h:175
void addWaveLengthNComplexFieldDataOHC(const Real wavelength, const OphComplexField &complex_field)
Function to add ComplexField when adding wavelength data.
Definition: Openholo.h:353
vec2 pixel_pitch
Definition: Openholo.h:65
void setWaveLengthUnitOHC(const LenUnit length_unit)
Definition: Openholo.h:338
void getWavelengthOHC(vector< Real > &wavelength)
Definition: Openholo.h:380
void setFieldEncoding(const FldStore _fldStore, const FldCodeType _fldCodeType)
void getWaveLengthNumOHC(uint &wavelength_num)
Definition: Openholo.h:383
void getComplexFieldData(OphComplexField &cmplx_field, uint wavelen_idx)
Definition: ImgCodecOhc.h:81
ColorType getColorType()
void addWaveLengthOHC(const Real wavelength)
Definition: Openholo.h:356
void addComplexFieldData(const OphComplexField &data)
void setNumOfWavlen(const uint n_wavlens)
void setWaveLengthNumOHC(const uint wavelength_num)
Definition: Openholo.h:329
void addComplexFieldDataOHC(const OphComplexField &complex_field)
Definition: Openholo.h:359
void setPhaseEncoding(const BPhaseCode _bPhaseCode, const double _phaseCodeMin, const double _phaseCodeMax)
void addWavelength(const Real wavlen)
ImgDecoderOhc * OHC_decoder
Definition: Openholo.h:314
uint waveNum
Definition: Openholo.h:69
void setPixelPitch(Real pitchX, Real pitchY)
Definition: Openholo.h:182
ivec2 pixel_number
Definition: Openholo.h:64
#define OPH_DLL
Definition: Base.h:52
parameters h
LenUnit getUnitOfWavlen()
void setPixelPitch(vec2 p)
Function for setting the output pixel pitch.
Definition: Openholo.h:181
void setColorType(const ColorType _clrType)
bool bUseDP
Definition: Openholo.h:63
void setPixelPitch(const double _pxPitchX, const double _pxPitchY, const LenUnit unit=LenUnit::m)
void setFieldEncodingOHC(const FldStore field_store, const FldCodeType field_code_type)
Definition: Openholo.h:341
Complex< Real > ** complex_H
Definition: Openholo.h:307
void setWavelength(const Real _wavlen, const LenUnit _unit=LenUnit::m)
void setNumOfPixel(const uint _pxNumX, const uint _pxNumY)
float Real
Definition: typedef.h:55
Complex< Real > ** getComplexField(void)
Function for getting the complex field.
Definition: Openholo.h:159
bool bMergeImg
Definition: Openholo.h:72
void setPixelNumber(ivec2 n)
Function for setting the output resolution.
Definition: Openholo.h:174
void getColorTypeOHC(ColorType &color_type)
Definition: Openholo.h:386
void setUnitOfWavlen(const LenUnit unit)
#define _X
Definition: define.h:80
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.
Definition: Openholo.h:313
OphConfig context_
Definition: Openholo.h:306
Definition: Bitmap.h:49
void getComplexFieldDataOHC(OphComplexField &cmplx, uint wavelen_idx)
Definition: Openholo.h:398
#define OPH_FORWARD
Definition: define.h:66
Real * wave_length
Definition: Openholo.h:70
void getWavelength(std::vector< double_t > &wavlen_array)
int w
Definition: 2D-RS.py:16
unsigned int uint
Definition: typedef.h:62
void addWavelengthNComplexFieldData(const Real wavlen, const OphComplexField &data)
bool bRotation
Definition: Openholo.h:71