Openholo  v1.1
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 GEN_EXPORT
52 #define GEN_DLL __declspec(dllexport)
53 #else
54 #define GEN_DLL __declspec(dllimport)
55 #endif
56 
57 struct OphPointCloudConfig;
58 struct OphPointCloudData;
59 struct OphDepthMapConfig;
60 struct OphMeshData;
61 struct OphWRPConfig;
62 
68 class GEN_DLL ophGen : public Openholo
69 {
70 public:
71 
72  enum ENCODE_FLAG {
83  ENCODE_EDBINARY
84  };
85 
86 public:
90  explicit ophGen(void);
91 
92 protected:
96  virtual ~ophGen(void) = 0;
97 
98 public:
105  inline Real** getEncodedBuffer(void) { return m_lpEncoded; }
112  inline uchar** getNormalizedBuffer(void) { return m_lpNormalized; }
113 
117  void initialize(void);
118 
127  int loadPointCloud(const char* pc_file, OphPointCloudData *pc_data_);
128 
136  bool readConfig(const char* fname);
137 
147  void propagationAngularSpectrum(int ch, Complex<Real>* input_u, Real propagation_dist, Real k, Real lambda);
148 
156  void conv_fft2(Complex<Real>* src1, Complex<Real>* src2, Complex<Real>* dst, ivec2 size);
157 
158 
162  void normalize(void);
163 
175  bool save(const char* fname, uint8_t bitsperpixel = 8, uchar* src = nullptr, uint px = 0, uint py = 0);
176 
181  void* load(const char* fname);
182 
190  virtual bool loadAsOhc(const char *fname);
191 
192  bool mergeColor(int idx, int width, int height, uchar *src, uchar *dst);
193  bool separateColor(int idx, int width, int height, uchar *src, uchar *dst);
194 
195 protected:
206  bool save(const char* fname, uint8_t bitsperpixel, uint px, uint py, uint fnum, uchar* args ...);
207 
212  void resetBuffer();
213 
214 
215 public:
216 
217  void setEncodeMethod(unsigned int ENCODE_FLAG) { ENCODE_METHOD = ENCODE_FLAG; }
218 
232  //void encoding(unsigned int ENCODE_FLAG, Complex<Real>* holo = nullptr);
233  void encoding(unsigned int ENCODE_FLAG, Complex<Real>* holo = nullptr, Real* encoded = nullptr);
234 
235  void encoding();
236  /*
237  * @brief Encoding Functions
238  * @details
239  * ENCODE_SSB : Single Side Band Encoding@n
240  * ENCODE_OFFSSB : Off-axis + Single Side Band Encoding@n
241  * @param[in] ENCODE_FLAG encoding method.
242  * @param[in] SSB_PASSBAND shift direction.
243  * @param[in] holo buffer to encode.
244  * @overload
245  */
246  virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND, Complex<Real>* holo = nullptr, Real* encoded = nullptr);
247  enum SSB_PASSBAND { SSB_LEFT, SSB_RIGHT, SSB_TOP, SSB_BOTTOM };
248 
266  void encoding(unsigned int BIN_ENCODE_FLAG, unsigned int ENCODE_FLAG, Real threshold, Complex<Real>* holo = nullptr, Real* encoded = nullptr);
267 
268 public:
269 
270  bool Shift(Real x, Real y);
277  void waveCarry(Real carryingAngleX, Real carryingAngleY, Real distance);
278 
279  void waveCarry(Complex<Real>* src, Complex<Real>* dst, Real wavelength, int carryIdxX, int carryIdxY);
280 protected:
293 
294 private:
296  int m_nOldChannel;
297 
298 protected:
301 
303  Complex<Real>* src1FT;
304  Complex<Real>* src2FT;
305  Complex<Real>* dstFT;
306 
307 public:
308  void transVW(int nSize, Real *dst, Real *src);
309  int getStream() { return m_nStream; }
310  Real getFieldLength() { return m_dFieldLength; }
317  ivec2& getEncodeSize(void) { return m_vecEncodeSize; }
318 
323  void setResolution(ivec2 resolution);
324 
330  Real getElapsedTime() { return m_elapsedTime; };
331 
332 protected:
339  void RealPart(Complex<Real>* holo, Real* encoded, const int size);
340  void ImaginearyPart(Complex<Real>* holo, Real* encoded, const int size);
341 
342  void Phase(Complex<Real>* holo, Real* encoded, const int size);
343  void Amplitude(Complex<Real>* holo, Real* encoded, const int size);
344  void TwoPhase(Complex<Real>* holo, Real* encoded, const int size);
345  void Burckhardt(Complex<Real>* holo, Real* encoded, const int size);
346  void SimpleNI(Complex<Real>* holo, Real* encoded, const int size);
347 
355  void singleSideBand(Complex<Real>* holo, Real* encoded, const ivec2 holosize, int passband);
356 
365  void freqShift(Complex<Real>* src, Complex<Real>* dst, const ivec2 holosize, int shift_x, int shift_y);
366 
367 
368 public:
369  enum ED_WType { FLOYD_STEINBERG, SINGLE_RIGHT, SINGLE_DOWN, ITERATIVE_DESIGN };
370  bool saveRefImages(char* fnameW, char* fnameWC, char* fnameAS, char* fnameSSB, char* fnameHP, char* fnameFreq, char* fnameReal, char* fnameBin, char* fnameReconBin, char* fnameReconErr, char* fnameReconNo);
371 
372 protected:
374  int ss;
375  Complex<Real>* AS;
376  Complex<Real>* normalized;
377  Complex<Real>* fftTemp;
379  Complex<Real>* weightC;
380  Complex<Real>* freqW;
385 
386  bool binaryErrorDiffusion(Complex<Real>* holo, Real* encoded, const ivec2 holosize, const int type, Real threshold);
387  bool getWeightED(const ivec2 holosize, const int type, ivec2* pNw);
388  bool shiftW(ivec2 holosize);
389  void binarization(Complex<Real>* src, Real* dst, const int size, int ENCODE_FLAG, Real threshold);
390 
391 
392  //public:
393  //bool carrierWaveMultiplexingEncoding(char* dirName, uint ENCODE_METHOD, Real cenFxIdx, Real cenFyIdx, Real stepFx, Real stepFy, int nFx, int nFy);
394  //bool carrierWaveMultiplexingEncoding(char* dirName, uint ENCODE_METHOD, uint PASSBAND, Real cenFxIdx, Real cenFyIdx, Real stepFx, Real stepFy, int nFx, int nFy);
395 
396  //protected:
397 
398 
399 
400 public:
408  void fresnelPropagation(OphConfig context, Complex<Real>* in, Complex<Real>* out, Real distance);
416  void fresnelPropagation(Complex<Real>* in, Complex<Real>* out, Real distance, uint channel);
417 protected:
425  void encodeSideBand(bool bCPU, ivec2 sig_location);
437  void encodeSideBand_CPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
438 
450  void encodeSideBand_GPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
451 
459  void getShiftPhaseValue(Complex<Real>& shift_phase_val, int idx, ivec2 sig_location);
460 
468  void getRandPhaseValue(Complex<Real>& rand_phase_val, bool rand_phase);
469 
470  void ScaleChange(Real *src, Real *dst, int nSize, Real scaleX, Real scaleY, Real scaleZ);
471  void GetMaxMin(Real *src, int len, Real& max, Real& min);
472 
473 public:
474 
475  void AngularSpectrum(Complex<Real> *src, Complex<Real> *dst, Real lambda, Real distance);
476  void RS_Propagation(vec3 src, Complex<Real> *dst, Real lambda, Real distance, Real amplitude);
477  void RS_Propagation(uchar *src, Complex<Real> *dst, Real lambda, Real distance);
478  void Fresnel_Convolution(vec3 src, Complex<Real> *dst, Real lambda, Real distance, Real amplitude);
479  void Fresnel_FFT(Complex<Real> *src, Complex<Real> *dst, Real lambda, Real waveRatio, Real distance);
480  bool readImage(const char* fname, bool bRGB);
481 
484  int m_width;
485  int m_height;
486  int m_bpp;
487 protected:
491  virtual void ophFree(void);
492 };
493 
500  vec3 scale;
515 
517  : scale(0, 0, 0), distance(0), filter_shape_flag(0), focal_length_lens_in(0), focal_length_lens_out(0), focal_length_lens_eye_piece(0), tilt_angle(0, 0)
518  {}
519 };
520 
529  int n_colors;
538 
539  OphPointCloudData() :vertex(nullptr), color(nullptr), phase(nullptr) { n_points = 0; n_colors = 0; isPhaseParse = 0; }
540 };
541 
575  vector<int> render_depth;
584 
585  OphDepthMapConfig() :fieldLength(0), near_depthmap(0), far_depthmap(0), num_of_depth(0) {}
586 };
587 
594  ulonglong n_faces = 0;
603 };
604 
613  vec3 scale;
615  int num_wrp;
620 
621 };
622 
633 
635 
636  OphIFTAConfig() :near_depthmap(0), far_depthmap(0), num_of_depth(0), num_of_iteration(0) {}
637 };
638 #endif // !__ophGen_h
639 
ENCODE_FLAG
Definition: ophGen.h:72
uchar * imgRGB
Definition: ophGen.h:482
Real focal_length_lens_eye_piece
Focal length of eyepiece lens.
Definition: ophGen.h:512
Abstract class.
Definition: Openholo.h:84
Real * vertex
Geometry of point clouds.
Definition: ophGen.h:531
int color_channels
The number of color.
Definition: ophGen.h:596
uint DEFAULT_DEPTH_QUANTIZATION
default value of the depth quantization - 256
Definition: ophGen.h:579
Complex< Real > * freqW
Definition: ophGen.h:380
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:563
Complex< Real > * normalized
Definition: ophGen.h:376
Real * phase
Phase value of point clouds.
Definition: ophGen.h:535
Real distance
Offset value of point cloud.
Definition: ophGen.h:502
bool RANDOM_PHASE
If true, random phase is imposed on each depth layer.
Definition: ophGen.h:583
uint num_of_depth
Definition: ophGen.h:573
Complex< Real > * dstFT
Definition: ophGen.h:305
ulonglong n_points
Number of points.
Definition: ophGen.h:527
unsigned char uchar
Definition: typedef.h:64
Configuration for WRP.
Definition: ophGen.h:609
Real * color
Color array.
Definition: ophGen.h:602
#define GEN_DLL
Definition: ophGen.h:54
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:611
Real * maskHP
Definition: ophGen.h:384
Real m_dFieldLength
Definition: ophGen.h:299
float scaleX
Definition: FFT_method.py:20
uchar ** getNormalizedBuffer(void)
Function for getting the normalized(0~255) complex field buffer.
Definition: ophGen.h:112
Real focal_length_lens_out
Focal length of output lens of Telecentric.
Definition: ophGen.h:510
vec2 tilt_angle
Tilt angle for spatial filtering.
Definition: ophGen.h:514
ivec2 & getEncodeSize(void)
Function for getting encode size.
Definition: ophGen.h:317
Complex< Real > * src1FT
buffer to conv_fft2
Definition: ophGen.h:303
int num_wrp
Number of wavefront recording plane(WRP)
Definition: ophGen.h:615
Real focal_length_lens_in
Focal length of input lens of Telecentric.
Definition: ophGen.h:508
bool FLAG_CHANGE_DEPTH_QUANTIZATION
if true, change the depth quantization from the default value.
Definition: ophGen.h:577
crop phase
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
uchar * imgDepth
Definition: ophGen.h:483
vector< int > render_depth
Used when only few specific depth levels are rendered, usually for test purpose.
Definition: ophGen.h:575
Real getFieldLength()
Definition: ophGen.h:310
Real * color
Color data of point clouds.
Definition: ophGen.h:533
float scaleZ
Definition: 2D-RS.py:20
Complex< Real > * fftTemp
Definition: ophGen.h:377
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:613
def k(wvl)
Definition: Depthmap.py:16
void setEncodeMethod(unsigned int ENCODE_FLAG)
Definition: ophGen.h:217
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:500
Complex image ch
uint NUMBER_OF_DEPTH_QUANTIZATION
depth level of input depthmap.
Definition: ophGen.h:581
Real m_elapsedTime
Elapsed time of generate hologram.
Definition: ophGen.h:288
unsigned long long ulonglong
Definition: typedef.h:67
ivec2 m_vecEncodeSize
Encoded hologram size, varied from encoding type.
Definition: ophGen.h:282
Real near_depthmap
near value of depth in object
Definition: ophGen.h:565
Real ** getEncodedBuffer(void)
Function for getting the encoded complex field buffer.
Definition: ophGen.h:105
OphIFTAConfig()
Definition: ophGen.h:636
ED_WType
Definition: ophGen.h:369
Real wrp_location
Location distance of WRP.
Definition: ophGen.h:617
Real * weight
Definition: ophGen.h:378
Real ** m_lpEncoded
buffer to encoded.
Definition: ophGen.h:290
int m_width
Definition: ophGen.h:484
Real far_depthmap
far value of depth in object
Definition: ophGen.h:567
Real near_depthmap
near value of depth in object
Definition: ophGen.h:628
int ss
Binary Encoding - Error diffusion.
Definition: ophGen.h:374
Real getElapsedTime()
Function for getting elapsed time.
Definition: ophGen.h:330
Real * vertex
Vertex array.
Definition: ophGen.h:600
Complex< Real > * src2FT
Definition: ophGen.h:304
Data for triangular mesh.
Definition: ophGen.h:592
__managed__ float amplitude
Definition: ophPAS_GPU.cpp:28
Complex< Real > * weightC
Definition: ophGen.h:379
SSB_PASSBAND
Passband in Single-side band encoding.
Definition: ophGen.h:247
int n_colors
Number of color channel.
Definition: ophGen.h:529
int getStream()
Definition: ophGen.h:309
virtual bool loadAsOhc(const char *fname)
Function to read OHC file.
Definition: Openholo.cpp:287
bool isPhaseParse
Selects wheter to parse the phase data.
Definition: ophGen.h:537
int num_of_depth
num_of_depth = NUMBER_OF_DEPTH_QUANTIZATION
Definition: ophGen.h:632
Real * maskSSB
Definition: ophGen.h:383
vec2 filter_width
Width of spatial bandpass filter.
Definition: ophGen.h:506
int num_of_iteration
Definition: ophGen.h:634
Configuration for Point Cloud.
Definition: ophGen.h:498
Data for Point Cloud.
Definition: ophGen.h:525
Real propagation_distance
Distance of Hologram plane.
Definition: ophGen.h:619
float Real
Definition: typedef.h:55
Complex< Real > * AS
Definition: ophGen.h:375
uchar ** m_lpNormalized
buffer to normalized.
Definition: ophGen.h:292
Real * binary
Definition: ophGen.h:382
int m_bpp
Definition: ophGen.h:486
int m_nStream
Definition: ophGen.h:300
Real far_depthmap
far value of depth in object
Definition: ophGen.h:630
int8_t * filter_shape_flag
Shape of spatial bandpass filter ("Circle" or "Rect" for now)
Definition: ophGen.h:504
int m_height
Definition: ophGen.h:485
int ENCODE_METHOD
Encoding method flag.
Definition: ophGen.h:284
unsigned int uint
Definition: typedef.h:62
virtual void ophFree(void)
Pure virtual function for override in child classes.
Definition: Openholo.cpp:783
uint * face_idx
Face indexes.
Definition: ophGen.h:598
Definition: ophGen.h:68
Configuration for Depth Map.
Definition: ophGen.h:561
Real * realEnc
Definition: ophGen.h:381