Openholo  v4.1
Open Source Digital Holographic Library
OpenholoGeneration.cpp
Go to the documentation of this file.
1 #include <ophPointCloud.h>
2 #include <ophDepthMap.h>
3 #include <ophTriMesh.h>
4 #include <ophLightField.h>
5 #include <ophWRP.h>
6 #include <omp.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string>
10 #include <limits.h>
11 
12 string encodeToString(unsigned int enc)
13 {
14  string name;
15  switch (enc)
16  {
17  case 0: name = "Phase"; break;
18  case 1: name = "Amplitude"; break;
19  case 2: name = "Real"; break;
20  case 3: name = "Imaginary"; break;
21  default: name = "Unknown";
22  }
23  return name;
24 }
25 
26 void ex_PointCloud(const char* conf, const char* input, unsigned int flag, unsigned int encode, unsigned int mode)
27 {
28  printf("===== ex_PointCloud START =====\n");
29  string diff = (flag == ophPointCloud::PC_DIFF_RS) ? "R-S" : "Fresnel";
30  ophPointCloud* Hologram = new ophPointCloud();
31  Hologram->SetMode(mode);
32  Hologram->readConfig(conf);
33  Hologram->loadPointCloud(input);
34  Hologram->generateHologram(flag);
35  Hologram->encoding(encode);
36  Hologram->normalize();
37 
38  char buf[PATH_MAX] = { 0, };
39  sprintf(buf, "Result/PointCloud_%s_%s.bmp", diff.c_str(), encodeToString(encode).c_str());
40  Hologram->save(buf, Hologram->getContext().waveNum * 8);
41  Hologram->release();
42  printf("====== ex_PointCloud END ======\n");
43 }
44 
45 void ex_DepthMap(const char* conf, char* p[3], unsigned int encode, unsigned int mode)
46 {
47  printf("====== ex_DepthMap START ======\n");
48  ophDepthMap* Hologram = new ophDepthMap();
49  Hologram->SetMode(mode);
50  Hologram->readConfig(conf); // Read Config Parameters for Depth Map CGH]
51  Hologram->readImageDepth(p[0], p[1], p[2]); // Load Depth and RGB image
52  Hologram->generateHologram();
53  Hologram->encoding(encode);
54  Hologram->normalize();
55 
56  char buf[PATH_MAX] = { 0, };
57  sprintf(buf, "Result/DepthMap_%s.bmp", encodeToString(encode).c_str());
58  Hologram->save(buf, Hologram->getContext().waveNum * 8);
59  Hologram->release();
60  printf("====== ex_DepthMap END ======\n");
61 }
62 
63 void ex_LightField(const char* conf, const char* input, unsigned int encode, unsigned int mode)
64 {
65  printf("====== ex_LightField START ======\n");
66  ophLF* Hologram = new ophLF();
67  Hologram->SetMode(mode);
68  Hologram->readConfig(conf); // "Config/Generation_PointCloud (RGB).xml"
69  Hologram->loadLF(input, "bmp"); // "PointCloud & WRP/pointcloud_1470.ply"
70  Hologram->generateHologram();
71  ((ophGen*)Hologram)->encoding(encode);
72  Hologram->normalize();
73 
74  char buf[PATH_MAX] = { 0, };
75  sprintf(buf, "Result/LightField_%s.bmp", encodeToString(encode).c_str());
76  Hologram->save(buf, Hologram->getContext().waveNum * 8);
77  Hologram->release();
78  printf("====== ex_LightField END ======\n");
79 }
80 
81 void ex_TriMesh(const char* conf, const char* input, unsigned int encode, unsigned int mode)
82 {
83  printf("====== ex_TriMesh START ======\n");
84  ophTri* Hologram = new ophTri();
85  Hologram->SetMode(mode);
86  Hologram->readConfig(conf);
87  Hologram->loadMeshData(input, "ply");
88  Hologram->generateHologram(Hologram->SHADING_FLAT);
89  Hologram->encoding(encode);
90  Hologram->normalize();
91 
92  char buf[PATH_MAX] = { 0, };
93  sprintf(buf, "Result/TriMesh_%s.bmp", encodeToString(encode).c_str());
94  Hologram->save(buf, Hologram->getContext().waveNum * 8);
95  Hologram->release();
96 
97  printf("====== ex_TriMesh END ======\n");
98 }
99 
100 void ex_WRP(const char* conf, const char* input, unsigned int encode, unsigned int mode)
101 {
102  printf("====== ex_WRP START ======\n");
103  ophWRP* Hologram = new ophWRP();
104  Hologram->SetMode(mode);
105  Hologram->readConfig(conf); // "Config/Generation_PointCloud (RGB).xml"
106  Hologram->loadPointCloud(input); // "PointCloud & WRP/pointcloud_1470.ply"
107  Hologram->generateHologram();
108  ((ophGen*)Hologram)->encoding(encode);
109  Hologram->normalize();
110 
111  char buf[PATH_MAX] = { 0, };
112  sprintf(buf, "Result/WRP_%s.bmp", encodeToString(encode).c_str());
113  Hologram->save(buf, Hologram->getContext().waveNum * 8);
114  Hologram->release();
115 
116  printf("====== ex_WRP END ======\n");
117 }
118 
119 int main(int argc, char* argv[])
120 {
121  printf("====== Openholo Test main V0.1 ======\n");
122  char config[PATH_MAX] = { 0, };
123  char input[PATH_MAX] = { 0, };
124  char* p[3];
125 
126  int alg = 0;
127  int flag = 0;
128  int encode = 0;
129  int mode = 0;
130 
131  printf("argc : %d ", argc);
132 
133  for (int i = 1; i < argc; i++) {
134  if (!strcmp("-a", argv[i])) { // check algorithm
135  alg = atoi(argv[i + 1]);
136  printf("alg = %d \n", alg);
137  }
138  else if (!strcmp("-c", argv[i])) { // check config path
139  strcpy(config, argv[i + 1]);
140  printf("config = %s \n", config);
141  }
142  else if (!strcmp("-i", argv[i])) { // check input path
143  if (alg == 1) { // if, depthmap
144  for (int j = 0; j < 3; j++) {
145  p[j] = new char[12 * sizeof(argv[i + 1])];
146  strcpy(p[j], argv[i + j + 1]);
147  }
148  }
149  else if (alg >= 0 && alg < 5) {
150  strcpy(input, argv[i + 1]);
151  }
152  else {
153  printf("Invalid input path.\n");
154  break;
155  }
156  }
157  else if (!strcmp("-e", argv[i])) { // check encode method
158  encode = atoi(argv[i + 1]);
159  printf("encode = %u \n", encode);
160  }
161  else if (!strcmp("-m", argv[i])) { // check precision
162  if (atoi(argv[i + 1]) == 0)
163  {
164  mode |= MODE_FLOAT;
165  mode |= MODE_FASTMATH;
166  }
167  else if (atoi(argv[i + 1]) == 1)
168  mode |= MODE_DOUBLE;
169  printf("precision = %d\n", atoi(argv[i + 1]));
170  }
171  else if (!strcmp("-p", argv[i])) { // check mode
172  if (atoi(argv[i + 1]) == 0)
173  mode |= MODE_CPU;
174  else if (atoi(argv[i + 1]) == 1)
175  mode |= MODE_GPU;
176  printf("mode = %d\n", atoi(argv[i + 1]));
177  }
178  else if (!strcmp("-f", argv[i])) { // check flag
179  flag = atoi(argv[i + 1]);
180  printf("flag = %d\n", flag);
181  }
182  }
183 
184  unsigned int select = (unsigned int)alg;
185  switch (select)
186  {
187  case 0: ex_PointCloud(config, input, flag, encode, mode); break;
188  case 1: ex_DepthMap(config, p, encode, mode); break;
189  case 2: ex_LightField(config, input, encode, mode); break;
190  case 3: ex_TriMesh(config, input, encode, mode); break;
191  case 4: ex_WRP(config, input, encode, mode); break;
192  default: printf("Invalid algorithm selected.\n");
193  }
194  printf("====== Openholo Test main V0.1 END ======\n");
195 }
#define MODE_FLOAT
Definition: define.h:158
OphConfig & getContext(void)
Function for getting the current context.
Definition: Openholo.h:229
bool readImageDepth(const char *source_folder, const char *img_prefix, const char *depth_img_prefix)
Read image and depth map.
void ex_WRP(const char *conf, const char *input, unsigned int encode, unsigned int mode)
bool readConfig(const char *fname)
Light Field based CGH configuration file load.
Definition: ophWRP.h:114
Openholo Light Field based CGH generation.
Definition: ophLightField.h:94
name
Definition: setup.py:14
Real generateHologram(uint SHADING_FLAG)
Hologram generation.
Definition: ophTriMesh.cpp:465
void normalize()
void generateHologram()
Hologram generation.
virtual bool readConfig(const char *fname)
load to configuration file.
Definition: ophWRP.cpp:136
void SetMode(unsigned int mode)
Definition: ophGen.h:538
int main(int argc, char *argv[])
void normalize(void)
Normalization function to save as image file after hologram creation.
Definition: ophGen.cpp:677
virtual void encoding(unsigned int ENCODE_FLAG)
bool save(const char *fname, uint8_t bitsperpixel=8, uchar *src=nullptr, uint px=0, uint py=0)
Function for saving image files.
Definition: ophGen.cpp:712
int loadPointCloud(const char *pc_file)
override
string encodeToString(unsigned int enc)
void ex_DepthMap(const char *conf, char *p[3], unsigned int encode, unsigned int mode)
bool readConfig(const char *cfg_file)
Import Specification Config File(*.config) file.
virtual int loadPointCloud(const char *pc_file)
load to point cloud data.
Definition: ophWRP.cpp:128
Openholo Triangular Mesh based CGH generation.
Definition: ophTriMesh.h:113
bool readConfig(const char *fname)
Read parameters from a config file. (*.xml)
Definition: ophDepthMap.cpp:91
Openholo Point Cloud based Compter-generated holography.
#define MODE_DOUBLE
Definition: define.h:157
virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND)
bool loadMeshData(const char *fileName, const char *ext)
Mesh data load.
Definition: ophTriMesh.cpp:88
void ex_TriMesh(const char *conf, const char *input, unsigned int encode, unsigned int mode)
This class generates CGH based on depth map.
Definition: ophDepthMap.h:108
uint waveNum
Definition: Openholo.h:105
virtual void encoding(unsigned int ENCODE_FLAG)
#define MODE_GPU
Definition: define.h:156
#define MODE_CPU
Definition: define.h:155
#define MODE_FASTMATH
Definition: define.h:159
bool readConfig(const char *fname)
Triangular mesh basc CGH configuration file load.
Definition: ophTriMesh.cpp:120
void ex_LightField(const char *conf, const char *input, unsigned int encode, unsigned int mode)
Real generateHologram(void)
Generate a hologram, main funtion. When the calculation is finished, the angular spectrum is performe...
unsigned long release(void)
Call release() when reference is finished.
Definition: Base.h:88
Real generateHologram(uint diff_flag=PC_DIFF_RS)
Generate a hologram, main funtion.
int loadLF(const char *directory, const char *exten)
Light Field images load.
void ex_PointCloud(const char *conf, const char *input, unsigned int flag, unsigned int encode, unsigned int mode)
Definition: ophGen.h:76
void generateHologram(void)
Generate a hologram, main funtion.
Definition: ophWRP.cpp:434