Openholo  v5.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  system("pause");
78  exit(EXIT_FAILURE);
79  }
80 }
81 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
82 
83 
84 #define HANDLE_NULL( a ) {if (a == NULL) { \
85  printf( "Host memory failed in %s at line %d\n", \
86  __FILE__, __LINE__ ); \
87  exit( EXIT_FAILURE );}}
88 // for PointCloud only GPU
89 typedef struct _CudaPointCloudConfig {
90  int n_points;
91  double scale_X;
92  double scale_Y;
93  double scale_Z;
94 
95  double offset_depth;
96 
97  int pn_X;
98  int pn_Y;
99 
100  int offset_X; // x-axis start offset
101  int offset_Y; // y-axis start offset
102 
103  double pp_X;
104  double pp_Y;
105 
106  double half_ss_X;
107  double half_ss_Y;
108 
109  double k;
110  double lambda;
111 
113  const int &n_points,
114  const vec3 &scale_factor,
115  const Real &offset_depth,
116  const ivec2 &pixel_number,
117  const ivec2 &offset,
118  const vec2 &pixel_pitch,
119  const vec2 &ss,
120  const Real &k,
121  const Real &lambda
122  )
123  {
124  this->n_points = n_points;
125  this->scale_X = scale_factor[_X];
126  this->scale_Y = scale_factor[_Y];
127  this->scale_Z = scale_factor[_Z];
128  this->offset_depth = offset_depth;
129 
130  // Output Image Size
131  this->pn_X = pixel_number[_X];
132  this->pn_Y = pixel_number[_Y];
133 
134  // Start offset
135  this->offset_X = offset[_X];
136  this->offset_Y = offset[_Y];
137 
138  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
139  this->pp_X = pixel_pitch[_X];
140  this->pp_Y = pixel_pitch[_Y];
141 
142  // Length (Width) of complex field at eyepiece plane (by simple magnification)
143  this->half_ss_X = ss[_X] / 2;
144  this->half_ss_Y = ss[_Y] / 2;
145 
146  // Wave Number
147  this->k = k;
148 
149  this->lambda = lambda;
150  }
152 
154  double det_tx;
155  double det_ty;
156 
158  const int &n_points,
159  const vec3 &scale_factor,
160  const Real &offset_depth,
161  const ivec2 &pixel_number,
162  const ivec2 &offset,
163  const vec2 &pixel_pitch,
164  const vec2 &ss,
165  const Real &k,
166  const Real &lambda
167  )
168  : _CudaPointCloudConfig(n_points, scale_factor, offset_depth, pixel_number, offset, pixel_pitch, ss, k, lambda)
169  {
170  double tx = lambda / (2 * pixel_pitch[_X]);
171  double ty = lambda / (2 * pixel_pitch[_Y]);
172 
173  this->det_tx = tx / sqrt(1 - tx * tx);
174  this->det_ty = ty / sqrt(1 - ty * ty);
175  }
176 
178  : _CudaPointCloudConfig(cuda_config)
179  {
180  double tx = lambda / (2 * cuda_config.pp_X);
181  double ty = lambda / (2 * cuda_config.pp_Y);
182 
183  this->det_tx = tx / sqrt(1 - tx * tx);
184  this->det_ty = ty / sqrt(1 - ty * ty);
185  }
187 
188 
190 
191  double tx;
192  double ty;
193 
195  const int &n_points,
196  const vec3 &scale_factor,
197  const Real &offset_depth,
198  const ivec2 &pixel_number,
199  const ivec2 &offset,
200  const vec2 &pixel_pitch,
201  const vec2 &ss,
202  const Real &k,
203  const Real &lambda
204  )
205  : _CudaPointCloudConfig(n_points, scale_factor, offset_depth, pixel_number, offset, pixel_pitch, ss, k, lambda)
206  {
207  this->tx = lambda / (2 * pixel_pitch[_X]);
208  this->ty = lambda / (2 * pixel_pitch[_Y]);
209  }
210 
212  : _CudaPointCloudConfig(cuda_config)
213  {
214  this->tx = lambda / (2 * cuda_config.pp_X);
215  this->ty = lambda / (2 * cuda_config.pp_Y);
216  }
218 
219 
220 extern "C"
221 {
222  void sum_Kernel(
223  const int& nBlocks, const int& nThreads, cuDoubleComplex* dst, cuDoubleComplex* src, int size
224  );
225  void cudaPointCloud_RS(
226  const int& nBlocks, const int& nThreads, Vertex* cuda_vertex_data, cuDoubleComplex* cuda_dst,
227  const CudaPointCloudConfigRS* cuda_config, const uint& iColor, const uint& mode
228  );
229 
231  const int& nBlocks, const int& nThreads, Vertex* cuda_vertex_data, cuDoubleComplex* cuda_dst,
232  const CudaPointCloudConfigFresnel* cuda_config, const uint& iColor, const uint& mode
233  );
234 }
235 
236 #endif
void cudaPointCloud_Fresnel(const int &nBlocks, const int &nThreads, Vertex *cuda_vertex_data, cuDoubleComplex *cuda_dst, const CudaPointCloudConfigFresnel *cuda_config, const uint &iColor, const uint &mode)
double lambda
Wave Number = (2 * PI) / lambda;.
_CudaPointCloudConfigRS(_CudaPointCloudConfig &cuda_config)
double pp_Y
Pixel pitch of SLM in x direction.
double ty
tx = lambda / (2 * pp_X)
double scale_Y
Scaling factor of x coordinate of point cloud.
float Real
Definition: typedef.h:55
_CudaPointCloudConfig(const int &n_points, 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)
struct _CudaPointCloudConfig CudaPointCloudConfig
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
double half_ss_Y
(pixel_x * nx) / 2
_CudaPointCloudConfigRS(const int &n_points, 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)
#define _Y
Definition: define.h:96
int pn_X
Offset value of point cloud in z direction.
#define _X
Definition: define.h:92
_CudaPointCloudConfigRS CudaPointCloudConfigRS
double k
(pixel_y * ny) / 2
double offset_depth
Scaling factor of z coordinate of point cloud.
structure for 2-dimensional Real type vector and its arithmetic.
Definition: vec.h:66
Definition: struct.h:102
int offset_X
Number of pixel of SLM in y direction.
_CudaPointCloudConfigFresnel CudaPointCloudConfigFresnel
double scale_Z
Scaling factor of y coordinate of point cloud.
structure for 3-dimensional Real type vector and its arithmetic.
Definition: vec.h:466
_CudaPointCloudConfigFresnel(const int &n_points, 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)
double det_ty
tx / sqrt(1 - tx^2), tx = lambda / (2 * pp_X)
_CudaPointCloudConfigFresnel(_CudaPointCloudConfig &cuda_config)
void sum_Kernel(const int &nBlocks, const int &nThreads, cuDoubleComplex *dst, cuDoubleComplex *src, int size)
double scale_X
number of point cloud
double half_ss_X
Pixel pitch of SLM in y direction.
int pn_Y
Number of pixel of SLM in x direction.
void cudaPointCloud_RS(const int &nBlocks, const int &nThreads, Vertex *cuda_vertex_data, cuDoubleComplex *cuda_dst, const CudaPointCloudConfigRS *cuda_config, const uint &iColor, const uint &mode)
#define _Z
Definition: define.h:100
unsigned int uint
Definition: typedef.h:62