Openholo  v4.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 #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 
108 class GEN_DLL ophDepthMap : public ophGen {
109 public:
110  enum IMAGE_TYPE {
111  COLOR = 0,
112  DEPTH = 1
113  };
114 
119  explicit ophDepthMap();
120 
121 protected:
125  virtual ~ophDepthMap();
126 
127 public:
132  bool readConfig(const char* fname);
133 
143  bool readImage(const char* fname, IMAGE_TYPE type = COLOR);
144 
156  bool readImageDepth(const char* source_folder, const char* img_prefix, const char* depth_img_prefix);
157  //bool readImageDepth(const char* rgb, const char* depth);
158 
163  Real generateHologram(void);
164 
165  virtual void encoding(unsigned int ENCODE_FLAG);
166  virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND);
167 
177  void setViewingWindow(bool is_ViewingWindow);
178 
179  ivec2 getRGBImgSize() { return m_vecRGBImg; };
180  ivec2 getDepthImgSize() { return m_vecDepthImg; };
181 
182  void setRGBImgSize(ivec2 size) {
183  m_vecRGBImg[_X] = size[_X];
184  m_vecRGBImg[_Y] = size[_Y];
185  };
186 
187  void setDepthImgSize(ivec2 size) {
188  m_vecDepthImg[_X] = size[_X];
189  m_vecDepthImg[_Y] = size[_Y];
190  };
191 
193  dm_config_ = config;
194  };
195  void setResolution(ivec2 resolution);
196  uint* getProgress() { return &m_nProgress; }
197 
198 
199  void normalize();
200 
201  inline void setFieldLens(Real fieldlens) { dm_config_.fieldLength = fieldlens; }
202  inline void setNearDepth(Real neardepth) { dm_config_.near_depthmap = neardepth; }
203  inline void setFarDepth(Real fardetph) { dm_config_.far_depthmap = fardetph; }
204  inline void setNumOfDepth(uint numofdepth) {
205  dm_config_.default_depth_quantization = numofdepth;
206  dm_config_.num_of_depth_quantization = numofdepth;
207  dm_config_.num_of_depth = numofdepth;
208  dm_config_.render_depth.clear();
209  dm_config_.change_depth_quantization = true;
210  for(int i = 1; i <= (int)numofdepth; i++)
211  dm_config_.render_depth.push_back(i);
212  }
213  inline void setRGBImageBuffer(int idx, unsigned char* buffer, unsigned long long size)
214  {
215  if (idx < 0 || idx > 2) return;
216  if (m_vecRGB.size() > idx)
217  {
218  if (m_vecRGB[idx] != nullptr)
219  {
220  delete[] m_vecRGB[idx];
221  m_vecRGB[idx] = new uchar[size];
222  memcpy(m_vecRGB[idx], buffer, size);
223  }
224  }
225  else
226  {
227  uchar* pImg = new uchar[size];
228  memcpy(pImg, buffer, size);
229  m_vecRGB.push_back(pImg);
230  }
231  }
232 
233  inline void setDepthImageBuffer(unsigned char* buffer, unsigned long long size)
234  {
235  if (depth_img != nullptr)
236  {
237  delete[] depth_img;
238  depth_img = nullptr;
239  }
240  depth_img = new unsigned char[size];
241  memcpy(depth_img, buffer, size);
242  }
243 
244  inline Real getFieldLens(void) { return dm_config_.fieldLength; }
245  inline Real getNearDepth(void) { return dm_config_.near_depthmap; }
246  inline Real getFarDepth(void) { return dm_config_.far_depthmap; }
247  inline uint getNumOfDepth(void) { return dm_config_.num_of_depth; }
248  inline void getRenderDepth(std::vector<int>& renderdepth) { renderdepth = dm_config_.render_depth; }
249  inline unsigned char* getRGBImageBuffer(int idx) { return m_vecRGB[idx]; }
250  inline unsigned char* getDepthImageBuffer() { return depth_img; }
251 
252  inline const OphDepthMapConfig& getConfig() { return dm_config_; }
253 
254 private:
260  void initCPU();
261 
267  void initGPU();
268 
274  bool prepareInputdataCPU();
275 
281  bool prepareInputdataGPU();
282 
289  void getDepthValues();
290 
295  void changeDepthQuanCPU();
296 
302  void changeDepthQuanGPU();
303 
308  void transVW();
309 
321  void calcHoloCPU();
322 
336  void calcHoloGPU();
337 
341  bool convertImage();
342 
343 protected:
344  void free_gpu(void);
345 
346  void ophFree(void);
347 
348 private:
349  bool is_ViewingWindow;
350  unsigned char* depth_img;
351  vector<uchar*> m_vecRGB;
352  ivec2 m_vecRGBImg;
353  ivec2 m_vecDepthImg;
354  unsigned char* img_src_gpu;
355  unsigned char* dimg_src_gpu;
356  Real* depth_index_gpu;
357 
358  vector<Real *> m_vecImgSrc;
359  vector<int *> m_vecAlphaMap;
360  Real* dmap_src;
361  uint* depth_index;
362  vector<short> depth_fill;
363  Real* dmap;
364 
365  Real dstep;
366  vector<Real> dlevel;
367  vector<Real> dlevel_transform;
368 
369  OphDepthMapConfig dm_config_;
370 
371  cufftDoubleComplex* u_o_gpu_;
372  cufftDoubleComplex* u_complex_gpu_;
373  cufftDoubleComplex* k_temp_d_;
374 
375  cudaStream_t stream_;
376 
377  uint m_nProgress;
378 };
379 
380 #endif //>__ophDepthMap_h
void setNearDepth(Real neardepth)
Definition: ophDepthMap.h:202
void setRGBImageBuffer(int idx, unsigned char *buffer, unsigned long long size)
Definition: ophDepthMap.h:213
void getRenderDepth(std::vector< int > &renderdepth)
Definition: ophDepthMap.h:248
void setFieldLens(Real fieldlens)
Definition: ophDepthMap.h:201
void setDepthImgSize(ivec2 size)
Definition: ophDepthMap.h:187
void setConfig(OphDepthMapConfig config)
Definition: ophDepthMap.h:192
unsigned char uchar
Definition: typedef.h:64
ivec2 getRGBImgSize()
Definition: ophDepthMap.h:179
float Real
Definition: typedef.h:55
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
void setRGBImgSize(ivec2 size)
Definition: ophDepthMap.h:182
Real getFieldLens(void)
Definition: ophDepthMap.h:244
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:203
#define _Y
Definition: define.h:96
ivec2 getDepthImgSize()
Definition: ophDepthMap.h:180
#define _X
Definition: define.h:92
Real getFarDepth(void)
Definition: ophDepthMap.h:246
const OphDepthMapConfig & getConfig()
Definition: ophDepthMap.h:252
#define GEN_DLL
Definition: ophGen.h:61
This class generates CGH based on depth map.
Definition: ophDepthMap.h:108
unsigned char * getDepthImageBuffer()
Definition: ophDepthMap.h:250
uint getNumOfDepth(void)
Definition: ophDepthMap.h:247
Real getNearDepth(void)
Definition: ophDepthMap.h:245
void setDepthImageBuffer(unsigned char *buffer, unsigned long long size)
Definition: ophDepthMap.h:233
Definition: Bitmap.h:49
uint * getProgress()
Definition: ophDepthMap.h:196
unsigned int uint
Definition: typedef.h:62
Definition: ophGen.h:76
void setNumOfDepth(uint numofdepth)
Definition: ophDepthMap.h:204
Configuration for Depth Map.
Definition: ophGen.h:613
unsigned char * getRGBImageBuffer(int idx)
Definition: ophDepthMap.h:249