Openholo  v4.2
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 _CudaPointCloudConfig {
89  int n_points;
90  double scale_X;
91  double scale_Y;
92  double scale_Z;
93 
94  double offset_depth;
95 
96  int pn_X;
97  int pn_Y;
98 
99  int offset_X; // x-axis start offset
100  int offset_Y; // y-axis start offset
101 
102  double pp_X;
103  double pp_Y;
104 
105  double half_ss_X;
106  double half_ss_Y;
107 
108  double k;
109  double lambda;
110 
112  const int &n_points,
113  const vec3 &scale_factor,
114  const Real &offset_depth,
115  const ivec2 &pixel_number,
116  const ivec2 &offset,
117  const vec2 &pixel_pitch,
118  const vec2 &ss,
119  const Real &k,
120  const Real &lambda
121  )
122  {
123  this->n_points = n_points;
124  this->scale_X = scale_factor[_X];
125  this->scale_Y = scale_factor[_Y];
126  this->scale_Z = scale_factor[_Z];
127  this->offset_depth = offset_depth;
128 
129  // Output Image Size
130  this->pn_X = pixel_number[_X];
131  this->pn_Y = pixel_number[_Y];
132 
133  // Start offset
134  this->offset_X = offset[_X];
135  this->offset_Y = offset[_Y];
136 
137  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
138  this->pp_X = pixel_pitch[_X];
139  this->pp_Y = pixel_pitch[_Y];
140 
141  // Length (Width) of complex field at eyepiece plane (by simple magnification)
142  this->half_ss_X = ss[_X] / 2;
143  this->half_ss_Y = ss[_Y] / 2;
144 
145  // Wave Number
146  this->k = k;
147 
148  this->lambda = lambda;
149  }
151 
153  double det_tx;
154  double det_ty;
155 
157  const int &n_points,
158  const vec3 &scale_factor,
159  const Real &offset_depth,
160  const ivec2 &pixel_number,
161  const ivec2 &offset,
162  const vec2 &pixel_pitch,
163  const vec2 &ss,
164  const Real &k,
165  const Real &lambda
166  )
167  : _CudaPointCloudConfig(n_points, scale_factor, offset_depth, pixel_number, offset, pixel_pitch, ss, k, lambda)
168  {
169  double tx = lambda / (2 * pixel_pitch[_X]);
170  double ty = lambda / (2 * pixel_pitch[_Y]);
171 
172  this->det_tx = tx / sqrt(1 - tx * tx);
173  this->det_ty = ty / sqrt(1 - ty * ty);
174  }
175 
177  : _CudaPointCloudConfig(cuda_config)
178  {
179  double tx = lambda / (2 * cuda_config.pp_X);
180  double ty = lambda / (2 * cuda_config.pp_Y);
181 
182  this->det_tx = tx / sqrt(1 - tx * tx);
183  this->det_ty = ty / sqrt(1 - ty * ty);
184  }
186 
187 
189 
190  double tx;
191  double ty;
192 
194  const int &n_points,
195  const vec3 &scale_factor,
196  const Real &offset_depth,
197  const ivec2 &pixel_number,
198  const ivec2 &offset,
199  const vec2 &pixel_pitch,
200  const vec2 &ss,
201  const Real &k,
202  const Real &lambda
203  )
204  : _CudaPointCloudConfig(n_points, scale_factor, offset_depth, pixel_number, offset, pixel_pitch, ss, k, lambda)
205  {
206  this->tx = lambda / (2 * pixel_pitch[_X]);
207  this->ty = lambda / (2 * pixel_pitch[_Y]);
208  }
209 
211  : _CudaPointCloudConfig(cuda_config)
212  {
213  this->tx = lambda / (2 * cuda_config.pp_X);
214  this->ty = lambda / (2 * cuda_config.pp_Y);
215  }
217 
218 
219 extern "C"
220 {
221  void cudaPointCloud_RS(
222  const int& nBlocks, const int& nThreads, Vertex* cuda_vertex_data, cuDoubleComplex* cuda_dst,
223  const CudaPointCloudConfigRS* cuda_config, const uint& iColor, const uint& mode
224  );
225 
227  const int& nBlocks, const int& nThreads, Vertex* cuda_vertex_data, cuDoubleComplex* cuda_dst,
228  const CudaPointCloudConfigFresnel* cuda_config, const uint& iColor, const uint& mode
229  );
230 }
231 
232 #endif
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.
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)
_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)
float Real
Definition: typedef.h:55
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)
int pn_X
Offset value of point cloud in z direction.
double k
(pixel_y * ny) / 2
#define _X
Definition: define.h:92
_CudaPointCloudConfigRS CudaPointCloudConfigRS
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)
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.
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)
#define _Y
Definition: define.h:96
double det_ty
tx / sqrt(1 - tx^2), tx = lambda / (2 * pp_X)
_CudaPointCloudConfigFresnel(_CudaPointCloudConfig &cuda_config)
double scale_X
number of point cloud
double half_ss_X
Pixel pitch of SLM in y direction.
#define _Z
Definition: define.h:100
int pn_Y
Number of pixel of SLM in x direction.
_CudaPointCloudConfigFresnel CudaPointCloudConfigFresnel
unsigned int uint
Definition: typedef.h:62
struct _CudaPointCloudConfig CudaPointCloudConfig