Openholo  v4.1
Open Source Digital Holographic Library
OpenholoGeneration.py
Go to the documentation of this file.
1 import gradio as gr
2 import subprocess
3 import sys
4 import os
5 import pathlib
6 import shutil
7 from time import sleep
8 from xml.etree.ElementTree import parse
9 from tqdm import tqdm
10 
11 
12 PointConfig=""
13 DepthConfig=""
14 LightConfig=""
15 TrimeshConfig=""
16 WrpConfig=""
17 ply=""
18 rgb=""
19 depth=""
20 light=""
21 trimesh=""
22 wrpply=""
23 
24 def plyfile(file, progress=gr.Progress(track_tqdm=True)):
25  progress(0, desc="Uploading Starting")
26  file_paths = file.name
27 
28  for i in progress.tqdm(file_paths, desc="Uploading from file"):
29  #sleep(0.1)
30  progress(1)
31 
32  global ply
33  ply = file_paths
34 
35  return file_paths
36 
37 def rgbfile(file, progress=gr.Progress(track_tqdm="True")):
38  progress(0, desc="Uploading Starting")
39  rgbfile_paths = file.name
40 
41  for i in progress.tqdm(rgbfile_paths, desc="Uploading from file"):
42  #sleep(0.1)
43  progress(1)
44 
45  rgbfile_name = os.path.basename(rgbfile_paths).split('/')[-1]
46  rgb_name = os.path.splitext(rgbfile_name)
47 
48  global rgb
49  rgb = rgb_name[0]
50  currentPath = os.getcwd()
51 
52  if os.path.exists(rgbfile_paths):
53  shutil.move(rgbfile_paths , currentPath+"//DepthMap//"+rgbfile_name)
54  yield rgbfile_paths
55 
56 
57 def depthfile(file, progress=gr.Progress(track_tqdm="True")):
58  depthfile_paths = file.name
59  progress(0, desc="Uploading Starting")
60 
61  for i in progress.tqdm(depthfile_paths, desc="Uploading from file"):
62  #sleep(0.01)
63  progress(1)
64 
65  depthfile_name = os.path.basename(depthfile_paths).split('/')[-1]
66  depth_name = os.path.splitext(depthfile_name)
67 
68  global depth
69  depth = depth_name[0]
70 
71  currentPath = os.getcwd()
72 
73  if os.path.exists(depthfile_paths):
74  shutil.move(depthfile_paths , currentPath+"//DepthMap//"+depthfile_name)
75  return depthfile_paths
76 
77 def lightfile(directory, progress=gr.Progress(track_tqdm="True")):
78  progress(0, desc="lightfile Uploading Starting")
79 
80  for file in directory:
81  lightfile_name = os.path.basename(file.name).split('/')[-1]
82  light_name = os.path.splitext(lightfile_name)
83  currentPath = os.getcwd()
84  if os.path.exists(file.name):
85  shutil.move(file.name , currentPath+"//LightField//"+light_name[0])
86 
87  global light
88  light = os.getcwd()+"//LightField//"
89 
90  return light
91 
92 def trimeshfile(file, progress=gr.Progress(track_tqdm=True)):
93  progress(0, desc="trimeshfile Uploading Starting")
94  trimesh_file_paths = file.name
95 
96  for i in progress.tqdm(trimesh_file_paths, desc="trimeshfile Uploading from file"):
97  #sleep(0.1)
98  progress(1)
99 
100  global trimesh
101  trimesh = trimesh_file_paths
102 
103  return trimesh_file_paths
104 
105 def wrpplyfile(file, progress=gr.Progress(track_tqdm=True)):
106  progress(0, desc="wrpplyfile Uploading Starting")
107  wrp_file_paths = file.name
108 
109  for i in progress.tqdm(wrp_file_paths, desc="wrpplyfile Uploading from file"):
110  #sleep(0.1)
111  progress(1)
112 
113  global wrpply
114  wrpply = wrp_file_paths
115 
116  return wrp_file_paths
117 
118 def pointXmlParing(file):
119  point_file_paths = file.name
120  tree = parse(point_file_paths)
121  root = tree.getroot()
122 
123  global PointConfig
124  PointConfig = point_file_paths
125  point_ScaleX = root.find("ScaleX").text
126  point_ScaleY = root.find("ScaleY").text
127  point_ScaleZ = root.find("ScaleZ").text
128  point_Distance = root.find("Distance").text
129  point_SLM_PixelPitchX = root.find("SLM_PixelPitchX").text
130  point_SLM_PixelPitchY = root.find("SLM_PixelPitchY").text
131  point_SLM_PixelNumX = root.find("SLM_PixelNumX").text
132  point_SLM_PixelNumY = root.find("SLM_PixelNumY").text
133  point_SLM_WaveLength_1 = root.find("SLM_WaveLength_1").text
134  point_SLM_WaveLength_2 = root.find("SLM_WaveLength_2").text
135  point_SLM_WaveLength_3 = root.find("SLM_WaveLength_3").text
136 
137  return {point_Scale_X:point_ScaleX,
138  point_Scale_Y:point_ScaleY,
139  point_Scale_Z:point_ScaleZ,
140  point_Distance_pre:point_Distance,
141  point_PixelPitch_X:point_SLM_PixelPitchX,
142  point_PixelPitch_Y:point_SLM_PixelPitchY,
143  point_PixelNum_X:point_SLM_PixelNumX,
144  point_PixelNum_Y:point_SLM_PixelNumY,
145  point_WaveLength_1:point_SLM_WaveLength_1,
146  point_WaveLength_2:point_SLM_WaveLength_2,
147  point_WaveLength_3:point_SLM_WaveLength_3
148  }
149 
150 def depthXmlParing(file):
151  depth_file_paths = file.name
152  tree = parse(depth_file_paths)
153  root = tree.getroot()
154 
155  global DepthConfig
156  DepthConfig = depth_file_paths
157 
158  depth_Field_Lens = root.find("FieldLength").text
159  depth_Near_Depth = root.find("NearOfDepth").text
160  depth_Far_Depth = root.find("FarOfDepth").text
161  depth_Num_OfDepth = "256"
162  depth_PixelPitch_X= root.find("SLM_PixelPitchX").text
163  depth_PixelPitch_Y = root.find("SLM_PixelPitchY").text
164  depth_PixelNum_X = root.find("SLM_PixelNumX").text
165  depth_PixelNum_Y = root.find("SLM_PixelNumY").text
166  depth_Wave_Length1 = root.find("SLM_WaveLength_1").text
167  depth_Wave_Length2 = root.find("SLM_WaveLength_2").text
168  depth_Wave_Length3 = root.find("SLM_WaveLength_3").text
169 
170  return {depth_FieldLength:depth_Field_Lens,
171  depth_NearOfDepth:depth_Near_Depth,
172  depth_FarOfDepth:depth_Far_Depth,
173  depth_NumOfDepth:depth_Num_OfDepth,
174  depth_PixelPitchX:depth_PixelPitch_X,
175  depth_PixelPitchY:depth_PixelPitch_Y,
176  depth_PixelNumX:depth_PixelNum_X,
177  depth_PixelNumY:depth_PixelNum_Y,
178  depth_WaveLength1:depth_Wave_Length1,
179  depth_WaveLength2:depth_Wave_Length2,
180  depth_WaveLength3:depth_Wave_Length3
181  }
182 
183 
184 def lightXmlParing(file):
185  light_file_paths = file.name
186  tree = parse(light_file_paths)
187  root = tree.getroot()
188 
189  global LightConfig
190  LightConfig = light_file_paths
191 
192  light_distance = root.find("Distance").text
193  light_Image_NumOf_X = root.find("Image_NumOfX").text
194  light_Image_NumOf_Y = root.find("Image_NumOfY").text
195  light_PixelPitch_X= root.find("SLM_PixelPitchX").text
196  light_PixelPitch_Y = root.find("SLM_PixelPitchY").text
197  light_PixelNum_X = root.find("SLM_PixelNumX").text
198  light_PixelNum_Y = root.find("SLM_PixelNumY").text
199  light_Wave_Length1 = root.find("SLM_WaveLength_1").text
200  light_Wave_Length2 = root.find("SLM_WaveLength_2").text
201  light_Wave_Length3 = root.find("SLM_WaveLength_3").text
202 
203  return {light_Distance:light_distance,
204  light_Image_NumOfX:light_Image_NumOf_X,
205  light_Image_NumOfY:light_Image_NumOf_Y,
206  light_PixelPitchX:light_PixelPitch_X,
207  light_PixelPitchY:light_PixelPitch_Y,
208  light_PixelNumX:light_PixelNum_X,
209  light_PixelNumY:light_PixelNum_Y,
210  light_WaveLength1:light_Wave_Length1,
211  light_WaveLength2:light_Wave_Length2,
212  light_WaveLength3:light_Wave_Length3
213  }
214 
216  trimesh_file_paths = file.name
217  tree = parse(trimesh_file_paths)
218  root = tree.getroot()
219 
220  global TrimeshConfig
221  TrimeshConfig = trimesh_file_paths
222 
223  trimesh_ScaleX = root.find("ScaleX").text
224  trimesh_ScaleY = root.find("ScaleY").text
225  trimesh_ScaleZ = root.find("ScaleZ").text
226  trimesh_LampDirectionX = root.find("LampDirectionX").text
227  trimesh_LampDirectionY = root.find("LampDirectionY").text
228  trimesh_LampDirectionZ = root.find("LampDirectionZ").text
229  trimesh_PixelPitchX = root.find("SLM_PixelPitchX").text
230  trimesh_PixelPitchY = root.find("SLM_PixelPitchY").text
231  trimesh_PixelNumX = root.find("SLM_PixelNumX").text
232  trimesh_PixelNumY = root.find("SLM_PixelNumY").text
233  trimesh_Wave_Length1 = root.find("SLM_WaveLength_1").text
234  trimesh_Wave_Length2 = root.find("SLM_WaveLength_2").text
235  trimesh_Wave_Length3 = root.find("SLM_WaveLength_3").text
236 
237  return {trimesh_Scale_X:trimesh_ScaleX,
238  trimesh_Scale_Y:trimesh_ScaleY,
239  trimesh_Scale_Z:trimesh_ScaleZ,
240  trimesh_LampDirection_X:trimesh_LampDirectionX,
241  trimesh_LampDirection_Y:trimesh_LampDirectionY,
242  trimesh_LampDirection_Z:trimesh_LampDirectionZ,
243  trimesh_PixelPitch_X:trimesh_PixelPitchX,
244  trimesh_PixelPitch_Y:trimesh_PixelPitchY,
245  trimesh_PixelNum_X:trimesh_PixelNumX,
246  trimesh_PixelNum_Y:trimesh_PixelNumY,
247  trimesh_WaveLength_1:trimesh_Wave_Length1,
248  trimesh_WaveLength_2:trimesh_Wave_Length2,
249  trimesh_WaveLength_3:trimesh_Wave_Length3
250  }
251 
252 def wrpXmlParing(file):
253  wrp_file_paths = file.name
254  tree = parse(wrp_file_paths)
255  root = tree.getroot()
256 
257  global WrpConfig
258  WrpConfig = wrp_file_paths
259 
260  print("[wrpXmlParing] root = ",root)
261  wrp_ScaleX = root.find("ScaleX").text
262  wrp_ScaleY = root.find("ScaleY").text
263  wrp_ScaleZ = root.find("ScaleZ").text
264  wrp_distance = root.find("Distance").text
265  wrp_NumOfWRP = root.find("NumOfWRP").text
266  wrp_LocationOfWRP = root.find("LocationOfWRP").text
267  wrp_SLM_PixelPitchX = root.find("SLM_PixelPitchX").text
268  wrp_SLM_PixelPitchY = root.find("SLM_PixelPitchY").text
269  wrp_SLM_PixelNumX = root.find("SLM_PixelNumX").text
270  wrp_SLM_PixelNumY = root.find("SLM_PixelNumY").text
271  wrp_SLM_WaveLength_1 = root.find("SLM_WaveLength_1").text
272  wrp_SLM_WaveLength_2 = root.find("SLM_WaveLength_2").text
273  wrp_SLM_WaveLength_3 = root.find("SLM_WaveLength_3").text
274 
275  return {wrp_Scale_X:wrp_ScaleX,
276  wrp_Scale_Y:wrp_ScaleY,
277  wrp_Scale_Z:wrp_ScaleZ,
278  wrp_Distance:wrp_distance,
279  wrp_NumOf_WRP:wrp_NumOfWRP,
280  wrp_WRP_Location:wrp_LocationOfWRP,
281  wrp_PixelPitch_X:wrp_SLM_PixelPitchX,
282  wrp_PixelPitch_Y:wrp_SLM_PixelPitchY,
283  wrp_PixelNum_X:wrp_SLM_PixelNumX,
284  wrp_PixelNum_Y:wrp_SLM_PixelNumY,
285  wrp_WaveLength_1:wrp_SLM_WaveLength_1,
286  wrp_WaveLength_2:wrp_SLM_WaveLength_2,
287  wrp_WaveLength_3:wrp_SLM_WaveLength_3
288  }
289 
290 def pointGenerate(Diffraction,Encoding,Precision,pc_mode):
291  file = pathlib.Path("OpenholoGeneration")
292  plyfile = pathlib.Path(ply)
293 
294  if Diffraction == "R-S":
295  diff = "0"
296  elif Diffraction == "Fresnel":
297  diff = "1"
298 
299  if Encoding == "Phase":
300  enc = "0"
301  elif Encoding == "Amplitude":
302  enc = "1"
303  elif Encoding == "Real":
304  enc = "2"
305  elif Encoding == "Imaginary":
306  enc = "3"
307 
308  if Precision == "single":
309  pre = "0"
310  else:
311  pre = "1"
312 
313  if pc_mode == "CPU":
314  mode = "0"
315  else:
316  mode = "1"
317 
318  if file.exists ():
319  if plyfile.exists () :
320  subprocess.run(['./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" -e \"{}\" -m \"{}\" -p \"{}\" -f \"{}\"'.format("0",PointConfig, ply, enc, pre, mode, diff)], shell=True)
321  else:
322  print("File upload did not complete. Please try again after the file is uploaded.")
323  else:
324  print("OpenholoGeneration file does not exist, so it does not work normally")
325  return './Result/PointCloud_'+Diffraction+"_"+Encoding+'.bmp'
326 
327 def depthGenerate(Encoding,pc_mode):
328  file = pathlib.Path("OpenholoGeneration")
329  currentPath = os.getcwd()
330  rgbfile = pathlib.Path(currentPath+"//DepthMap//"+rgb+".bmp")
331  depthfile = pathlib.Path(currentPath+"//DepthMap//"+depth+".bmp")
332 
333  if Encoding == "Phase":
334  enc = "0"
335  elif Encoding == "Amplitude":
336  enc = "1"
337  elif Encoding == "Real":
338  enc = "2"
339  elif Encoding == "Imaginary":
340  enc = "3"
341 
342  if pc_mode == "CPU":
343  mode = "0"
344  elif pc_mode == "GPU":
345  mode = "1"
346 
347  if file.exists () :
348  if rgbfile.exists () and depthfile.exists () :
349  subprocess.run(['./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" \"{}\" \"{}\" -e \"{}\" -m \"{}\" -p \"{}\"'.format("1",DepthConfig, './DepthMap', rgb, depth, enc, "1", mode)], shell=True)
350  else:
351  print("File upload did not complete. Please try again after the file is uploaded.")
352  else:
353  print("OpenholoGeneration file does not exist, so it does not work normally")
354 
355  return './Result/DepthMap_'+Encoding+'.bmp'
356 
357 def lightGenerate(Encoding,pc_mode):
358  file = pathlib.Path("OpenholoGeneration")
359  lightdir = pathlib.Path(light)
360 
361  if Encoding == "Phase":
362  enc = "0"
363  elif Encoding == "Amplitude":
364  enc = "1"
365  elif Encoding == "Real":
366  enc = "2"
367  elif Encoding == "Imaginary":
368  enc = "3"
369  if pc_mode == "CPU":
370  mode = "0"
371  else:
372  mode = "1"
373 
374  if file.exists ():
375  if lightdir.exists () :
376  subprocess.run(['./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" -e \"{}\" -m \"{}\" -p \"{}\"'.format("2",LightConfig, light, enc, "1", mode)], shell=True)
377  else:
378  print("File upload did not complete. Please try again after the file is uploaded.")
379  else:
380  print("OpenholoGeneration file does not exist, so it does not work normally")
381  return './Result/LightField_'+Encoding+'.bmp'
382 
383 def trimeshGenerate(Encoding,pc_mode):
384  file = pathlib.Path("OpenholoGeneration")
385  trimeshfile = pathlib.Path(trimesh)
386 
387  if Encoding == "Phase":
388  enc = "0"
389  elif Encoding == "Amplitude":
390  enc = "1"
391  elif Encoding == "Real":
392  enc = "2"
393  elif Encoding == "Imaginary":
394  enc = "3"
395  if pc_mode == "CPU":
396  mode = "0"
397  else:
398  mode = "1"
399 
400  if file.exists ():
401  if trimeshfile.exists () :
402  subprocess.run(['./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" -e \"{}\" -m \"{}\" -p \"{}\"'.format("3",TrimeshConfig, trimesh, enc, "1", mode)], shell=True)
403  else:
404  print("File upload did not complete. Please try again after the file is uploaded.")
405  else:
406  print("OpenholoGeneration file does not exist, so it does not work normally")
407  return './Result/TriMesh_'+Encoding+'.bmp'
408 
409 def wrpGenerate(Encoding,pc_mode):
410  file = pathlib.Path("OpenholoGeneration")
411  wrpplyfile = pathlib.Path(wrpply)
412 
413  if Encoding == "Phase":
414  enc = "0"
415  elif Encoding == "Amplitude":
416  enc = "1"
417  elif Encoding == "Real":
418  enc = "2"
419  elif Encoding == "Imaginary":
420  enc = "3"
421 
422  if pc_mode == "CPU":
423  mode = "0"
424  else:
425  mode = "1"
426 
427  if file.exists ():
428  if wrpplyfile.exists () :
429  subprocess.run(['./OpenholoGeneration -a \"{}\" -c \"{}\" -i \"{}\" -e \"{}\" -m \"{}\" -p \"{}\"'.format("4",WrpConfig, wrpply, enc, "1", mode)], shell=True)
430  else:
431  print("File upload did not complete. Please try again after the file is uploaded.")
432  else:
433  print("OpenholoGeneration file does not exist, so it does not work normally")
434  return './Result/WRP_'+Encoding+'.bmp'
435 
436 #theme=gr.themes.Soft(),
437 # gr.themes.Base()/gr.themes.Default()/gr.themes.Glass()/gr.themes.Monochrome()/gr.themes.Soft() //primary_hue="red", secondary_hue="pink"
438 with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {background-color: #CFE3EA}", title="Openholo Generation") as demo:
439 
440  gr.HTML("<img src='/file/logo_m.png' align='left' vspace='14' hspace='14'> <font size ='6'><b>Hologram generation methods by Openholo library</b>")
441 
442  with gr.Tab(label = "Point Cloud"):
443  with gr.Column():
444  with gr.Row() as row:
445  with gr.Column():
446  pointxml = gr.File(label="Choose a PointCloud Config (.xml) File to Upload",interactive="True")
447  with gr.Column():
448  ply = gr.File(label="Choose a PointCloud (*.ply) File to Upload",interactive="True")
449  plyout = gr.Textbox(label="[Warning] Please wait until the size of the ply file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
450  with gr.Row() as row:
451  with gr.Column():
452  point_Scale_X = gr.Textbox(label = "Scale X", placeholder="0.01")
453  point_Scale_X.change(lambda s: s, inputs=point_Scale_X)
454  with gr.Column():
455  point_Scale_Y = gr.Textbox(label = "Scale Y", placeholder="0.01")
456  point_Scale_Y.change(lambda s: s, inputs=point_Scale_Y)
457  with gr.Column():
458  point_Scale_Z = gr.Textbox(label = "Scale Z", placeholder="0.01")
459  point_Scale_Z.change(lambda s: s, inputs=point_Scale_Z)
460  with gr.Row() as row:
461  point_Distance_pre = gr.Textbox(label = "Distance", placeholder="0.5")
462  point_Distance_pre.change(lambda s: s, inputs=point_Distance_pre)
463  with gr.Row() as row:
464  with gr.Column():
465  point_PixelPitch_X = gr.Textbox(label = "PixelPitch X", placeholder="10e-6")
466  point_PixelPitch_X.change(lambda s: s, inputs=point_PixelPitch_X)
467  with gr.Column():
468  point_PixelPitch_Y = gr.Textbox(label = "PixelPitch Y", placeholder="10e-6")
469  point_PixelPitch_Y.change(lambda s: s, inputs=point_PixelPitch_Y)
470  with gr.Row() as row:
471  with gr.Column():
472  point_PixelNum_X = gr.Textbox(label = "PixelNum X", placeholder="1920")
473  point_PixelNum_X.change(lambda s: s, inputs=point_PixelNum_X)
474  with gr.Column():
475  point_PixelNum_Y = gr.Textbox(label = "PixelNum Y", placeholder="1080")
476  point_PixelNum_Y.change(lambda s: s, inputs=point_PixelNum_Y)
477  with gr.Row() as row:
478  with gr.Column():
479  point_WaveLength_1 = gr.Textbox(label = "WaveLength1", placeholder="638e-9")
480  point_WaveLength_1.change(lambda s: s, inputs=point_WaveLength_1)
481  with gr.Column():
482  point_WaveLength_2 = gr.Textbox(label = "WaveLength2", placeholder="520e-9")
483  point_WaveLength_2.change(lambda s: s, inputs=point_WaveLength_2)
484  with gr.Column():
485  point_WaveLength_3 = gr.Textbox(label = "WaveLength3", placeholder="450e-9")
486  point_WaveLength_3.change(lambda s: s, inputs=point_WaveLength_3)
487  with gr.Row() as row:
488  with gr.Column():
489  Diffraction = gr.Dropdown(['R-S','Fresnel'], value="R-S", label = "Diffraction Flag" , info="Choose an flag!")
490  with gr.Column():
491  Encoding = gr.Dropdown(['Phase','Amplitude','Real','Imaginary'], value="Phase", label = "Encoding Method" , info="Choose an encoding!")
492  with gr.Row() as row:
493  with gr.Column():
494  Precision = gr.Radio(["single", "double"], value="single", label="Precision (GPGPU)")
495  with gr.Column():
496  pc_mode = gr.Radio(["CPU", "GPU"], value="GPU", label="CPU / GPU")
497 
498  pointOutput = gr.Image(label="Point Cloud Bmp")
499  pointGen = gr.Button(value = "Generate Point Cloud Hologram")
500  pointxml.upload(fn=pointXmlParing, inputs=pointxml,outputs=[point_Scale_X,point_Scale_Y,point_Scale_Z,point_Distance_pre,point_PixelPitch_X,point_PixelPitch_Y,point_PixelNum_X,point_PixelNum_Y,point_WaveLength_1,point_WaveLength_2,point_WaveLength_3])
501  ply.upload(fn=plyfile, inputs=ply, outputs=plyout, show_progress="True")
502  pointGen.click(fn=pointGenerate,inputs=[Diffraction,Encoding,Precision,pc_mode],outputs=pointOutput)
503 
504  with gr.Tab(label = "DepthMap"):
505  with gr.Column():
506  with gr.Row() as row:
507  with gr.Column():
508  depthxml = gr.File(label="Choose a Depthmap Xml File to Upload",interactive="True")
509  with gr.Column():
510  bmprgb = gr.File(label="Choose a Rgb File to Upload",interactive="True")
511  rgbout = gr.Textbox(label="[Warning] Please wait until the size of the rgb file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
512  with gr.Column():
513  bmpdepth = gr.File(label="Choose a Depthmap File to Upload",interactive="True")
514  depthout = gr.Textbox(label="[Warning] Please wait until the size of the depth file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
515  with gr.Row() as row:
516  with gr.Column():
517  depth_FieldLength = gr.Textbox(label = "Field Lens(m)", placeholder="1000e-3")
518  depth_FieldLength.change(lambda s: s, inputs=depth_FieldLength)
519  with gr.Column():
520  depth_NumOfDepth = gr.Textbox(label = "Num Of Depth", placeholder="256")
521  depth_NumOfDepth.change(lambda s: s, inputs=depth_NumOfDepth)
522  with gr.Row() as row:
523  with gr.Column():
524  depth_NearOfDepth = gr.Textbox(label = "Near Depth(m)", placeholder="0.4")
525  depth_NearOfDepth.change(lambda s: s, inputs=depth_NearOfDepth)
526  with gr.Column():
527  depth_FarOfDepth = gr.Textbox(label = "Far Depth(m)", placeholder="0.6")
528  depth_FarOfDepth.change(lambda s: s, inputs=depth_FarOfDepth)
529  with gr.Row() as row:
530  with gr.Column():
531  depth_PixelPitchX = gr.Textbox(label = "PixelPitch X(m)", placeholder="10e-6")
532  depth_PixelPitchX.change(lambda s: s, inputs=depth_PixelPitchX)
533  with gr.Column():
534  depth_PixelPitchY = gr.Textbox(label = "PixelPitch Y(m)", placeholder="10e-6")
535  depth_PixelPitchY.change(lambda s: s, inputs=depth_PixelPitchY)
536  with gr.Row() as row:
537  with gr.Column():
538  depth_PixelNumX = gr.Textbox(label = "PixelNum X", placeholder="1920")
539  depth_PixelNumX.change(lambda s: s, inputs=depth_PixelNumX)
540  with gr.Column():
541  depth_PixelNumY = gr.Textbox(label = "PixelNum Y", placeholder="1080")
542  depth_PixelNumY.change(lambda s: s, inputs=depth_PixelNumY)
543  with gr.Row() as row:
544  with gr.Column():
545  depth_WaveLength1 = gr.Textbox(label = "WaveLength1(m)", placeholder="638e-9")
546  depth_WaveLength1.change(lambda s: s, inputs=depth_WaveLength1)
547  with gr.Column():
548  depth_WaveLength2 = gr.Textbox(label = "WaveLength2(m)", placeholder="520e-9")
549  depth_WaveLength2.change(lambda s: s, inputs=depth_WaveLength2)
550  with gr.Column():
551  depth_WaveLength3 = gr.Textbox(label = "WaveLength3(m)", placeholder="450e-9")
552  depth_WaveLength3.change(lambda s: s, inputs=depth_WaveLength3)
553  with gr.Row() as row:
554  with gr.Column():
555  Propagation = gr.Dropdown(['Angular Spectrum'], value="Angular Spectrum", label = "Propagation Method" , info="Choose an Propagation!")
556  with gr.Column():
557  Encoding = gr.Dropdown(['Phase','Amplitude','Real','Imaginary'], value="Phase", label = "Encoding Method", info="Choose an Encoding!")
558  with gr.Row() as row:
559  with gr.Column():
560  pc_mode = gr.Radio(["CPU", "GPU"], value="GPU", label="CPU / GPU", info="Choose an mode!")
561  depthxml.upload(fn=depthXmlParing, inputs=depthxml,outputs=[depth_FieldLength,depth_NearOfDepth,depth_FarOfDepth,depth_NumOfDepth,depth_PixelPitchX,depth_PixelPitchY,depth_PixelNumX,depth_PixelNumY,depth_WaveLength1,depth_WaveLength2,depth_WaveLength3])
562  bmprgb.upload(fn=rgbfile, inputs=bmprgb, outputs=rgbout, show_progress="True")
563  bmpdepth.upload(fn=depthfile, inputs=bmpdepth, outputs=depthout, show_progress="True")
564  depthOutput = gr.Image(label="DepthMap Bmp")
565  depthGen = gr.Button(value = "Generate DepthMap Hologram")
566  depthGen.click(fn=depthGenerate, inputs=[Encoding,pc_mode] ,outputs=depthOutput)
567 
568  with gr.Tab(label = "LightField"):
569  with gr.Column():
570  with gr.Row() as row:
571  with gr.Column():
572  lightxml = gr.File(label="Choose a LightField Xml File to Upload",interactive="True")
573  with gr.Column():
574  lightbmp = gr.File(label="Image Folder to Upload",interactive="True", file_count="directory")
575  with gr.Row() as row:
576  with gr.Column():
577  light_Distance = gr.Textbox(label = "Distance", placeholder="0.5")
578  light_Distance.change(lambda s: s, inputs=light_Distance)
579  with gr.Row() as row:
580  with gr.Column():
581  light_Image_NumOfX = gr.Textbox(label = "Num of Img X", placeholder="10")
582  light_Image_NumOfX.change(lambda s: s, inputs=light_Image_NumOfX)
583  with gr.Column():
584  light_Image_NumOfY = gr.Textbox(label = "Num of Img Y", placeholder="10")
585  light_Image_NumOfY.change(lambda s: s, inputs=light_Image_NumOfY)
586  with gr.Row() as row:
587  with gr.Column():
588  light_PixelPitchX = gr.Textbox(label = "PixelPitch X(m)", placeholder="1e-5")
589  light_PixelPitchX.change(lambda s: s, inputs=light_PixelPitchX)
590  with gr.Column():
591  light_PixelPitchY = gr.Textbox(label = "PixelPitch Y(m)", placeholder="1e-5")
592  light_PixelPitchY.change(lambda s: s, inputs=light_PixelPitchY)
593  with gr.Row() as row:
594  with gr.Column():
595  light_PixelNumX = gr.Textbox(label = "PixelNum X", placeholder="1920")
596  light_PixelNumX.change(lambda s: s, inputs=light_PixelNumX)
597  with gr.Column():
598  light_PixelNumY = gr.Textbox(label = "PixelNum Y", placeholder="1080")
599  light_PixelNumY.change(lambda s: s, inputs=light_PixelNumY)
600  with gr.Row() as row:
601  with gr.Column():
602  light_WaveLength1 = gr.Textbox(label = "WaveLength1(m)", placeholder="638e-9")
603  light_WaveLength1.change(lambda s: s, inputs=light_WaveLength1)
604  with gr.Column():
605  light_WaveLength2 = gr.Textbox(label = "WaveLength2(m)", placeholder="520e-9")
606  light_WaveLength2.change(lambda s: s, inputs=light_WaveLength2)
607  with gr.Column():
608  light_WaveLength3 = gr.Textbox(label = "WaveLength3(m)", placeholder="450e-9")
609  light_WaveLength3.change(lambda s: s, inputs=light_WaveLength3)
610  with gr.Row() as row:
611  with gr.Column():
612  Encoding = gr.Dropdown(['Phase','Amplitude','Real','Imaginary'], value="Phase", label = "Encoding Method", info="Choose an Encoding!")
613  with gr.Column():
614  pc_mode = gr.Radio(["CPU", "GPU"], value="GPU", label="CPU / GPU", info="Choose an mode!")
615 
616  lightxml.upload(fn=lightXmlParing, inputs=lightxml,outputs=[light_Distance,light_Image_NumOfX,light_Image_NumOfY,light_PixelPitchX,light_PixelPitchY,light_PixelNumX,light_PixelNumY,light_WaveLength1,light_WaveLength2,light_WaveLength3])
617  lightbmp.upload(fn=lightfile, inputs=lightbmp, show_progress="True")
618  lightOutput = gr.Image(label="LightField Bmp")
619  lightGen = gr.Button(value = "Generate LightField Hologram")
620  lightGen.click(fn=lightGenerate, inputs=[Encoding,pc_mode] ,outputs=lightOutput)
621 
622  with gr.Tab(label = "Triangle Mesh"):
623  with gr.Column():
624  with gr.Row() as row:
625  with gr.Column():
626  trimeshxml = gr.File(label="Choose a Triangle Mesh Config (.xml) File to Upload",interactive="True")
627  with gr.Column():
628  trimeshply = gr.File(label="Choose a Triangle Mesh (*.ply) File to Upload",interactive="True")
629  trimeshplyout = gr.Textbox(label="[Warning] Please wait until the size of the Triangle Mesh file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
630  with gr.Row() as row:
631  with gr.Column():
632  trimesh_Scale_X = gr.Textbox(label = "Scale X", placeholder="0.005")
633  trimesh_Scale_X.change(lambda s: s, inputs=trimesh_Scale_X)
634  with gr.Column():
635  trimesh_Scale_Y = gr.Textbox(label = "Scale Y", placeholder="0.005")
636  trimesh_Scale_Y.change(lambda s: s, inputs=trimesh_Scale_Y)
637  with gr.Column():
638  trimesh_Scale_Z = gr.Textbox(label = "Scale Z", placeholder="0.005")
639  trimesh_Scale_Z.change(lambda s: s, inputs=trimesh_Scale_Z)
640  with gr.Row() as row:
641  with gr.Column():
642  trimesh_LampDirection_X = gr.Textbox(label = "LampDirectionX", placeholder="0")
643  trimesh_LampDirection_X.change(lambda s: s, inputs=trimesh_LampDirection_X)
644  with gr.Column():
645  trimesh_LampDirection_Y = gr.Textbox(label = "LampDirectionY", placeholder="0.3")
646  trimesh_LampDirection_Y.change(lambda s: s, inputs=trimesh_LampDirection_Y)
647  with gr.Column():
648  trimesh_LampDirection_Z = gr.Textbox(label = "LampDirectionZ", placeholder="1")
649  trimesh_LampDirection_Z.change(lambda s: s, inputs=trimesh_LampDirection_Z)
650  with gr.Row() as row:
651  with gr.Column():
652  trimesh_PixelPitch_X = gr.Textbox(label = "PixelPitch X", placeholder="10e-6")
653  trimesh_PixelPitch_X.change(lambda s: s, inputs=trimesh_PixelPitch_X)
654  with gr.Column():
655  trimesh_PixelPitch_Y = gr.Textbox(label = "PixelPitch Y", placeholder="10e-6")
656  trimesh_PixelPitch_Y.change(lambda s: s, inputs=trimesh_PixelPitch_Y)
657  with gr.Row() as row:
658  with gr.Column():
659  trimesh_PixelNum_X = gr.Textbox(label = "PixelNum X", placeholder="1920")
660  trimesh_PixelNum_X.change(lambda s: s, inputs=trimesh_PixelNum_X)
661  with gr.Column():
662  trimesh_PixelNum_Y = gr.Textbox(label = "PixelNum Y", placeholder="1080")
663  trimesh_PixelNum_Y.change(lambda s: s, inputs=trimesh_PixelNum_Y)
664  with gr.Row() as row:
665  with gr.Column():
666  trimesh_WaveLength_1 = gr.Textbox(label = "WaveLength1", placeholder="638e-9")
667  trimesh_WaveLength_1.change(lambda s: s, inputs=trimesh_WaveLength_1)
668  with gr.Column():
669  trimesh_WaveLength_2 = gr.Textbox(label = "WaveLength2", placeholder="520e-9")
670  trimesh_WaveLength_2.change(lambda s: s, inputs=trimesh_WaveLength_2)
671  with gr.Column():
672  trimesh_WaveLength_3 = gr.Textbox(label = "WaveLength3", placeholder="450e-9")
673  trimesh_WaveLength_3.change(lambda s: s, inputs=trimesh_WaveLength_3)
674  with gr.Row() as row:
675  with gr.Column():
676  Encoding = gr.Dropdown(['Phase','Amplitude','Real','Imaginary'], value="Phase", label = "Encoding Method" , info="Choose an encoding!")
677  with gr.Column():
678  pc_mode = gr.Radio(["CPU", "GPU"], value="GPU", label="CPU / GPU")
679  trimeshOutput = gr.Image(label="Triangle Mesh Bmp")
680  trimeshGen = gr.Button(value = "Generate Triangle Mesh Hologram")
681  trimeshxml.upload(fn=trimeshXmlParing, inputs=trimeshxml,outputs=[trimesh_Scale_X,trimesh_Scale_Y,trimesh_Scale_Z,trimesh_LampDirection_X,trimesh_LampDirection_Y,trimesh_LampDirection_Z,trimesh_PixelPitch_X,trimesh_PixelPitch_Y,trimesh_PixelNum_X,trimesh_PixelNum_Y,trimesh_WaveLength_1,trimesh_WaveLength_2,trimesh_WaveLength_3])
682  trimeshply.upload(fn=trimeshfile, inputs=trimeshply, outputs=trimeshplyout, show_progress="True")
683  trimeshGen.click(fn=trimeshGenerate,inputs=[Encoding,pc_mode],outputs=trimeshOutput)
684 
685  with gr.Tab(label = "WRP"):
686  with gr.Column():
687  with gr.Row() as row:
688  with gr.Column():
689  wrpxml = gr.File(label="Choose a WRP Config (.xml) File to Upload",interactive="True")
690  with gr.Column():
691  wrpply = gr.File(label="Choose a WRP (*.ply) File to Upload",interactive="True")
692  wrpplyout = gr.Textbox(label="[Warning] Please wait until the size of the ply file to be uploaded is large and displayed in the temporary path in the text box below. The upload is complete when the box below is displayed.")
693  with gr.Row() as row:
694  with gr.Column():
695  wrp_Scale_X = gr.Textbox(label = "Scale X", placeholder="0.0015")
696  wrp_Scale_X.change(lambda s: s, inputs=wrp_Scale_X)
697  with gr.Column():
698  wrp_Scale_Y = gr.Textbox(label = "Scale Y", placeholder="0.0015")
699  wrp_Scale_Y.change(lambda s: s, inputs=wrp_Scale_Y)
700  with gr.Column():
701  wrp_Scale_Z = gr.Textbox(label = "Scale Z", placeholder="0.0015")
702  wrp_Scale_Z.change(lambda s: s, inputs=wrp_Scale_Z)
703  with gr.Row() as row:
704  with gr.Column():
705  wrp_Distance = gr.Textbox(label = "Distance", placeholder="0.5")
706  wrp_Distance.change(lambda s: s, inputs=wrp_Distance)
707  with gr.Column():
708  wrp_NumOf_WRP = gr.Textbox(label = "NumOfWRP", placeholder="1")
709  wrp_NumOf_WRP.change(lambda s: s, inputs=wrp_NumOf_WRP)
710  with gr.Column():
711  wrp_WRP_Location = gr.Textbox(label = "LocationOfWRP", placeholder="0.003")
712  wrp_WRP_Location.change(lambda s: s, inputs=wrp_WRP_Location)
713  with gr.Row() as row:
714  with gr.Column():
715  wrp_PixelPitch_X = gr.Textbox(label = "PixelPitch X", placeholder="1e-5")
716  wrp_PixelPitch_X.change(lambda s: s, inputs=wrp_PixelPitch_X)
717  with gr.Column():
718  wrp_PixelPitch_Y = gr.Textbox(label = "PixelPitch Y", placeholder="1e-5")
719  wrp_PixelPitch_Y.change(lambda s: s, inputs=wrp_PixelPitch_Y)
720  with gr.Row() as row:
721  with gr.Column():
722  wrp_PixelNum_X = gr.Textbox(label = "PixelNum X", placeholder="1920")
723  wrp_PixelNum_X.change(lambda s: s, inputs=wrp_PixelNum_X)
724  with gr.Column():
725  wrp_PixelNum_Y = gr.Textbox(label = "PixelNum Y", placeholder="1080")
726  wrp_PixelNum_Y.change(lambda s: s, inputs=wrp_PixelNum_Y)
727  with gr.Row() as row:
728  with gr.Column():
729  wrp_WaveLength_1 = gr.Textbox(label = "WaveLength1", placeholder="638e-9")
730  wrp_WaveLength_1.change(lambda s: s, inputs=wrp_WaveLength_1)
731  with gr.Column():
732  wrp_WaveLength_2 = gr.Textbox(label = "WaveLength2", placeholder="520e-9")
733  wrp_WaveLength_2.change(lambda s: s, inputs=wrp_WaveLength_2)
734  with gr.Column():
735  wrp_WaveLength_3 = gr.Textbox(label = "WaveLength3", placeholder="450e-9")
736  wrp_WaveLength_3.change(lambda s: s, inputs=wrp_WaveLength_3)
737  with gr.Row() as row:
738  with gr.Column():
739  Encoding = gr.Dropdown(['Phase','Amplitude','Real','Imaginary'], value="Phase", label = "Encoding Method" , info="Choose an encoding!")
740  with gr.Column():
741  pc_mode = gr.Radio(["CPU", "GPU"], value="GPU", label="CPU / GPU")
742  wrpOutput = gr.Image(label="WRP Bmp")
743  wrpGen = gr.Button(value = "Generate WRP Hologram")
744  wrpxml.upload(fn=wrpXmlParing, inputs=wrpxml,outputs=[ wrp_Scale_X, wrp_Scale_Y, wrp_Scale_Z, wrp_Distance, wrp_NumOf_WRP, wrp_WRP_Location, wrp_PixelPitch_X, wrp_PixelPitch_Y, wrp_PixelNum_X, wrp_PixelNum_Y, wrp_WaveLength_1, wrp_WaveLength_2, wrp_WaveLength_3])
745  wrpply.upload(fn=wrpplyfile, inputs=wrpply, outputs=wrpplyout, show_progress="True")
746  wrpGen.click(fn=wrpGenerate,inputs=[Encoding,pc_mode],outputs=wrpOutput)
747 
748 if __name__ == "__main__":
749  demo.queue(concurrency_count=10).launch(share=True)
750  #demo.launch(share=True)