Openholo  v1.1
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 "sys.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];
64  Real glShift[3];
65  Real loRot[4];
66 };
67 
72 struct TextMap {
73  Complex<Real>* pattern;
74  ivec2 dim;
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 private:
129  const char* meshDataFileName;
130 
131 private:
132 
133  Real* triMeshArray;
134  Complex<Real>* angularSpectrum;
135  OphMeshData* meshData;
136 
137  // ==== GPU Variables ===============================================
138  bool is_CPU;
139 
140 private:
141 
142  //Real fieldLength;
143  vec3 objSize;
144 
145  Real carrierWave[3] = { 0,0,1 };
146  vec3 illumination;
147  int SHADING_TYPE;
148 
149  bool randPhase;
150  bool occlusion;
151  bool textureMapping;
152  TextMap texture;
153 
154 public:
155  void setObjSize(vec3 in) { objSize = in; }
156  void setObjShift(vec3 in) { context_.shift[_X] = in[_X]; context_.shift[_Y] = in[_Y]; context_.shift[_Z] = in[_Z]; }
157  void setCarrierWave(Real in1, Real in2, Real in3) { carrierWave[_X] = in1; carrierWave[_Y] = in2; carrierWave[_Z] = in3; }
158  void setIllumination(vec3 in) { illumination = in; }
159  void setIllumination(Real inx, Real iny, Real inz) { illumination = { inx, iny, inz }; }
160  void setShadingType(int in) { SHADING_TYPE = in; }
161 
162  void setRandPhase(bool in) { randPhase = in; }
163  void setOcclusion(bool in) { occlusion = in; }
164  void setTextureMapping(bool in) { textureMapping = in; }
165  void setTextureImgDim(int dim1, int dim2) { texture.dim[0] = dim1; texture.dim[1] = dim2; }
166  void setTexturePeriod(Real in) { texture.period = in; }
167 
168  ulonglong getNumMesh() { return meshData->n_faces; }
169  Real* getMeshData() { return triMeshArray; }
170  Complex<Real>* getAngularSpectrum() { return angularSpectrum; }
171  Real* getScaledMeshData() { return scaledMeshData; }
172 
173  const vec3& getObjSize(void) { return objSize; }
174  const vec3& getObjShift(void) { return context_.shift; }
175  const vec3& getIllumination(void) { return illumination; }
176  //const Real& getFieldLens(void) { return fieldLength; }
186  void setMode(bool is_CPU);
187 
192  void setPrecision(bool bPrecision) { bSinglePrecision = bPrecision; }
193  bool getPrecision() { return bSinglePrecision; }
194 public:
201  bool readConfig(const char* fname);
202 
211  bool loadMeshData(const char* fileName, const char* ext);
212 
220  //void objScaleShift();
221  //void objScaleShift(vec3 objSize_, vector<Real> objShift_);
222  //void objScaleShift(vec3 objSize_, vec3 objShift_);
223 
224  enum SHADING_FLAG { SHADING_FLAT, SHADING_CONTINUOUS };
225 
228  void loadTexturePattern(const char* fileName, const char* ext);
229 
230 
236  bool generateHologram(uint SHADING_FLAG);
237 
238  void reconTest(const char* fname);
239 
240  bool TM = false;
241  int idxCarr, idxCarrFx, idxCarrFy;
242  void triTimeMultiplexing(char* dirName, uint ENCODE_METHOD, Real cenFx, Real cenFy, Real rangeFx, Real rangeFy, Real stepFx, Real stepFy);
243 
253  void setViewingWindow(bool is_ViewingWindow);
254 
255  uint* getProgress() { return &m_nProgress; }
256 private:
257 
258  // Inner functions
260 
261  void initializeAS();
262  void prepareMeshData();
263  void objSort(bool isAscending);
264  bool checkValidity(vec3 no);
265  bool findGeometricalRelations(Real* mesh, vec3 no, geometric& geom);
266  void calGlobalFrequency(Real** frequency);
267  bool calFrequencyTerm(Real** frequency, Real** fl, Real* freqTermX, Real* freqTermY, geometric& geom);
268  uint refAS_Flat(vec3 na, Real** frequency, Real* mesh, Real* freqTermX, Real* freqTermY, geometric& geom);
269  void refASInner_flat(Real* freqTermX, Real* freqTermY);
270  bool refAS_Continuous(uint n, Real* freqTermX, Real* freqTermY);
271  bool generateAS(uint SHADING_FLAG);
272  bool findNormals(uint SHADING_FLAG);
273  bool refToGlobal(Real** frequency, Real** fl, geometric& geom);
274 
275  bool loadMeshText(const char* fileName);
276 
277  void initialize_GPU();
278  void generateAS_GPU(uint SHADING_FLAG);
279  void refAS_GPU(int idx, int ch, uint SHADING_FLAG);
280 
281  // correct the output scale of the ophGen::conv_fft2
282  void conv_fft2_scale(Complex<Real>* src1, Complex<Real>* src2, Complex<Real>* dst, ivec2 size);
283 private:
284 
285  Real* scaledMeshData;
286 
287 private:
288 
289  // Inner global parameters
291  vec3* no;
292  vec3* na;
293  vec3* nv;
294 
295 private:
296 
297  // Inner local parameters
299 
300  geometric geom;
301  Complex<Real>* refAS;
302 
303  // calGlobalFrequency()
304  Real dfx, dfy;
305 
306  // findNormals()
307 
308 
309  // findGeometricalRelations()
310  Real mesh_local[9] = { 0.0 };
311  Real th, ph;
312  Real temp;
313 
314 
315  // calFrequencyTerm()
316  Real k, kk;
317  Real* flxShifted;
318  Real* flyShifted;
319  Real det;
320  Real* invLoRot;
321 
322 
323  // refAS_Flat() , refAS_Continuous()
324 
325  Complex<Real> refTerm1;
326  Complex<Real> refTerm2;
327  Complex<Real> refTerm3;
328 
329 
330 
332  vec3 av;
333 
335  Complex<Real>* rearAS;
336  Complex<Real>* convol;
337 
339  Complex<Real>* phaseTerm;
340 
341  bool is_ViewingWindow;
342 
344  Complex<Real>* textFFT;
345  Real textFreqX;
346  Real textFreqY;
347  Complex<Real> refTemp;
348  Real* tempFreqTermX;
349  Real* tempFreqTermY;
350  bool bSinglePrecision;
351  uint m_nProgress;
352 
353 };
354 
355 
356 
357 #endif
ulonglong n_faces
The number of faces in object.
Definition: ophGen.h:594
bool getPrecision()
Definition: ophTriMesh.h:193
#define GEN_DLL
Definition: ophGen.h:54
SHADING_FLAG
Mesh object data scaling and shifting.
Definition: ophTriMesh.h:224
void setOcclusion(bool in)
Definition: ophTriMesh.h:163
const vec3 & getObjSize(void)
Definition: ophTriMesh.h:173
void setTextureMapping(bool in)
Definition: ophTriMesh.h:164
#define _Y
Definition: define.h:84
int idxCarrFy
Definition: ophTriMesh.h:241
ulonglong getNumMesh()
Definition: ophTriMesh.h:168
void setTexturePeriod(Real in)
Definition: ophTriMesh.h:166
void setShadingType(int in)
Definition: ophTriMesh.h:160
def k(wvl)
Definition: Depthmap.py:16
void setIllumination(vec3 in)
Definition: ophTriMesh.h:158
Complex image ch
unsigned long long ulonglong
Definition: typedef.h:67
void setIllumination(Real inx, Real iny, Real inz)
Definition: ophTriMesh.h:159
Openholo Triangular Mesh based CGH generation.
Definition: ophTriMesh.h:113
Complex< Real > * pattern
Definition: ophTriMesh.h:73
geometrical relations
Definition: ophTriMesh.h:62
void setTextureImgDim(int dim1, int dim2)
Definition: ophTriMesh.h:165
ivec2 dim
Definition: ophTriMesh.h:74
Real * getMeshData()
Definition: ophTriMesh.h:169
Real * getScaledMeshData()
Definition: ophTriMesh.h:171
void setObjShift(vec3 in)
Definition: ophTriMesh.h:156
Data for triangular mesh.
Definition: ophGen.h:592
Complex< Real > * getAngularSpectrum()
Definition: ophTriMesh.h:170
Real period
Definition: ophTriMesh.h:75
void setPrecision(bool bPrecision)
Function for setting precision.
Definition: ophTriMesh.h:192
void setRandPhase(bool in)
Definition: ophTriMesh.h:162
#define _Z
Definition: define.h:88
void setObjSize(vec3 in)
Definition: ophTriMesh.h:155
float Real
Definition: typedef.h:55
texture mapping parameters
Definition: ophTriMesh.h:72
const vec3 & getIllumination(void)
Definition: ophTriMesh.h:175
const vec3 & getObjShift(void)
Definition: ophTriMesh.h:174
#define _X
Definition: define.h:80
void setCarrierWave(Real in1, Real in2, Real in3)
Definition: ophTriMesh.h:157
Real freq
Definition: ophTriMesh.h:76
Definition: Bitmap.h:49
virtual ~ophTri(void)
Destructor.
Definition: ophTriMesh.h:126
uint * getProgress()
Definition: ophTriMesh.h:255
unsigned int uint
Definition: typedef.h:62
Definition: ophGen.h:68