Openholo  v1.0
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 
52 #include "include.h"
53 
54 //Build Option : Multi Core Processing (OpenMP)
55 #ifdef _OPENMP
56 #include <omp.h>
57 #endif
58 using namespace oph;
59 
60 
64 
102 
104 
105 
111 class GEN_DLL ophDepthMap : public ophGen {
112 
113 public:
114  explicit ophDepthMap();
115 
116 protected:
117  virtual ~ophDepthMap();
118 
119 public:
129  void setMode(bool is_CPU);
130  bool readConfig(const char* fname);
131  bool readImageDepth(const char* source_folder, const char* img_prefix, const char* depth_img_prefix);
132 
137  Real generateHologram(void);
138 
139  void encodeHologram(void);
140  virtual void encoding(unsigned int ENCODE_FLAG);
141  virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND);
142 
152  void setViewingWindow(bool is_ViewingWindow);
153 
154  ivec2 getRGBImgSize() { return m_vecRGBImg; };
155  ivec2 getDepthImgSize() { return m_vecDepthImg; };
156 
158  dm_config_ = config;
159  };
160  void setResolution(ivec2 resolution);
161  uint* getPercent() { return &n_percent; }
162 
163 public:
164  inline void setFieldLens(Real fieldlens) { dm_config_.fieldLength = fieldlens; }
165  inline void setNearDepth(Real neardepth) { dm_config_.near_depthmap = neardepth; }
166  inline void setFarDepth(Real fardetph) { dm_config_.far_depthmap = fardetph; }
167  inline void setNumOfDepth(uint numofdepth) { dm_config_.num_of_depth = numofdepth; }
168 
169  inline Real getFieldLens(void) { return dm_config_.fieldLength; }
170  inline Real getNearDepth(void) { return dm_config_.near_depthmap; }
171  inline Real getFarDepth(void) { return dm_config_.far_depthmap; }
172  inline uint getNumOfDepth(void) { return dm_config_.num_of_depth; }
173  inline void getRenderDepth(std::vector<int>& renderdepth) { renderdepth = dm_config_.render_depth; }
174 
175  inline const OphDepthMapConfig& getConfig() { return dm_config_; }
176 
177 private:
178 
179  void initialize();
180  void initCPU();
181  void initGPU();
182 
183  bool prepareInputdataCPU(uchar* img, uchar* dimg);
184  bool prepareInputdataGPU(uchar* img, uchar* dimg);
185 
186  void getDepthValues();
187  void changeDepthQuanCPU();
188  void changeDepthQuanGPU();
189 
190  void transVW();
191 
192  void calcHoloCPU(void);
193  void calcHoloGPU(void);
194  void propagationAngularSpectrumGPU(uint channel, cufftDoubleComplex* input_u, Real propagation_dist);
195 
196 protected:
197  void free_gpu(void);
198 
199  void ophFree(void);
200 
201 private:
202  bool is_CPU;
203  bool is_ViewingWindow;
204  unsigned char* depth_img;
205  unsigned char* rgb_img;
206  ivec2 m_vecRGBImg;
207  ivec2 m_vecDepthImg;
208  unsigned char* img_src_gpu;
209  unsigned char* dimg_src_gpu;
210  Real* depth_index_gpu;
211 
212  Real* img_src;
213  Real* dmap_src;
214  Real* depth_index;
215  int* alpha_map;
216 
217  Real* dmap;
218 
219  Real dstep;
220  vector<Real> dlevel;
221  vector<Real> dlevel_transform;
222 
223  OphDepthMapConfig dm_config_;
224 
225 
226  uint n_percent;
227 };
228 
229 #endif //>__ophDepthMap_h
void setNearDepth(Real neardepth)
Definition: ophDepthMap.h:165
ENCODE_FLAG
Definition: ophGen.h:72
void getRenderDepth(std::vector< int > &renderdepth)
Definition: ophDepthMap.h:173
void setFieldLens(Real fieldlens)
Definition: ophDepthMap.h:164
void setConfig(OphDepthMapConfig config)
Definition: ophDepthMap.h:157
SSB_PASSBAND
Definition: ophGen.h:227
unsigned char uchar
Definition: typedef.h:64
ivec2 getRGBImgSize()
Definition: ophDepthMap.h:154
float Real
Definition: typedef.h:55
Real getFieldLens(void)
Definition: ophDepthMap.h:169
void setFarDepth(Real fardetph)
Definition: ophDepthMap.h:166
ivec2 getDepthImgSize()
Definition: ophDepthMap.h:155
Real getFarDepth(void)
Definition: ophDepthMap.h:171
const OphDepthMapConfig & getConfig()
Definition: ophDepthMap.h:175
#define GEN_DLL
Definition: ophGen.h:54
This class generates CGH based on depth map.
Definition: ophDepthMap.h:111
uint getNumOfDepth(void)
Definition: ophDepthMap.h:172
Real getNearDepth(void)
Definition: ophDepthMap.h:170
uint * getPercent()
Definition: ophDepthMap.h:161
Definition: Bitmap.h:49
unsigned int uint
Definition: typedef.h:62
Definition: ophGen.h:68
void setNumOfDepth(uint numofdepth)
Definition: ophDepthMap.h:167
Configuration for Depth Map.
Definition: ophGen.h:463