Openholo  v5.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 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 
217  bool save(const char* fname, uint8_t bitsperpixel = 8, uchar* src = nullptr, uint px = 0, uint py = 0);
218 
223  void* load(const char* fname);
224 
232  virtual bool loadAsOhc(const char *fname);
233 
234 protected:
245  bool save(const char* fname, uint8_t bitsperpixel, uint px, uint py, uint fnum, uchar* args ...);
246 
251  void resetBuffer();
252 
253 
254 public:
259  void setPrecision(uint precision) { m_precision = precision; }
260  uint getPrecision() { return m_precision; }
261 
262  void setEncodeMethod(unsigned int ENCODE_FLAG) { ENCODE_METHOD = ENCODE_FLAG; }
263 
277  //void encoding(unsigned int ENCODE_FLAG, Complex<Real>* holo = nullptr);
278  void encoding(unsigned int ENCODE_FLAG);
279  void encoding(unsigned int ENCODE_FLAG, Complex<Real>* holo, Real* encoded);
280  //template<typename T>
281  //void encoding(unsigned int ENCODE_FLAG, Complex<T>* holo = nullptr, T* encoded = nullptr);
282 
283  void encoding();
284  /*
285  * @brief Encoding Functions
286  * @details
287  * ENCODE_SSB : Single Side Band Encoding@n
288  * ENCODE_OFFSSB : Off-axis + Single Side Band Encoding@n
289  * @param[in] ENCODE_FLAG encoding method.
290  * @param[in] SSB_PASSBAND shift direction.
291  * @param[in] holo buffer to encode.
292  * @overload
293  */
294  virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND, Complex<Real>* holo = nullptr, Real* encoded = nullptr);
295  enum SSB_PASSBAND { SSB_LEFT, SSB_RIGHT, SSB_TOP, SSB_BOTTOM };
296 
314  void encoding(unsigned int BIN_ENCODE_FLAG, unsigned int ENCODE_FLAG, Real threshold, Complex<Real>* holo = nullptr, Real* encoded = nullptr);
315 
316 public:
317 
318  bool Shift(Real x, Real y);
325  void waveCarry(Real carryingAngleX, Real carryingAngleY, Real distance);
326 
327  void waveCarry(Complex<Real>* src, Complex<Real>* dst, Real wavelength, int carryIdxX, int carryIdxY);
328 protected:
341 
342 private:
344  uint m_nOldChannel;
345  uint m_precision;
346 
347 protected:
350  unsigned int m_mode;
351 
352 public:
353  void transVW(int nVertex, Vertex *dst, Vertex *src);
354  void transVW(int nVertex, Real *dst, Real *src);
355  int getStream() { return m_nStream; }
356  Real getFieldLength() { return m_dFieldLength; }
363  ivec2& getEncodeSize(void) { return m_vecEncodeSize; }
364 
369  void setResolution(ivec2 resolution);
370 
376  Real getElapsedTime() { return m_elapsedTime; };
377 
378 protected:
385  template <typename T>
386  void RealPart(Complex<T>* holo, T* encoded, const int size);
387  template <typename T>
388  void ImaginaryPart(Complex<T>* holo, T* encoded, const int size);
389  template <typename T>
390  void Phase(Complex<T>* holo, T* encoded, const int size);
391  template <typename T>
392  void Amplitude(Complex<T>* holo, T* encoded, const int size);
393  template <typename T>
394  void TwoPhase(Complex<T>* holo, T* encoded, const int size);
395  template <typename T>
396  void Burckhardt(Complex<T>* holo, T* encoded, const int size);
397  template <typename T>
398  void SimpleNI(Complex<T>* holo, T* encoded, const int size);
399 
407  void singleSideBand(Complex<Real>* holo, Real* encoded, const ivec2 holosize, int passband);
408 
417  void freqShift(Complex<Real>* holo, Complex<Real>* encoded, const ivec2 holosize, int shift_x, int shift_y);
418 
419 
420 public:
421  enum ED_WType { FLOYD_STEINBERG, SINGLE_RIGHT, SINGLE_DOWN, ITERATIVE_DESIGN };
422  bool saveRefImages(char* fnameW, char* fnameWC, char* fnameAS, char* fnameSSB, char* fnameHP, char* fnameFreq, char* fnameReal, char* fnameBin, char* fnameReconBin, char* fnameReconErr, char* fnameReconNo);
423 
424 protected:
437 
438  bool binaryErrorDiffusion(Complex<Real>* holo, Real* encoded, const ivec2 holosize, const int type, Real threshold);
439  bool getWeightED(const ivec2 holosize, const int type, ivec2* pNw);
440  bool shiftW(ivec2 holosize);
441  void binarization(Complex<Real>* src, Real* dst, const int size, int ENCODE_FLAG, Real threshold);
442 
443  void CorrectionChromaticAberration(uchar* src, uchar* dst, int width, int height, int scaleFactor = 2);
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(Complex<Real>* in, Complex<Real>* out, Real distance, uint channel);
462 protected:
468  void encodeSideBand(unsigned int passband);
480  void encodeSideBand_CPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
481 
493  void encodeSideBand_GPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
494 
502  void getShiftPhaseValue(Complex<Real>& shift_phase_val, int idx, ivec2 sig_location);
503 
511  void GetRandomPhaseValue(Complex<Real>& rand_phase_val, bool rand_phase);
512 
513  void ScaleChange(Real *src, Real *dst, int nSize, Real scaleX, Real scaleY, Real scaleZ);
514  void GetMaxMin(Real *src, int len, Real& max, Real& min);
515 
516 public:
520  void SetRandomPhase(bool bRandomPhase) { m_bRandomPhase = bRandomPhase; }
521 
528  bool GetRandomPhase() { return m_bRandomPhase; }
529  void SetMode(unsigned int mode) { m_mode = mode; }
530  unsigned int GetMode() { return m_mode; }
531 
532 
533 
534 protected:
535 
539  virtual void ophFree(void);
540 };
541 
563 
565  : 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)
566  {}
567 };
568 
577  int n_colors;
580 
581  OphPointCloudData() : n_points(0), n_colors(0), vertices(nullptr) {}
582 };
583 
617  vector<int> render_depth;
626 
627  OphDepthMapConfig() :fieldLength(0.0), near_depthmap(0.0), far_depthmap(0.0), num_of_depth(0), change_depth_quantization(false)
628  , default_depth_quantization(0), num_of_depth_quantization(0), random_phase(false) {}
629 };
630 
637  ulonglong n_faces = 0;
639  OphMeshData() : faces(nullptr) { n_faces = 0; }
640 };
641 
652  int num_wrp;
657 
659  : fieldLength(0.0), scale(0.0, 0.0, 0.0), num_wrp(0), wrp_location(0.0), propagation_distance(0.0)
660  { }
661 
662  OphWRPConfig(Real _fieldLength, vec3 _scale, int _num_wrp, Real _wrp_location, Real _propagation_distance)
663  : fieldLength(_fieldLength), scale(_scale), num_wrp(_num_wrp), wrp_location(_wrp_location), propagation_distance(_propagation_distance)
664  { }
665 };
666 
677 
679 
680  OphIFTAConfig() :near_depthmap(0), far_depthmap(0), num_of_depth(0), num_of_iteration(0) {}
681  OphIFTAConfig(Real _near_depthmap, Real _far_depthmap, int _num_of_depth, int _num_of_iteration)
682  :near_depthmap(_near_depthmap), far_depthmap(_far_depthmap), num_of_depth(_num_of_depth), num_of_iteration(_num_of_iteration) {}
683 };
684 
685 
686 #endif // !__ophGen_h
687 
ENCODE_FLAG
Definition: ophGen.h:84
Real focal_length_lens_eye_piece
Focal length of eyepiece lens.
Definition: ophGen.h:560
Abstract class.
Definition: Openholo.h:145
OphWRPConfig(Real _fieldLength, vec3 _scale, int _num_wrp, Real _wrp_location, Real _propagation_distance)
Definition: ophGen.h:662
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:605
Real distance
Offset value of point cloud.
Definition: ophGen.h:550
uint num_of_depth
Definition: ophGen.h:615
Real * weight
Definition: ophGen.h:429
OphIFTAConfig(Real _near_depthmap, Real _far_depthmap, int _num_of_depth, int _num_of_iteration)
Definition: ophGen.h:681
ulonglong n_points
Number of points.
Definition: ophGen.h:575
SSB_PASSBAND
Definition: ophGen.h:295
unsigned char uchar
Definition: typedef.h:64
Configuration for WRP.
Definition: ophGen.h:646
Complex< Real > * weightC
Definition: ophGen.h:430
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:648
Real m_dFieldLength
Definition: ophGen.h:348
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:338
Real focal_length_lens_out
Focal length of output lens of Telecentric.
Definition: ophGen.h:558
vec2 tilt_angle
Tilt angle for spatial filtering.
Definition: ophGen.h:562
float Real
Definition: typedef.h:55
ivec2 & getEncodeSize(void)
Function for getting encode size.
Definition: ophGen.h:363
Definition: struct.h:86
OphWRPConfig()
Definition: ophGen.h:658
int num_wrp
Number of wavefront recording plane(WRP)
Definition: ophGen.h:652
unsigned int GetMode()
Definition: ophGen.h:530
Real focal_length_lens_in
Focal length of input lens of Telecentric.
Definition: ophGen.h:556
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
bool GetRandomPhase()
Function for getting the random phase.
Definition: ophGen.h:528
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:529
bool random_phase
If true, random phase is imposed on each depth layer.
Definition: ophGen.h:625
PRECISION
Definition: ophGen.h:79
Real getFieldLength()
Definition: ophGen.h:356
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:650
void setEncodeMethod(unsigned int ENCODE_FLAG)
Definition: ophGen.h:262
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:548
OphMeshData()
Definition: ophGen.h:639
Real m_elapsedTime
Elapsed time of generate hologram.
Definition: ophGen.h:336
unsigned long long ulonglong
Definition: typedef.h:67
ivec2 m_vecEncodeSize
Encoded hologram size, varied from encoding type.
Definition: ophGen.h:330
unsigned int m_mode
Definition: ophGen.h:350
Complex< Real > * freqW
Definition: ophGen.h:431
Real near_depthmap
near value of depth in object
Definition: ophGen.h:607
Real ** getEncodedBuffer(void)
Function for getting the encoded complex field buffer.
Definition: ophGen.h:117
OphIFTAConfig()
Definition: ophGen.h:680
ED_WType
Definition: ophGen.h:421
Real wrp_location
Location distance of WRP.
Definition: ophGen.h:654
uint getPrecision()
Definition: ophGen.h:260
bool m_bRandomPhase
Definition: ophGen.h:436
#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:428
Real far_depthmap
far value of depth in object
Definition: ophGen.h:609
Definition: struct.h:102
Real near_depthmap
near value of depth in object
Definition: ophGen.h:672
Real getElapsedTime()
Function for getting elapsed time.
Definition: ophGen.h:376
Real * realEnc
Definition: ophGen.h:432
Data for triangular mesh.
Definition: ophGen.h:635
int8_t * filter_shape_flag
Shape of spatial bandpass filter ("Circle" or "Rect" for now)
Definition: ophGen.h:552
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:334
int n_colors
Number of color channel.
Definition: ophGen.h:577
Vertex * vertices
Data of point clouds.
Definition: ophGen.h:579
int getStream()
Definition: ophGen.h:355
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:676
Face * faces
Definition: ophGen.h:638
vec2 filter_width
Width of spatial bandpass filter.
Definition: ophGen.h:554
int num_of_iteration
Definition: ophGen.h:678
Configuration for Point Cloud.
Definition: ophGen.h:546
uchar ** m_lpNormalized
buffer to normalized.
Definition: ophGen.h:340
Complex< Real > * AS
Binary Encoding - Error diffusion.
Definition: ophGen.h:426
uint num_of_depth_quantization
depth level of input depthmap.
Definition: ophGen.h:623
Data for Point Cloud.
Definition: ophGen.h:573
Real propagation_distance
Distance of Hologram plane.
Definition: ophGen.h:656
void SetRandomPhase(bool bRandomPhase)
Function for setting the random phase.
Definition: ophGen.h:520
bool change_depth_quantization
if true, change the depth quantization from the default value.
Definition: ophGen.h:619
Complex< Real > * normalized
Definition: ophGen.h:427
int m_nStream
Definition: ophGen.h:349
Real far_depthmap
far value of depth in object
Definition: ophGen.h:674
vector< int > render_depth
Used when only few specific depth levels are rendered, usually for test purpose.
Definition: ophGen.h:617
uint default_depth_quantization
default value of the depth quantization - 256
Definition: ophGen.h:621
int ENCODE_METHOD
Encoding method flag.
Definition: ophGen.h:332
void setPrecision(uint precision)
Function for setting precision.
Definition: ophGen.h:259
unsigned int uint
Definition: typedef.h:62
virtual void ophFree(void)
Pure virtual function for override in child classes.
Definition: Openholo.cpp:811
Real * maskHP
Definition: ophGen.h:435
Definition: ophGen.h:76
Configuration for Depth Map.
Definition: ophGen.h:603
Real * binary
Definition: ophGen.h:433
Real * maskSSB
Definition: ophGen.h:434