Openholo  v1.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 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 {
81  ENCODE_SYMMETRIZATION
82  };
83 
84 public:
88  explicit ophGen(void);
89 
90 protected:
94  virtual ~ophGen(void) = 0;
95 
96 public:
103  inline Real** getEncodedBuffer(void) { return holo_encoded; }
110  inline uchar** getNormalizedBuffer(void) { return holo_normalized; }
111 
115  void initialize(void);
116 
125  int loadPointCloud(const char* pc_file, OphPointCloudData *pc_data_);
126 
134  bool readConfig(const char* fname);
135 
145  void propagationAngularSpectrum(int ch, Complex<Real>* input_u, Real propagation_dist, Real k, Real lambda);
146 
150  void normalize(void);
151 
163  bool save(const char* fname, uint8_t bitsperpixel = 8, uchar* src = nullptr, uint px = 0, uint py = 0);
164 
169  void* load(const char* fname);
170 
178  virtual bool loadAsOhc(const char *fname);
179 
180 protected:
191  bool save(const char* fname, uint8_t bitsperpixel, uint px, uint py, uint fnum, uchar* args ...);
192 
197  void resetBuffer();
198 
199 public:
214  virtual void encoding(unsigned int ENCODE_FLAG, Complex<Real>* holo = nullptr, bool bShift = false);
215  /*
216  * @brief Encoding Functions
217  * @details
218  * ENCODE_SSB : Single Side Band Encoding@n
219  * ENCODE_OFFSSB : Off-axis + Single Side Band Encoding@n
220  * @param[in] ENCODE_FLAG encoding method.
221  * @param[in] SSB_PASSBAND shift direction.
222  * @param[in] holo buffer to encode.
223  * @overload
224  */
225  virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND, Complex<Real>* holo = nullptr);
226  void encoding();
227  enum SSB_PASSBAND { SSB_LEFT, SSB_RIGHT, SSB_TOP, SSB_BOTTOM };
228 
229 public:
236  void waveCarry(Real carryingAngleX, Real carryingAngleY, Real distance);
237 
238 protected:
240  ivec2 encode_size;
251 
252 private:
254  int nOldChannel;
255 
256 public:
263  ivec2& getEncodeSize(void) { return encode_size; }
264 
269  void setResolution(ivec2 resolution);
270 
276  Real getElapsedTime() { return elapsedTime; };
277 
278 protected:
285  void numericalInterference(Complex<Real>* holo, Real* encoded, const int size);
286  void twoPhaseEncoding(Complex<Real>* holo, Real* encoded, const int size);
287  void burckhardt(Complex<Real>* holo, Real* encoded, const int size);
288 
296  void singleSideBand(Complex<Real>* holo, Real* encoded, const ivec2 holosize, int passband);
297 
305  void encodeSymmetrization(Complex<Real>* holo, Real* encoded, const ivec2 sig_loc);
314  void freqShift(Complex<Real>* src, Complex<Real>* dst, const ivec2 holosize, int shift_x, int shift_y);
315 public:
323  void fresnelPropagation(OphConfig context, Complex<Real>* in, Complex<Real>* out, Real distance);
331  void fresnelPropagation(Complex<Real>* in, Complex<Real>* out, Real distance, uint channel);
332 protected:
340  void encodeSideBand(bool bCPU, ivec2 sig_location);
352  void encodeSideBand_CPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
353 
365  void encodeSideBand_GPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location);
366 
374  void getShiftPhaseValue(Complex<Real>& shift_phase_val, int idx, ivec2 sig_location);
375 
383  void getRandPhaseValue(Complex<Real>& rand_phase_val, bool rand_phase);
384 
385 protected:
389  virtual void ophFree(void);
390 };
391 
402  vec3 scale;
417 
419  : n_streams(0), scale(0, 0, 0), offset_depth(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)
420  {}
421 };
422 
431  int n_colors;
440 
441  OphPointCloudData() :vertex(nullptr), color(nullptr), phase(nullptr) { n_points = 0; n_colors = 0; isPhaseParse = 0; }
442 };
443 
477  vector<int> render_depth;
486 
487  OphDepthMapConfig() :fieldLength(0), near_depthmap(0), far_depthmap(0), num_of_depth(0){}
488 };
489 
496  ulonglong n_faces = 0;
505 };
506 
515  vec3 scale;
517  int num_wrp;
522 
523 };
524 
525 #endif // !__ophGen_h
ENCODE_FLAG
Definition: ophGen.h:72
Real * vertex
Geometry of point clouds.
Definition: ophGen.h:433
Real focal_length_lens_eye_piece
Focal length of eyepiece lens.
Definition: ophGen.h:414
Abstract class.
Definition: Openholo.h:83
Real offset_depth
Offset value of point cloud.
Definition: ophGen.h:404
Real * color
Color data of point clouds.
Definition: ophGen.h:435
int color_channels
The number of color.
Definition: ophGen.h:498
uint DEFAULT_DEPTH_QUANTIZATION
default value of the depth quantization - 256
Definition: ophGen.h:481
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:465
bool RANDOM_PHASE
If true, random phase is imposed on each depth layer.
Definition: ophGen.h:485
uint num_of_depth
Definition: ophGen.h:475
ulonglong n_points
Number of points.
Definition: ophGen.h:429
SSB_PASSBAND
Definition: ophGen.h:227
unsigned char uchar
Definition: typedef.h:64
Configuration for WRP.
Definition: ophGen.h:511
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:513
uchar ** getNormalizedBuffer(void)
Function for getting the normalized(0~255) complex field buffer.
Definition: ophGen.h:110
Real focal_length_lens_out
Focal length of output lens of Telecentric.
Definition: ophGen.h:412
vec2 tilt_angle
Tilt angle for spatial filtering.
Definition: ophGen.h:416
float Real
Definition: typedef.h:55
ivec2 & getEncodeSize(void)
Function for getting encode size.
Definition: ophGen.h:263
int num_wrp
Number of wavefront recording plane(WRP)
Definition: ophGen.h:517
Real focal_length_lens_in
Focal length of input lens of Telecentric.
Definition: ophGen.h:410
bool FLAG_CHANGE_DEPTH_QUANTIZATION
if true, change the depth quantization from the default value.
Definition: ophGen.h:479
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:170
Real elapsedTime
Elapsed time of generate hologram.
Definition: ophGen.h:246
Real fieldLength
fieldLength variable for viewing window.
Definition: ophGen.h:398
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:515
vec3 scale
Scaling factor of coordinate of point cloud.
Definition: ophGen.h:402
uint NUMBER_OF_DEPTH_QUANTIZATION
depth level of input depthmap.
Definition: ophGen.h:483
unsigned long long ulonglong
Definition: typedef.h:67
ivec2 encode_size
Encoded hologram size, varied from encoding type.
Definition: ophGen.h:240
Real near_depthmap
near value of depth in object
Definition: ophGen.h:467
Real ** getEncodedBuffer(void)
Function for getting the encoded complex field buffer.
Definition: ophGen.h:103
Real wrp_location
Location distance of WRP.
Definition: ophGen.h:519
int n_streams
stream count for CUDA
Definition: ophGen.h:400
uint * face_idx
Face indexes.
Definition: ophGen.h:500
Real ** holo_encoded
buffer to encoded.
Definition: ophGen.h:248
#define GEN_DLL
Definition: ophGen.h:54
Real * vertex
Vertex array.
Definition: ophGen.h:502
Real far_depthmap
far value of depth in object
Definition: ophGen.h:469
Real getElapsedTime()
Function for getting elapsed time.
Definition: ophGen.h:276
Data for triangular mesh.
Definition: ophGen.h:494
int8_t * filter_shape_flag
Shape of spatial bandpass filter ("Circle" or "Rect" for now)
Definition: ophGen.h:406
int SSB_PASSBAND
Passband in Single-side band encoding.
Definition: ophGen.h:244
int n_colors
Number of color channel.
Definition: ophGen.h:431
Real * color
Color array.
Definition: ophGen.h:504
virtual bool loadAsOhc(const char *fname)
Function to read OHC file.
Definition: Openholo.cpp:249
bool isPhaseParse
Selects wheter to parse the phase data.
Definition: ophGen.h:439
vec2 filter_width
Width of spatial bandpass filter.
Definition: ophGen.h:408
Configuration for Point Cloud.
Definition: ophGen.h:396
Data for Point Cloud.
Definition: ophGen.h:427
Real propagation_distance
Distance of Hologram plane.
Definition: ophGen.h:521
uchar ** holo_normalized
buffer to normalized.
Definition: ophGen.h:250
vector< int > render_depth
Used when only few specific depth levels are rendered, usually for test purpose.
Definition: ophGen.h:477
int ENCODE_METHOD
Encoding method flag.
Definition: ophGen.h:242
unsigned int uint
Definition: typedef.h:62
virtual void ophFree(void)
Pure virtual function for override in child classes.
Definition: Openholo.cpp:589
Definition: ophGen.h:68
Configuration for Depth Map.
Definition: ophGen.h:463
Real * phase
Phase value of point clouds.
Definition: ophGen.h:437