Openholo  v4.2
Open Source Digital Holographic Library
ophRec.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 #ifndef __OphReconstruction_h
47 #define __OphReconstruction_h
48 
49 #include "Openholo.h"
50 
51 #ifdef _WIN64
52 #ifdef RECON_EXPORT
53 #define RECON_DLL __declspec(dllexport)
54 #else
55 #define RECON_DLL __declspec(dllimport)
56 #endif
57 #else
58 #ifdef RECON_EXPORT
59 #define RECON_DLL __attribute__((visibility("default")))
60 #else
61 #define RECON_DLL
62 #endif
63 #endif
64 
65 
66 
67 
69 {
70  Real EyeLength;
71  Real EyePupilDiaMeter;
72  Real EyeBoxSizeScale;
73  vec2 EyeBoxSize;
74  int EyeBoxUnit;
75  vec3 EyeCenter;
76  Real EyeFocusDistance;
77  Real ResultSizeScale;
78  Real SimulationTo;
79  Real SimulationFrom;
80  int SimulationStep;
81  int SimulationMode;
82  Real RatioAtRetina;
83  Real RatioAtPupil;
84  bool CreatePupilFieldImg;
85  bool CenteringRetinaImg;
86  bool ViewingWindow;
87  bool SimulationPos[3];
88 
90  : EyeLength(0.0), EyePupilDiaMeter(0.0), EyeBoxSizeScale(0.0), EyeBoxSize(0.0, 0.0), EyeBoxUnit(0),
91  EyeCenter(0.0, 0.0, 0.0), EyeFocusDistance(0.0), ResultSizeScale(0.0), SimulationTo(0.0), SimulationFrom(0.0),
92  SimulationStep(0), SimulationMode(0), RatioAtRetina(0.0), RatioAtPupil(0.0), CreatePupilFieldImg(false),
93  CenteringRetinaImg(false), ViewingWindow(false)
94  {
95  SimulationPos[0] = SimulationPos[1] = SimulationPos[2] = false;
96  }
97 };
98 
104 class RECON_DLL ophRec : public Openholo
105 {
106 public:
110  explicit ophRec(void);
111 
112 protected:
116  virtual ~ophRec(void);
117 
118 
119 private:
120  vector<Real *> m_vecEncoded;
121  vector<uchar *> m_vecNormalized;
122 
123  std::vector<Complex<Real>*> field_set_;
124  std::vector<double*> field_ret_set_;
125 
126  std::vector<double*> res_set_;
127  std::vector<double*> res_set_norm_255_;
128 
129  std::vector<ivec2> pn_set_; // Pixel number of output plane
130  std::vector<vec2> pp_set_; // Pixel pitch of output plane
131  std::vector<ivec2> pn_ret_set_;
132  std::vector<vec2> pp_ret_set_;
133  std::vector<vec2> ss_ret_set_;
134 
135  std::vector<Real*> recon_set;
136  std::vector<uchar*> img_set;
137  std::vector<ivec2> img_size;
138  std::vector<Real*> focus_recon_set;
139  std::vector<uchar*> focus_img_set;
140  std::vector<ivec2> focus_img_size;
141 
142  int m_oldSimStep;
143 
144 
145  OphRecConfig rec_config;
146  int m_nOldChannel;
147  int m_idx;
148  unsigned int m_mode;
149 
150 protected:
154  virtual void ophFree(void);
155  void Clear();
156  void GetPupilFieldFromHologram();
157  void GetPupilFieldFromVWHologram();
158  void Propagation_Fresnel_FFT(int chnum);
159  void ASM_Propagation();
160  void ASM_Propagation_GPU();
161  void GetPupilFieldImage(Complex<Real>* src, double* dst, int pnx, int pny, double ppx, double ppy, double scaleX, double scaleY);
162  void getVarname(int vtr, vec3& var_vals, std::string& varname2);
163 public:
164  void SaveImage(const char* path, const char* ext = "bmp");
165  void setConfig(OphRecConfig config) { rec_config = config; }
166  void SetMode(unsigned int mode) { m_mode = mode; }
167  OphRecConfig& getConfig() { return rec_config; }
168  bool ReconstructImage();
169  bool readConfig(const char* fname);
170  bool readImage(const char* path);
171  bool readImagePNA(const char* phase, const char* amplitude);
172  bool readImageRNI(const char* real, const char* imaginary);
173  void Perform_Simulation();
174  void Initialize();
175  bool save(const char * fname, uint8_t bitsperpixel, uchar* src, uint px, uint py);
176  template<typename T>
177  void normalize(T* src, uchar* dst, int x, int y)
178  {
179  T maxVal = src[0];
180  T minVal = src[0];
181  int size = x * y;
182 
183  for (int i = 0; i < size; i++)
184  {
185  if (src[i] < minVal)
186  minVal = src[i];
187  if (src[i] > maxVal)
188  maxVal = src[i];
189  }
190  T gap = maxVal - minVal;
191 
192  for (int i = 0; i < y; i++)
193  {
194  int base = i * x;
195  //int base2 = (y - 1 - i) * x;
196 
197  for (int j = 0; j < x; j++)
198  {
199  dst[base + j] = (uchar)((src[base + j] - minVal) / gap * 255.0);
200  }
201  }
202  }
203  template<typename T>
204  void normalize(T* src, uchar* dst, int x, int y, T max, T min)
205  {
206  T gap = max - min;
207 
208  for (int i = 0; i < y; i++)
209  {
210  int base = i * x;
211  for (int j = 0; j < x; j++)
212  {
213  dst[base + j] = (uchar)((src[base + j] - min) / gap * 255.0);
214  }
215  }
216  }
217  vector<uchar*>& getNormalizedBuffer() { return m_vecNormalized; };
218 
219 };
220 
221 
222 #endif // !__OphReconstruction_h
Abstract class.
Definition: Openholo.h:145
#define RECON_DLL
Definition: ophRec.h:61
void normalize(T *src, uchar *dst, int x, int y, T max, T min)
Definition: ophRec.h:204
unsigned char uchar
Definition: typedef.h:64
void SetMode(unsigned int mode)
Definition: ophRec.h:166
Definition: ophRec.h:85
float Real
Definition: typedef.h:55
void setConfig(OphRecConfig config)
Definition: ophRec.h:165
vector< uchar * > & getNormalizedBuffer()
Definition: ophRec.h:217
OphRecConfig & getConfig()
Definition: ophRec.h:167
OphRecConfig()
Definition: ophRec.h:89
unsigned int uint
Definition: typedef.h:62
virtual void ophFree(void)
Pure virtual function for override in child classes.
Definition: Openholo.cpp:805
void normalize(T *src, uchar *dst, int x, int y)
Definition: ophRec.h:177