Openholo  v1.0
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 
58 using namespace oph;
59 
60 
62 {
63  oph::ivec2 pixel_number; //< SLM_PIXEL_NUMBER_X & SLM_PIXEL_NUMBER_Y
64  oph::vec2 pixel_pitch; //< SLM_PIXEL_PITCH_X & SLM_PIXEL_PITCH_Y
65 
66  Real k; //< 2 * PI / lambda(wavelength)
67  vec2 ss; //< pn * pp
68  uint waveNum; // wave num
69  Real* wave_length; //< wave length
70 };
71 
72 
73 
74 
75 
76 
83 class OPH_DLL Openholo : public Base{
84 
85 public:
89  explicit Openholo(void);
90 
91 protected:
96  virtual ~Openholo(void) = 0;
97 
98 protected:
107  bool checkExtension(const char* fname, const char* ext);
108 
109 public:
121  virtual bool saveAsImg(const char* fname, uint8_t bitsperpixel, uchar* src, int width, int height);
122 
130  virtual uchar* loadAsImg(const char* fname);
131 
139  virtual bool saveAsOhc(const char *fname);
140 
148  virtual bool loadAsOhc(const char *fname);
149 
156  inline Complex<Real>** getComplexField(void) { return complex_H; }
157 
158 
165  OphConfig& getContext(void) { return context_; }
166 
171  inline void setPixelNumber(ivec2 n) { context_.pixel_number[_X] = n[_X]; context_.pixel_number[_Y] = n[_Y]; }
172 
177  inline void setPixelPitch(vec2 p) { context_.pixel_pitch[_X] = p[_X]; context_.pixel_pitch[_Y] = p[_Y]; }
178 
184  inline void setWaveLength(Real w, const uint idx) { context_.wave_length[idx] = w; }
185 protected:
194  bool loadAsImgUpSideDown(const char* fname, uchar* dst);
195 
206  bool getImgSize(int& w, int& h, int& bytesperpixel, const char* fname);
207 
217  void imgScaleBilnear(uchar* src, uchar* dst, int w, int h, int neww, int newh);
218 
227  void convertToFormatGray8(uchar* src, uchar* dst, int w, int h, int bytesperpixel);
228 
236  void fft1(int n, Complex<Real>* in, int sign = OPH_FORWARD, uint flag = OPH_ESTIMATE);
237 
245  void fft2(ivec2 n, Complex<Real>* in, int sign = OPH_FORWARD, uint flag = OPH_ESTIMATE);
253  void fft3(ivec3 n, Complex<Real>* in, int sign = OPH_FORWARD, uint flag = OPH_ESTIMATE);
254 
259  void fftExecute(Complex<Real>* out);
260  void fftFree(void);
270  void fftwShift(Complex<Real>* src, Complex<Real>* dst, int nx, int ny, int type, bool bNormalized = false);
271 
279  void fftShift(int nx, int ny, Complex<Real>* input, Complex<Real>* output);
280 
281 protected:
285  virtual void ophFree(void);
286 
287 private:
291  fftw_plan plan_fwd, plan_bwd;
292  fftw_complex *fft_in, *fft_out;
293  int pnx, pny, pnz;
294  int fft_sign;
295 
296 protected:
298  Complex<Real>** complex_H;
299 
300 protected:
306 
307 protected:
311  inline void setPixelNumberOHC(const ivec2 pixel_number)
312  { OHC_encoder->setNumOfPixel(pixel_number); }
313 
314  inline void setPixelPitchOHC(const vec2 pixel_pitch)
315  { OHC_encoder->setPixelPitch(pixel_pitch); }
316 
317  inline void setWavelengthOHC(const Real wavelength, const LenUnit wavelength_unit)
318  { OHC_encoder->setWavelength(wavelength, wavelength_unit); }
319 
320  inline void setWaveLengthNumOHC(const uint wavelength_num)
321  { OHC_encoder->setNumOfWavlen(wavelength_num); }
322 
323  inline void setColorTypeOHC(const ColorType color_type)
324  { OHC_encoder->setColorType(color_type); }
325 
326  inline void setColorArrangeOHC(const ColorArran color_arrange)
327  { OHC_encoder->setColorArrange(color_arrange); }
328 
329  inline void setWaveLengthUnitOHC(const LenUnit length_unit)
330  { OHC_encoder->setUnitOfWavlen(length_unit); }
331 
332  inline void setFieldEncodingOHC(const FldStore field_store, const FldCodeType field_code_type)
333  { OHC_encoder->setFieldEncoding(field_store, field_code_type); }
334 
335  inline void setPhaseEncodingOHC(const BPhaseCode phase_code, const vec2 phase_code_range)
336  { OHC_encoder->setPhaseEncoding(phase_code, phase_code_range); }
337 
338  //inline void setCompressedFormatType(const CompresType compress_type)
339  // { OHC_encoder->setCompressedFormatType(compress_type); }
340 
344  inline void addWaveLengthNComplexFieldDataOHC(const Real wavelength, const OphComplexField& complex_field)
345  { OHC_encoder->addWavelengthNComplexFieldData(wavelength, complex_field); }
346 
347  inline void addWaveLengthOHC(const Real wavelength)
348  { OHC_encoder->addWavelength(wavelength); }
349 
350  inline void addComplexFieldDataOHC(const OphComplexField& complex_field)
351  { OHC_encoder->addComplexFieldData(complex_field); }
352 
356  //inline void addLinkFilePath(const std::string& path)
357  // { OHC_encoder->addLinkFilePath(path); }
358 
362  //inline void getLinkFilePath(std::vector<std::string> &linkFilePath_array)
363  // { OHC_decoder->getLinkFilePath(linkFilePath_array); }
364 
365  inline void getPixelNumberOHC(ivec2& pixel_number)
366  { pixel_number = OHC_decoder->getNumOfPixel(); }
367 
368  inline void getPixelPitchOHC(vec2& pixel_pitch)
369  { pixel_pitch = OHC_decoder->getPixelPitch(); }
370 
371  inline void getWavelengthOHC(vector<Real>& wavelength)
372  { OHC_decoder->getWavelength(wavelength); }
373 
374  inline void getWaveLengthNumOHC(uint& wavelength_num)
375  { wavelength_num = OHC_decoder->getNumOfWavlen(); }
376 
377  inline void getColorTypeOHC(ColorType& color_type)
378  { color_type = OHC_decoder->getColorType(); }
379 
380  inline void getColorArrangeOHC(ColorArran& color_arrange)
381  { color_arrange = OHC_decoder->getColorArrange(); }
382 
383  inline void getWaveLengthUnitOHC(LenUnit& length_unit)
384  { length_unit = OHC_decoder->getUnitOfWavlen(); }
385 
386  inline void getComplexFieldDataOHC(Complex<Real>** cmplx, uint wavelen_idx)
387  { OHC_decoder->getComplexFieldData(cmplx, wavelen_idx); }
388 
389  inline void getComplexFieldDataOHC(OphComplexField& cmplx, uint wavelen_idx)
390  { OHC_decoder->getComplexFieldData(cmplx, wavelen_idx); }
391 
392  //inline void getCompressedFormatType(const CompresType compress_type)
393  // { OHC_encoder->setCompressedFormatType(compress_type); }
394 
395 
396 };
397 
398 #endif // !__Openholo_h
OphConfig & getContext(void)
Function for getting the current context.
Definition: Openholo.h:165
void setColorArrangeOHC(const ColorArran color_arrange)
Definition: Openholo.h:326
void setPhaseEncodingOHC(const BPhaseCode phase_code, const vec2 phase_code_range)
Definition: Openholo.h:335
Abstract class.
Definition: Openholo.h:83
Real k
Definition: Openholo.h:66
Definition: Base.h:55
void getPixelPitchOHC(vec2 &pixel_pitch)
Definition: Openholo.h:368
Real * wave_length
Definition: Openholo.h:69
void setColorArrange(const ColorArran _clrArrange)
ColorArran getColorArrange()
void setPixelNumberOHC(const ivec2 pixel_number)
getter/setter for OHC file read and write
Definition: Openholo.h:311
unsigned char uchar
Definition: typedef.h:64
void getColorArrangeOHC(ColorArran &color_arrange)
Definition: Openholo.h:380
float Real
Definition: typedef.h:55
void setPixelPitchOHC(const vec2 pixel_pitch)
Definition: Openholo.h:314
vec2 ss
Definition: Openholo.h:67
#define OPH_ESTIMATE
Definition: define.h:76
void getComplexFieldDataOHC(Complex< Real > **cmplx, uint wavelen_idx)
Definition: Openholo.h:386
void setColorTypeOHC(const ColorType color_type)
Definition: Openholo.h:323
void getWaveLengthUnitOHC(LenUnit &length_unit)
Definition: Openholo.h:383
void setWaveLength(Real w, const uint idx)
Function for setting the wave length.
Definition: Openholo.h:184
void getPixelNumberOHC(ivec2 &pixel_number)
Definition: Openholo.h:365
#define _Y
Definition: define.h:84
void setWavelengthOHC(const Real wavelength, const LenUnit wavelength_unit)
Definition: Openholo.h:317
void addWaveLengthNComplexFieldDataOHC(const Real wavelength, const OphComplexField &complex_field)
Function to add ComplexField when adding wavelength data.
Definition: Openholo.h:344
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.
Definition: Openholo.h:304
void setWaveLengthUnitOHC(const LenUnit length_unit)
Definition: Openholo.h:329
void getWavelengthOHC(vector< Real > &wavelength)
Definition: Openholo.h:371
void setFieldEncoding(const FldStore _fldStore, const FldCodeType _fldCodeType)
void getWaveLengthNumOHC(uint &wavelength_num)
Definition: Openholo.h:374
void getComplexFieldData(OphComplexField &cmplx_field, uint wavelen_idx)
Definition: ImgCodecOhc.h:81
ImgDecoderOhc * OHC_decoder
Definition: Openholo.h:305
ColorType getColorType()
#define _X
Definition: define.h:80
#define OPH_DLL
Definition: Base.h:52
void addWaveLengthOHC(const Real wavelength)
Definition: Openholo.h:347
void addComplexFieldData(const OphComplexField &data)
void setNumOfWavlen(const uint n_wavlens)
oph::ivec2 pixel_number
Definition: Openholo.h:63
void setWaveLengthNumOHC(const uint wavelength_num)
Definition: Openholo.h:320
void addComplexFieldDataOHC(const OphComplexField &complex_field)
Definition: Openholo.h:350
void setPhaseEncoding(const BPhaseCode _bPhaseCode, const double _phaseCodeMin, const double _phaseCodeMax)
oph::matrix< Complex< Real > > OphComplexField
Definition: mat.h:421
void addWavelength(const Real wavlen)
uint waveNum
Definition: Openholo.h:68
LenUnit getUnitOfWavlen()
void setPixelPitch(vec2 p)
Function for setting the output pixel pitch.
Definition: Openholo.h:177
void setColorType(const ColorType _clrType)
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:332
void setWavelength(const Real _wavlen, const LenUnit _unit=LenUnit::m)
void setNumOfPixel(const uint _pxNumX, const uint _pxNumY)
Complex< Real > ** getComplexField(void)
Function for getting the complex field.
Definition: Openholo.h:156
void setPixelNumber(ivec2 n)
Function for setting the output resolution.
Definition: Openholo.h:171
void getColorTypeOHC(ColorType &color_type)
Definition: Openholo.h:377
void setUnitOfWavlen(const LenUnit unit)
OphConfig context_
Definition: Openholo.h:297
#define OPH_FORWARD
Definition: define.h:66
Complex< Real > ** complex_H
Definition: Openholo.h:298
Definition: Bitmap.h:49
void getComplexFieldDataOHC(OphComplexField &cmplx, uint wavelen_idx)
Definition: Openholo.h:389
void getWavelength(std::vector< double_t > &wavlen_array)
unsigned int uint
Definition: typedef.h:62
void addWavelengthNComplexFieldData(const Real wavlen, const OphComplexField &data)
oph::vec2 pixel_pitch
Definition: Openholo.h:64