Openholo  v4.0
Open Source Digital Holographic Library
ophGen.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 __ophGen_h
47 #define __ophGen_h
48 
49 #include "Openholo.h"
50 
51 #ifdef _WIN64
52 #ifdef GEN_EXPORT
53 #define GEN_DLL __declspec(dllexport)
54 #else
55 #define GEN_DLL __declspec(dllimport)
56 #endif
57 #else
58 #ifdef GEN_EXPORT
59 #define GEN_DLL __attribute__((visibility("default")))
60 #else
61 #define GEN_DLL
62 #endif
63 #endif
64 
65 struct OphPointCloudConfig;
66 struct OphPointCloudData;
67 struct OphDepthMapConfig;
68 struct OphMeshData;
69 struct OphWRPConfig;
70 
76 class GEN_DLL ophGen : public Openholo
77 {
78 public:
79  enum PRECISION {
82  };
83 
84  enum ENCODE_FLAG {
95  ENCODE_EDBINARY
96  };
97 
98 public:
102  explicit ophGen(void);
103 
104 protected:
108  virtual ~ophGen(void) = 0;
109 
110 public:
117  Real** getEncodedBuffer(void) { return m_lpEncoded; }
124  uchar** getNormalizedBuffer(void) { return m_lpNormalized; }
125 
129  void initialize(void);
130 
139  int loadPointCloud(const char* pc_file, OphPointCloudData *pc_data_);
140 
148  bool readConfig(const char* fname);
149 
158  void RS_Diffraction(Point src, Complex<Real> *dst, Real lambda, Real distance, Real amplitude);
159 
168  void Fresnel_Diffraction(Point src, Complex<Real> *dst, Real lambda, Real distance, Real amplitude);
169 
178  void Fresnel_FFT(Complex<Real> *src, Complex<Real> *dst, Real lambda, Real waveRatio, Real distance);
179 
180 
189  void AngularSpectrumMethod(Complex<Real>* src, Complex<Real>* dst, Real lambda, Real distance);
190 
198  void conv_fft2(Complex<Real>* src1, Complex<Real>* src2, Complex<Real>* dst, ivec2 size);
199 
200 
204  void normalize(void);
205  void normalize(uint ch);
206 
218  bool save(const char* fname, uint8_t bitsperpixel = 8, uchar* src = nullptr, uint px = 0, uint py = 0);
219 
224  void* load(const char* fname);
225 
233  virtual bool loadAsOhc(const char *fname);
234 
235 protected:
246  bool save(const char* fname, uint8_t bitsperpixel, uint px, uint py, uint fnum, uchar* args ...);
247 
252  void resetBuffer();
253 
254 
255 public:
260  void setPrecision(uint precision) { m_precision = precision; }
261  uint getPrecision() { return m_precision; }
262 
263  void setEncodeMethod(unsigned int ENCODE_FLAG) { ENCODE_METHOD = ENCODE_FLAG; }
264 
278  //void encoding(unsigned int ENCODE_FLAG, Complex<Real>* holo = nullptr);
279  void encoding(unsigned int ENCODE_FLAG);
280  void encoding(unsigned int ENCODE_FLAG, Complex<Real>* holo, Real* encoded);
281  //template<typename T>
282  //void encoding(unsigned int ENCODE_FLAG, Complex<T>* holo = nullptr, T* encoded = nullptr);
283 
284  void encoding();
285  /*
286  * @brief Encoding Functions
287  * @details
288  * ENCODE_SSB : Single Side Band Encoding@n
289  * ENCODE_OFFSSB : Off-axis + Single Side Band Encoding@n
290  * @param[in] ENCODE_FLAG encoding method.
291  * @param[in] SSB_PASSBAND shift direction.
292  * @param[in] holo buffer to encode.
293  * @overload
294  */
295  virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND, Complex<Real>* holo = nullptr, Real* encoded = nullptr);
296  enum SSB_PASSBAND { SSB_LEFT, SSB_RIGHT, SSB_TOP, SSB_BOTTOM };
297 
315  void encoding(unsigned int BIN_ENCODE_FLAG, unsigned int ENCODE_FLAG, Real threshold, Complex<Real>* holo = nullptr, Real* encoded = nullptr);
316 
317 public:
318 
319  bool Shift(Real x, Real y);
326  void waveCarry(Real carryingAngleX, Real carryingAngleY, Real distance);
327 
328  void waveCarry(Complex<Real>* src, Complex<Real>* dst, Real wavelength, int carryIdxX, int carryIdxY);
329 protected:
342 
343 private:
345  uint m_nOldChannel;
346  uint m_precision;
347 
348 protected:
351  unsigned int m_mode;
352 
353 public:
354  void transVW(int nVertex, Vertex *dst, Vertex *src);
355  void transVW(int nVertex, Real *dst, Real *src);
356  int getStream() { return m_nStream; }
357  Real getFieldLength() { return m_dFieldLength; }
364  ivec2& getEncodeSize(void) { return m_vecEncodeSize; }
365 
370  void setResolution(ivec2 resolution);
371 
377  Real getElapsedTime() { return m_elapsedTime; };
378 
379 protected:
386  template <typename T>
387  void RealPart(Complex<T>* holo, T* encoded, const int size);
388  template <typename T>
389  void ImaginaryPart(Complex<T>* holo, T* encoded, const int size);
390  template <typename T>
391  void Phase(Complex<T>* holo, T* encoded, const int size);
392  template <typename T>
393  void Amplitude(Complex<T>* holo, T* encoded, const int size);
394  template <typename T>
395  void TwoPhase(Complex<T>* holo, T* encoded, const int size);
396  template <typename T>
397  void Burckhardt(Complex<T>* holo, T* encoded, const int size);
398  template <typename T>
399  void SimpleNI(Complex<T>* holo, T* encoded, const int size);
400 
408  void singleSideBand(Complex<Real>* holo, Real* encoded, const ivec2 holosize, int passband);
409 
418  void freqShift(Complex<Real>* holo, Complex<Real>* encoded, const ivec2 holosize, int shift_x, int shift_y);
419 
420 
421 public:
422  enum ED_WType { FLOYD_STEINBERG, SINGLE_RIGHT, SINGLE_DOWN, ITERATIVE_DESIGN };
423  bool saveRefImages(char* fnameW, char* fnameWC, char* fnameAS, char* fnameSSB, char* fnameHP, char* fnameFreq, char* fnameReal, char* fnameBin, char* fnameReconBin, char* fnameReconErr, char* fnameReconNo);
424 
425 protected:
438 
439  bool binaryErrorDiffusion(Complex<Real>* holo, Real* encoded, const ivec2 holosize, const int type, Real threshold);
440  bool getWeightED(const ivec2 holosize, const int type, ivec2* pNw);
441  bool shiftW(ivec2 holosize);
442  void binarization(Complex<Real>* src, Real* dst, const int size, int ENCODE_FLAG, Real threshold);
443  void CorrectionChromaticAberration(uchar* src, uchar* dst, int width, int height, int ch);
444 
445  //public:
446  //bool carrierWaveMultiplexingEncoding(char* dirName, uint ENCODE_METHOD, Real cenFxIdx, Real cenFyIdx, Real stepFx, Real stepFy, int nFx, int nFy);
447  //bool carrierWaveMultiplexingEncoding(char* dirName, uint ENCODE_METHOD, uint PASSBAND, Real cenFxIdx, Real cenFyIdx, Real stepFx, Real stepFy, int nFx, int nFy);
448 
449  //protected:
450 
451 
452 
453 public:
461  void fresnelPropagation(OphConfig context, Complex<Real>* in, Complex<Real>* out, Real distance);
469  void fresnelPropagation(Complex<Real>* in, Complex<Real>* out, Real distance, uint channel);
470 protected:
478  void encodeSideBand(bool bCPU, ivec2 sig_location);
490  void encodeSideBand_CPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
491 
503  void encodeSideBand_GPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
504 
512  void getShiftPhaseValue(Complex<Real>& shift_phase_val, int idx, ivec2 sig_location);
513 
521  void GetRandomPhaseValue(Complex<Real>& rand_phase_val, bool rand_phase);
522 
523  void ScaleChange(Real *src, Real *dst, int nSize, Real scaleX, Real scaleY, Real scaleZ);
524  void GetMaxMin(Real *src, int len, Real& max, Real& min);
525 
526 public:
530  void SetRandomPhase(bool bRandomPhase) { m_bRandomPhase = bRandomPhase; }
531 
538  bool GetRandomPhase() { return m_bRandomPhase; }
539  void SetMode(unsigned int mode) { m_mode = mode; }
540  unsigned int GetMode() { return m_mode; }
541 
542 
543 
544 protected:
545 
549  virtual void ophFree(void);
550 };
551 
573 
575  : scale(0.0, 0.0, 0.0), distance(0.0), filter_shape_flag(0), focal_length_lens_in(0.0), focal_length_lens_out(0.0), focal_length_lens_eye_piece(0.0), tilt_angle(0.0, 0.0)
576  {}
577 };
578 
587  int n_colors;
590 
591  OphPointCloudData() : n_points(0), n_colors(0), vertices(nullptr) {}
592 };
593 
627  vector<int> render_depth;
636 
637  OphDepthMapConfig() :fieldLength(0.0), near_depthmap(0.0), far_depthmap(0.0), num_of_depth(0), change_depth_quantization(false)
638  , default_depth_quantization(0), num_of_depth_quantization(0), random_phase(false) {}
639 };
640 
647  ulonglong n_faces = 0;
649  OphMeshData() : faces(nullptr) { n_faces = 0; }
650 };
651 
662  int num_wrp;
667 
669  : fieldLength(0.0), scale(0.0, 0.0, 0.0), num_wrp(0), wrp_location(0.0), propagation_distance(0.0)
670  { }
671 
672  OphWRPConfig(Real _fieldLength, vec3 _scale, int _num_wrp, Real _wrp_location, Real _propagation_distance)
673  : fieldLength(_fieldLength), scale(_scale), num_wrp(_num_wrp), wrp_location(_wrp_location), propagation_distance(_propagation_distance)
674  { }
675 };
676 
687 
689 
690  OphIFTAConfig() :near_depthmap(0), far_depthmap(0), num_of_depth(0), num_of_iteration(0) {}
691  OphIFTAConfig(Real _near_depthmap, Real _far_depthmap, int _num_of_depth, int _num_of_iteration)
692  :near_depthmap(_near_depthmap), far_depthmap(_far_depthmap), num_of_depth(_num_of_depth), num_of_iteration(_num_of_iteration) {}
693 };
694 
695 
696 #endif // !__ophGen_h
697 
ENCODE_FLAG
Definition: ophGen.h:84
Real focal_length_lens_eye_piece
Focal length of eyepiece lens.
Definition: ophGen.h:570
Abstract class.
Definition: Openholo.h:109
OphWRPConfig(Real _fieldLength, vec3 _scale, int _num_wrp, Real _wrp_location, Real _propagation_distance)
Definition: ophGen.h:672
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:615
Real distance
Offset value of point cloud.
Definition: ophGen.h:560
uint num_of_depth
Definition: ophGen.h:625
Real * weight
Definition: ophGen.h:430
OphIFTAConfig(Real _near_depthmap, Real _far_depthmap, int _num_of_depth, int _num_of_iteration)
Definition: ophGen.h:691
ulonglong n_points
Number of points.
Definition: ophGen.h:585
SSB_PASSBAND
Definition: ophGen.h:296
unsigned char uchar
Definition: typedef.h:64
Configuration for WRP.
Definition: ophGen.h:656
Complex< Real > * weightC
Definition: ophGen.h:431
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:658
Real m_dFieldLength
Definition: ophGen.h:349
uchar ** getNormalizedBuffer(void)
Function for getting the normalized(0~255) complex field buffer.
Definition: ophGen.h:124
Real ** m_lpEncoded
buffer to encoded.
Definition: ophGen.h:339
Real focal_length_lens_out
Focal length of output lens of Telecentric.
Definition: ophGen.h:568
vec2 tilt_angle
Tilt angle for spatial filtering.
Definition: ophGen.h:572
float Real
Definition: typedef.h:55
ivec2 & getEncodeSize(void)
Function for getting encode size.
Definition: ophGen.h:364
Definition: struct.h:86
OphWRPConfig()
Definition: ophGen.h:668
int num_wrp
Number of wavefront recording plane(WRP)
Definition: ophGen.h:662
unsigned int GetMode()
Definition: ophGen.h:540
Real focal_length_lens_in
Focal length of input lens of Telecentric.
Definition: ophGen.h:566
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
bool GetRandomPhase()
Function for getting the random phase.
Definition: ophGen.h:538
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 SetMode(unsigned int mode)
Definition: ophGen.h:539
bool random_phase
If true, random phase is imposed on each depth layer.
Definition: ophGen.h:635
PRECISION
Definition: ophGen.h:79
Real getFieldLength()
Definition: ophGen.h:357
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:660
void setEncodeMethod(unsigned int ENCODE_FLAG)
Definition: ophGen.h:263
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:558
OphMeshData()
Definition: ophGen.h:649
Real m_elapsedTime
Elapsed time of generate hologram.
Definition: ophGen.h:337
unsigned long long ulonglong
Definition: typedef.h:67
ivec2 m_vecEncodeSize
Encoded hologram size, varied from encoding type.
Definition: ophGen.h:331
unsigned int m_mode
Definition: ophGen.h:351
Complex< Real > * freqW
Definition: ophGen.h:432
Real near_depthmap
near value of depth in object
Definition: ophGen.h:617
Real ** getEncodedBuffer(void)
Function for getting the encoded complex field buffer.
Definition: ophGen.h:117
OphIFTAConfig()
Definition: ophGen.h:690
ED_WType
Definition: ophGen.h:422
Real wrp_location
Location distance of WRP.
Definition: ophGen.h:664
uint getPrecision()
Definition: ophGen.h:261
bool m_bRandomPhase
Definition: ophGen.h:437
#define GEN_DLL
Definition: ophGen.h:61
structure for 2-dimensional Real type vector and its arithmetic.
Definition: vec.h:66
Complex< Real > * fftTemp
Definition: ophGen.h:429
Real far_depthmap
far value of depth in object
Definition: ophGen.h:619
Definition: struct.h:102
Real near_depthmap
near value of depth in object
Definition: ophGen.h:682
Real getElapsedTime()
Function for getting elapsed time.
Definition: ophGen.h:377
Real * realEnc
Definition: ophGen.h:433
Data for triangular mesh.
Definition: ophGen.h:645
int8_t * filter_shape_flag
Shape of spatial bandpass filter ("Circle" or "Rect" for now)
Definition: ophGen.h:562
structure for 3-dimensional Real type vector and its arithmetic.
Definition: vec.h:466
int SSB_PASSBAND
Passband in Single-side band encoding.
Definition: ophGen.h:335
int n_colors
Number of color channel.
Definition: ophGen.h:587
Vertex * vertices
Data of point clouds.
Definition: ophGen.h:589
int getStream()
Definition: ophGen.h:356
virtual bool loadAsOhc(const char *fname)
Function to read OHC file.
Definition: Openholo.cpp:280
Definition: struct.h:115
int num_of_depth
num_of_depth = num_of_depth_quantization
Definition: ophGen.h:686
Face * faces
Definition: ophGen.h:648
vec2 filter_width
Width of spatial bandpass filter.
Definition: ophGen.h:564
int num_of_iteration
Definition: ophGen.h:688
Configuration for Point Cloud.
Definition: ophGen.h:556
uchar ** m_lpNormalized
buffer to normalized.
Definition: ophGen.h:341
Complex< Real > * AS
Binary Encoding - Error diffusion.
Definition: ophGen.h:427
uint num_of_depth_quantization
depth level of input depthmap.
Definition: ophGen.h:633
Data for Point Cloud.
Definition: ophGen.h:583
Real propagation_distance
Distance of Hologram plane.
Definition: ophGen.h:666
void SetRandomPhase(bool bRandomPhase)
Function for setting the random phase.
Definition: ophGen.h:530
bool change_depth_quantization
if true, change the depth quantization from the default value.
Definition: ophGen.h:629
Complex< Real > * normalized
Definition: ophGen.h:428
int m_nStream
Definition: ophGen.h:350
Real far_depthmap
far value of depth in object
Definition: ophGen.h:684
vector< int > render_depth
Used when only few specific depth levels are rendered, usually for test purpose.
Definition: ophGen.h:627
uint default_depth_quantization
default value of the depth quantization - 256
Definition: ophGen.h:631
int ENCODE_METHOD
Encoding method flag.
Definition: ophGen.h:333
void setPrecision(uint precision)
Function for setting precision.
Definition: ophGen.h:260
unsigned int uint
Definition: typedef.h:62
virtual void ophFree(void)
Pure virtual function for override in child classes.
Definition: Openholo.cpp:805
Real * maskHP
Definition: ophGen.h:436
Definition: ophGen.h:76
Configuration for Depth Map.
Definition: ophGen.h:613
Real * binary
Definition: ophGen.h:434
Real * maskSSB
Definition: ophGen.h:435