Openholo  v2.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 private:
138 
139  //Real fieldLength;
140  vec3 objSize;
141 
142  Real carrierWave[3] = { 0,0,1 };
143  vec3 illumination;
144  int SHADING_TYPE;
145 
146  bool randPhase;
147  bool occlusion;
148  bool textureMapping;
149  TextMap texture;
150 
151 public:
152  void setObjSize(vec3 in) { objSize = in; }
153  void setObjShift(vec3 in) { context_.shift[_X] = in[_X]; context_.shift[_Y] = in[_Y]; context_.shift[_Z] = in[_Z]; }
154  void setCarrierWave(Real in1, Real in2, Real in3) { carrierWave[_X] = in1; carrierWave[_Y] = in2; carrierWave[_Z] = in3; }
155  void setIllumination(vec3 in) { illumination = in; }
156  void setIllumination(Real inx, Real iny, Real inz) { illumination = { inx, iny, inz }; }
157  void setShadingType(int in) { SHADING_TYPE = in; }
158 
159  void setRandPhase(bool in) { randPhase = in; }
160  void setOcclusion(bool in) { occlusion = in; }
161  void setTextureMapping(bool in) { textureMapping = in; }
162  void setTextureImgDim(int dim1, int dim2) { texture.dim[0] = dim1; texture.dim[1] = dim2; }
163  void setTexturePeriod(Real in) { texture.period = in; }
164 
165  ulonglong getNumMesh() { return meshData->n_faces; }
166  Real* getMeshData() { return triMeshArray; }
167  Complex<Real>* getAngularSpectrum() { return angularSpectrum; }
168  Real* getScaledMeshData() { return scaledMeshData; }
169 
170  const vec3& getObjSize(void) { return objSize; }
171  const vec3& getObjShift(void) { return context_.shift; }
172  const vec3& getIllumination(void) { return illumination; }
173  //const Real& getFieldLens(void) { return fieldLength; }
174 
175 public:
182  bool readConfig(const char* fname);
183 
192  bool loadMeshData(const char* fileName, const char* ext);
193 
201  //void objScaleShift();
202  //void objScaleShift(vec3 objSize_, vector<Real> objShift_);
203  //void objScaleShift(vec3 objSize_, vec3 objShift_);
204 
205  enum SHADING_FLAG { SHADING_FLAT, SHADING_CONTINUOUS };
206 
209  void loadTexturePattern(const char* fileName, const char* ext);
210 
211 
217  bool generateHologram(uint SHADING_FLAG);
218 
219  void reconTest(const char* fname);
220 
221  bool TM = false;
222  int idxCarr, idxCarrFx, idxCarrFy;
223  void triTimeMultiplexing(char* dirName, uint ENCODE_METHOD, Real cenFx, Real cenFy, Real rangeFx, Real rangeFy, Real stepFx, Real stepFy);
224 
234  void setViewingWindow(bool is_ViewingWindow);
235 
236  uint* getProgress() { return &m_nProgress; }
237 private:
238 
239  // Inner functions
241 
242  void initializeAS();
243  void prepareMeshData();
244  void objSort(bool isAscending);
245  bool checkValidity(vec3 no);
246  bool findGeometricalRelations(Real* mesh, vec3 no, geometric& geom);
247  void calGlobalFrequency(Real** frequency);
248  bool calFrequencyTerm(Real** frequency, Real** fl, Real* freqTermX, Real* freqTermY, geometric& geom);
249  uint refAS_Flat(vec3 na, Real** frequency, Real* mesh, Real* freqTermX, Real* freqTermY, geometric& geom);
250  void refASInner_flat(Real* freqTermX, Real* freqTermY);
251  bool refAS_Continuous(uint n, Real* freqTermX, Real* freqTermY);
252  bool generateAS(uint SHADING_FLAG);
253  bool findNormals(uint SHADING_FLAG);
254  bool refToGlobal(Real** frequency, Real** fl, geometric& geom);
255 
256  bool loadMeshText(const char* fileName);
257 
258  void initialize_GPU();
259  void generateAS_GPU(uint SHADING_FLAG);
260  void refAS_GPU(int idx, int ch, uint SHADING_FLAG);
261 
262  // correct the output scale of the ophGen::conv_fft2
263  void conv_fft2_scale(Complex<Real>* src1, Complex<Real>* src2, Complex<Real>* dst, ivec2 size);
264 private:
265 
266  Real* scaledMeshData;
267 
268 private:
269 
270  // Inner global parameters
272  vec3* no;
273  vec3* na;
274  vec3* nv;
275 
276 private:
277 
278  // Inner local parameters
280 
281  geometric geom;
282  Complex<Real>* refAS;
283 
284  // calGlobalFrequency()
285  Real dfx, dfy;
286 
287  // findNormals()
288 
289 
290  // findGeometricalRelations()
291  Real mesh_local[9] = { 0.0 };
292  Real th, ph;
293  Real temp;
294 
295 
296  // calFrequencyTerm()
297  Real k, kk;
298  Real* flxShifted;
299  Real* flyShifted;
300  Real det;
301  Real* invLoRot;
302 
303 
304  // refAS_Flat() , refAS_Continuous()
305 
306  Complex<Real> refTerm1;
307  Complex<Real> refTerm2;
308  Complex<Real> refTerm3;
309 
310 
311 
313  vec3 av;
314 
316  Complex<Real>* rearAS;
317  Complex<Real>* convol;
318 
320  Complex<Real>* phaseTerm;
321 
322  bool is_ViewingWindow;
323 
325  Complex<Real>* textFFT;
326  Real textFreqX;
327  Real textFreqY;
328  Complex<Real> refTemp;
329  Real* tempFreqTermX;
330  Real* tempFreqTermY;
331  uint m_nProgress;
332 
333 };
334 
335 
336 
337 #endif
ulonglong n_faces
The number of faces in object.
Definition: ophGen.h:618
#define GEN_DLL
Definition: ophGen.h:54
SHADING_FLAG
Mesh object data scaling and shifting.
Definition: ophTriMesh.h:205
void setOcclusion(bool in)
Definition: ophTriMesh.h:160
const vec3 & getObjSize(void)
Definition: ophTriMesh.h:170
void setTextureMapping(bool in)
Definition: ophTriMesh.h:161
#define _Y
Definition: define.h:84
int idxCarrFy
Definition: ophTriMesh.h:222
ulonglong getNumMesh()
Definition: ophTriMesh.h:165
void setTexturePeriod(Real in)
Definition: ophTriMesh.h:163
void setShadingType(int in)
Definition: ophTriMesh.h:157
def k(wvl)
Definition: Depthmap.py:16
void setIllumination(vec3 in)
Definition: ophTriMesh.h:155
unsigned long long ulonglong
Definition: typedef.h:67
void setIllumination(Real inx, Real iny, Real inz)
Definition: ophTriMesh.h:156
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:162
ivec2 dim
Definition: ophTriMesh.h:74
Real * getMeshData()
Definition: ophTriMesh.h:166
Real * getScaledMeshData()
Definition: ophTriMesh.h:168
void setObjShift(vec3 in)
Definition: ophTriMesh.h:153
Data for triangular mesh.
Definition: ophGen.h:616
delete [] temp
Definition: ImgControl.cpp:239
Complex< Real > * getAngularSpectrum()
Definition: ophTriMesh.h:167
Real period
Definition: ophTriMesh.h:75
void setRandPhase(bool in)
Definition: ophTriMesh.h:159
#define _Z
Definition: define.h:88
void setObjSize(vec3 in)
Definition: ophTriMesh.h:152
float Real
Definition: typedef.h:55
texture mapping parameters
Definition: ophTriMesh.h:72
const vec3 & getIllumination(void)
Definition: ophTriMesh.h:172
const vec3 & getObjShift(void)
Definition: ophTriMesh.h:171
#define _X
Definition: define.h:80
void setCarrierWave(Real in1, Real in2, Real in3)
Definition: ophTriMesh.h:154
Real freq
Definition: ophTriMesh.h:76
Definition: Bitmap.h:49
virtual ~ophTri(void)
Destructor.
Definition: ophTriMesh.h:126
uint * getProgress()
Definition: ophTriMesh.h:236
unsigned int uint
Definition: typedef.h:62
Definition: ophGen.h:68