Openholo  v4.0
Open Source Digital Holographic Library
ophPointCloud_GPU.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 
53 #ifndef __ophPointCloud_GPU_h
54 #define __ophPointCloud_GPU_h
55 
56 #include "ophPointCloud.h"
57 
58 #define __DEBUG_LOG_GPU_SPEC_
59 
60 /* CUDA Library Include */
61 #include <cuda_runtime_api.h>
62 #include <cuComplex.h>
63 
64 #define __CUDA_INTERNAL_COMPILATION__ //for CUDA Math Module
65 #include <math_constants.h>
66 //#include <math_functions_dbl_ptx3.h> //Double Precision Floating
67 #include <vector_functions.h> //Vector Processing Function
68 #undef __CUDA_INTERNAL_COMPILATION__
69 
70 #define OPH_CUDA_N_STREAM 100
71 static void HandleError(cudaError_t err,
72  const char *file,
73  int line) {
74  if (err != cudaSuccess) {
75  printf("%s in %s at line %d\n", cudaGetErrorString(err),
76  file, line);
77  exit(EXIT_FAILURE);
78  }
79 }
80 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
81 
82 
83 #define HANDLE_NULL( a ) {if (a == NULL) { \
84  printf( "Host memory failed in %s at line %d\n", \
85  __FILE__, __LINE__ ); \
86  exit( EXIT_FAILURE );}}
87 // for PointCloud only GPU
88 typedef struct KernelConst {
89  int n_points;
90  int n_streams;
91 
92  double scale_X;
93  double scale_Y;
94  double scale_Z;
95 
96  double offset_depth;
97 
98  int pn_X;
99  int pn_Y;
100 
101  int offset_X; // x-axis start offset
102  int offset_Y; // y-axis start offset
103 
104  double pp_X;
105  double pp_Y;
106 
107  double half_ss_X;
108  double half_ss_Y;
109 
110  double k;
111  double lambda;
112 
114  const int &n_points,
115  const int &n_streams,
116  const vec3 &scale_factor,
117  const Real &offset_depth,
118  const ivec2 &pixel_number,
119  const ivec2 &offset,
120  const vec2 &pixel_pitch,
121  const vec2 &ss,
122  const Real &k,
123  const Real &lambda
124  )
125  {
126  this->n_points = n_points;
127  this->n_streams = n_streams;
128  this->scale_X = scale_factor[_X];
129  this->scale_Y = scale_factor[_Y];
130  this->scale_Z = scale_factor[_Z];
131  this->offset_depth = offset_depth;
132 
133  // Output Image Size
134  this->pn_X = pixel_number[_X];
135  this->pn_Y = pixel_number[_Y];
136 
137  // Start offset
138  this->offset_X = offset[_X];
139  this->offset_Y = offset[_Y];
140 
141  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
142  this->pp_X = pixel_pitch[_X];
143  this->pp_Y = pixel_pitch[_Y];
144 
145  // Length (Width) of complex field at eyepiece plane (by simple magnification)
146  this->half_ss_X = ss[_X] / 2;
147  this->half_ss_Y = ss[_Y] / 2;
148 
149  // Wave Number
150  this->k = k;
151 
152  this->lambda = lambda;
153  }
154 } GpuConst;
155 
156 typedef struct KernelConst_NotEncodedRS : public KernelConst {
157  double det_tx;
158  double det_ty;
159 
161  const int &n_points,
162  const int &n_streams,
163  const vec3 &scale_factor,
164  const Real &offset_depth,
165  const ivec2 &pixel_number,
166  const ivec2 &offset,
167  const vec2 &pixel_pitch,
168  const vec2 &ss,
169  const Real &k,
170  const Real &lambda
171  )
172  : KernelConst(n_points, n_streams, scale_factor, offset_depth, pixel_number, offset, pixel_pitch, ss, k, lambda)
173  {
174  double tx = lambda / (2 * pixel_pitch[_X]);
175  double ty = lambda / (2 * pixel_pitch[_Y]);
176 
177  this->det_tx = tx / sqrt(1 - tx * tx);
178  this->det_ty = ty / sqrt(1 - ty * ty);
179  }
180 
182  : KernelConst(cuda_config)
183  {
184  double tx = lambda / (2 * cuda_config.pp_X);
185  double ty = lambda / (2 * cuda_config.pp_Y);
186 
187  this->det_tx = tx / sqrt(1 - tx * tx);
188  this->det_ty = ty / sqrt(1 - ty * ty);
189  }
190 } GpuConstNERS;
191 
192 
193 typedef struct KernelConst_NotEncodedFrsn : public KernelConst {
194 
195  double tx;
196  double ty;
197 
199  const int &n_points,
200  const int &n_streams,
201  const vec3 &scale_factor,
202  const Real &offset_depth,
203  const ivec2 &pixel_number,
204  const ivec2 &offset,
205  const vec2 &pixel_pitch,
206  const vec2 &ss,
207  const Real &k,
208  const Real &lambda
209  )
210  : KernelConst(n_points, n_streams, scale_factor, offset_depth, pixel_number, offset, pixel_pitch, ss, k, lambda)
211  {
212  this->tx = lambda / (2 * pixel_pitch[_X]);
213  this->ty = lambda / (2 * pixel_pitch[_Y]);
214  }
215 
217  : KernelConst(cuda_config)
218  {
219  this->tx = lambda / (2 * cuda_config.pp_X);
220  this->ty = lambda / (2 * cuda_config.pp_Y);
221  }
222 } GpuConstNEFR;
223 
224 
225 extern "C"
226 {
227  void cudaPointCloud_RS(
228  const int& nBlocks, const int& nThreads, const int& n_pts_per_stream,
229  Vertex* cuda_vertex_data,
230  cuDoubleComplex* cuda_dst,
231  const GpuConstNERS* cuda_config, const uint& iChannel, const uint& mode
232  );
233 
235  const int& nBlocks, const int& nThreads, const int& n_pts_per_stream,
236  Vertex* cuda_vertex_data,
237  cuDoubleComplex* cuda_dst,
238  const GpuConstNEFR* cuda_config, const uint& iChannel, const uint& mode
239  );
240 }
241 
242 #endif
KernelConst_NotEncodedFrsn(GpuConst &cuda_config)
KernelConst_NotEncodedFrsn(const int &n_points, const int &n_streams, const vec3 &scale_factor, const Real &offset_depth, const ivec2 &pixel_number, const ivec2 &offset, const vec2 &pixel_pitch, const vec2 &ss, const Real &k, const Real &lambda)
ty = lambda / (2 * pp_Y)
int offset_X
Number of pixel of SLM in y direction.
double lambda
Wave Number = (2 * PI) / lambda;.
double half_ss_Y
(pixel_x * nx) / 2
struct KernelConst GpuConst
KernelConst_NotEncodedRS(const int &n_points, const int &n_streams, const vec3 &scale_factor, const Real &offset_depth, const ivec2 &pixel_number, const ivec2 &offset, const vec2 &pixel_pitch, const vec2 &ss, const Real &k, const Real &lambda)
ty / sqrt(1 - ty^2), ty = lambda / (2 * pp_Y)
double pp_Y
Pixel pitch of SLM in x direction.
float Real
Definition: typedef.h:55
KernelConst_NotEncodedRS(GpuConst &cuda_config)
double offset_depth
Scaling factor of z coordinate of point cloud.
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
double det_ty
tx / sqrt(1 - tx^2), tx = lambda / (2 * pp_X)
void cudaPointCloud_RS(const int &nBlocks, const int &nThreads, const int &n_pts_per_stream, Vertex *cuda_vertex_data, cuDoubleComplex *cuda_dst, const GpuConstNERS *cuda_config, const uint &iChannel, const uint &mode)
double pp_X
Number of pixel of SLM in y direction.
#define _Y
Definition: define.h:96
double scale_Y
Scaling factor of x coordinate of point cloud.
KernelConst(const int &n_points, const int &n_streams, const vec3 &scale_factor, const Real &offset_depth, const ivec2 &pixel_number, const ivec2 &offset, const vec2 &pixel_pitch, const vec2 &ss, const Real &k, const Real &lambda)
KernelConst_NotEncodedFrsn GpuConstNEFR
double scale_Z
Scaling factor of y coordinate of point cloud.
#define _X
Definition: define.h:92
KernelConst_NotEncodedRS GpuConstNERS
double half_ss_X
Pixel pitch of SLM in y direction.
structure for 2-dimensional Real type vector and its arithmetic.
Definition: vec.h:66
double tx
Definition: ophWRP_GPU.h:103
Definition: struct.h:102
int n_streams
number of point cloud
int pn_X
Offset value of point cloud in z direction.
structure for 3-dimensional Real type vector and its arithmetic.
Definition: vec.h:466
double scale_X
number of streams
double ty
Definition: ophWRP_GPU.h:104
int pn_Y
Number of pixel of SLM in x direction.
void cudaPointCloud_Fresnel(const int &nBlocks, const int &nThreads, const int &n_pts_per_stream, Vertex *cuda_vertex_data, cuDoubleComplex *cuda_dst, const GpuConstNEFR *cuda_config, const uint &iChannel, const uint &mode)
#define _Z
Definition: define.h:100
double k
(pixel_y * ny) / 2
unsigned int uint
Definition: typedef.h:62
double ty
tx = lambda / (2 * pp_X)