Openholo  v2.1
Open Source Digital Holographic Library
ophDepthMap.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 __ophDepthMap_h
47 #define __ophDepthMap_h
48 
49 #include "ophGen.h"
50 #include <cufft.h>
51 #include "include.h"
52 
53 //Build Option : Multi Core Processing (OpenMP)
54 #ifdef _OPENMP
55 #include <omp.h>
56 #endif
57 using namespace oph;
58 
59 
63 
101 
103 
104 
110 class GEN_DLL ophDepthMap : public ophGen {
111 
112 public:
113  explicit ophDepthMap();
114 
115 protected:
116  virtual ~ophDepthMap();
117 
118 public:
119  bool readConfig(const char* fname);
120  bool readImageDepth(const char* source_folder, const char* img_prefix, const char* depth_img_prefix);
121  //bool readImageDepth(const char* rgb, const char* depth);
122 
127  Real generateHologram(void);
128 
129  virtual void encoding(unsigned int ENCODE_FLAG);
130  virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND);
131 
141  void setViewingWindow(bool is_ViewingWindow);
142 
143  ivec2 getRGBImgSize() { return m_vecRGBImg; };
144  ivec2 getDepthImgSize() { return m_vecDepthImg; };
145 
147  dm_config_ = config;
148  };
149  void setResolution(ivec2 resolution);
150  uint* getProgress() { return &m_nProgress; }
151 
152 
153  void normalize();
154 
155 public:
156  inline void setFieldLens(Real fieldlens) { dm_config_.fieldLength = fieldlens; }
157  inline void setNearDepth(Real neardepth) { dm_config_.near_depthmap = neardepth; }
158  inline void setFarDepth(Real fardetph) { dm_config_.far_depthmap = fardetph; }
159  inline void setNumOfDepth(uint numofdepth) { dm_config_.num_of_depth = numofdepth; }
160 
161  inline Real getFieldLens(void) { return dm_config_.fieldLength; }
162  inline Real getNearDepth(void) { return dm_config_.near_depthmap; }
163  inline Real getFarDepth(void) { return dm_config_.far_depthmap; }
164  inline uint getNumOfDepth(void) { return dm_config_.num_of_depth; }
165  inline void getRenderDepth(std::vector<int>& renderdepth) { renderdepth = dm_config_.render_depth; }
166 
167  inline const OphDepthMapConfig& getConfig() { return dm_config_; }
168 
169 private:
170 
171  void initialize();
172  void initCPU();
173  void initGPU();
174 
175  bool prepareInputdataCPU();
176  bool prepareInputdataGPU();
177 
178  void getDepthValues();
179  void changeDepthQuanCPU();
180  void changeDepthQuanGPU();
181 
182  void transVW();
183 
184  void calcHoloCPU();
185  void calcHoloGPU();
186  void propagationAngularSpectrumGPU(uint channel, cufftDoubleComplex* input_u, Real propagation_dist);
187 
188 protected:
189  void free_gpu(void);
190 
191  void ophFree(void);
192 
193 private:
194  bool is_ViewingWindow;
195  unsigned char* depth_img;
196  vector<uchar*> m_vecRGB;
197  ivec2 m_vecRGBImg;
198  ivec2 m_vecDepthImg;
199  unsigned char* img_src_gpu;
200  unsigned char* dimg_src_gpu;
201  Real* depth_index_gpu;
202 
203  vector<Real *> m_vecImgSrc;
204  vector<int *> m_vecAlphaMap;
205  Real* dmap_src;
206  short* depth_index;
207  vector<short> depth_fill;
208  Real* dmap;
209 
210  Real dstep;
211  vector<Real> dlevel;
212  vector<Real> dlevel_transform;
213 
214  OphDepthMapConfig dm_config_;
215 
216 
217  uint m_nProgress;
218 };
219 
220 #endif //>__ophDepthMap_h
void setNearDepth(Real neardepth)
Definition: ophDepthMap.h:157
void getRenderDepth(std::vector< int > &renderdepth)
Definition: ophDepthMap.h:165
void setFieldLens(Real fieldlens)
Definition: ophDepthMap.h:156
void setConfig(OphDepthMapConfig config)
Definition: ophDepthMap.h:146
#define GEN_DLL
Definition: ophGen.h:54
ivec2 getRGBImgSize()
Definition: ophDepthMap.h:143
Real getFieldLens(void)
Definition: ophDepthMap.h:161
void normalize(const Complex< T > *src, Complex< T > *dst, const int &size)
Normalize all elements of Complex<T>* src from 0 to 1.
Definition: function.h:176
void setFarDepth(Real fardetph)
Definition: ophDepthMap.h:158
ivec2 getDepthImgSize()
Definition: ophDepthMap.h:144
Real getFarDepth(void)
Definition: ophDepthMap.h:163
const OphDepthMapConfig & getConfig()
Definition: ophDepthMap.h:167
This class generates CGH based on depth map.
Definition: ophDepthMap.h:110
uint getNumOfDepth(void)
Definition: ophDepthMap.h:164
Real getNearDepth(void)
Definition: ophDepthMap.h:162
float Real
Definition: typedef.h:55
Definition: Bitmap.h:49
uint * getProgress()
Definition: ophDepthMap.h:150
unsigned int uint
Definition: typedef.h:62
Definition: ophGen.h:68
void setNumOfDepth(uint numofdepth)
Definition: ophDepthMap.h:159
Configuration for Depth Map.
Definition: ophGen.h:585