Openholo  v1.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 
51 //Build Option : Multi Core Processing (OpenMP)
52 #ifdef _OPENMP
53 #include <omp.h>
54 #endif
55 using namespace oph;
56 
61 struct geometric {
62  Real glRot[9];
63  Real glShift[3];
64  Real loRot[4];
65 };
66 
70 
93 
100 class GEN_DLL ophTri : public ophGen
101 {
102 public:
106  explicit ophTri(void) {
107  is_ViewingWindow = false;
108  is_CPU = true;
109  scaledMeshData = nullptr;
110  normalizedMeshData = nullptr;
111  angularSpectrum = nullptr;
112  }
113 
114 protected:
118  virtual ~ophTri(void) {}
119 
120 private:
121  const char* meshDataFileName;
122 
123 private:
124 
125  Real* triMeshArray;
126  Complex<Real>* angularSpectrum;
127  OphMeshData* meshData;
128 
129  // ==== GPU Variables ===============================================
130  bool is_CPU;
131 
132 private:
133  Real fieldLength;
134  Real objSize;
135  vec3 objShift;
136 
137  Real carrierWave[3] = { 0,0,1 };
138 
139  vec3 illumination;
140  int SHADING_TYPE;
141 
142 public:
143  void setObjSize(Real in) { objSize = in; }
144  void setObjShift(vec3 in) { objShift[_X] = in[_X]; objShift[_Y] = in[_Y]; objShift[_Z] = in[_Z]; }
145  void setObjShift(vector<Real> in) { objShift[_X] = in[_X]; objShift[_Y] = in[_Y]; objShift[_Z] = in[_Z]; }
146  void setCarrierWave(Real in1, Real in2, Real in3) { carrierWave[_X] = in1; carrierWave[_Y] = in2; carrierWave[_Z] = in3; }
147  void setIllumination(vec3 in) { illumination = in; }
148  void setIllumination(Real inx, Real iny, Real inz) { illumination = { inx, iny, inz }; }
149  void setShadingType(int in) { SHADING_TYPE = in; }
150  ulonglong getNumMesh() { return meshData->n_faces; }
151  Real* getMeshData() { return triMeshArray; }
152  Complex<Real>* getAngularSpectrum() { return angularSpectrum; }
153  Real* getScaledMeshData() { return scaledMeshData; }
154 
155  const Real& getObjSize(void) { return objSize; }
156  const vec3& getObjShift(void) { return objShift; }
157  const vec3& getIllumination(void) { return illumination; }
158  const Real& getFieldLens(void) { return fieldLength; }
168  void setMode(bool is_CPU);
169 public:
176  bool readConfig(const char* fname);
177 
186  bool loadMeshData(const char* fileName, const char* ext);
187 
195  void objScaleShift();
196  void objScaleShift(Real objSize_, vector<Real> objShift_);
197  void objScaleShift(Real objSize_, vec3 objShift_);
198 
199  enum SHADING_FLAG { SHADING_FLAT, SHADING_CONTINUOUS };
200 
206  void generateHologram(uint SHADING_FLAG);
207  void generateMeshHologram();
208 
218  void setViewingWindow(bool is_ViewingWindow);
219 
220 private:
221 
222  // Inner functions
224 
225  void initializeAS();
226  void objNormCenter();
227  uint checkValidity(Real* mesh, vec3 no);
228  uint findGeometricalRelations(Real* mesh, vec3 no);
229  void calGlobalFrequency();
230  uint calFrequencyTerm();
231  uint refAS_Flat(vec3 na);
232  uint refAS_Continuous(uint n);
233  void randPhaseDist(Complex<Real>* AS);
234  void generateAS(uint SHADING_FLAG);
235  uint findNormals(uint SHADING_FLAG);
236  uint refToGlobal();
237 
238  uint loadMeshText(const char* fileName);
239  inline Real transVW(Real pt) {
240  Real transPt = -fieldLength * pt / (pt - fieldLength);
241  return transPt;
242  }
243  void initialize_GPU();
244  void generateAS_GPU(uint SHADING_FLAG);
245  void refAS_GPU(int idx, uint SHADING_FLAG);
246 private:
247 
248  Real* normalizedMeshData;
249  Real* scaledMeshData;
250 
251 private:
252 
253  // Inner global parameters
255 
256  Real refTri[9] = { 0,0,0,1,1,0,1,0,0 };
257  Real* fx;
258  Real* fy;
259  Real* fz;
260  vec3* no;
261  vec3* na;
262  vec3* nv;
263 
264 private:
265 
266  // Inner local parameters
268 
269  vec3 n;
270  Real shadingFactor;
271  geometric geom;
272  Real* mesh_local;
273  Real* flx;
274  Real* fly;
275  Real* flz;
276  Real* freqTermX;
277  Real* freqTermY;
278  Complex<Real>* refAS;
279 
280  Complex<Real> refTerm1;
281  Complex<Real> refTerm2;
282  Complex<Real> refTerm3;
283 
284  Complex<Real> D1;
285  Complex<Real> D2;
286  Complex<Real> D3;
287 
288  Complex<Real>* ASTerm;
289  Complex<Real>* randTerm;
290  Complex<Real>* phaseTerm;
291  Complex<Real>* convol;
292  bool is_ViewingWindow;
293 
294 };
295 
296 
297 
298 #endif
ulonglong n_faces
The number of faces in object.
Definition: ophGen.h:496
SHADING_FLAG
Definition: ophTriMesh.h:199
void setObjShift(vector< Real > in)
Definition: ophTriMesh.h:145
float Real
Definition: typedef.h:55
const Real & getFieldLens(void)
Definition: ophTriMesh.h:158
void setObjSize(Real in)
SHADING_FLAT, SHADING_CONTINUOUS.
Definition: ophTriMesh.h:143
#define _Y
Definition: define.h:84
ulonglong getNumMesh()
Definition: ophTriMesh.h:150
const Real & getObjSize(void)
Definition: ophTriMesh.h:155
void setShadingType(int in)
Definition: ophTriMesh.h:149
void setIllumination(vec3 in)
Definition: ophTriMesh.h:147
unsigned long long ulonglong
Definition: typedef.h:67
#define _X
Definition: define.h:80
void setIllumination(Real inx, Real iny, Real inz)
Definition: ophTriMesh.h:148
Openholo Triangular Mesh based CGH generation.
Definition: ophTriMesh.h:100
geometrical relations
Definition: ophTriMesh.h:61
#define GEN_DLL
Definition: ophGen.h:54
Real * getMeshData()
Definition: ophTriMesh.h:151
Real * getScaledMeshData()
Definition: ophTriMesh.h:153
void setObjShift(vec3 in)
Definition: ophTriMesh.h:144
Data for triangular mesh.
Definition: ophGen.h:494
Complex< Real > * getAngularSpectrum()
Definition: ophTriMesh.h:152
const vec3 & getIllumination(void)
Definition: ophTriMesh.h:157
const vec3 & getObjShift(void)
Definition: ophTriMesh.h:156
void setCarrierWave(Real in1, Real in2, Real in3)
Definition: ophTriMesh.h:146
Definition: Bitmap.h:49
virtual ~ophTri(void)
Destructor.
Definition: ophTriMesh.h:118
#define _Z
Definition: define.h:88
unsigned int uint
Definition: typedef.h:62
Definition: ophGen.h:68
ophTri(void)
Constructor.
Definition: ophTriMesh.h:106