Openholo  v1.0
Open Source Digital Holographic Library
ophLightField.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 __ophLightField_h
47 #define __ophLightField_h
48 
49 #include "ophGen.h"
50 #include <fstream>
51 #include <io.h>
52 
53 using namespace oph;
54 
55 
56 //Build Option : Multi Core Processing (OpenMP)
57 #ifdef _OPENMP
58 #include <omp.h>
59 #endif
60 
63 
90 
97 class GEN_DLL ophLF : public ophGen
98 {
99 public:
103  explicit ophLF(void);
104 
105 protected:
109  virtual ~ophLF(void) {}
110 
111 private:
112 
113  uchar** LF;
114  Complex<Real>* RSplane_complex_field;
115 
116  // ==== GPU Variables ===============================================
117  bool is_CPU;
118 
119 private:
120 
121  // Light Field save parameters
122 
123  const char* LF_directory;
124  const char* ext;
125 
126 public:
127  inline void setNumImage(int nx, int ny) { num_image[_X] = nx; num_image[_Y] = ny; }
128  inline void setNumImage(ivec2 num) { num_image = num; }
129  inline void setResolImage(int nx, int ny) { resolution_image[_X] = nx; resolution_image[_Y] = ny; }
130  inline void setResolImage(ivec2 num) { resolution_image = num; }
131  inline void setDistRS2Holo(Real dist) { distanceRS2Holo = dist; }
132  inline void setFieldLens(Real lens) { fieldLens = lens; }
133  inline ivec2 getNumImage() { return num_image; }
134  inline ivec2 getResolImage() { return resolution_image; }
135  inline Real getDistRS2Holo() { return distanceRS2Holo; }
136  inline Real getFieldLens() { return fieldLens; }
137  inline uchar** getLF() { return LF; }
138  inline oph::Complex<Real>* getRSPlane() { return RSplane_complex_field; }
139 public:
150  bool readConfig(const char* fname);
151 
159  int loadLF(const char* directory, const char* exten);
160  int loadLF();
161  //void readPNG(const string filename, uchar* data);
162 
167  void generateHologram();
168 
169  //virtual int saveAsOhc(const char* fname);
170 
171  //virtual int saveAsOhc(const char* fname);
181  void setMode(bool is_CPU);
182 
183  // for Testing
184  void writeIntensity_gray8_bmp(const char* fileName, int nx, int ny, Complex<Real>* complexvalue, int k = -1);
194  void setViewingWindow(bool is_ViewingWindow);
195 protected:
196 
197  // Inner functions
198 
199  void initializeLF();
200  void convertLF2ComplexField();
201 
202  // ==== GPU Methods ===============================================
203  void prepareInputdataGPU();
204  void convertLF2ComplexField_GPU();
205  void fresnelPropagation_GPU();
206 
207 private:
208 
209  ivec2 num_image;
210  ivec2 resolution_image;
211  Real distanceRS2Holo;
212  Real fieldLens;
213  bool is_ViewingWindow;
214  int nImages;
215 };
216 
217 
218 #endif
unsigned char uchar
Definition: typedef.h:64
float Real
Definition: typedef.h:55
void setNumImage(int nx, int ny)
Openholo Light Field based CGH generation.
Definition: ophLightField.h:97
ivec2 getResolImage()
#define _Y
Definition: define.h:84
void setNumImage(ivec2 num)
uchar ** getLF()
#define _X
Definition: define.h:80
virtual ~ophLF(void)
Destructor.
#define GEN_DLL
Definition: ophGen.h:54
oph::Complex< Real > * getRSPlane()
void setDistRS2Holo(Real dist)
void setResolImage(ivec2 num)
Real getDistRS2Holo()
void setResolImage(int nx, int ny)
ivec2 getNumImage()
Definition: Bitmap.h:49
void setFieldLens(Real lens)
Real getFieldLens()
Definition: ophGen.h:68