Openholo  v4.0
Open Source Digital Holographic Library
ophTriMesh.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 __ophTriMesh_h
47 #define __ophTriMesh_h
48 
49 #include "ophGen.h"
50 #include <cufft.h>
51 
52 //Build Option : Multi Core Processing (OpenMP)
53 #ifdef _OPENMP
54 #include <omp.h>
55 #endif
56 using namespace oph;
57 
62 struct geometric {
63  Real glRot[9] = { 0, };
64  Real glShift[3] = { 0, };
65  Real loRot[4] = { 0, };
66 };
67 
72 struct TextMap {
77 };
78 
79 
83 
106 
113 class GEN_DLL ophTri : public ophGen
114 {
115 public:
120  explicit ophTri(void);
121 
122 protected:
126  virtual ~ophTri(void) {}
127 
128 public:
129  void setObjSize(vec3 in) { objSize = in; }
130  void setObjShift(vec3 in) { context_.shift[_X] = in[_X]; context_.shift[_Y] = in[_Y]; context_.shift[_Z] = in[_Z]; }
131  void setCarrierWave(Real in1, Real in2, Real in3) { carrierWave[_X] = in1; carrierWave[_Y] = in2; carrierWave[_Z] = in3; }
132  void setIllumination(vec3 in) { illumination = in; }
133  void setIllumination(Real inx, Real iny, Real inz) { illumination = { inx, iny, inz }; }
134  void setShadingType(int in) { SHADING_TYPE = in; }
135 
136  void setRandPhase(bool in) { randPhase = in; }
137  void setOcclusion(bool in) { occlusion = in; }
138  void setTextureMapping(bool in) { textureMapping = in; }
139  void setTextureImgDim(int dim1, int dim2) { texture.dim[0] = dim1; texture.dim[1] = dim2; }
140  void setTexturePeriod(Real in) { texture.period = in; }
141 
142  ulonglong getNumMesh() { return meshData->n_faces; }
143 
144 
145  //Real* getMeshData() { return triMeshArray; }
146  Face* getMeshData() { return triMeshArray; }
147  Complex<Real>* getAngularSpectrum() { return angularSpectrum; }
148  //Real* getScaledMeshData() { return scaledMeshData; }
149  Face* getScaledMeshData() { return scaledMeshData; }
150 
151  const vec3& getObjSize(void) { return objSize; }
152  const vec3& getObjShift(void) { return context_.shift; }
153  const vec3& getIllumination(void) { return illumination; }
154  //const Real& getFieldLens(void) { return fieldLength; }
155 
156 public:
163  bool readConfig(const char* fname);
164 
173  bool loadMeshData(const char* fileName, const char* ext);
174 
182  //void objScaleShift();
183  //void objScaleShift(vec3 objSize_, vector<Real> objShift_);
184  //void objScaleShift(vec3 objSize_, vec3 objShift_);
185 
186  enum SHADING_FLAG { SHADING_FLAT, SHADING_CONTINUOUS };
187 
190  void loadTexturePattern(const char* fileName, const char* ext);
191 
192  virtual void encoding(unsigned int ENCODE_FLAG);
193 
194 
200  Real generateHologram(uint SHADING_FLAG);
201 
202  void reconTest(const char* fname);
203 
204  void triTimeMultiplexing(char* dirName, uint ENCODE_METHOD, Real cenFx, Real cenFy, Real rangeFx, Real rangeFy, Real stepFx, Real stepFy);
205 
215  void setViewingWindow(bool is_ViewingWindow);
216 
217  uint* getProgress() { return &m_nProgress; }
218 private:
219 
220  // Inner functions
222 
223  void initializeAS();
224  void prepareMeshData();
225  void objSort(bool isAscending);
226  bool checkValidity(vec3 no);
227  bool findGeometricalRelations(Face mesh, vec3 no, geometric& geom);
228 
234  void calGlobalFrequency(Point* frequency, Real lambda);
235  bool calFrequencyTerm(Point* frequency, Point* fl, Real* freqTermX, Real* freqTermY, geometric& geom, Real lambda);
236  bool calFrequencyTerm(Real** frequency, Real** fl, Real* freqTermX, Real* freqTermY, geometric& geom);
237  void refAS_Flat(vec3 na, Point* frequency, Face mesh, Real* freqTermX, Real* freqTermY, geometric& geom, Real lambda);
238  void refASInner_flat(Real* freqTermX, Real* freqTermY);
239  bool refAS_Continuous(uint n, Real* freqTermX, Real* freqTermY);
240  bool generateAS(uint SHADING_FLAG);
241  bool findNormals(uint SHADING_FLAG);
242  bool refToGlobal(Complex<Real> *dst, Point* frequency, Point* fl, geometric& geom);
243  bool refToGlobal(Real** frequency, Real** fl, geometric& geom);
244 
245  bool loadMeshText(const char* fileName);
246 
247  void initialize_GPU();
248  void generateAS_GPU(uint SHADING_FLAG);
249  //void refAS_GPU(int idx, MeshKernelConfig* config, geometric &geometric);
250 
251  // correct the output scale of the ophGen::conv_fft2
252  void conv_fft2_scale(Complex<Real>* src1, Complex<Real>* src2, Complex<Real>* dst, ivec2 size);
253 private:
254  Face* scaledMeshData;
255 
256  // Inner global parameters
258  vec3* no;
259  vec3* na;
260  vec3* nv;
261 
262  Complex<Real>* angularSpectrum;
263  Complex<Real>* refAS;
264 
266  Complex<Real>* rearAS;
267  Complex<Real>* convol;
268 
270  Complex<Real>* phaseTerm;
271 
272  bool is_ViewingWindow;
273 
274  OphMeshData* meshData;
275  Real* tempFreqTermX;
276  Real* tempFreqTermY;
277 
278  // calGlobalFrequency()
279  Real dfx, dfy;
280 
281  // findNormals()
282 
283 
284  // findGeometricalRelations()
285  Real mesh_local[9] = { 0.0 };
286  Real th, ph;
287  Real temp;
288 
289 
290  // calFrequencyTerm()
291  Real k, kk;
292  Real* flxShifted;
293  Real* flyShifted;
294  Real det;
295  Real* invLoRot;
296 
297 
298  // refAS_Flat() , refAS_Continuous()
299 
300  Complex<Real> refTerm1;
301  Complex<Real> refTerm2;
302  Complex<Real> refTerm3;
303 
304 
305 
307  vec3 av;
308 
309 
311  Complex<Real>* textFFT;
312  Real textFreqX;
313  Real textFreqY;
314  Complex<Real> refTemp;
315  uint m_nProgress;
316  const char* meshDataFileName;
317 
318  //* triMeshArray; /// Original triangular mesh array (N*9)
319  Face* triMeshArray;
320 
321  //Real fieldLength;
322  vec3 objSize;
323 
324  Real carrierWave[3] = { 0,0,1 };
325  vec3 illumination;
326  int SHADING_TYPE;
327 
328  bool randPhase;
329  bool occlusion;
330  bool textureMapping;
331  TextMap texture;
332  bool TM = false;
333  int idxCarr, idxCarrFx, idxCarrFy;
334  cufftDoubleComplex* angularSpectrum_GPU;
335  cufftDoubleComplex* ffttemp;
336 
337  cudaStream_t streamTriMesh;
338 
339 };
340 
341 
342 
343 #endif
Face * getScaledMeshData()
Definition: ophTriMesh.h:149
SHADING_FLAG
Mesh object data scaling and shifting.
Definition: ophTriMesh.h:186
float Real
Definition: typedef.h:55
void setOcclusion(bool in)
Definition: ophTriMesh.h:137
const vec3 & getObjSize(void)
Definition: ophTriMesh.h:151
Definition: struct.h:86
void setTextureMapping(bool in)
Definition: ophTriMesh.h:138
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
#define _Y
Definition: define.h:96
ulonglong getNumMesh()
Definition: ophTriMesh.h:142
Complex< Real > * pattern
Definition: ophTriMesh.h:73
void setTexturePeriod(Real in)
Definition: ophTriMesh.h:140
void setShadingType(int in)
Definition: ophTriMesh.h:134
void setIllumination(vec3 in)
Definition: ophTriMesh.h:132
unsigned long long ulonglong
Definition: typedef.h:67
#define _X
Definition: define.h:92
void setIllumination(Real inx, Real iny, Real inz)
Definition: ophTriMesh.h:133
Openholo Triangular Mesh based CGH generation.
Definition: ophTriMesh.h:113
geometrical relations
Definition: ophTriMesh.h:62
#define GEN_DLL
Definition: ophGen.h:61
void setTextureImgDim(int dim1, int dim2)
Definition: ophTriMesh.h:139
ivec2 dim
Definition: ophTriMesh.h:74
void setObjShift(vec3 in)
Definition: ophTriMesh.h:130
Data for triangular mesh.
Definition: ophGen.h:645
Complex< Real > * getAngularSpectrum()
Definition: ophTriMesh.h:147
structure for 3-dimensional Real type vector and its arithmetic.
Definition: vec.h:466
Real period
Definition: ophTriMesh.h:75
Definition: struct.h:115
Face * getMeshData()
Definition: ophTriMesh.h:146
void setRandPhase(bool in)
Definition: ophTriMesh.h:136
void setObjSize(vec3 in)
Definition: ophTriMesh.h:129
texture mapping parameters
Definition: ophTriMesh.h:72
const vec3 & getIllumination(void)
Definition: ophTriMesh.h:153
const vec3 & getObjShift(void)
Definition: ophTriMesh.h:152
void setCarrierWave(Real in1, Real in2, Real in3)
Definition: ophTriMesh.h:131
Real freq
Definition: ophTriMesh.h:76
Definition: Bitmap.h:49
virtual ~ophTri(void)
Destructor.
Definition: ophTriMesh.h:126
#define _Z
Definition: define.h:100
uint * getProgress()
Definition: ophTriMesh.h:217
unsigned int uint
Definition: typedef.h:62
Definition: ophGen.h:76